{"id":1640,"date":"2017-04-11T13:50:03","date_gmt":"2017-04-11T11:50:03","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1640"},"modified":"2017-04-13T09:23:36","modified_gmt":"2017-04-13T07:23:36","slug":"libsndfile-invalid-memory-read-and-invalid-memory-write-in","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/11\/libsndfile-invalid-memory-read-and-invalid-memory-write-in\/","title":{"rendered":"libsndfile: invalid memory READ and invalid memory WRITE in flac_buffer_copy (flac.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.mega-nerd.com\/libsndfile\">libsndfile<\/a> is a C library for reading and writing files containing sampled sound.<\/p>\n<p>A fuzz via the sndfile-resample command-line tool of libsamplerate, discovered and invalid memory read and an invalid memory write. The upstream author Erik de Castro Lopo (erikd) said that they was fixed in the recent commit 60b234301adf258786d8b90be5c1d437fc8799e0 which addresses CVE-2017-7585. As usual I&#8217;m providing the stacktrace and the reproducer so that all release distros can test and check if their version is affected or not.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># sndfile-resample -to 24000 -c 1 $FILE out\r\n==959==ERROR: AddressSanitizer: SEGV on unknown address 0x0000013cc000 (pc 0x7fc1ba91251c bp 0x60e000000040 sp 0x7fff95597f70 T0)\r\n==959==The signal is caused by a WRITE memory access.\r\n    #0 0x7fc1ba91251b in flac_buffer_copy \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:264\r\n    #1 0x7fc1ba913404 in flac_read_loop \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:884\r\n    #2 0x7fc1ba913505 in flac_read_flac2f \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:949\r\n    #3 0x7fc1ba907a49 in sf_readf_float \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/sndfile.c:1870\r\n    #4 0x5135c5 in sample_rate_convert \/tmp\/portage\/media-libs\/libsamplerate-0.1.8-r1\/work\/libsamplerate-0.1.8\/examples\/sndfile-resample.c:213:29\r\n    #5 0x5135c5 in main \/tmp\/portage\/media-libs\/libsamplerate-0.1.8-r1\/work\/libsamplerate-0.1.8\/examples\/sndfile-resample.c:163\r\n    #6 0x7fc1b9a4178f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n    #7 0x419f88 in _init (\/usr\/bin\/sndfile-resample+0x419f88)\r\n\r\nAddressSanitizer can not provide additional info.\r\nSUMMARY: AddressSanitizer: SEGV \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:264 in flac_buffer_copy\r\n==959==ABORTING\r\n<\/font><\/pre>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00261-libsndfile-invalidwrite-flac_buffer_copy\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00261-libsndfile-invalidwrite-flac_buffer_copy<\/a><br \/>\n<strong>CVE:<\/strong><br \/>\nCVE-2017-7741<\/p>\n<p>#################<\/p>\n<pre><font size=\"2\"># sndfile-resample -to 24000 -c 1 $FILE out\r\n==32533==ERROR: AddressSanitizer: SEGV on unknown address 0x000000004000 (pc 0x7f576a5e8512 bp 0x60e000000040 sp 0x7ffeab4e66d0 T0)\r\n==32533==The signal is caused by a READ memory access.\r\n    #0 0x7f576a5e8511 in flac_buffer_copy \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:263\r\n    #1 0x7f576a5e9404 in flac_read_loop \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:884\r\n    #2 0x7f576a5e9505 in flac_read_flac2f \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:949\r\n    #3 0x7f576a5dda49 in sf_readf_float \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/sndfile.c:1870\r\n    #4 0x5135c5 in sample_rate_convert \/tmp\/portage\/media-libs\/libsamplerate-0.1.8-r1\/work\/libsamplerate-0.1.8\/examples\/sndfile-resample.c:213:29\r\n    #5 0x5135c5 in main \/tmp\/portage\/media-libs\/libsamplerate-0.1.8-r1\/work\/libsamplerate-0.1.8\/examples\/sndfile-resample.c:163\r\n    #6 0x7f576971778f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n    #7 0x419f88 in _init (\/usr\/bin\/sndfile-resample+0x419f88)\r\n\r\nAddressSanitizer can not provide additional info.\r\nSUMMARY: AddressSanitizer: SEGV \/tmp\/portage\/media-libs\/libsndfile-1.0.27-r1\/work\/libsndfile-1.0.27\/src\/flac.c:263 in flac_buffer_copy\r\n==32533==ABORTING\r\n<\/font><\/pre>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00260-libsndfile-invalidread-flac_buffer_copy\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00260-libsndfile-invalidread-flac_buffer_copy<\/a><br \/>\n<strong>CVE:<\/strong><br \/>\nCVE-2017-7742<\/p>\n<p><strong>Affected version:<\/strong><br \/>\n1.0.27<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n1.0.28<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/erikd\/libsndfile\/commit\/60b234301adf258786d8b90be5c1d437fc8799e0\">https:\/\/github.com\/erikd\/libsndfile\/commit\/60b234301adf258786d8b90be5c1d437fc8799e0<\/a><\/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-11: bugs discovered and reported to upstream<br \/>\n2017-04-11: blog post about the issues<br \/>\n2017-04-12: 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=\"FMz32HUKEW\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/04\/11\/libsndfile-invalid-memory-read-and-invalid-memory-write-in\/\">libsndfile: invalid memory READ and invalid memory WRITE in flac_buffer_copy (flac.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\/04\/11\/libsndfile-invalid-memory-read-and-invalid-memory-write-in\/embed\/#?secret=FMz32HUKEW\" data-secret=\"FMz32HUKEW\" width=\"600\" height=\"338\" title=\"&#8220;libsndfile: invalid memory READ and invalid memory WRITE in flac_buffer_copy (flac.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: libsndfile is a C library for reading and writing files containing sampled sound. A fuzz via the sndfile-resample command-line tool of libsamplerate, discovered and invalid memory read and an invalid memory write. The upstream author Erik de Castro Lopo &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/04\/11\/libsndfile-invalid-memory-read-and-invalid-memory-write-in\/\">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-qs","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1640"}],"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=1640"}],"version-history":[{"count":7,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1640\/revisions"}],"predecessor-version":[{"id":1650,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1640\/revisions\/1650"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}