Monday, December 26, 2016

NT 4.0, .NET 1.1, and INTLFXSR.SYS problems

Here is the code from a disassembly of INTLFXSR.SYS with symbols:
.text:000102A0 ; __stdcall FxsrGetProcessorFeatures()
.text:000102A0                 public _FxsrGetProcessorFeatures@0
.text:000102A0 _FxsrGetProcessorFeatures@0 proc near   ; CODE XREF: DriverEntry(x,x)+61 p
.text:000102A0                 push    edi
.text:000102A1                 push    esi
.text:000102A2                 push    ebx
.text:000102A3                 pushf
.text:000102A4                 pop     eax
.text:000102A5                 push    eax
.text:000102A6                 mov     ecx, eax
.text:000102A8                 xor     eax, 40000h
.text:000102AD                 push    eax
.text:000102AE                 popf
.text:000102AF                 pushf
.text:000102B0                 pop     eax
.text:000102B1                 cmp     ecx, eax
.text:000102B3                 jz      short cpu_is_i386
.text:000102B5                 mov     eax, ecx
.text:000102B7                 xor     eax, 200000h
.text:000102BC                 push    eax
.text:000102BD                 popf
.text:000102BE                 pushf
.text:000102BF                 pop     eax
.text:000102C0                 cmp     ecx, eax
.text:000102C2                 jz      short other_cpu
.text:000102C4                 mov     eax, 0
.text:000102C9                 cpuid
.text:000102CB                 cmp     eax, 3
.text:000102CE                 jg      short cpu_identified
.text:000102D0                 mov     _VerifyIntel, ebx
.text:000102D6                 mov     dword_106C4, edx
.text:000102DC                 mov     dword_106C8, ecx
.text:000102E2                 lea     esi, _VerifyIntel
.text:000102E8                 lea     edi, _GenuineIntel ; "GenuineIntel"
.text:000102EE                 mov     ecx, 0Ch
.text:000102F3                 repe cmpsb
.text:000102F5                 jnz     short other_cpu
.text:000102F7                 mov     eax, 1
.text:000102FC                 cpuid
.text:000102FE                 mov     eax, edx
.text:00010300                 jmp     short cpu_identified
.text:00010302 ; ---------------------------------------------------------------------------
.text:00010302 other_cpu:                              ; CODE XREF: FxsrGetProcessorFeatures()+22 j
.text:00010302                                         ; FxsrGetProcessorFeatures()+55 j
.text:00010302                 mov     eax, 0
.text:00010307                 jmp     short cpu_identified
.text:00010309 ; ---------------------------------------------------------------------------
.text:00010309 cpu_is_i386:                            ; CODE XREF: FxsrGetProcessorFeatures()+13 j
.text:00010309                 mov     eax, 0
.text:0001030E cpu_identified:                         ; CODE XREF: FxsrGetProcessorFeatures()+2E j
.text:0001030E                                         ; FxsrGetProcessorFeatures()+60 j ...
.text:0001030E                 popf
.text:0001030F                 pop     ebx
.text:00010310                 pop     esi
.text:00010311                 pop     edi
.text:00010312                 retn
.text:00010312 _FxsrGetProcessorFeatures@0 endp
If you know x86 assembly, you will notice that it relies on a GenuineIntel CPU and for CPUID leaf 0 to return a value less than 3.
As for the .NET Framework 1.1 problems, the way to determine if SSE is supported is to first use CPUID to determine if the SSE bit is set. But there is also an extra step. Without CR4.OSFXSR set, SSE instructions will cause #UD. This can be caught on Windows as a SEH exception. My guess is that .NET 1.1 is not doing that, which is why it crashes without INTLFXSR.SYS properly loaded.

Tuesday, June 16, 2015

Why your Core 2 processor appear to not have CMPXCHG16B

From :
"AW67. Enabling PECI via the PECI_CTL MSR Does Not Enable PECI and May Corrupt the CPUID Feature Flags
Problem: Writing PECI_CTL MSR (Platform Environment Control Interface Control Register) will not update the PECI_CTL MSR (5A0H), instead it will write to the VMM Feature Flag Mask MSR (CPUID_FEATURE_MASK1, 478H).
Implication: Due to this erratum, PECI (Platform Environment Control Interface) will not be enabled as expected by the software. In addition, due to this erratum, processor features reported in ECX following execution of leaf 1 of CPUID (EAX=1) may be masked. Software utilizing CPUID leaf 1 to verify processor capabilities may not work as intended.
Workaround: It is possible for the BIOS to contain a workaround for this erratum. Do not initialize PECI before processor update is loaded. Also, load processor update as soon as possible after RESET as documented in the RS – Wolfdale Processor Family Bios Writers Guide, Section 14.8.3 Bootstrap Processor Initialization Requirements. "
The CMPXCHG16B feature flag is one of the flags that is reported in ECX.
This erratum only affects E0/R0 steppings of 45nm Core 2, as you can see in the Summary Table of Changes.
Generally a BIOS update will contain the needed microcode update mentioned above.
For those who have Intel motherboards, from :
"I got fed up and went to Intel on this one.  One of their second level people finally gave me the suggestion that I should again flash the BIOS update, but use the method for full bios refresh, rather than the windows-based update process.  I suspect that the microcode fix referred to in AV69 is in a part of the bios core that is not updated unless you do the full refresh."

Thursday, October 30, 2014

The history of the MS C runtime DLL

In the earliest days, there was the Win32 SDK shipped with the NT betas and the final release of NT 3.1. The CRT DLL was called CRTDLL.DLL.

Visual C++ 1.0 for NT shipped around the time of NT 3.1 release, and it used MSVCRT10.DLL. This was followed by MSVCRT20.DLL (for 2.x) and MSVCRT40.DLL (for 4.0).

Visual C++ 4.2 introduced the now famous MSVCRT.DLL, which was also used by 5.0 and 6.0. The 6.0 MSVCRT had a new heap allocator that exposed bugs in existing apps, forcing MS to issue the Microsoft Libraries Update.

As a result, starting with Win2000 the MSVCRT.DLL was now part of Windows. Future versions of Visual C++ used MSVCR70.DLL etc. For 7.x the DLLs was supposed to go into the application directory. 8.0 and 9.0 used SxS (with the exception of Win2000 and older where it was supposed to be placed in System32, if I remembered correctly). 10.0 abandoned SxS and always used System32, This is also true for 11.0 and 12.0.

14.0 will split the CRT into two parts, one is the version specific vcruntime140.dll etc, and the other is the non version specific backward compatible appcrt.dll and desktopcrt.dll. See MS's blog article for more details.

Tuesday, August 19, 2014

My wishlist for Satya

I originally posted this as a comment on the blog, but I think it is important enough that I posted it here too.
"I agree, but I do have several items on my wishlist for Satya, including ending the Yahoo-Bing and the MS-Novell deal, ending the Android patent attacks, putting an end to the SCO lawsuit,"
"For example, the MS-Novell deal is so bad that FSF put a provision in GPLv3 against it. I don’t know how much power MS has right now to end the SCO lawsuit, but it was quite famous. So is the FAT/exFAT patents and how it has been used to attack Android and other things that uses them (I am thinking that existing patents should go to the public domain and any remaining exFAT patent applications withdrawn from USPTO if possible)."
If you don't remember, the patent part of the Microsoft-Novell deal was discriminatory, which means that it was limited to specific customers. The point of free software, including licenses like the GPL, is that it allows free distribution of software without any royalty based patent licensing requirements. This is why the GPLv3 had a provision against it. Another problem is the $100 million worth of vouchers, to get customers to buy SUSE. Why should MS help a competitor like this? This deal was renewed in 2011 for four years, and it still have the same problems. Since then Novell has abandoned Mono, making the deal less valuable for MS than it was before.
Also, the FAT patents are not the only patents MS used to attack Android, and ChromeOS is also attacked using similar patents. Most of these patent attacks are based on FUD.
"And I forgot to mention OOXML. I just realized that Office for Windows don’t use the “Open XML” term that much inside the software. I am thinking of a proposal where the standard would be withdrawn from ISO, the “Office Open XML” term would be depreciated, and the “Strict Open XML” option would be removed (I doubt it is catching on). Note this don’t change the file format itself in anyway, the contents of the ISO standard would be merged with MS-DOCX/XLSX/PPTX."

