#6493 [Engine] serve loop: GENI prompt can write past the position table; --cvec offsets unchecked (static analysis)
open · @DamirLukina88 · 0 コメント · GitHub で見る
Server & APIAMD / HIPNVIDIA / CUDAModels & quantsSecurityLinux
本文
### Area
[Engine] (speed, kernels, models, the server and API)
### Desktop app, Terminal or source?
Source (read on `main` at 3142b66b9).
### What happened
Unconfirmed static analysis: I found these by reading the code and have not reproduced them. Neither is reachable through `terminal/serve`, which never sends such a request. They matter only to a client that writes the engine's stdin protocol itself, or to a damaged control-vector file.
**1. A GENI prompt longer than the context writes past the position table.** In `engine/src/program/generate.cpp`, `mrope_host` holds `o.max_context + 64` cells (line 5902). A GENI request writes a position for every prompt id, `put(i, …)` for `i < n` (lines 18219 and 18237), without comparing `n` to the table's size. The check that refuses an over-long prompt, `if (n + max_new + 8 > o.max_context)` at line 18275, runs only after those writes. So a GENI line with more than `max_context + 64` ids would write past the end of `mrope_host`. Text requests are not affected: their loop stops at `cells`.
The same check's sum `n + max_new + 8` can also overflow for a huge `max_new` (it is parsed with `strtoll`), which would let the request through.
**2. `--cvec` reads each `direction.<layer>` tensor without checking its offset.** In `load_control_vectors` (line 2713), `f.tensor_data(t)` is read for `N` floats right after the type and size check, and the tensor's offset is never compared with `file_size() - data_start()`. Other readers of `tensor_data()` make that comparison first (for example `gguf_reader.hpp` around line 598). A truncated or damaged control-vector file would be read past the end of its mapping.
The SYCL copy, `engine/sycl/src/program/generate.cpp`, has the same code (lines 3198, 10427, 10481 and 1538).
**A possible fix**, on a branch in my fork: `fix/serve-loop-input-checks` at https://github.com/DamirLukina88/D.L.-AI---Strata/tree/fix/serve-loop-input-checks, one commit on top of 3142b66b9 (both copies, 30 lines added, 10 removed):
- the context check moves before the image positions and is written as `max_new > max_context - 8 - n`, so it no longer overflows;
- the cvec reader refuses a tensor whose offset and size do not fit the file ("… is truncated").
Built for HIP here (ROCm 7.2, gfx1102). It has not been run on a model, and I could not build CUDA, SYCL or Metal. If you want it, I'll open it as a draft pull request and list those as not run.
### Reproduction status
Unconfirmed static analysis: found by reading, not reproduced.
### Strata version
0.2.17 (`main` at 3142b66b9)
### Graphics card, memory and system
Not hardware-specific. Read and built on an AMD Radeon RX 7600 XT 16 GB, Ryzen 5 3600, 32 GB RAM, CachyOS Linux, ROCm 7.2.
関連リンク
インストール・モデル・リリースへのサイト内リンク。