🐛 [BUG] - fuzz harness over-reads its input, cannot vary TM/AOS frame length, and suppresses crashes

Aperta
#557 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@0xiviel ci sta già lavorando.

Dal 28/9/2026.

  • #559 di @0xiviel — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, python
Ambito
testing, tooling

Direzione di ricerca

Start in support/fuzz/src/fuzz_harness.c, examining the frame-size constants and the signal handlers around lines 172-179; use support/fuzz/scripts/build-fuzz.sh to build the harness. Reproduce with the short TM input and afl-showmap using the generated corpus from support/fuzz/generate_corpus.py. Done means TM/AOS lengths vary with input, crashes are reported instead of returning success, and the default build provides coverage feedback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

This is about support/fuzz/ test tooling, not about the library. Nothing here is a vulnerability in CryptoLib and no advisory is implied or sought.

Follow-up to #546, which reported that the harness does not compile and that build-fuzz.sh reports success anyway. With the build restored locally I was able to run the harness for the first time, and three further defects are visible. Two of them mean the harness cannot report what it is pointed at. All measurements below are from 626dc621 on dev, using the repo's own support/fuzz/scripts/build-fuzz.sh and support/fuzz/generate_corpus.py. The harness does not build at 626dc621, so anything that requires a running harness was measured on top of it: D1 with only the missing ignore_anti_replay argument added, since the full PR removes D1, and D2 to D4 with PR #559 applied.

PR #559 fixes D1 and the #546 build break. D2, D3 and D4 stay open.

defect status
D1 create_tm_frame and create_aos_frame read past the fuzzer's input fixed by PR #559
D2 TM and AOS frame length still cannot vary open
D3 The harness suppresses crashes, including ASan's open
D4 No coverage feedback in the default build configuration open, reported as §3 of #546

D1, the harness read past the fuzzer's input (fixed by the PR)

Both frame builders overwrote their size parameter before testing it:

const size_t MIN_TM_SIZE = 1786;
size                     = MIN_TM_SIZE;   // discards the caller's length
size_t frame_size        = (size < MIN_TM_SIZE) ? MIN_TM_SIZE : size;

That made if (size < MIN_TM_SIZE) always false, so the memset branch was dead and control always reached the else branch, which copies frame_size bytes out of data. With a 9 byte input the harness read 1786 bytes.

Every trace in this report is from 626dc621 with only the missing ignore_anti_replay argument added, which is the smallest tree on which the harness both compiles and still has this bug. Those two added lines sit above everything else in the file and shift it all down by two, so the line numbers in these traces are two higher than in an unmodified checkout. The mapping, once, for all of them:

unmodified 626dc621 the tree these traces come from
memcpy in create_tm_frame :135 :137
memcpy in create_aos_frame :164 :166
create_tm_frame call in LLVMFuzzerTestOneInput :232 :234
==130060==ERROR: AddressSanitizer: use-after-poison on address 0x7f264c12a809
READ of size 1786 at 0x7f264c12a809 thread T0
    #1 create_tm_frame support/fuzz/src/fuzz_harness.c:137:9

create_aos_frame behaves the same way. Removing the two assignments fixes it; the ternary on the next line already computes the intended value. Verified: with the PR applied, the 9 byte TM input produces no ASan error. The short-input branch is reachable again, so nothing is copied out of the fuzzer's buffer at all.

D2, TM and AOS frame length still cannot vary (open)

Removing the overwrite does not give the fuzzer control of the frame length, because MIN_TM_SIZE and MIN_AOS_SIZE are both 1786 and so is MAX_FRAME_SIZE, which is also the size of the static frame buffers:

#define MAX_FRAME_SIZE    1786
static uint8_t tm_frame_buffer[MAX_FRAME_SIZE];
static uint8_t aos_frame_buffer[MAX_FRAME_SIZE];

So frame_size is 1786 for every input below 1786 bytes and 1785 for every input above it. Those are the only two values reachable. Every TM and AOS execution therefore drives Crypto_TM_ApplySecurity and Crypto_AOS_ApplySecurity at essentially one fixed length. TC does not have this problem: TC_MAX_FRAME_SIZE is 1024 while the minimum is 6, so TC length tracks the input.

Giving TM and AOS real length coverage needs the buffers and MAX_FRAME_SIZE raised above the minimum frame size, which is a design decision rather than a small fix, so the PR leaves it alone.

D3, the harness suppresses crashes, including ASan's (open)

fuzz_harness.c:172-179 installs handlers for SIGSEGV, SIGABRT, SIGILL and SIGFPE that longjmp back into LLVMFuzzerTestOneInput, which then returns 0, reporting the test case as a pass.

The effect is visible in the D1 output above. ASan detected the over-read, printed its report and printed ABORTING, and the process still exited 0 and printed Execution successful.:

==130060==ERROR: AddressSanitizer: use-after-poison ...
==130060==ABORTING
Execution successful.
EXIT CODE: 0

A fuzzing harness needs the process to die, because that death is the reporting channel to AFL++. As shipped, AFL++ is told the input was fine.

One limitation worth stating: ASan's report is suppressed here because AFL++ requires abort_on_error=1 and so routes the failure through SIGABRT. With ASan's Linux default the crash would surface normally. The suppression of a raw SIGSEGV does not depend on any sanitizer setting.

D4, no coverage feedback in the default build (open, already §3 of #546)

Re-confirmed on this tree with the harness actually running. A 60 second afl-fuzz run on the shipped default build:

execs_done        : 2521
bitmap_cvg        : 0.00%
edges_found       : 1

and independently:

$ afl-showmap -o /dev/null -- ./build/fuzz/bin/fuzz_harness <input>
[+] Captured 0 tuples (map size 65536, highest value 0, total values 0)

The live status line reads map=1 ... cvg=0.00%. The harness binary is instrumented but the library under test is not, so there is no edge feedback, no corpus evolution, and the power schedules have nothing to act on. Cause and the -flto detail are in §3 of #546.

Two further observations

  • The AOS apply path still aborts under ASan, for the separate reason recorded in #556.
  • Saved crashes do not reproduce. Each of three 60 second runs saved exactly one sig:06 case, all on selector 4 (Crypto_AOS_ProcessSecurity) and all mutated from the same seed, and none of the three replays, 0 of 5 standalone runs each. The first of them also ran clean under afl-showmap. Two of those runs had the D1 fix and one had only the build fix, so this is pre-existing and not something the PR introduces. I have not root caused it and I am not claiming a defect in the library; I mention it because a saved crash that will not replay is what a harness in this state produces, and D3 is the reason AFL++ has so little to go on.
Branch Name

dev

Reproduction steps
1. git checkout 626dc621
2. For D1: add only the missing `ignore_anti_replay` argument to the Crypto_Config_TM and Crypto_Config_AOS calls, so the harness compiles with the bug still present.
   cd support/fuzz/scripts && ./build-fuzz.sh
   printf '\x02ABCDEFGH' > tm_short.bin
   ASAN_OPTIONS=abort_on_error=1:detect_leaks=0 ./build/fuzz-asan/bin/fuzz_harness tm_short.bin; echo $?
   Observe READ of size 1786 from a 9 byte input, then ABORTING, then exit code 0 and "Execution successful."
   The same run demonstrates D3: ASan aborted and the process still reported success.
3. For D2 and D4: apply PR #559 and rebuild.
   cd support/fuzz/scripts && ./build-fuzz.sh
4. D4: python3 support/fuzz/generate_corpus.py -o corpus
   afl-showmap -o /dev/null -- ./build/fuzz/bin/fuzz_harness corpus/02_tm_00.bin
   Observe "Captured 0 tuples".
5. D2: compare the MIN_TM_SIZE and MIN_AOS_SIZE constants at the top of create_tm_frame and create_aos_frame against MAX_FRAME_SIZE in fuzz_harness.c. All three are 1786.
Screenshots

Logs
# D1, 9-byte input, ASan build of 626dc621 plus only the missing ignore_anti_replay
# argument. Line numbers are two higher than an unmodified checkout; see the
# mapping table in the D1 section above.
==130060==ERROR: AddressSanitizer: use-after-poison on address 0x7f264c12a809
READ of size 1786 at 0x7f264c12a809 thread T0
    #1 create_tm_frame support/fuzz/src/fuzz_harness.c:137:9
    #2 LLVMFuzzerTestOneInput support/fuzz/src/fuzz_harness.c:234:35
==130060==ABORTING
Execution successful.
EXIT CODE: 0

# D4, 60-second afl-fuzz on the shipped default build, PR applied
execs_done        : 2521
bitmap_cvg        : 0.00%
edges_found       : 1
saved_crashes     : 1
OS

Linux (Kali, kernel 7.1.5), clang 21.1.8, cmake 4.3.4, AFL++ 5.02c, libgcrypt 1.12.2, x86_64.


Analysis performed with AI assistance (Claude, Anthropic). Every number above is captured tool output from the environment listed, not an estimate.

Lingua principale
C
Stelle
178
Fork
70
Merge medio
1h 32m
PR unite (30g)
1

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nasa/CryptoLib

Tutte le issue di nasa/CryptoLib

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.