{"id":100435,"date":"2018-12-07T07:00:00","date_gmt":"2018-12-07T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=100435"},"modified":"2020-09-10T06:55:52","modified_gmt":"2020-09-10T13:55:52","slug":"20181207-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20181207-00\/?p=100435","title":{"rendered":"The case of the buffer overflow vulnerability that was neither a buffer overflow nor a vulnerability"},"content":{"rendered":"<p>A security vulnerability report claimed to have found a buffer overrun. Their instructions were to perform a specific sequence of operations in Explorer while watching the output in the debugger:<\/p>\n<div style=\"position: relative; max-width: 45em; background-color: white; color: #202020;\">\n<pre style=\"white-space: pre-wrap;\">pcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(7) tid(b2c) 80070002 The system cannot find the file specified\r\npcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(8) tid(b2c) 80070002 The system cannot find the file specified\r\npcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(9) tid(b2c) 80070002 The system cannot find the file specified\r\n<\/pre>\n<div style=\"position: absolute; height: 100%; width: 100%; top: 0px; left: 0px; background-image: repeating-linear-gradient(-10deg, gray, transparent 4px, transparent 12px, gray 16px),repeating-linear-gradient(80deg, #c0c0c0, transparent 8px, transparent 24px, #c0c0c0 32px),repeating-linear-gradient(90deg, white, white .2px, transparent .2px, transparent 2px),repeating-linear-gradient(white, white .2px, transparent .2px, transparent 2px);\">\u00a0<\/div>\n<\/div>\n<p>Oh, I forgot to mention that the finder didn&#8217;t copy the text out of the debugger. Nor did they attach a screen shot of the debugger. Nope, they attached a digital photo of their CRT monitor, complete with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Moir%C3%A9_pattern\"> Moir\u00e9 pattern<\/a>.<\/p>\n<p>I&#8217;ll remove the Moir\u00e9 pattern for you from this and all the other screen shots. I&#8217;ll also do the organic OCR\u00b9 and convert it to text. Because I&#8217;m a nice guy that wants his writing to be readable. (Unlike the finder, apparently.)<\/p>\n<div style=\"max-width: 45em;\">\n<pre style=\"white-space: pre-wrap;\">pcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(7) tid(b2c) 80070002 The system cannot find the file specified\r\npcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(8) tid(b2c) 80070002 The system cannot find the file specified\r\npcshell\\<wbr \/>shell\\<wbr \/>explorer\\<wbr \/>something.cpp(80)\\<wbr \/>explorer.exe!<wbr \/>00007FF813D017E2: (caller: 00007FF813CB690C) ReturnHr(9) tid(b2c) 80070002 The system cannot find the file specified\r\n<\/pre>\n<\/div>\n<p>Okay, this is some debug spew that&#8217;s logging a <i>File not found<\/i> error.<\/p>\n<p>The finder, however, didn&#8217;t characterize it as debug spew, but rather described it as &#8220;an exception&#8221;. Their next step was to set a breakpoint on the reported address <code>00007FF813D017E2<\/code> and repeat the scenario, and then when the breakpoint hits, take a stack trace.<\/p>\n<pre>0:002&gt; k\r\n # Child-SP\r\n00 0000009c`aa2ffae0 00007ff8`13cb690c explorer!&lt;lambda_bab32d760b0e6e31&gt;::operator()+0x704c2\r\n01 0000009c`aa2ffb90 00007ff8`13cb5eed explorer!Windows::Internal::ComTaskPool::CThread::_ThreadProc+0x228\r\n02 0000009c`aa2ffc80 00007ff8`13cb5e39 explorer!Windows::Internal::ComTaskPool::CThread::s_ExecuteThreadPr\r\n03 0000009c`aa2ffcd0 00007ff8`91adc774 explorer!Windows::Internal::ComTaskPool::CThread::s_ThreadProc+0x9\r\n04 0000009c`aa2ffd00 00007ff8`91defd51 kernel32!BaseThreadInitThunk+0x14\r\n05 0000009c`aa2ffd30 00000000`00000000 ntdll!RtlUserThreadStart+0x21\r\n<\/pre>\n<p>A little disassembling around the first return address reveals<\/p>\n<pre>00007ff8`13cb6906 ff1557351100 call    qword ptr [explorer!_guard_dispatch_icall_ptr (00007ff8`3cbfe08)]\r\n00007ff8`13cb690c 488b4b50     mov     rcx, qword ptr [rbx+50h]\r\n<\/pre>\n<p>The finder explained that &#8220;the function is <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>, not the <code>lambda_<\/code><code>bab32d...<\/code>. Decompiling the code at <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>, you&#8217;ll see the buffer overflow.&#8221; Here&#8217;s the code in question:<\/p>\n<pre>0:002&gt; u 00007ff8`13cbfe08\r\nexplorer!_guard_dispatch_icall_fptr:\r\n00007ff8`13cbfe08 206388     and     byte ptr [rbx-78h],ah\r\n00007ff8`13cb6e0b 9a         <span style=\"border: solid 1px black;\">???<\/span> \u21d0\r\n<\/pre>\n<p>In the screen shot, they highlighted the second line. And that was the end of their report.<\/p>\n<p>It seems that the finder saw a debug message, and then started fumbling around. They saw that the disassembler printed <code>???<\/code> which they interpreted as a clear sign of a security vulnerability.<\/p>\n<p>But that&#8217;s not what they found.<\/p>\n<p>First of all, the messages that appear on the debugger are some error logging trace messages. They aren&#8217;t exceptions.<\/p>\n<p>Next, the instruction prior to the return address is an indirect call, but they somehow thought this was a label, because they said that the function was misreported by the debugger as <code>lambda_<\/code><code>bab32d...<\/code> when it was actually <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>. Nope, the function really is <code>lambda_<\/code><code>bab32d...<\/code>. What it&#8217;s doing is <i>calling through<\/i> the function pointer <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>.<\/p>\n<p>Next, the finder misread the disassembly. In Intel notation, square brackets around an effective address mean &#8220;the memory stored at this address&#8221;. The <code>call qword ptr [_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr]<\/code> doesn&#8217;t mean &#8220;call the function <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>.&#8221; It means &#8220;read eight bytes from <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code>, treat those eight bytes as a 64-bit value, interpret that value as an address, and call to that address.&#8221; The bytes you see at <code>_guard_<\/code><code>dispatch_<\/code><code>icall_<\/code><code>fptr<\/code> are not code; they are data. Disassembling them as code is meaningless.<\/p>\n<p>So +1 on the finder for resourcefulness and curiosity. But \u22121 for not really understanding what you are doing, \u22121 for not checking your work with a colleague before sending it in, and \u22121 for poor presentation.<\/p>\n<p>\u00b9 In other words, I used my eyeballs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not quite knowing how assembly language works, I guess.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-100435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Not quite knowing how assembly language works, I guess.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=100435"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100435\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=100435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=100435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=100435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}