Bug 156811 - Fuzzed image causes undefined behavior in btrfsck (qgroup-verify.c:find_parent_root())
Summary: Fuzzed image causes undefined behavior in btrfsck (qgroup-verify.c:find_paren...
Status: RESOLVED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: btrfs (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Josef Bacik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-14 19:19 UTC by Lukas Lueg
Modified: 2016-09-30 17:02 UTC (History)
1 user (show)

See Also:
Kernel Version: 4.6.6-300.fc24-x86_64
Subsystem:
Regression: No
Bisected commit-id:


Attachments
Image exposing undefined behavior (17.73 KB, application/gzip)
2016-09-14 19:19 UTC, Lukas Lueg
Details
UBSAN-log (4.21 KB, text/x-log)
2016-09-14 19:20 UTC, Lukas Lueg
Details

Description Lukas Lueg 2016-09-14 19:19:46 UTC
Created attachment 233391 [details]
Image exposing undefined behavior

More news from the fuzzer. The attached image causes btrfsck to engage in undefined behavior; using btrfs-progs v4.7-42-g56e9586. You need to compile with UBSAN in order to reproduce.

The juicy parts:

qgroup-verify.c:333:15: runtime error: member access within null pointer of type 'struct ref'
    #0 0x88684f in find_parent_roots /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:333:15
    #1 0x877a71 in account_all_refs /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:525:11
    #2 0x87513b in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:1372:8
    #3 0x536d3a in cmd_check /home/lukas/dev/btrfsfuzz/src-ubsan/cmds-check.c:11637:9
    #4 0x490560 in main /home/lukas/dev/btrfsfuzz/src-ubsan/btrfs.c:243:8
    #5 0x7f35b46ab730 in __libc_start_main (/lib64/libc.so.6+0x20730)
    #6 0x422188 in _start (/home/lukas/dev/btrfsfuzz/bin-ubsan/bin/btrfs+0x422188)


We don't strictly need UBSAN as the error can be spotted by naked eye in find_parent_root(): The line "node = &ref->bytenr_node" gets a reference to a member of a NULL pointer before the pointer is checked against being NULL on the next line. It should be the other way around...
Comment 1 Lukas Lueg 2016-09-14 19:20:02 UTC
Created attachment 233401 [details]
UBSAN-log
Comment 2 David Sterba 2016-09-30 17:02:44 UTC
UB fixed and better error handling in place, image added, thanks. Closing.

Note You need to log in before you can comment on or make changes to this bug.