Description:
libarchive is a multi-format archive and compression library.
After it got fuzzed by hanno and some other people (1 2 3)I decided to fuzz it too.
A crafted file causes an use-after-free in the bid_entry function in the mtree parser.
This bug seems to be similar to THIS use-after-free but in this case ASan reports that happens in the bid_entry function instead of detect_form.
The complete ASan output:
# bsdtar -t -f $FILE ==25892==ERROR: AddressSanitizer: heap-use-after-free on address 0x7f2eec8eb31b at pc 0x7f2eec2b9bb6 bp 0x7ffc198b3b30 sp 0x7ffc198b3b28 READ of size 1 at 0x7f2eec8eb31b thread T0 #0 0x7f2eec2b9bb5 in bid_entry /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read_support_format_mtree.c:567:7 #1 0x7f2eec2b9bb5 in detect_form /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read_support_format_mtree.c:676 #2 0x7f2eec17f18b in choose_format /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:712:10 #3 0x7f2eec17f18b in archive_read_open1 /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:529 #4 0x7f2eec1b6f1f in archive_read_open_filename /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read_open_filename.c:109:9 #5 0x501f66 in read_archive /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/tar/read.c:223:6 #6 0x501473 in tar_mode_t /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/tar/read.c:94:2 #7 0x4f8929 in main /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/tar/bsdtar.c:803:3 #8 0x7f2eeb1f261f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.22-r4/work/glibc-2.22/csu/libc-start.c:289 #9 0x41b778 in _init (/usr/bin/bsdtar+0x41b778) 0x7f2eec8eb31b is located 27419 bytes inside of 131072-byte region [0x7f2eec8e4800,0x7f2eec904800) freed by thread T0 here: #0 0x4c29c0 in free /var/tmp/portage/sys-devel/llvm-3.8.0-r3/work/llvm-3.8.0.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38 #1 0x7f2eec186c68 in __archive_read_filter_ahead /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:1450:5 previously allocated by thread T0 here: #0 0x4c2cc8 in malloc /var/tmp/portage/sys-devel/llvm-3.8.0-r3/work/llvm-3.8.0.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52 #1 0x7f2eec186bca in __archive_read_filter_ahead /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:1436:17 SUMMARY: AddressSanitizer: heap-use-after-free /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read_support_format_mtree.c:567:7 in bid_entry Shadow bytes around the buggy address: 0x0fe65d915610: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915620: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915630: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915650: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0fe65d915660: fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915670: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915680: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d915690: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d9156a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0fe65d9156b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==25892==ABORTING
Affected version:
3.2.1
Fixed version:
3.2.2
Commit fix:
https://github.com/libarchive/libarchive/commit/eec077f52bfa2d3f7103b4b74d52572ba8a15aca
Credit:
This bug was discovered by Agostino Sarubbo of Gentoo.
CVE:
CVE-2016-8688
Timeline:
2016-08-11: bug discovered
2016-08-11: bug reported to upstream
2016-09-11: blog post about the issue
2016-09-19: upstream released a patch
2016-10-16: CVE Assigned
2016-10-24: Upstream released 3.2.2
Note:
This bug was found with American Fuzzy Lop.
Permalink:
libarchive: bsdtar use-after-free in bid_entry (archive_read_support_format_mtree.c)