Exploit the possiblities

Windows Kernel Pool nt!RtlpCopyLegacyContextX86 Memory Disclosure

Windows Kernel Pool nt!RtlpCopyLegacyContextX86 Memory Disclosure
Posted Oct 16, 2017
Authored by Google Security Research, mjurczyk

The Microsoft Windows kernel pool suffers from a nt!RtlpCopyLegacyContextX86 related memory disclosure vulnerability.

tags | advisory, kernel
systems | windows
advisories | CVE-2017-11784
MD5 | e7fc69388cdf09d854702265504b52eb

Windows Kernel Pool nt!RtlpCopyLegacyContextX86 Memory Disclosure

Change Mirror Download
Windows Kernel pool memory disclosure in nt!RtlpCopyLegacyContextX86

CVE-2017-11784


One kernel memory disclosure in the exception handling code has already been discovered and reported as Windows Kernel stack memory disclosure in exception handling (nt!KiDispatchException) issue #1177. It was fixed in the June Patch Tuesday as CVE-2017-8482. However, it seems there is another bug in this code area, this time a pool (as opposed to stack) memory leak. We've had some trouble reproducing this behavior outside of our Bochs setup, but we have performed some analysis to better understand the root cause of the bug. The analysis, specific to Windows 7 32-bit, is presented below.

The leak occurs in the nt!RtlpCopyLegacyContextX86 routine, under the following stack trace:

--- cut ---
#1 nt!RtlpCopyLegacyContextX86
#2 nt!RtlpCopyLegacyContext
#3 nt!RtlpCopyExtendedContext
[...]
--- cut ---

It does not matter if the nt!RtlpCopyExtendedContext function is reached through a user-mode exception, a soft exception triggered manually with RaiseException(), or a GetThreadContext() call -- we have seen the disclosure take place in all three cases. An example of a full callstack is as follows:

--- cut ---
#1 nt!RtlpCopyLegacyContextX86
#2 nt!RtlpCopyLegacyContext
#3 nt!RtlpCopyExtendedContext
#4 nt!KiDispatchException
#5 nt!KiRaiseException
#6 nt!NtRaiseException
#7 nt!KiSystemServicePostCall
--- cut ---

More precisely, the leak happens inside of an inlined memcpy() call, while copying 512 bytes corresponding to the CONTEXT.ExtendedRegisters field to userland. The construct can be represented as the following C code:

--- cut ---
if ( (ContextFlags & CONTEXT_EXTENDED_REGISTERS) == CONTEXT_EXTENDED_REGISTERS )
memcpy(DestContext->ExtendedRegisters, SourceContext->ExtendedRegisters, sizeof(DestContext->ExtendedRegisters));
--- cut ---

Within that memory region, 192 (0xC0) bytes at offset 0x120 (or offset 0x1EC in relation to the start of the CONTEXT structure) are uninitialized pool memory bytes, originating from an allocation made in nt!KeAllocateXStateContext:

--- cut ---
.text:0048B8DE push 76615358h ; Tag
.text:0048B8E3 add eax, 40h
.text:0048B8E6 push eax ; NumberOfBytes
.text:0048B8E7 push 0 ; PoolType
.text:0048B8E9 call _ExAllocatePoolWithTag@12 ; ExAllocatePoolWithTag(x,x,x)
--- cut ---

The memory appears to be allocated for an XSAVE_AREA structure, which has the following definition:

--- cut ---
kd> dt _XSAVE_AREA /r
ntdll!_XSAVE_AREA
+0x000 LegacyState : _XSAVE_FORMAT
+0x000 ControlWord : Uint2B
+0x002 StatusWord : Uint2B
+0x004 TagWord : UChar
+0x005 Reserved1 : UChar
+0x006 ErrorOpcode : Uint2B
+0x008 ErrorOffset : Uint4B
+0x00c ErrorSelector : Uint2B
+0x00e Reserved2 : Uint2B
+0x010 DataOffset : Uint4B
+0x014 DataSelector : Uint2B
+0x016 Reserved3 : Uint2B
+0x018 MxCsr : Uint4B
+0x01c MxCsr_Mask : Uint4B
+0x020 FloatRegisters : [8] _M128A
+0x000 Low : Uint8B
+0x008 High : Int8B
+0x0a0 XmmRegisters : [8] _M128A
+0x000 Low : Uint8B
+0x008 High : Int8B
+0x120 Reserved4 : [192] UChar
+0x1e0 StackControl : [7] Uint4B
+0x1fc Cr0NpxState : Uint4B
+0x200 Header : _XSAVE_AREA_HEADER
+0x000 Mask : Uint8B
+0x008 Reserved : [7] Uint8B
--- cut ---

As is clearly visible, offset 0x120 of the structure is aligned with the "Reserved4" field consisting of 192 bytes, which is exactly how many uninitialized bytes we're observing in the leak. This suggests that the NPX context saved in XSAVE_AREA contains leftover pool bytes, which may be then copied to user-mode when a thread context with the CONTEXT_EXTENDED_REGISTERS flag is requested by a malicious, local process.

Repeatedly triggering the vulnerability could allow local authenticated attackers to defeat certain exploit mitigations (kernel ASLR) or read other secrets stored in the kernel address space.

This bug is subject to a 90 day disclosure deadline. After 90 days elapse or a patch has been made broadly available, the bug report will become visible to the public.



Found by: mjurczyk

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

November 2017

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    22 Files
  • 2
    Nov 2nd
    28 Files
  • 3
    Nov 3rd
    10 Files
  • 4
    Nov 4th
    1 Files
  • 5
    Nov 5th
    5 Files
  • 6
    Nov 6th
    15 Files
  • 7
    Nov 7th
    15 Files
  • 8
    Nov 8th
    13 Files
  • 9
    Nov 9th
    9 Files
  • 10
    Nov 10th
    9 Files
  • 11
    Nov 11th
    3 Files
  • 12
    Nov 12th
    2 Files
  • 13
    Nov 13th
    15 Files
  • 14
    Nov 14th
    17 Files
  • 15
    Nov 15th
    19 Files
  • 16
    Nov 16th
    15 Files
  • 17
    Nov 17th
    19 Files
  • 18
    Nov 18th
    4 Files
  • 19
    Nov 19th
    2 Files
  • 20
    Nov 20th
    9 Files
  • 21
    Nov 21st
    15 Files
  • 22
    Nov 22nd
    23 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2016 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close