← all findings · FIND-0005 · samples/sample-c · accepted · filed 2026-09-16 14:23 UTC
High8.9stack_write
Cluster FCL-217bf9c2 (singleton)
The RCF decoder's CHECK handler copies a self-check field into a fixed 32-byte buffer inside the decode context. The only bound on the copy length is an assert(), which the shipped release build compiles out (-DNDEBUG). A single CHECK field (type 0x09) whose length exceeds 32 bytes then overflows the buffer. Because the context lives on rcfg_decode's stack, this is a contiguous, attacker-controlled stack write of up to ~65000 bytes. The attacker gains a stack smash leading to control-flow hijack. The length comes straight from the stream's field header.
Act on it
Fix
Replace the debug-only `assert` with a real runtime bound that ships in all configurations: `if (len > sizeof(ctx->check)) return;` (or clamp `len`) before the `memcpy`.
Where
src/rcfg.c:handle_check:198 · reached through the file-format surface
Reproduce
input input (107 B).
Confidence
reportable — source review placed the trigger within attacker_controls=bytes; 2 accept / 0 reject from independent reviewers; source-anchored trigger review voted Promote on 2 verified source anchors.
Affects
boundary untrusted RCF stream decoded from file input; attacker controls bytes; needs the caller to normal public call.

Fields

Field Value
Severity High8.9
Class stack-buffer-overflow
Primitive stack_write
File src/rcfg.c
Function handle_check
Line 198
Location src/rcfg.c:handle_check:198
Surface file-format
Boundary untrusted RCF stream decoded from file input
Trigger source bytes
Caller controls bytes
Caller contract unspecified
Trusted caller actions normal public call
Parameter control direct
Reproducer carrier cli
Advisory no— patch.diff included
Dedup key [loc] src/rcfg.c:198

Summary

The RCF decoder's CHECK handler copies a self-check field into a fixed 32-byte buffer inside the decode context. The only bound on the copy length is an assert(), which the shipped release build compiles out (-DNDEBUG). A single CHECK field (type 0x09) whose length exceeds 32 bytes then overflows the buffer. Because the context lives on rcfg_decode's stack, this is a contiguous, attacker-controlled stack write of up to ~65000 bytes. The attacker gains a stack smash leading to control-flow hijack. The length comes straight from the stream's field header.

Root Cause

handle_check (src/rcfg.c:195-200) does assert(len <= sizeof(ctx->check)) then memcpy(ctx->check, val, len). ctx->check is uint8_t check[32] (RCFG_CHECK_CAP, src/rcfg.c:22, 41). The assert is the only bound. In any build compiled with -DNDEBUG — the standard release configuration, per the CMakeLists comment that "both ordinary Debug and Release configurations are supported" — the assert expands to nothing, so memcpy runs with an unchecked len. len is the field's u16 length from the header (flen, src/rcfg.c:237), clamped only to bytes present in the stream (src/rcfg.c:243-245), so it ranges up to 65535 and is attacker-chosen. The invariant the copy assumes (len <= 32) is enforced only by debug tooling that does not ship.

Data Flow

Field bytes flow from the file into an unbounded copy over the context struct.

Source snippets referenced in Data Flow:

↳ Referenced in: step: read_file (src/rcfg_cli.c:34) — reads the input file into a heap buffer.

From src/rcfg_cli.c (lines 32–36):

