Repository navigation
server: fix heap-buffer-overflow from negative n_discard (CVE-2026-21869) - #22267
ServeurpersoCom merged 4 commits into
Conversation
…026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c
|
Hi @SongTonyLi, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
@ggml-bot check one more time, I wrote the PR fully myself. |
ngxson
left a comment
There was a problem hiding this comment.
A general note is that it should be a requirement to specify this very clearly on the title of the bug report when it is public:
(requires context shifting - not enabled by default)
We don't want to spread panic among users after all. Features that are prone to bugs / errors are already disabled by default.
ServeurpersoCom
left a comment
There was a problem hiding this comment.
LGTM. Verified n_discard has a single external entry point at the JSON parse boundary (server-task.cpp) and a single usage site at the context shift (server-context.cpp), with no other paths in include/, src/, or common/. The clamp is at the right spot, and the semantics are preserved since n_discard == 0 falls through to the existing n_left / 2 auto-discard path. +1 on @ngxson's point about flagging the context-shift requirement in public advisories.
|
Thank you all for the quick responses. When is it gonna be merged? I feel like this vulnerability is pretty severe. |
Now:) |
|
additional credit: ARiSE Lab @ Columbia University |
|
@ggerganov looks like this is merged, can you also update the patched versions at GHSA-8947-pfff-2f3c? |
|
@ServeurpersoCom Can you update the patched versions at GHSA-8947-pfff-2f3c? |
I don't have edit rights on the GHSA itself (repository write access doesn't grant advisory edit permissions). |
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
…869) (ggml-org#22267) * server: clamp n_discard to non-negative at JSON parse boundary (CVE-2026-21869) A negative n_discard from client JSON causes heap-buffer-overflow in update_slots() context-shift loop (CWE-787, CVSS 8.8). Clamp to 0 at ingress; n_discard=0 already triggers auto-discard (n_left/2). Ref: GHSA-8947-pfff-2f3c * cont : cleaner * cont : cleanerer * cont : cleanest --------- Co-authored-by: Georgi Gerganov <[email protected]>
Overview
Proposing a fix for GHSA-8947-pfff-2f3c (CVE-2026-21869, CWE-787, CVSS 8.8 High).
This vulnerability is still present on current master (
0d0764dfd257, 2026-04-22) — everyllama-serverdeployment with context shift enabled is exploitable by any unauthenticated remote client. The fix is a single-linestd::max(0, ...)clamp onn_discardat the JSON parse boundary.Proposed Fix
Check the commit.
Since
n_discard = 0already triggers the auto-discard path (n_left / 2at the context shift site), clamping negative values to zero preserves all existing semantics with no behavior change for valid inputs.Additional Information
Root Cause Analysis
The vulnerability is a missing non-negative check on a client-controlled integer parameter that is later used in array index arithmetic.
Reproduction
ASan output on current master (
0d0764df):PoC payload:
{ "prompt": "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.", "stream": false, "cache_prompt": true, "n_predict": 512, "n_keep": 64, "n_discard": -32, "temperature": 0.0 }We provide the following Docker image with ASan-instrumented build and minimal GGUF for independent verification:
Post-fix: same PoC runs clean under both ASan and Valgrind,
n_discardnormalizes to auto-discard. No new cppcheck warnings.Requirements
std::max(0, ...)) was human-conceived. Every line can be independently explained and defended.Note
If this PR has been created by an AI agent on behalf of a contributor, the contributor is
still responsible for the PR and must review and understand the changes being proposed.
The contributor must also be able to explain and defend the changes when questioned.
llama.cpp restricts AI-generated contributions. See AGENTS.md and
CONTRIBUTING.md for more information.
Columbia University Security Research Team