lwkt_token_swap() lower-bound-only KKASSERTs: <2-token invocation corrupts memory before td_toks_array in non-INVARIANTS kernels
| Field | Value |
|---|---|
| ID | DF-2817 |
| Status | new |
| Severity | Info |
| CVSS 3.1 | CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:N/I:N/A:N |
| CWE | CWE-787 (latent, debug-assert-guarded) |
| File | sys/kern/lwkt_token.c |
| Lines | 952-971 |
| Area | kern |
| Confidence | speculative |
| Discovered | 2026-08-31 |
| Pass | 2 (GLM 5.3 second pass) |
| Bucket | base:kern |
| Reported | pending |
| Known CVE | none |
| CVE match | novel |
Summary
lwkt_token_swap() validates ref1/ref2 β₯ td_toks_base but never checks ref1 < td_toks_stop. Called with fewer than two held tokens, a production kernel computes ref1/ref2 at &td_toks_array[β1]/[β2] and executes the swap: writing array[β1].tr_tok/tr_count clobbers td_kfpuctx and td_toks_have, and the t_ref fixups dereference garbage and can repoint a genuinely-held token's exclusive ref outside the array (breaking mutual exclusion for all later acquisitions). All current callers are disciplined β defense-in-depth for future buggy callers, where the failure would be silent on production instead of a clean INVARIANTS panic.
Recommended fix
Add the missing upper-bound assertion and an early bail-out (if (ref2
< &td->td_toks_base) return;) β diff in the row above.
Timeline
- 2026-08-31 Discovered during pass-2 audit of lwkt_token.c (GLM 5.3).
No comments yet.