exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

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
SHA-256 | 9b0a218fd882e743c80327592b205f6e39c6228c5a3712d6268189b601f7b6cc

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

Login or Register to add favorites

File Archive:

March 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close