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 heap overflow in the detect_form function in the mtree parser.
The complete ASan output:
# bsdtar -t -f $FILE ==25612==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fadef29981e at pc 0x7fadeec6fbac bp 0x7ffd2318bb30 sp 0x7ffd2318bb28 READ of size 1 at 0x7fadef29981e thread T0 #0 0x7fadeec6fbab 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:692:26 #1 0x7fadeeb3518b in choose_format /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:712:10 #2 0x7fadeeb3518b in archive_read_open1 /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read.c:529 #3 0x7fadeeb6cf1f 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 #4 0x501f66 in read_archive /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/tar/read.c:223:6 #5 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 #6 0x4f8929 in main /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/tar/bsdtar.c:803:3 #7 0x7fadedba861f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.22-r4/work/glibc-2.22/csu/libc-start.c:289 #8 0x41b778 in _init (/usr/bin/bsdtar+0x41b778) 0x7fadef29981e is located 4126 bytes to the right of 262144-byte region [0x7fadef258800,0x7fadef298800) 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 0x7fadeeb3cbca 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-buffer-overflow /var/tmp/portage/app-arch/libarchive-3.2.1-r3/work/libarchive-3.2.1/libarchive/archive_read_support_format_mtree.c:692:26 in detect_form Shadow bytes around the buggy address: 0x0ff63de4b2b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b2c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b2d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b2e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b2f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa =>0x0ff63de4b300: fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b310: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b320: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b330: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b340: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0ff63de4b350: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 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 ==25612==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: heap-based buffer overflow in detect_form (archive_read_support_format_mtree.c)