{"id":1492,"date":"2017-03-20T12:12:39","date_gmt":"2017-03-20T10:12:39","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1492"},"modified":"2017-03-20T12:41:21","modified_gmt":"2017-03-20T10:41:21","slug":"libpcre-heap-based-bufffer-overflow-in-regexflip8_or_16-pcretest-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/20\/libpcre-heap-based-bufffer-overflow-in-regexflip8_or_16-pcretest-c\/","title":{"rendered":"libpcre: heap-based buffer overflow in regexflip8_or_16 (pcretest.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.pcre.org\">libpcre<\/a> is a perl-compatible regular expression library.<\/p>\n<p>A fuzz on libpcre1 through the pcretest utility revealed an heap overflow in the utility itself. Will follow a feedback from upstream.<\/p>\n<blockquote><p>I am not going to do anything about this one. (a) It is concerned with a feature of pcretest that has been dropped from pcre2test, and (b) the input contains binary zeros, which are not supported in pcretest input. This is documented for pcre2test but not, I see for pcretest. I have added a paragraph to the documentation.<\/p><\/blockquote>\n<p>However, it does not cost much for me inform the community that this bug exists.<br \/>\nIn any case, if you have a web application that calls directly the pcretest utility to parse untrusted data, then you are affected.<br \/>\nAlso, it is important share the details because some distros\/packagers may want to patch this issue instead of follow the upstream&#8217;s way.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># pcretest -16 -d $FILE\r\n==30352==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60b00000b000 at pc 0x00000053cef0 bp 0x7ffd02dccb90 sp 0x7ffd02dccb88\r\nREAD of size 2 at 0x60b00000b000 thread T0\r\n    #0 0x53ceef in regexflip8_or_16 \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:2552:24\r\n    #1 0x53ceef in regexflip \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:2792\r\n    #2 0x53ceef in main \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:4425\r\n    #3 0x7fb6693d678f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n    #4 0x41b438 in _init (\/usr\/bin\/pcretest+0x41b438)\r\n\r\n0x60b00000b000 is located 0 bytes to the right of 112-byte region [0x60b00000af90,0x60b00000b000)\r\nallocated by thread T0 here:\r\n    #0 0x4d41f8 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 0x53e883 in new_malloc \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:2372:15\r\n    #2 0x7fb66a9473a1 in pcre16_compile2 \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcre_compile.c:9393:19\r\n    #3 0x5335d9 in main \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:4034:5\r\n    #4 0x7fb6693d678f 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-buffer-overflow \/tmp\/portage\/dev-libs\/libpcre-8.40\/work\/pcre-8.40\/pcretest.c:2552:24 in regexflip8_or_16\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n8.40<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\nN\/A<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\nN\/A<\/p>\n<p><strong>Credit:<\/strong><br \/>\nThis bug was discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00196-pcre-heapoverflow-regexflip8_or_16\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00196-pcre-heapoverflow-regexflip8_or_16<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-02-22: bug discovered and reported to upstream<br \/>\n2017-03-20: blog post about the issue<\/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=\"fwkSjDsi7p\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/03\/20\/libpcre-heap-based-bufffer-overflow-in-regexflip8_or_16-pcretest-c\/\">libpcre: heap-based bufffer overflow in regexflip8_or_16 (pcretest.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\/03\/20\/libpcre-heap-based-bufffer-overflow-in-regexflip8_or_16-pcretest-c\/embed\/#?secret=fwkSjDsi7p\" data-secret=\"fwkSjDsi7p\" width=\"600\" height=\"338\" title=\"&#8220;libpcre: heap-based bufffer overflow in regexflip8_or_16 (pcretest.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: libpcre is a perl-compatible regular expression library. A fuzz on libpcre1 through the pcretest utility revealed an heap overflow in the utility itself. Will follow a feedback from upstream. I am not going to do anything about this one. &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/20\/libpcre-heap-based-bufffer-overflow-in-regexflip8_or_16-pcretest-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-o4","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1492"}],"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=1492"}],"version-history":[{"count":3,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1492\/revisions"}],"predecessor-version":[{"id":1499,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1492\/revisions\/1499"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}