Skip to content

feat(native): --model-input makes the program's libc input nondeterministic - #99

Open
GuilhermeBn198 wants to merge 1 commit into
developfrom
feat/model-libc-input
Open

GuilhermeBn198 wants to merge 1 commit into
developfrom
feat/model-libc-input

Conversation

@GuilhermeBn198

@GuilhermeBn198 GuilhermeBn198 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In native mode, a call such as fgets(buf, n, stdin) is a real call. KLEE runs it concretely:

  • stdin is empty;
  • getenv finds nothing;
  • connect is refused;
  • accept waits until the time limit.

AFL++ varies only the __VERIFIER_nondet_* values. A flaw that needs input is therefore never reached. In the JBCS campaign, 80 of the 100 flawed Juliet CWE-761 programs came out TRUE (FN). The input-sourced CWE-190 families were also lost: fscanf gave 200/200 TIMEOUT, and fgets/connect_socket gave 50/50 FN.

Change

  • --model-input (opt-in): NonDetPass, given -m2c-model-input, retargets the program's declarations of libc input functions to map2check_input_* in the new LibcInputModel.c. The retargeted functions are:

    • fgets, fgetc/getc, getchar, fread;
    • fgetws, fgetwc/getwc, getwchar;
    • fscanf/scanf, read, recv, recvfrom, getenv.

    Content and length come from map2check_non_det_*: symbolic under KLEE, the fuzzer's bytes under AFL++, and read back on replay. This is the model --wasm already uses for WASI's fd_read.

  • Connections and files: connect, bind, listen and accept succeed. Opening a missing file for reading gives /dev/null, so the program still reaches its modelled reads.

  • --input-bound N (default 4) bounds the bytes over all calls. NonDetPass defines the global map2check_input_max from it. A TRUE holds for inputs of at most N bytes. Numbers read by fscanf take no bytes and get their whole range.

  • Opt-in because in SV-COMP and Test-Comp the input comes only from __VERIFIER_nondet_*, and modelled libc input would misalign the test vectors. It is ignored with --wasm.

Calibration on Juliet

The run used 64 programs, bad and good: CWE-761, 12 families; CWE-190, the fgets, fscanf, connect_socket and listen_socket families. Each ran with --timeout 60 and the #97 harness.

bound 4 bound 8
CWE-761 bad, input-sourced (20) 20 TP 20 TP
CWE-190 fscanf bad (10) 10 TP 10 TP
CWE-190 fgets/socket bad (30) inconclusive inconclusive
good, input-sourced inconclusive, no FP inconclusive, no FP
  • CWE-190 fgets/socket: these stay out of reach. The overflow needs atoi("2147483647"), which is 10 bytes.
  • Inconclusive goods: the good programs mostly come from the per-path cost fixed in perf(library): write the analysis logs only for a violation #98. After that fix, the CWE-761 good above is proven TRUE by KLEE with bound 4 in 24 s.
  • Default bound: bounds 4 and 8 found the same flaws, and only 4 lets KLEE exhaust the paths, so 4 is the default.

Tests

tests/integration/test_model_input.sh (added to CI) passed 10/10:

  • Without the option, stdin input stays TRUE.
  • With it, FALSE-FREE is reached through fgets, fgetws, getenv, a missing file, connect+recv, and listen/accept+recv.
  • FALSE (overflow) is reached through fscanf("%d"), and FALSE-DEREF through fread.
  • The fixed fgets program is TRUE.

…nistic

Without it, fgets on stdin reads nothing, getenv finds nothing, connect is
refused and accept waits forever: a flaw that needs input is never reached
and the verdict is TRUE (Juliet CWE-761: 80 of 100 flawed programs FN).

NonDetPass, given -m2c-model-input, retargets the program's declarations of
fgets, fgetc/getc, getchar, fread, fgetws, fgetwc/getwc, getwchar,
fscanf/scanf, read, recv, recvfrom, getenv, fopen, connect, bind, listen and
accept to map2check_input_* in LibcInputModel.c. Their content and length
come from map2check_non_det_*: symbolic under KLEE, the fuzzer's bytes under
AFL++, read back on replay -- the model --wasm uses for WASI's fd_read.

The bytes over all calls are bounded by --input-bound (default 4); a TRUE
holds for inputs of at most that size. Every byte is a branch, so a larger
bound keeps KLEE from exhausting the paths; on a Juliet calibration (CWE-761
and CWE-190, 64 programs) bounds 4 and 8 found the same flaws.

Opt-in: in SV-COMP and Test-Comp the input comes only from
__VERIFIER_nondet_*, and modelled libc input would misalign the test vectors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant