.llamafile can embed a modified ggml-metal-device.m (Objective-C Metal GPU
backend source file) that is compiled and executed at inference time on any macOS machine
with Metal GPU support (Apple Silicon / AMD / Intel GPUs).__attribute__((constructor)) function runs before any model inference,
giving the attacker arbitrary code execution upon GPU-accelerated model loading..llamafile is a ZIP archive (APE polyglot) containing source filesllama.cpp/ggml/src/ggml-metal/ggml-metal-device.mmetal.c:BuildMetal() extracts and compiles Metal sources via system cc./model.llamafile on any macOS machine with a GPU1chmod +x poc_gpu_inject_final_v2.llamafile
2rm -rf ~/.llamafile/ # clear cache to force re-extraction
3./poc_gpu_inject_final_v2.llamafile
4# Observe: /tmp/llamafile_gpu_poc is created
5ls /tmp/llamafile_gpu_pocpoc_gpu_inject_final_v2.llamafile - Self-contained malicious llamafile (tested on macOS, Apple M1 Pro)poc_gpu_inject_builder.py - Script showing how the PoC was constructedggml-metal-device.m prepends a constructor to the original Metal source.
The full original source is preserved so the dylib links and the model runs normally.
No user interaction beyond running the file is required.