32       return NULL;
33     }
34 ▶   if (fread(buf, 1, (size_t)size, fp) != (size_t)size) {
35       free(buf);
36       fclose(fp);

↳ Referenced in: step: rcfg_decode (src/rcfg.c:237) — reads the CHECK field's u16 length.

From src/rcfg.c (lines 235–239):

235     while (remaining >= RCFG_FIELD_HEADER) {
236       uint8_t  type = p[0];
237 ▶     uint16_t flen = read_be16(p + 1);
238       p += RCFG_FIELD_HEADER;
239       remaining -= RCFG_FIELD_HEADER;

↳ Referenced in: step: rcfg_decode (src/rcfg.c:243) — clamps length only to remaining stream bytes.

From src/rcfg.c (lines 241–245):

241       /* Clamp the value to what is actually present so a handler never walks off
242        * the end of the stream on the declared length alone. */
243 ▶     if (flen > remaining) {
244         flen = (uint16_t)remaining;
245       }

↳ Referenced in: step: dispatch (src/rcfg.c:216) — routes type 0x09 to handle_check.

From src/rcfg.c (lines 214–218):

214       case RCFG_T_FLUSH: handle_flush(ctx); break;
215       case RCFG_T_OPT:   handle_opt(ctx, val, len); break;
216 ▶     case RCFG_T_CHECK: handle_check(ctx, val, len); break;
217       default:           break; /* unknown tag: skip */
218     }

↳ Referenced in: step: handle_check (src/rcfg.c:197) — assert bound is a no-op under -DNDEBUG.

From src/rcfg.c (lines 195–199):

195   static void handle_check(rcfg_ctx *ctx, const uint8_t *val, uint16_t len)
196   {
197 ▶   assert(len <= sizeof(ctx->check));
198     memcpy(ctx->check, val, len);
199     ctx->check_len = len;

↳ Referenced in: step: handle_check (src/rcfg.c:198) — memcpy copies up to 65535 bytes into the 32-byte ctx->check, overrunning the on-stack context.

From src/rcfg.c (lines 196–200):

196   {
197     assert(len <= sizeof(ctx->check));
198 ▶   memcpy(ctx->check, val, len);
199     ctx->check_len = len;
200   }

Impact

Any release-configured consumer of untrusted RCF streams is exposed. A 107-byte input (one CHECK field, len 100) overwrites ctx and everything above it on the rcfg_decode frame. Confirmed with a release ASan build (-O2 -g1 -DNDEBUG -fsanitize=address): stack-buffer-overflow WRITE of size 100 at the ctx object (SCARINESS 60) — see release-asan.txt. Both length and contents are attacker-controlled, giving a return-address-overwrite primitive. Note: the audit's default build-asan/rcfg keeps asserts enabled and aborts on the assert instead of showing the overflow; the overflow is real only when NDEBUG is set, which the shipped build does.

Fix Direction

Replace the debug-only assert with a real runtime bound that ships in all configurations: if (len > sizeof(ctx->check)) return; (or clamp len) before the memcpy. Security-relevant length validation must never depend on assert, which is elided under NDEBUG.

Severity rationale

Severity is the CVSS v4.0 score — one industry-standard metric, computed by the vendored FIRST reference scorer. Base metrics come from the primitive and surface, with Attack Vector/Requirements also reflecting the trigger's caller-control facts (a trusted local API/call-sequence reads as AV:L/AT:P). The Threat metric (E) is read locally, not from threat intelligence: it grades how far this audit got toward proving the bug — a reproducer that fires is E:P, an unproven argument is E:U — so a demonstrated bug outranks a written one. FIRST defines E against public exploit availability, which is not what is measured here, and nothing in this run is publicly disclosed. Read E as reproduction confidence. The Environmental Security Requirements (CR/IR/AR) are left Not Defined — they model a deploying organisation's asset importance, which the scorer cannot derive, so a generic score keeps the CVSS-B worst case. Environmental modified impacts are set only to floor impact where reachability facts justify it (non-shipping surfaces, caller-only triggers). Cluster size remains a priority/verification fact because CVSS v4.0 has no cluster metric.

CVSS-BT v4.0: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P → 8.9 (High) CVSS-B baseline: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N → 9.3 (Critical)

Metric Value Derived from
Attack Vector (AV) N surface tier = file
Attack Complexity (AC) L fixed — not separately modelled
Attack Requirements (AT) N intrinsic attack preconditions
Privileges Required (PR) N worst case — no auth signal
User Interaction (UI) N surface tier
Vuln Conf/Integ/Avail H/H/H primitive class = stack_write
Subseq Conf/Integ/Avail N/N/N primitive class
Threat Exploit Maturity (E) P local reproduction evidence — not public exploit availability
Env Requirements (CR/IR/AR) X/X/X not defined — deployer-set asset importance (CVSS-B baseline)
Env Modified AV/AC/AT/PR/UI X/X/X/X/X caller control / contract concern
Env Modified C/I/A impacts X/X/X/X/X/X non-shipping / caller-only reachability floor; demonstrated disclosure / availability

Severity level: High — CVSS bands: Critical ≥ 9.0, High ≥ 7.0, Medium ≥ 4.0, Low ≥ 0.1, None = 0.0.

Verification facts (not part of severity — triage priority): testcase on disk.

Field derivation (each line is a reviewable claim):

  • surface=file → AV:N/UI:N
  • class=stack_write → VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
  • class preconditions → AT:N
  • PR:N (worst case — no auth signal), AC:L
  • reproducer/testcase artifact on disk → E:P
  • CR/IR/AR not defined — environmental requirements are a deployer concern (CVSS-B baseline)
  • caller controls input bytes → MAT:X