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 detect_form function in the mtree parser.
This bug seems to be similar to THIS use-after-free, but in this case ASan does not mention bid_entry.
The complete ASan output:
# bsdtar -t -f $FILE ==23484==ERROR: AddressSanitizer: heap-use-after-free on address 0x7fb5fce53b12 at pc 0x7fb5fc825bac bp 0x7ffe5622bb30 sp 0x7ffe5622bb28 READ of size 1 at 0x7fb5fce53b12 thread T0 #0 0x7fb5fc825bab 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 0x7fb5fc6eb18b 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 0x7fb5fc6eb18b 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 0x7fb5fc722f1f 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 0x7fb5fb75e61f 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) 0x7fb5fce53b12 is located 13074 bytes inside of 131072-byte region [0x7fb5fce50800,0x7fb5fce70800) 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 0x7fb5fc6f2c68 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 0x7fb5fc6f2bca 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:692:26 in detect_form Shadow bytes around the buggy address: 0x0ff73f9c2710: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2720: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2730: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2740: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2750: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0ff73f9c2760: fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2770: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2780: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c2790: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c27a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0ff73f9c27b0: 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 ==23484==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 detect_form (archive_read_support_format_mtree.c)