{"id":2110,"date":"2017-09-01T16:28:40","date_gmt":"2017-09-01T14:28:40","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=2110"},"modified":"2017-09-01T19:50:52","modified_gmt":"2017-09-01T17:50:52","slug":"libzip-use-after-free-in-_zip_buffer_free-zip_buffer-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/09\/01\/libzip-use-after-free-in-_zip_buffer_free-zip_buffer-c\/","title":{"rendered":"libzip: use-after-free in _zip_buffer_free (zip_buffer.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"https:\/\/github.com\/nih-at\/libzip\">libzip<\/a> is a library for manipulating zip archives.<\/p>\n<p>The relevant ASan output of the issue:<\/p>\n<pre><font size=\"2\"># ziptool $FILE cat index\r\n==1771==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030000000d1 at pc 0x7f267d085fc1 bp 0x7ffed21f65f0 sp 0x7ffed21f65e8                                                                           \r\nREAD of size 1 at 0x6030000000d1 thread T0                                                                                                                                                                        \r\n    #0 0x7f267d085fc0 in _zip_buffer_free \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_buffer.c:53:17                                                                                         \r\n    #1 0x7f267d092646 in _zip_dirent_read \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_dirent.c                                                                                               \r\n    #2 0x7f267d0aabfe in _zip_read_cdir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:380:69                                                                                            \r\n    #3 0x7f267d0aabfe in _zip_find_central_dir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:613                                                                                        \r\n    #4 0x7f267d0aabfe in _zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:200                                                                                                    \r\n    #5 0x7f267d0a89b7 in zip_open_from_source \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:148:11                                                                                      \r\n    #6 0x7f267d0a7e93 in zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:74:15                                                                                                   \r\n    #7 0x513392 in read_from_file \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:698:13                                                                                                   \r\n    #8 0x513392 in main \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:1113                                                                                                               \r\n    #9 0x7f267c1b5680 in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.23-r4\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289                                                                                    \r\n    #10 0x41b058 in _init (\/usr\/bin\/ziptool+0x41b058)                                                                                                                                                             \r\n                                                                                                                                                                                                                  \r\n0x6030000000d1 is located 1 bytes inside of 32-byte region [0x6030000000d0,0x6030000000f0)                                                                                                                        \r\nfreed by thread T0 here:                                                                                                                                                                                          \r\n    #0 0x4d0850 in __interceptor_cfree \/var\/tmp\/portage\/sys-libs\/compiler-rt-sanitizers-4.0.1\/work\/compiler-rt-4.0.1.src\/lib\/asan\/asan_malloc_linux.cc:55                                                         \r\n    #1 0x7f267d085f83 in _zip_buffer_free \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_buffer.c:57:5                                                                                          \r\n    #2 0x7f267d0935ea in _zip_dirent_read \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_dirent.c:571:9                                                                                         \r\n    #3 0x7f267d0aabfe in _zip_read_cdir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:380:69                                                                                            \r\n    #4 0x7f267d0aabfe in _zip_find_central_dir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:613                                                                                        \r\n    #5 0x7f267d0aabfe in _zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:200                                                                                                    \r\n    #6 0x7f267d0a89b7 in zip_open_from_source \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:148:11                                                                                      \r\n    #7 0x7f267d0a7e93 in zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:74:15                                                                                                   \r\n    #8 0x513392 in read_from_file \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:698:13\r\n    #9 0x513392 in main \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:1113\r\n    #10 0x7f267c1b5680 in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.23-r4\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n\r\npreviously allocated by thread T0 here:\r\n    #0 0x4d0a08 in malloc \/var\/tmp\/portage\/sys-libs\/compiler-rt-sanitizers-4.0.1\/work\/compiler-rt-4.0.1.src\/lib\/asan\/asan_malloc_linux.cc:66\r\n    #1 0x7f267d0879d8 in _zip_buffer_new \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_buffer.c:168:35\r\n    #2 0x7f267d0879d8 in _zip_buffer_new_from_source \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_buffer.c:190\r\n    #3 0x7f267d0927c2 in _zip_dirent_read \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_dirent.c:443:23\r\n    #4 0x7f267d0aabfe in _zip_read_cdir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:380:69\r\n    #5 0x7f267d0aabfe in _zip_find_central_dir \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:613\r\n    #6 0x7f267d0aabfe in _zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:200\r\n    #7 0x7f267d0a89b7 in zip_open_from_source \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:148:11\r\n    #8 0x7f267d0a7e93 in zip_open \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_open.c:74:15\r\n    #9 0x513392 in read_from_file \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:698:13\r\n    #10 0x513392 in main \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/src\/ziptool.c:1113\r\n    #11 0x7f267c1b5680 in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.23-r4\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n\r\nSUMMARY: AddressSanitizer: heap-use-after-free \/var\/tmp\/portage\/dev-libs\/libzip-1.2.0\/work\/libzip-1.2.0\/lib\/zip_buffer.c:53:17 in _zip_buffer_free\r\nShadow bytes around the buggy address:\r\n  0x0c067fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c067fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c067fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c067fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c067fff8000: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa fd fd\r\n=&gt;0x0c067fff8010: fd fd fa fa fd fd fd fd fa fa[fd]fd fd fd fa fa\r\n  0x0c067fff8020: 00 00 00 00 fa fa fd fd fd fa fa fa fd fd fd fd\r\n  0x0c067fff8030: fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00\r\n  0x0c067fff8040: 00 fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c067fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c067fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\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  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 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==1771==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n1.2.0<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n1.3.0<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/nih-at\/libzip\/commit\/2217022b7d1142738656d891e00b3d2d9179b796\">https:\/\/github.com\/nih-at\/libzip\/commit\/2217022b7d1142738656d891e00b3d2d9179b796<\/a><\/p>\n<p><strong>Credit:<\/strong><br \/>\nThis bug was discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>CVE:<\/strong><br \/>\nThis issue can be identified as CVE-2017-12858 which was originally discovered by Brian Carpenter<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00239-libzip-UAF-_zip_buffer_free\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00239-libzip-UAF-_zip_buffer_free<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-08-29: upstream released a fix as it fixed another issue<br \/>\n2017-08-24: bug discovered and reported to upstream<br \/>\n2017-09-01: blog post about the issue<\/p>\n<p><strong>Note:<\/strong><br \/>\nThis bug was found with <a href=\"http:\/\/lcamtuf.coredump.cx\/afl\">American Fuzzy Lop<\/a>.<br \/>\nThis bug was identified with bare metal servers donated by <a href=\"https:\/\/www.packet.net\/\">Packet<\/a>. This work is also supported by the <a href=\"https:\/\/www.coreinfrastructure.org\">Core Infrastructure Initiative<\/a>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"XMt0FVuIws\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/09\/01\/libzip-use-after-free-in-_zip_buffer_free-zip_buffer-c\/\">libzip: use-after-free in _zip_buffer_free (zip_buffer.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\/2017\/09\/01\/libzip-use-after-free-in-_zip_buffer_free-zip_buffer-c\/embed\/#?secret=XMt0FVuIws\" data-secret=\"XMt0FVuIws\" width=\"600\" height=\"338\" title=\"&#8220;libzip: use-after-free in _zip_buffer_free (zip_buffer.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: libzip is a library for manipulating zip archives. The relevant ASan output of the issue: # ziptool $FILE cat index ==1771==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030000000d1 at pc 0x7f267d085fc1 bp 0x7ffed21f65f0 sp 0x7ffed21f65e8 READ of size 1 at 0x6030000000d1 &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/09\/01\/libzip-use-after-free-in-_zip_buffer_free-zip_buffer-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-y2","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2110"}],"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=2110"}],"version-history":[{"count":5,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2110\/revisions"}],"predecessor-version":[{"id":2116,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2110\/revisions\/2116"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=2110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=2110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=2110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}