{"id":1947,"date":"2017-08-05T13:27:29","date_gmt":"2017-08-05T11:27:29","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1947"},"modified":"2017-08-18T15:43:57","modified_gmt":"2017-08-18T13:43:57","slug":"graphicsmagick-use-after-free-in-readwmfimage-wmf-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/08\/05\/graphicsmagick-use-after-free-in-readwmfimage-wmf-c\/","title":{"rendered":"graphicsmagick: use-after-free in ReadWMFImage (wmf.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.graphicsmagick.org\/\">graphicsmagick<\/a> is a collection of tools and libraries for many image formats.<\/p>\n<p>The complete ASan output of the issue:<\/p>\n<pre><font size=\"2\"># gm convert -negate -clip $FILE out\r\n==24889==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0000005c0 at pc 0x7fca38d0da52 bp 0x7ffc6119c090 sp 0x7ffc6119c088\r\nREAD of size 8 at 0x60c0000005c0 thread T0\r\n    #0 0x7fca38d0da51 in ReadWMFImage \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/coders\/wmf.c:2720:5\r\n    #1 0x7fca3e7e7e88 in ReadImage \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/magick\/constitute.c:1607:13\r\n    #2 0x7fca3e67af18 in ConvertImageCommand \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/magick\/command.c:4348:22\r\n    #3 0x7fca3e6b70c5 in MagickCommand \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/magick\/command.c:8869:17\r\n    #4 0x7fca3e76285b in GMCommandSingle \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/magick\/command.c:17396:10\r\n    #5 0x7fca3e75f991 in GMCommand \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/magick\/command.c:17449:16\r\n    #6 0x7fca3cfca680 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    #7 0x419cd8 in _init (\/usr\/bin\/gm+0x419cd8)\r\n\r\n0x60c0000005c0 is located 64 bytes inside of 120-byte region [0x60c000000580,0x60c0000005f8)\r\nfreed by thread T0 here:\r\n    #0 0x4cf4d0 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 0x7fca38ac70cd in wmf_lite_destroy \/var\/tmp\/portage\/media-libs\/libwmf-0.2.8.4-r6\/work\/libwmf-0.2.8.4\/src\/api.c:336\r\n\r\npreviously allocated by thread T0 here:\r\n    #0 0x4cf688 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 0x7fca38ac72f7 in wmf_malloc \/var\/tmp\/portage\/media-libs\/libwmf-0.2.8.4-r6\/work\/libwmf-0.2.8.4\/src\/api.c:482\r\n\r\nSUMMARY: AddressSanitizer: heap-use-after-free \/var\/tmp\/portage\/media-gfx\/graphicsmagick-1.3.26\/work\/GraphicsMagick-1.3.26\/coders\/wmf.c:2720:5 in ReadWMFImage\r\nShadow bytes around the buggy address:\r\n  0x0c187fff8060: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00\r\n  0x0c187fff8070: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa\r\n  0x0c187fff8080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c187fff8090: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00\r\n  0x0c187fff80a0: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa\r\n=&gt;0x0c187fff80b0: fd fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fa\r\n  0x0c187fff80c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd\r\n  0x0c187fff80d0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa\r\n  0x0c187fff80e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c187fff80f0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00\r\n  0x0c187fff8100: 00 00 00 00 00 00 00 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==24889==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n1.3.26<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\nN\/A<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"http:\/\/hg.code.sf.net\/p\/graphicsmagick\/code\/rev\/be898b7c97bd\">http:\/\/hg.code.sf.net\/p\/graphicsmagick\/code\/rev\/be898b7c97bd<\/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-12936<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00302-graphicsmagick-UAF-ReadWMFImage\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00302-graphicsmagick-UAF-ReadWMFImage<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-07-14: bug discovered and reported to upstream<br \/>\n2017-07-26: upstream released a fix<br \/>\n2017-08-05: blog post about the issue<br \/>\n2017-08-18: 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>.<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=\"vT4MgUsAeF\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/08\/05\/graphicsmagick-use-after-free-in-readwmfimage-wmf-c\/\">graphicsmagick: use-after-free in ReadWMFImage (wmf.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\/08\/05\/graphicsmagick-use-after-free-in-readwmfimage-wmf-c\/embed\/#?secret=vT4MgUsAeF\" data-secret=\"vT4MgUsAeF\" width=\"600\" height=\"338\" title=\"&#8220;graphicsmagick: use-after-free in ReadWMFImage (wmf.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: graphicsmagick is a collection of tools and libraries for many image formats. The complete ASan output of the issue: # gm convert -negate -clip $FILE out ==24889==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0000005c0 at pc 0x7fca38d0da52 bp 0x7ffc6119c090 sp 0x7ffc6119c088 &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/08\/05\/graphicsmagick-use-after-free-in-readwmfimage-wmf-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-vp","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1947"}],"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=1947"}],"version-history":[{"count":4,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1947\/revisions"}],"predecessor-version":[{"id":2054,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1947\/revisions\/2054"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}