Bug 154961 - Fuzzed image causes a heap buffer overflow in btrfsck
Summary: Fuzzed image causes a heap buffer overflow in btrfsck
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-08-27 17:29 UTC by Lukas Lueg
Modified: 2016-09-03 19:35 UTC (History)
2 users (show)

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


Attachments
Image triggering btrfsck to read beyond buffer (17.62 KB, application/gzip)
2016-08-27 17:29 UTC, Lukas Lueg
Details
Full ASAN log (3.91 KB, text/x-log)
2016-08-27 17:29 UTC, Lukas Lueg
Details

Description Lukas Lueg 2016-08-27 17:29:35 UTC
Created attachment 230821 [details]
Image triggering btrfsck to read beyond buffer

More news from the fuzzer. See the attached image to reproduce using btrfs-progs btrfs-progs v4.7-42-g56e9586. You may need to compile with ASAN, could not reproduce without...


==2572==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000018d86 at pc 0x000000547c3c bp 0x7ffd60ec5ef0 sp 0x7ffd60ec5ee8
READ of size 8 at 0x621000018d86 thread T0
    #0 0x547c3b in btrfs_stripe_offset /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1357:1
    #1 0x5391f7 in btrfs_stripe_offset_nr /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1399:9
    #2 0x538790 in btrfs_new_chunk_record /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:5209:4
    #3 0x56c55d in process_chunk_item /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:5225:8
    #4 0x5634e7 in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6290:5
    #5 0x55c489 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8338:10
    #6 0x541d53 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8505:8
    #7 0x53d565 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11430:9
    #8 0x4f105f in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8
    #9 0x7f40dcd8b730 in __libc_start_main (/lib64/libc.so.6+0x20730)
    #10 0x421238 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421238)
Comment 1 Lukas Lueg 2016-08-27 17:29:56 UTC
Created attachment 230831 [details]
Full ASAN log
Comment 2 Qu Wenruo 2016-08-30 04:08:56 UTC
https://bugzilla.kernel.org/show_bug.cgi?id=155201

The fix for above BZ will cover this.
The final chunk validation checker will ensure such invalid chunk size get ignored.
And early warning layer for wrong key type will find the problem and leave above final defense idle.

Thanks,
Qu
Comment 3 David Sterba 2016-09-03 19:35:11 UTC
Image added to the testsuite, passes with asan enabled. Closing, thanks.

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