{"id":1655,"date":"2017-04-17T19:33:56","date_gmt":"2017-04-17T17:33:56","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1655"},"modified":"2017-04-23T12:40:54","modified_gmt":"2017-04-23T10:40:54","slug":"libcroco-heap-overflow-and-undefined-behavior","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/17\/libcroco-heap-overflow-and-undefined-behavior\/","title":{"rendered":"libcroco: heap overflow and undefined behavior"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"https:\/\/git.gnome.org\/browse\/libcroco\/\">libcroco<\/a> is a Generic Cascading Style Sheet (CSS) parsing and manipulation toolkit.<\/p>\n<p>A fuzz on it discovered and heap overflow and an undefined behavior.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># csslint-0.6 $FILE\r\n==9246==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400000007a at pc 0x7f3771a05074 bp 0x7fff426076a0 sp 0x7fff42607698                                                                          \r\nREAD of size 1 at 0x60400000007a thread T0                                                                                                                                                                        \r\n    #0 0x7f3771a05073 in cr_input_read_byte \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-input.c:416:19                                                                                      \r\n    #1 0x7f3771a3c0ba in cr_tknzr_parse_rgb \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-tknzr.c:1295:17                                                                                     \r\n    #2 0x7f3771a3c0ba in cr_tknzr_get_next_token \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-tknzr.c:2127                                                                                   \r\n    #3 0x7f3771ab6688 in cr_parser_parse_any_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:1179:18                                                                              \r\n    #4 0x7f3771ab6c1e in cr_parser_parse_any_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:1215:34                                                                              \r\n    #5 0x7f3771ab6c1e in cr_parser_parse_any_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:1215:34                                                                              \r\n    #6 0x7f3771ab6c1e in cr_parser_parse_any_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:1215:34                                                                              \r\n    #7 0x7f3771ab9579 in cr_parser_parse_block_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:1005:26                                                                            \r\n    #8 0x7f3771a8882a in cr_parser_parse_atrule_core \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:798:26                                                                            \r\n    #9 0x7f3771ab0644 in cr_parser_parse_stylesheet \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c                                                                                    \r\n    #10 0x7f3771a8131e in cr_parser_parse \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:4381:26                                                                                      \r\n    #11 0x7f3771a804f1 in cr_parser_parse_file \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:2993:18                                                                                 \r\n    #12 0x7f3771b04869 in cr_om_parser_parse_file \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-om-parser.c:956:18                                                                            \r\n    #13 0x51506f in cssom_parse \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/csslint\/csslint.c:252:18                                                                                               \r\n    #14 0x51506f in main \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/csslint\/csslint.c:997                                                                                                         \r\n    #15 0x7f377041b78f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289                                                                                       \r\n    #16 0x41a9b8 in _init (\/usr\/bin\/csslint-0.6+0x41a9b8)\r\n\r\n0x60400000007a is located 0 bytes to the right of 42-byte region \r\n[0x604000000050,0x60400000007a)\r\nallocated by thread T0 here:\r\n    #0 0x4da285 in calloc \/tmp\/portage\/sys-libs\/compiler-rt-sanitizers-4.0.0\/work\/compiler-rt-4.0.0.src\/lib\/asan\/asan_malloc_linux.cc:74\r\n    #1 0x7f377168a1a0 in g_malloc0 \/tmp\/portage\/dev-libs\/glib-2.48.2\/work\/glib-2.48.2\/glib\/gmem.c:124\r\n    #2 0x7f3771a00c4d in cr_input_new_from_buf \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-input.c:151:26\r\n    #3 0x7f3771a027d6 in cr_input_new_from_uri \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-input.c:251:26\r\n    #4 0x7f3771a22797 in cr_tknzr_new_from_uri \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-tknzr.c:1642:17\r\n    #5 0x7f3771a8047c in cr_parser_parse_file \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-parser.c:2986:17\r\n    #6 0x7f3771b04869 in cr_om_parser_parse_file \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-om-parser.c:956:18\r\n    #7 0x51506f in cssom_parse \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/csslint\/csslint.c:252:18\r\n    #8 0x51506f in main \/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/csslint\/csslint.c:997\r\n    #9 0x7f377041b78f 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\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-input.c:416:19 in cr_input_read_byte\r\nShadow bytes around the buggy address:\r\n  0x0c087fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c087fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c087fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c087fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c087fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n=&gt;0x0c087fff8000: fa fa 00 00 00 00 00 fa fa fa 00 00 00 00 00[02]\r\n  0x0c087fff8010: fa fa 00 00 00 00 00 00 fa fa fa fa fa fa fa fa\r\n  0x0c087fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c087fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c087fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c087fff8050: 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==9246==ABORTING\r\n<\/font><\/pre>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/git.gnome.org\/browse\/libcroco\/commit\/?id=898e3a8c8c0314d2e6b106809a8e3e93cf9d4394\">https:\/\/git.gnome.org\/browse\/libcroco\/commit\/?id=898e3a8c8c0314d2e6b106809a8e3e93cf9d4394<\/a><br \/>\n<strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00267-libcroco-heapoverflow-cr_input_read_byte\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00267-libcroco-heapoverflow-cr_input_read_byte<\/a><br \/>\n<strong>CVE:<\/strong><br \/>\nCVE-2017-7960<\/p>\n<p>#####################################<\/p>\n<pre><font size=\"2\"># csslint-0.6 $FILE\r\n\/tmp\/portage\/dev-libs\/libcroco-0.6.12\/work\/libcroco-0.6.12\/src\/cr-tknzr.c:1283:15: runtime error: value 9.11111e+19 is outside the range of representable values of type 'long'\r\n<\/font><\/pre>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/git.gnome.org\/browse\/libcroco\/commit\/?id=9ad72875e9f08e4c519ef63d44cdbd94aa9504f7\">https:\/\/git.gnome.org\/browse\/libcroco\/commit\/?id=9ad72875e9f08e4c519ef63d44cdbd94aa9504f7<\/a><br \/>\n<strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00268-libcroco-outside-long\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00268-libcroco-outside-long<\/a><br \/>\n<strong>CVE:<\/strong><br \/>\nCVE-2017-7961<\/p>\n<p><strong>Affected version:<\/strong><br \/>\n0.6.11 and 0.6.12<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n0.6.13 (not released atm)<\/p>\n<p><strong>Credit:<\/strong><br \/>\nThese bugs were discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-04-12: bugs discovered and reported to upstream<br \/>\n2017-04-16: upstream released a patch<br \/>\n2017-04-17: blog post about the issues<br \/>\n2017-04-19: CVE assigned<\/p>\n<p><strong>Note:<\/strong><br \/>\nThese bugs were found with <a href=\"http:\/\/lcamtuf.coredump.cx\/afl\">American Fuzzy Lop<\/a>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"Szrvqoq55D\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/04\/17\/libcroco-heap-overflow-and-undefined-behavior\/\">libcroco: heap overflow and undefined behavior<\/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\/17\/libcroco-heap-overflow-and-undefined-behavior\/embed\/#?secret=Szrvqoq55D\" data-secret=\"Szrvqoq55D\" width=\"600\" height=\"338\" title=\"&#8220;libcroco: heap overflow and undefined behavior&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: libcroco is a Generic Cascading Style Sheet (CSS) parsing and manipulation toolkit. A fuzz on it discovered and heap overflow and an undefined behavior. The complete ASan output: # csslint-0.6 $FILE ==9246==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400000007a at pc &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/17\/libcroco-heap-overflow-and-undefined-behavior\/\">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-qH","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1655"}],"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=1655"}],"version-history":[{"count":4,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1655\/revisions"}],"predecessor-version":[{"id":1664,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1655\/revisions\/1664"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}