{"id":507,"date":"2016-09-11T11:56:55","date_gmt":"2016-09-11T09:56:55","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=507"},"modified":"2016-12-01T15:41:18","modified_gmt":"2016-12-01T13:41:18","slug":"libarchive-bsdtar-heap-based-buffer-overflow-in-read_header-archive_read_support_format_7zip-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2016\/09\/11\/libarchive-bsdtar-heap-based-buffer-overflow-in-read_header-archive_read_support_format_7zip-c\/","title":{"rendered":"libarchive: bsdtar: heap-based buffer overflow in read_Header (archive_read_support_format_7zip.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.libarchive.org\/\">libarchive<\/a> is a multi-format archive and compression library.<\/p>\n<p>After it got fuzzed by hanno and some other people (<a href=\"https:\/\/blog.fuzzing-project.org\/47-Many-invalid-memory-access-issues-in-libarchive.html\">1<\/a> <a href=\"https:\/\/blog.fuzzing-project.org\/48-Out-of-bounds-read-and-signed-integer-overflow-in-libarchive.html\">2<\/a> <a href=\"http:\/\/blog.talosintel.com\/2016\/06\/the-poisoned-archives.html\">3<\/a>)I decided to fuzz it too.<\/p>\n<p>A crafted file causes an heap overflow in the read_Header function in the 7zip parser.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># bsdtar -t -f $FILE\r\n==27481==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000ecbb at pc 0x7f01eb0e55fc bp 0x7fff63005ad0 sp 0x7fff63005ac8\r\nREAD of size 1 at 0x60200000ecbb thread T0\r\n    #0 0x7f01eb0e55fb in read_Header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:2601:9\r\n    #1 0x7f01eb0e55fb in slurp_central_directory \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:2923\r\n    #2 0x7f01eb0e55fb in archive_read_format_7zip_read_header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:638\r\n    #3 0x7f01eb07a0ec in _archive_read_next_header2 \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read.c:649:7\r\n    #4 0x7f01eb079c8f in _archive_read_next_header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read.c:687:8\r\n    #5 0x5021cb in read_archive \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/tar\/read.c:261:7\r\n    #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\r\n    #7 0x4f8929 in main \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/tar\/bsdtar.c:803:3\r\n    #8 0x7f01ea0df61f in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/csu\/libc-start.c:289\r\n    #9 0x41b778 in _init (\/usr\/bin\/bsdtar+0x41b778)\r\n\r\n0x60200000ecbb is located 0 bytes to the right of 11-byte region [0x60200000ecb0,0x60200000ecbb)\r\nallocated by thread T0 here:\r\n    #0 0x4c2e50 in calloc \/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:66\r\n    #1 0x7f01eb0dead3 in read_Header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:2454:24\r\n    #2 0x7f01eb0dead3 in slurp_central_directory \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:2923\r\n    #3 0x7f01eb0dead3 in archive_read_format_7zip_read_header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:638\r\n    #4 0x7f01eb07a0ec in _archive_read_next_header2 \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read.c:649:7\r\n    #5 0x7f01eb079c8f in _archive_read_next_header \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read.c:687:8\r\n    #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\r\n    #7 0x4f8929 in main \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/tar\/bsdtar.c:803:3\r\n    #8 0x7f01ea0df61f in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/csu\/libc-start.c:289\r\n\r\nSUMMARY: AddressSanitizer: heap-buffer-overflow \/var\/tmp\/portage\/app-arch\/libarchive-3.2.1-r3\/work\/libarchive-3.2.1\/libarchive\/archive_read_support_format_7zip.c:2601:9 in read_Header\r\nShadow bytes around the buggy address:\r\n  0x0c047fff9d40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9d50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n=&gt;0x0c047fff9d90: fa fa fa fa fa fa 00[03]fa fa fd fa fa fa fd fa\r\n  0x0c047fff9da0: fa fa 04 fa fa fa 01 fa fa fa 00 fa fa fa 00 fa\r\n  0x0c047fff9db0: fa fa 00 fa fa fa 04 fa fa fa 01 fa fa fa 00 fa\r\n  0x0c047fff9dc0: fa fa 00 fa fa fa 00 04 fa fa 00 04 fa fa 00 04\r\n  0x0c047fff9dd0: fa fa 00 04 fa fa 00 04 fa fa 00 04 fa fa 00 04\r\n  0x0c047fff9de0: fa fa 00 04 fa fa 00 04 fa fa 00 04 fa fa 00 04\r\nShadow byte legend (one shadow byte represents 8 application bytes):\r\n  Addressable:           00\r\n  Partially addressable: 01 02 03 04 05 06 07 \r\n  Heap left redzone:       fa\r\n  Heap right redzone:      fb\r\n  Freed heap region:       fd\r\n  Stack left redzone:      f1\r\n  Stack mid redzone:       f2\r\n  Stack right redzone:     f3\r\n  Stack partial redzone:   f4\r\n  Stack after return:      f5\r\n  Stack use after scope:   f8\r\n  Global redzone:          f9\r\n  Global init order:       f6\r\n  Poisoned by user:        f7\r\n  Container overflow:      fc\r\n  Array cookie:            ac\r\n  Intra object redzone:    bb\r\n  ASan internal:           fe\r\n  Left alloca redzone:     ca\r\n  Right alloca redzone:    cb\r\n==27481==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n3.2.1<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n3.2.2<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/libarchive\/libarchive\/commit\/7f17c791dcfd8c0416e2cd2485b19410e47ef126\">https:\/\/github.com\/libarchive\/libarchive\/commit\/7f17c791dcfd8c0416e2cd2485b19410e47ef126<\/a><\/p>\n<p><strong>Credit:<\/strong><br \/>\nThis bug was discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>CVE:<\/strong><br \/>\nCVE-2016-8689<\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2016-08-11: bug discovered<br \/>\n2016-08-11: bug reported to upstream<br \/>\n2016-09-11: blog post about the issue<br \/>\n2016-09-19: upstream released a patch<br \/>\n2016-10-16: CVE Assigned<br \/>\n2016-10-24: Upstream released 3.2.2<\/p>\n<p><strong>Note:<\/strong><br \/>\nThis bug was found with <a href=\"http:\/\/lcamtuf.coredump.cx\/afl\">American Fuzzy Lop<\/a>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"5SRCpQlA1y\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2016\/09\/11\/libarchive-bsdtar-heap-based-buffer-overflow-in-read_header-archive_read_support_format_7zip-c\/\">libarchive: bsdtar: heap-based buffer overflow in read_Header (archive_read_support_format_7zip.c)<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/blogs.gentoo.org\/ago\/2016\/09\/11\/libarchive-bsdtar-heap-based-buffer-overflow-in-read_header-archive_read_support_format_7zip-c\/embed\/#?secret=5SRCpQlA1y\" data-secret=\"5SRCpQlA1y\" width=\"600\" height=\"338\" title=\"&#8220;libarchive: bsdtar: heap-based buffer overflow in read_Header (archive_read_support_format_7zip.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 read_Header function in the &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2016\/09\/11\/libarchive-bsdtar-heap-based-buffer-overflow-in-read_header-archive_read_support_format_7zip-c\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":140,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[12,10],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2EaBc-8b","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/507"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/users\/140"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/comments?post=507"}],"version-history":[{"count":7,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":981,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/507\/revisions\/981"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}