{"id":1579,"date":"2017-04-03T17:13:15","date_gmt":"2017-04-03T15:13:15","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1579"},"modified":"2017-04-10T09:24:51","modified_gmt":"2017-04-10T07:24:51","slug":"elfutils-heap-based-buffer-overflow-in-handle_gnu_hash-readelf-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-handle_gnu_hash-readelf-c\/","title":{"rendered":"elfutils: heap-based buffer overflow in handle_gnu_hash (readelf.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"https:\/\/sourceware.org\/elfutils\/\">elfutils<\/a> is a set of libraries\/utilities to handle ELF objects (drop in replacement for libelf).<\/p>\n<p>A fuzz on eu-readelf showed an heap overflow.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># eu-readelf -a $FILE\r\n==1855==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000009ffc at pc 0x000000421a8c bp 0x7ffef67082e0 sp 0x7ffef67082d8\r\nREAD of size 4 at 0x611000009ffc thread T0\r\n    #0 0x421a8b in handle_gnu_hash \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:3268\r\n    #1 0x421a8b in handle_hash \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:3346\r\n    #2 0x4680f7 in process_elf_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:898\r\n    #3 0x47ae65 in process_dwflmod \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:690\r\n    #4 0x7f4bae746094 in dwfl_getmodules \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libdwfl\/dwfl_getmodules.c:82\r\n    #5 0x4365f2 in process_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:789\r\n    #6 0x405e50 in main \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:305\r\n    #7 0x7f4bacd6478f in __libc_start_main (\/lib64\/libc.so.6+0x2078f)\r\n    #8 0x406cd8 in _start (\/usr\/bin\/eu-readelf+0x406cd8)\r\n\r\n0x611000009ffc is located 0 bytes to the right of 252-byte region [0x611000009f00,0x611000009ffc)\r\nallocated by thread T0 here:\r\n    #0 0x7f4baecaa288 in malloc (\/usr\/lib\/gcc\/x86_64-pc-linux-gnu\/6.3.0\/libasan.so.3+0xc2288)\r\n    #1 0x7f4bae120f48 in convert_data \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:166\r\n    #2 0x7f4bae120f48 in __libelf_set_data_list_rdlock \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:434\r\n    #3 0x7f4bae1229ba in __elf_getdata_rdlock \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:541\r\n    #4 0x7f4bae122cae in elf_getdata \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:559\r\n    #5 0x41f100 in handle_gnu_hash \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:3206\r\n    #6 0x41f100 in handle_hash \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:3346\r\n    #7 0x4680f7 in process_elf_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:898\r\n    #8 0x47ae65 in process_dwflmod \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:690\r\n    #9 0x7f4bae746094 in dwfl_getmodules \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libdwfl\/dwfl_getmodules.c:82\r\n    #10 0x4365f2 in process_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:789\r\n    #11 0x405e50 in main \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:305\r\n    #12 0x7f4bacd6478f in __libc_start_main (\/lib64\/libc.so.6+0x2078f)\r\n\r\nSUMMARY: AddressSanitizer: heap-buffer-overflow \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:3268 in handle_gnu_hash\r\nShadow bytes around the buggy address:\r\n  0x0c227fff93a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff93b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff93c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff93d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff93e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n=&gt;0x0c227fff93f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[04]\r\n  0x0c227fff9400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff9410: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff9420: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff9430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c227fff9440: 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  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==1855==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n0.168<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n0.169 (not released atm)<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/sourceware.org\/ml\/elfutils-devel\/2017-q1\/msg00109.html\">https:\/\/sourceware.org\/ml\/elfutils-devel\/2017-q1\/msg00109.html<\/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-2017-7607<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00225-elfutils-heapoverflow-handle_gnu_hash\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00225-elfutils-heapoverflow-handle_gnu_hash<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-03-24: bug discovered and reported to upstream<br \/>\n2017-04-04: blog post about the issue<br \/>\n2017-04-09: CVE assigned<\/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=\"Ns6rgVUOuV\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-handle_gnu_hash-readelf-c\/\">elfutils: heap-based buffer overflow in handle_gnu_hash (readelf.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\/04\/03\/elfutils-heap-based-buffer-overflow-in-handle_gnu_hash-readelf-c\/embed\/#?secret=Ns6rgVUOuV\" data-secret=\"Ns6rgVUOuV\" width=\"600\" height=\"338\" title=\"&#8220;elfutils: heap-based buffer overflow in handle_gnu_hash (readelf.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: elfutils is a set of libraries\/utilities to handle ELF objects (drop in replacement for libelf). A fuzz on eu-readelf showed an heap overflow. The complete ASan output: # eu-readelf -a $FILE ==1855==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000009ffc at pc &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-handle_gnu_hash-readelf-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-pt","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1579"}],"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=1579"}],"version-history":[{"count":5,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1579\/revisions"}],"predecessor-version":[{"id":1618,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1579\/revisions\/1618"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}