Rushit21 commited on
Commit
857301d
·
verified ·
1 Parent(s): 552b924

Add README

Browse files
Files changed (1) hide show
  1. README.md +41 -0
README.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # llamafile GPU Source Injection PoC
2
+
3
+ Proof-of-concept for a remote code execution vulnerability in the llamafile format.
4
+
5
+ ## Vulnerability
6
+
7
+ A malicious `.llamafile` can embed a modified `ggml-metal-device.m` (Objective-C Metal GPU
8
+ backend source file) that is compiled and executed at inference time on any macOS machine
9
+ with Metal GPU support (Apple Silicon / AMD / Intel GPUs).
10
+
11
+ The injected `__attribute__((constructor))` function runs before any model inference,
12
+ giving the attacker arbitrary code execution upon GPU-accelerated model loading.
13
+
14
+ ## Technical Details
15
+
16
+ - **Format**: `.llamafile` is a ZIP archive (APE polyglot) containing source files
17
+ - **Target file**: `llama.cpp/ggml/src/ggml-metal/ggml-metal-device.m`
18
+ - **Vector**: `metal.c:BuildMetal()` extracts and compiles Metal sources via system `cc`
19
+ - **Trigger**: Running `./model.llamafile` on any macOS machine with a GPU
20
+ - **Impact**: Arbitrary code execution as the user running llamafile
21
+
22
+ ## Reproduction
23
+
24
+ ```bash
25
+ chmod +x poc_gpu_inject_final_v2.llamafile
26
+ rm -rf ~/.llamafile/ # clear cache to force re-extraction
27
+ ./poc_gpu_inject_final_v2.llamafile
28
+ # Observe: /tmp/llamafile_gpu_poc is created
29
+ ls /tmp/llamafile_gpu_poc
30
+ ```
31
+
32
+ ## Files
33
+
34
+ - `poc_gpu_inject_final_v2.llamafile` - Self-contained malicious llamafile (tested on macOS, Apple M1 Pro)
35
+ - `poc_gpu_inject_builder.py` - Script showing how the PoC was constructed
36
+
37
+ ## Notes
38
+
39
+ The embedded `ggml-metal-device.m` prepends a constructor to the original Metal source.
40
+ The full original source is preserved so the dylib links and the model runs normally.
41
+ No user interaction beyond running the file is required.