{"id":1582,"date":"2017-04-03T17:21:48","date_gmt":"2017-04-03T15:21:48","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1582"},"modified":"2017-04-10T09:27:42","modified_gmt":"2017-04-10T07:27:42","slug":"elfutils-heap-based-buffer-overflow-in-ebl_object_note_type_name-eblobjnotetypename-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-ebl_object_note_type_name-eblobjnotetypename-c\/","title":{"rendered":"elfutils: heap-based buffer overflow in ebl_object_note_type_name (eblobjnotetypename.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. Will follow a feedback from upstream:<\/p>\n<blockquote><p>Nice find. The issue is with notes that have a zero sized name (and also no descriptor data at the end of a note section).<\/p>\n<p>&#8220;The system reserves note information with no name (namesz==0) and with a zero-length name (name[0]==&#8217;\\0&#8242;) but currently defines no types. All other names must have at least one non-null character.&#8221;<\/p>\n<p>So we must explicitly check for namesz == 0 before using the name data in the note.<\/p><\/blockquote>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># eu-readelf -a $FILE\r\n==29866==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000ef9c at pc 0x7f910ac17150 bp 0x7fff92f7ed90 sp 0x7fff92f7e540\r\nREAD of size 1 at 0x60200000ef9c thread T0\r\n    #0 0x7f910ac1714f  (\/usr\/lib\/gcc\/x86_64-pc-linux-gnu\/6.3.0\/libasan.so.3+0x4514f)\r\n    #1 0x4f63a7 in ebl_object_note_type_name \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libebl\/eblobjnotetypename.c:48\r\n    #2 0x461251 in handle_notes_data \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:9372\r\n    #3 0x47209d in handle_notes \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:9455\r\n    #4 0x47209d in process_elf_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:916\r\n    #5 0x47ae65 in process_dwflmod \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:690\r\n    #6 0x7f910a730094 in dwfl_getmodules \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libdwfl\/dwfl_getmodules.c:82\r\n    #7 0x4365f2 in process_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:789\r\n    #8 0x405e50 in main \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:305\r\n    #9 0x7f9108d4e78f in __libc_start_main (\/lib64\/libc.so.6+0x2078f)\r\n    #10 0x406cd8 in _start (\/usr\/bin\/eu-readelf+0x406cd8)\r\n\r\n0x60200000ef9c is located 0 bytes to the right of 12-byte region [0x60200000ef90,0x60200000ef9c)\r\nallocated by thread T0 here:\r\n    #0 0x7f910ac94288 in malloc (\/usr\/lib\/gcc\/x86_64-pc-linux-gnu\/6.3.0\/libasan.so.3+0xc2288)\r\n    #1 0x7f910a10af48 in convert_data \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:166\r\n    #2 0x7f910a10af48 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 0x7f910a10c9ba in __elf_getdata_rdlock \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:541\r\n    #4 0x7f910a10ccae in elf_getdata \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libelf\/elf_getdata.c:559\r\n    #5 0x471fe7 in handle_notes \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:9455\r\n    #6 0x471fe7 in process_elf_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:916\r\n    #7 0x47ae65 in process_dwflmod \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:690\r\n    #8 0x7f910a730094 in dwfl_getmodules \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/libdwfl\/dwfl_getmodules.c:82\r\n    #9 0x4365f2 in process_file \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:789\r\n    #10 0x405e50 in main \/tmp\/portage\/dev-libs\/elfutils-0.168\/work\/elfutils-0.168\/src\/readelf.c:305\r\n    #11 0x7f9108d4e78f in __libc_start_main (\/lib64\/libc.so.6+0x2078f)\r\n\r\nSUMMARY: AddressSanitizer: heap-buffer-overflow (\/usr\/lib\/gcc\/x86_64-pc-linux-gnu\/6.3.0\/libasan.so.3+0x4514f) \r\nShadow bytes around the buggy address:\r\n  0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n=&gt;0x0c047fff9df0: fa fa 00[04]fa fa 00 02 fa fa 00 02 fa fa 00 01\r\n  0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c047fff9e40: 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==29866==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\/msg00111.html\">https:\/\/sourceware.org\/ml\/elfutils-devel\/2017-q1\/msg00111.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-7608<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00226-elfutils-heapoverflow-ebl_object_note_type_name\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00226-elfutils-heapoverflow-ebl_object_note_type_name<\/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=\"aDCYdYhbRq\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-ebl_object_note_type_name-eblobjnotetypename-c\/\">elfutils: heap-based buffer overflow in ebl_object_note_type_name (eblobjnotetypename.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-ebl_object_note_type_name-eblobjnotetypename-c\/embed\/#?secret=aDCYdYhbRq\" data-secret=\"aDCYdYhbRq\" width=\"600\" height=\"338\" title=\"&#8220;elfutils: heap-based buffer overflow in ebl_object_note_type_name (eblobjnotetypename.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. Will follow a feedback from upstream: Nice find. The issue is with notes that have a &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/03\/elfutils-heap-based-buffer-overflow-in-ebl_object_note_type_name-eblobjnotetypename-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-pw","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1582"}],"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=1582"}],"version-history":[{"count":4,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1582\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1582\/revisions\/1619"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}