Repository navigation
feat(native): --model-input makes the program's libc input nondeterministic - #99
Open
GuilhermeBn198 wants to merge 1 commit into
Open
GuilhermeBn198 wants to merge 1 commit into
GuilhermeBn198 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In native mode, a call such as
fgets(buf, n, stdin)is a real call. KLEE runs it concretely:getenvfinds nothing;connectis refused;acceptwaits 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:fscanfgave 200/200 TIMEOUT, andfgets/connect_socketgave 50/50 FN.Change
--model-input(opt-in): NonDetPass, given-m2c-model-input, retargets the program's declarations of libc input functions tomap2check_input_*in the newLibcInputModel.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--wasmalready uses for WASI'sfd_read.Connections and files:
connect,bind,listenandacceptsucceed. 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 globalmap2check_input_maxfrom it. A TRUE holds for inputs of at most N bytes. Numbers read byfscanftake 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_socketandlisten_socketfamilies. Each ran with--timeout 60and the #97 harness.fscanfbad (10)fgets/socket bad (30)fgets/socket: these stay out of reach. The overflow needsatoi("2147483647"), which is 10 bytes.Tests
tests/integration/test_model_input.sh(added to CI) passed 10/10:FALSE-FREEis reached throughfgets,fgetws,getenv, a missing file,connect+recv, andlisten/accept+recv.FALSE(overflow) is reached throughfscanf("%d"), andFALSE-DEREFthroughfread.fgetsprogram is TRUE.