{"id":2008,"date":"2017-08-10T16:35:33","date_gmt":"2017-08-10T14:35:33","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=2008"},"modified":"2017-08-16T08:44:12","modified_gmt":"2017-08-16T06:44:12","slug":"imagemagick-use-after-free-in-destroyimage-image-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/08\/10\/imagemagick-use-after-free-in-destroyimage-image-c\/","title":{"rendered":"imagemagick: use-after-free in DestroyImage (image.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.imagemagick.org\/script\/index.php\">imagemagick<\/a> is a software suite to create, edit, compose, or convert bitmap images.<\/p>\n<p>The complete ASan output of the issue:<\/p>\n<pre><font size=\"2\"># convert $FILE null\r\n==151587==ERROR: AddressSanitizer: heap-use-after-free on address 0x627000037d50 at pc 0x7f4697f94380 bp 0x7ffd1011d370 sp 0x7ffd1011d368\r\nREAD of size 8 at 0x627000037d50 thread T0\r\n    #0 0x7f4697f9437f in DestroyImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/image.c:1186:3\r\n    #1 0x7f4690bfaebf in ReadMATImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/coders\/mat.c:1374:14\r\n    #2 0x7f4697dc8844 in ReadImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:497:13\r\n    #3 0x7f4697dcbf01 in ReadImages \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:866:9\r\n    #4 0x7f469760e319 in ConvertImageCommand \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/convert.c:641:18\r\n    #5 0x7f4697737225 in MagickCommandGenesis \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/mogrify.c:183:14\r\n    #6 0x5093e9 in MagickMain \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:149:10\r\n    #7 0x5093e9 in main \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:180\r\n    #8 0x7f469630f680 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    #9 0x41a1f8 in _init (\/usr\/bin\/magick+0x41a1f8)\r\n\r\n0x627000037d50 is located 13392 bytes inside of 13488-byte region [0x627000034900,0x627000037db0)\r\nfreed by thread T0 here:\r\n    #0 0x4cf9f0 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 0x7f4698003b8a in RelinquishMagickMemory \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/memory.c:1042:3\r\n    #2 0x7f4697f942ed in DestroyImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/image.c:1221:19\r\n    #3 0x7f4697fd6454 in DeleteImageFromList \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/list.c:298:12\r\n    #4 0x7f4690bfab12 in ReadMATImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/coders\/mat.c:1344:11\r\n    #5 0x7f4697dc8844 in ReadImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:497:13\r\n    #6 0x7f4697dcbf01 in ReadImages \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:866:9\r\n    #7 0x7f469760e319 in ConvertImageCommand \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/convert.c:641:18\r\n    #8 0x7f4697737225 in MagickCommandGenesis \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/mogrify.c:183:14\r\n    #9 0x5093e9 in MagickMain \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:149:10\r\n    #10 0x5093e9 in main \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:180\r\n    #11 0x7f469630f680 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 0x4cfba8 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 0x7f4697f8c474 in AcquireImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/image.c:169:19\r\n    #2 0x7f4697f9026b in AcquireNextImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/image.c:395:15\r\n    #3 0x7f4690bfd5ad in ReadMATImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/coders\/mat.c:1284:5\r\n    #4 0x7f4697dc8844 in ReadImage \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:497:13\r\n    #5 0x7f4697dcbf01 in ReadImages \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/constitute.c:866:9\r\n    #6 0x7f469760e319 in ConvertImageCommand \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/convert.c:641:18\r\n    #7 0x7f4697737225 in MagickCommandGenesis \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickWand\/mogrify.c:183:14\r\n    #8 0x5093e9 in MagickMain \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:149:10\r\n    #9 0x5093e9 in main \/var\/tmp\/portage\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/utilities\/magick.c:180\r\n    #10 0x7f469630f680 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\/media-gfx\/imagemagick-7.0.6.5\/work\/ImageMagick-7.0.6-5\/MagickCore\/image.c:1186:3 in DestroyImage\r\nShadow bytes around the buggy address:\r\n  0x0c4e7fffef50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c4e7fffef60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c4e7fffef70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c4e7fffef80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c4e7fffef90: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n=&gt;0x0c4e7fffefa0: fd fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd fd\r\n  0x0c4e7fffefb0: fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa fa\r\n  0x0c4e7fffefc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c4e7fffefd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c4e7fffefe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c4e7fffeff0: 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==151587==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n7.0.6-5<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n7.0.6-6 (not released atm)<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/ImageMagick\/ImageMagick\/commit\/04178de2247e353fc095846784b9a10fefdbf890\">https:\/\/github.com\/ImageMagick\/ImageMagick\/commit\/04178de2247e353fc095846784b9a10fefdbf890<\/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-12877<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00305-imagemagick-UAF-DestroyImage\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00305-imagemagick-UAF-DestroyImage<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-08-09: bug discovered and reported to upstream<br \/>\n2017-08-10: blog post about the issue<br \/>\n2017-08-15: 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=\"4uXM394X1S\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/08\/10\/imagemagick-use-after-free-in-destroyimage-image-c\/\">imagemagick: use-after-free in DestroyImage (image.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\/10\/imagemagick-use-after-free-in-destroyimage-image-c\/embed\/#?secret=4uXM394X1S\" data-secret=\"4uXM394X1S\" width=\"600\" height=\"338\" title=\"&#8220;imagemagick: use-after-free in DestroyImage (image.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: imagemagick is a software suite to create, edit, compose, or convert bitmap images. The complete ASan output of the issue: # convert $FILE null ==151587==ERROR: AddressSanitizer: heap-use-after-free on address 0x627000037d50 at pc 0x7f4697f94380 bp 0x7ffd1011d370 sp 0x7ffd1011d368 READ of &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/08\/10\/imagemagick-use-after-free-in-destroyimage-image-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-wo","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2008"}],"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=2008"}],"version-history":[{"count":4,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2008\/revisions"}],"predecessor-version":[{"id":2021,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2008\/revisions\/2021"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=2008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=2008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=2008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}