{"id":1293,"date":"2017-02-09T21:53:31","date_gmt":"2017-02-09T19:53:31","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1293"},"modified":"2017-03-26T15:24:20","modified_gmt":"2017-03-26T13:24:20","slug":"mupdf-use-after-free-in-fz_subsample_pixmap-pixmap-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/02\/09\/mupdf-use-after-free-in-fz_subsample_pixmap-pixmap-c\/","title":{"rendered":"mupdf: use-after-free in fz_subsample_pixmap (pixmap.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/mupdf.com\/\">mupdf<\/a> is a lightweight PDF viewer and toolkit written in portable C.<\/p>\n<p>A fuzzing through mutool revealed a use-after-free. It seems that a fix for the recent <a href=\"https:\/\/bugs.ghostscript.com\/show_bug.cgi?id=697515\">heap overflow in fz_subsample_pixmap<\/a> fixes this issue too.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"> # mutool draw $FILE\r\n==17100==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c00000abb6 at pc 0x7fba6a8cee53 bp 0x7ffedf859700 sp 0x7ffedf8596f8                                                                                                                                       \r\nREAD of size 1 at 0x60c00000abb6 thread T0                                                                                                                                                                                                                                     \r\n    #0 0x7fba6a8cee52 in fz_subsample_pixmap \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/pixmap.c:1210:12                                                                                                                                            \r\n    #1 0x7fba6a8d4dfa in fz_get_pixmap_from_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:686:3                                                                                                                                          \r\n    #2 0x7fba6a88cfae in fz_draw_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/draw-device.c:1292:11                                                                                                                                        \r\n    #3 0x7fba6a7915f8 in fz_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/device.c:319:3                                                                                                                                                    \r\n    #4 0x7fba6a8b6ab4 in fz_run_display_list \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/list-device.c:1651:6                                                                                                                                        \r\n    #5 0x51d503 in drawband \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:562:4                                                                                                                                                              \r\n    #6 0x51b026 in dodrawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:918:6                                                                                                                                                            \r\n    #7 0x51edba in drawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1173:3                                                                                                                                                             \r\n    #8 0x51825b in drawrange \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1190:5                                                                                                                                                            \r\n    #9 0x514aa1 in mudraw_main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1733:7                                                                                                                                                          \r\n    #10 0x50eded in main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mutool.c:110:12                                                                                                                                                                \r\n    #11 0x7fba6973278f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289                                                                                                                                                    \r\n    #12 0x41e1a8 in _init (\/usr\/bin\/mutool+0x41e1a8)                                                                                                                                                                                                                           \r\n                                                                                                                                                                                                                                                                               \r\n0x60c00000abb6 is located 1 bytes to the right of 117-byte region [0x60c00000ab40,0x60c00000abb5)                                                                                                                                                                              \r\nfreed by thread T0 here:                                                                                                                                                                                                                                                       \r\n    #0 0x4d6c10 in free \/tmp\/portage\/sys-devel\/llvm-3.9.1-r1\/work\/llvm-3.9.1.src\/projects\/compiler-rt\/lib\/asan\/asan_malloc_linux.cc:47                                                                                                                                         \r\n    #1 0x7fba6a810878 in fz_free \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/memory.c:187:2                                                                                                                                                          \r\n    #2 0x7fba6a8d0a0c in fz_decomp_image_from_stream \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:330:3                                                                                                                                       \r\n    #3 0x7fba6a8d7cdc in compressed_image_get_pixmap \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:468:10\r\n    #4 0x7fba6a8d4a1f in fz_get_pixmap_from_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:677:9\r\n    #5 0x7fba6a88cfae in fz_draw_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/draw-device.c:1292:11\r\n    #6 0x7fba6a7915f8 in fz_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/device.c:319:3\r\n    #7 0x7fba6a8b6ab4 in fz_run_display_list \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/list-device.c:1651:6\r\n    #8 0x51d503 in drawband \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:562:4\r\n    #9 0x51b026 in dodrawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:918:6\r\n    #10 0x51edba in drawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1173:3\r\n    #11 0x51825b in drawrange \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1190:5\r\n    #12 0x514aa1 in mudraw_main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1733:7\r\n    #13 0x50eded in main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mutool.c:110:12\r\n    #14 0x7fba6973278f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n\r\npreviously allocated by thread T0 here:\r\n    #0 0x4d6f68 in malloc \/tmp\/portage\/sys-devel\/llvm-3.9.1-r1\/work\/llvm-3.9.1.src\/projects\/compiler-rt\/lib\/asan\/asan_malloc_linux.cc:64\r\n    #1 0x7fba6a80c08f in do_scavenging_malloc \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/memory.c:17:7\r\n    #2 0x7fba6a80c08f in fz_malloc_array \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/memory.c:80\r\n    #3 0x7fba6a8cfd40 in fz_decomp_image_from_stream \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:268:13\r\n    #4 0x7fba6a8d7cdc in compressed_image_get_pixmap \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:468:10\r\n    #5 0x7fba6a8d4a1f in fz_get_pixmap_from_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/image.c:677:9\r\n    #6 0x7fba6a88cfae in fz_draw_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/draw-device.c:1292:11\r\n    #7 0x7fba6a7915f8 in fz_fill_image \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/device.c:319:3\r\n    #8 0x7fba6a8b6ab4 in fz_run_display_list \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/list-device.c:1651:6\r\n    #9 0x51d503 in drawband \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:562:4\r\n    #10 0x51b026 in dodrawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:918:6\r\n    #11 0x51edba in drawpage \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1173:3\r\n    #12 0x51825b in drawrange \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1190:5\r\n    #13 0x514aa1 in mudraw_main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mudraw.c:1733:7\r\n    #14 0x50eded in main \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/tools\/mutool.c:110:12\r\n    #15 0x7fba6973278f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n\r\nSUMMARY: AddressSanitizer: heap-use-after-free \/tmp\/portage\/app-text\/mupdf-1.10a\/work\/mupdf-1.10a-source\/source\/fitz\/pixmap.c:1210:12 in fz_subsample_pixmap\r\nShadow bytes around the buggy address:\r\n  0x0c187fff9520: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c187fff9530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c187fff9540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c187fff9550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c187fff9560: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd\r\n=&gt;0x0c187fff9570: fd fd fd fd fd fd[fd]fa fa fa fa fa fa fa fa fa\r\n  0x0c187fff9580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 fa\r\n  0x0c187fff9590: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd\r\n  0x0c187fff95a0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa\r\n  0x0c187fff95b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd\r\n  0x0c187fff95c0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00\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==17100==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n1.10a<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n1.11 (that will be released in march)<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"http:\/\/git.ghostscript.com\/?p=mupdf.git;h=2c4e5867ee699b1081527bc6c6ea0e99a35a5c27\">http:\/\/git.ghostscript.com\/?p=mupdf.git;h=2c4e5867ee699b1081527bc6c6ea0e99a35a5c27<\/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-7264<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00149-mupdf-UAF-fz_subsample_pixmap\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00149-mupdf-UAF-fz_subsample_pixmap<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-02-06: bug discovered and reported to upstream<br \/>\n2017-02-09: upstream released a patch<br \/>\n2017-02-09: blog post about the issue<br \/>\n2017-03-26: 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=\"TfcNyDf2Vl\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/02\/09\/mupdf-use-after-free-in-fz_subsample_pixmap-pixmap-c\/\">mupdf: use-after-free in fz_subsample_pixmap (pixmap.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\/02\/09\/mupdf-use-after-free-in-fz_subsample_pixmap-pixmap-c\/embed\/#?secret=TfcNyDf2Vl\" data-secret=\"TfcNyDf2Vl\" width=\"600\" height=\"338\" title=\"&#8220;mupdf: use-after-free in fz_subsample_pixmap (pixmap.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: mupdf is a lightweight PDF viewer and toolkit written in portable C. A fuzzing through mutool revealed a use-after-free. It seems that a fix for the recent heap overflow in fz_subsample_pixmap fixes this issue too. The complete ASan output: &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/02\/09\/mupdf-use-after-free-in-fz_subsample_pixmap-pixmap-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-kR","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1293"}],"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=1293"}],"version-history":[{"count":8,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1293\/revisions"}],"predecessor-version":[{"id":1526,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1293\/revisions\/1526"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}