CRASH-001-1: stack-buffer-overflow in handle_blob
handle_blob @ rcfg.c:98dispatch @ rcfg.c:209rcfg_decode @ rcfg.c:247rcfg.c:97 compares the field length to RCFG_BLOB_LIMIT (4096) while the destination host buffer (rcfg.c:95) is only RCFG_HOST_CAP (128) bytes, so memcpy(host, val, len) at rcfg.c:98 overruns it../reproduce.sh — it clones the audited revision, builds with the sanitizer and replays the input; input input.bin (207 B); input repro.cmd (96 B); sanitizer log sanitizer.txt (14 KB); reproduced 5/5 times when re-run.Summary¶
The RCF decoder stages an opaque "host/identity" blob field into a small fixed on-stack buffer before hashing it. A stream consisting of the 4-byte magic plus one BLOB field whose value is longer than 128 bytes reaches the staging copy and writes past the buffer. The external party gets a caller-controlled linear stack overwrite of up to ~3968 bytes. The size guard at rcfg.c:97 compares the field length to RCFG_BLOB_LIMIT (4096) while the destination host buffer (rcfg.c:95) is only RCFG_HOST_CAP (128) bytes, so memcpy(host, val, len) at rcfg.c:98 overruns it.
Fields¶
| Field | Value |
|---|---|
| Severity | High8.9 |
| Class | memory-safety |
| Primitive | stack-buffer-overflow |
| Location | src/rcfg.c:handle_blob:98 |
| Surface | cli— report boundary is a shipped command-line tool |
| Boundary | RCF stream bytes decoded by rcfg_decode (CLI file input, attacker_controls=bytes) |
| Trigger source | bytes |
| Caller controls | entire input file — field type, big-endian u16 length, and value bytes |
| Caller contract | unspecified |
| Trusted caller actions | reads a file and calls rcfg_decode(data, len) once over the exact length |
| Parameter control | direct |
| Reproduction rate | 5/5 |
| Reproducer carrier | cli |
| Advisory | no— patch.diff included |
| Strategy | S3— Spec vs. implementation |
| Dedup frames | handle_blob rcfg.c:98 -> dispatch rcfg.c:209 -> rcfg_decode rcfg.c:247 |
Root Cause¶
handle_blob declares char host[RCFG_HOST_CAP] where RCFG_HOST_CAP is 128 (rcfg.c:20, rcfg.c:95). It admits the field with if (len <= RCFG_BLOB_LIMIT) — but RCFG_BLOB_LIMIT is 4096 (rcfg.c:23), the "largest host blob the format accepts", not the size of the staging buffer. The code confuses the format's accepted blob ceiling with the capacity of the buffer it copies into. Any field length in the range (128, 4096] passes the guard and memcpy(host, val, len) writes len bytes into a 128-byte object. len is the field length flen from rcfg_decode (rcfg.c:237), a caller-supplied big-endian u16 that the decoder only clamps down to remaining (rcfg.c:243-245) — it is never clamped to 128. With a 200-byte value ASan reports a WRITE of size 200 into the [32,160) host frame slot, a 40-byte overwrite past the end; a maximal in-range value overwrites ~3968 bytes of adjacent stack (saved registers, return address).
Data Flow¶
Caller-controlled file bytes flow from the CLI straight into the unguarded copy.
- step: read_file (src/rcfg_cli.c:34) — reads the whole input file into a heap buffer sized to its exact length.
- step: main (src/rcfg_cli.c:59) — passes the buffer and length to rcfg_decode.
- step: rcfg_decode (src/rcfg.c:237) — parses a field header, reads big-endian u16
flen, clamps it only toremaining. - step: dispatch (src/rcfg.c:209) — routes RCFG_T_BLOB (0x02) to handle_blob with
val=field bytes,len=flen. - step: handle_blob (src/rcfg.c:97) — admits the field because
len <= 4096, notlen <= 128. - step: handle_blob (src/rcfg.c:98) —
memcpy(host, val, len)writeslenbytes into the 128-bytehost, overflowing the stack frame.
Source snippets referenced in Data Flow:
↳ Referenced in: step: read_file (src/rcfg_cli.c:34) — reads the whole input file into a heap buffer sized to its exact length.
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: main (src/rcfg_cli.c:59) — passes the buffer and length to rcfg_decode.
From src/rcfg_cli.c (lines 57–61):
57 }
58
59 ▶ int fields = rcfg_decode(data, len);
60 free(data);
61
↳ Referenced in: step: rcfg_decode (src/rcfg.c:237) — parses a field header, reads big-endian u16 flen, clamps it only to remaining.
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: dispatch (src/rcfg.c:209) — routes RCFG_T_BLOB (0x02) to handle_blob with val=field bytes, len=flen.
From src/rcfg.c (lines 207–211):
207 switch (type) {
208 case RCFG_T_STR: handle_str(ctx, val, len); break;
209 ▶ case RCFG_T_BLOB: handle_blob(ctx, val, len); break;
210 case RCFG_T_ARRAY: handle_array(val, len); break;
211 case RCFG_T_SLICE: handle_slice(ctx, stream, stream_len, val, len); break;
↳ Referenced in: step: handle_blob (src/rcfg.c:97) — admits the field because len <= 4096, not len <= 128.
From src/rcfg.c (lines 95–99):
95 char host[RCFG_HOST_CAP];
96
97 ▶ if (len <= RCFG_BLOB_LIMIT) {
98 memcpy(host, val, len);
99 ctx->host_hash = fnv1a((const uint8_t *)host, len);
↳ Referenced in: step: handle_blob (src/rcfg.c:98) — memcpy(host, val, len) writes len bytes into the 128-byte host, overflowing the stack frame.
From src/rcfg.c (lines 96–100):
96
97 if (len <= RCFG_BLOB_LIMIT) {
98 ▶ memcpy(host, val, len);
99 ctx->host_hash = fnv1a((const uint8_t *)host, len);
100 }
Impact¶
Any consumer that decodes an untrusted RCF stream is exposed: a file/packet of ~135 bytes or more (magic + 3-byte header + >128 value bytes) reaches the overflow. The overwrite is contiguous, fully caller-controlled in both length (up to 4096, ~3968 past the end) and content, and lands over the return address of handle_blob, so this is a stack-smash with realistic control-flow-hijack potential, not merely a crash.
Fix Direction¶
Bound the copy by the destination buffer, not by the format ceiling: guard with len <= sizeof(host) (128) in handle_blob, or drop RCFG_BLOB_LIMIT from the admission test and reject/clamp anything larger than RCFG_HOST_CAP. Sizing host to RCFG_BLOB_LIMIT would also work but wastes stack; the format's own 128-byte staging intent (rcfg.c:20) is the right bound.
Expected sanitizer output¶
==75600==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x00016b5a4a20 at pc 0x0001051f2bb4 bp 0x00016b5a4970 sp 0x00016b5a4120
WRITE of size 200 at 0x00016b5a4a20 thread T0
SCARINESS: 60 (multi-byte-write-stack-buffer-overflow)
#0 0x0001051f2bb0 in __asan_memcpy (in libclang_rt.asan_osx_dynamic.dylib) + 816
#1 0x00010485930c in handle_blob rcfg.c:98
#2 0x000104858d60 in dispatch rcfg.c:209
#3 0x000104858a4c in rcfg_decode rcfg.c:247
#4 0x00010485a418 in main rcfg_cli.c:59
#5 0x00018d1844e0 in start (in dyld) + 6988
Address 0x00016b5a4a20 is located in stack of thread T0 at offset 160 in frame
#0 0x0001048591a8 in handle_blob rcfg.c:94
This frame has 1 object(s):
[32, 160) 'host' (line 95) <== Memory access at offset 160 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (targets/samples/sample-c/build-asan/rcfg:arm64+0x10000130c)
Full original output: sanitizer.txt.
Annotated stack frames (top-of-stack source):
#1 handle_blob — rcfg.c:98
From src/rcfg.c (lines 96–100):
96
97 if (len <= RCFG_BLOB_LIMIT) {
98 ▶ memcpy(host, val, len);
99 ctx->host_hash = fnv1a((const uint8_t *)host, len);
100 }
#2 dispatch — rcfg.c:209
From src/rcfg.c (lines 207–211):
207 switch (type) {
208 case RCFG_T_STR: handle_str(ctx, val, len); break;
209 ▶ case RCFG_T_BLOB: handle_blob(ctx, val, len); break;
210 case RCFG_T_ARRAY: handle_array(val, len); break;
211 case RCFG_T_SLICE: handle_slice(ctx, stream, stream_len, val, len); break;
#3 rcfg_decode — rcfg.c:247
From src/rcfg.c (lines 245–249):
245 }
246
247 ▶ dispatch(&ctx, data, len, type, p, flen);
248
249 p += flen;
#4 main — rcfg_cli.c:59
From src/rcfg_cli.c (lines 57–61):
57 }
58
59 ▶ int fields = rcfg_decode(data, len);
60 free(data);
61
#0 handle_blob — rcfg.c:94
From src/rcfg.c (lines 92–96):
92 * into a rolling hash. Blobs larger than the accepted limit are rejected. */
93 static void handle_blob(rcfg_ctx *ctx, const uint8_t *val, uint16_t len)
94 ▶ {
95 char host[RCFG_HOST_CAP];
96
Reproduce¶
Script — reproduce.sh
Run the sibling reproduce.sh:
./reproduce.sh # builds/runs with ASan against the in-place audit source
./reproduce.sh /path/to/src # or an existing checkout
Patch¶
Captured patch — patch.diff (11 lines)
--- a/src/rcfg.c+++ b/src/rcfg.c@@ -94,7 +94,7 @@ static void handle_blob(rcfg_ctx *ctx, const uint8_t *val, uint16_t len) { char host[RCFG_HOST_CAP]; - if (len <= RCFG_BLOB_LIMIT) {+ if (len <= sizeof(host)) { memcpy(host, val, len); ctx->host_hash = fnv1a((const uint8_t *)host, len); }
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 = library |
| 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): reproduction rate 5/5; testcase + sanitizer log on disk.
Field derivation (each line is a reviewable claim):
- surface=library → 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
- reproduction rate 5/5 → E:P
- CR/IR/AR not defined — environmental requirements are a deployer concern (CVSS-B baseline)
- caller controls input bytes → MAT:X