Friday, December 20, 2013

MS12-034, keyboard layouts‏, and a bug

I have reverse engineered this patch and its effects on keyboard layouts a bit. The patch works by shipping a new version of win32k for XP and Server 2003 that pay attention to a registry key. When this registry key is added, it restricts loading of keyboard layouts to the System32 folder (already done in Vista and later). This prevents further exploits on the keyboard layout loading code. This is the first part shipped in KB2676562.

The second part is a patch (KB2686509) that adds this registry key. Before this registry key is added, a DLL called kblchecker.dll is loaded that is shipped inside the patch. This DLL is supposed to enumerate all the keyboard layouts on the system and make sure they are all in the system32 folder because any other keyboard layout DLL is going to be disabled by this update. What I found out by black box testing this patch is that any registry key value (not subkeys or any value inside a subkey) in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboard Layout key regardless of name is going to make this check fail with no FaultyKeyboards.log being created, which looks like a bug. The reason MS is not fixing this bug is probably because all it does is makes the installation of this patch fail.

Tuesday, August 27, 2013

Petition to MS regarding old PowerPoint translators

Word formats dating to Word 1.x for Windows and Word 4.x for Macintosh and Excel formats dating to version 2.x (with exception of Microsoft Excel Chart (.xlc)) can be opened by changing File Block policy even in Office 2013 for Windows. Old PowerPoint formats however required separate translators. These translators was shipped with PowerPoint 2003 and earlier (though disabled by default in SP3), but no longer ships with 2007 or later. The name of these translator DLLs are PP4X322.DLL (for PowerPoint 4.0 and older) and PP7X32.DLL (for PowerPoint 95).

We ask MS to:
  1. Ship these DLLs separately from PowerPoint 2003 along with a utility to call them, to provide users with a way to read these old formats.
  2. Consider opening the source to the translators. This will save MS the work of documenting these old formats.

Sunday, July 14, 2013

How I found CVE-2013-1310 in IE6 and IE7

"Now, when such a .ipsum construct gains "layout" by a subset of layout properties (position: absolute; / float: any value; / display: inline-block; / zoom: 1;), what will happen? Right. Some will have to cancel the frozen process, others will have to reboot, data gets lost. Don't do it. (No, I don't link to a testcase here. IE7b3 is still crashing after scrolling/resizing. Depending on the memory already burned, you might have difficulties to stop the process...)"

I created this test manually (save and add zoom: 1 to .ipsum) and not only this bug is still in final IE7, I also noticed that there is also a potentially exploitable crash bug by opening the about box after opening this page. When this happens, it crashes with EIP at an invalid address.

After this, by adding onclick="window.showModalDialog('target.htm')" to <p class="ipsum">, creating the target.htm, then opening the page and clicking inside the box, I triggered various crashes including attempts at executing data (note that IE7 do not enable DEP by default) and heap termination on corruption.

I turned full pageheap on and after I did so it crashes reliably at:

(360.51c): Access violation - code c0000005 (first/second chance not available)
eax=00000004 ebx=08042e78 ecx=0000000a edx=065acfa0 esi=08042e78 edi=065289c0
eip=3ceff096 esp=04d04ba8 ebp=04d04bf8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
3ceff096 f3a5 rep movs dword ptr es:[edi],dword ptr [esi]

MS fixed this bug in the May 2013 Cumulative Update for IE6 and IE7.
Here is rendered in IE6 and IE7 before the patch:

After the patch (notice it is the same rendering as IE8+ in IE7 compat mode):