オンサイトセミナー
豊田孝の「IT談話館」 Windowsメモリダンプ解析を依頼する WinDbgとシステム分析




 本「IT談話館」一般公開記事は、10年以上の実務経験を持つ上級Windowsエンジニアを想定しています。
 本館は、Windowsカーネル深層を解析し、クラッシュ原因をはじめとするシステム内の「異様な動き」を検出・分析する
超高度な技術と実績を保有しています。



WinDbgとWindows 10システムサービス呼び出しの変遷と解析


 本「IT談話館」の「一般公開記事」は、「Active Memory Dump とカーネルメモリダンプ」の解析結果を基に起草されています。公開内容はあくまでも本館ビジネスに支障の出ない範囲に制限されていますが、Windowsビジネスを展開する上で必要となる、新規「商材」の発掘や同業他社との「差異」を確保し、人材と予算をはじめとする所有資源を適切に配置・投資する一助にはなるかもしれません。本「IT談話館」主筆の「豊田孝」はDKOM(Direct Kernel Object Manipulation)ベースの解析手法の第一人者であり、Windowsカーネル空間の解析分野では世界の先頭を走っています。

 現在、セキュリティー問題を無視することはできません。Microsoft社側の負担だけではなく、同社製品の利用者側の負担も増しています。困ったことではありますが、当面避けられません。セキュリティーの視点から「Windows10ソフトウェアセンサー」を見た場合、本「IT談話館」の確認範囲では、「カーネル層保護ロジック」に加え、次のような保護メカニズム階層が考案・実装されています。下記リンクはすべて本館記事を指しています。
  1. Silo/Server Silo
  2. Job
  3. Session
  4. Protected Process
  5. Mandatory Integrity Control(MIC)
  6. Windows API(+CPU)
  7. CPU
 本稿では、Windows 10環境で採取した3種類の「Active Memory Dump」を本「IT談話館」の独自解析コードで解析し、システムサービス呼び出しレベルの内部変遷を調査します。本稿末では、得られた調査結果と「Meltdown and Spectre」問題発生後のパッチ当てカーネル内部とを比較しています。なお、解析コードの開発知識の習得には、「時間と予算の投資」が必要です。

 Windows 10と一口にいいましても、ビルド番号やパッチ適応毎に、たとえば、次のようにカーネル内部が変更されています。
0: kd> vertarget
Windows 10 Kernel Version 10240 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 10240.16393.amd64fre.th1_st1.150717-1719
Machine Name:
Kernel base = 0xfffff803`15415000 PsLoadedModuleList = 0xfffff803`1573a030
Debug session time: Tue Aug  4 11:21:22.658 2015 (UTC + 9:00)
System Uptime: 0 days 18:04:16.257

ntdll!NtDeviceIoControlFile:
00007ffc`b04d3560 4c8bd1          mov     r10,rcx
00007ffc`b04d3563 b807000000      mov     eax,7
00007ffc`b04d3568 0f05            syscall
00007ffc`b04d356a c3              ret
1: kd> vertarget
Windows 10 Kernel Version 14393 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 14393.103.amd64fre.rs1_release_inmarket.160819-1924
Machine Name:
Kernel base = 0xfffff800`e6e7e000 PsLoadedModuleList = 0xfffff800`e71830a0
Debug session time: Sat Sep 17 04:18:01.076 2016 (UTC + 9:00)
System Uptime: 2 days 16:42:08.801

1: kd> uf ntdll!NtDeviceIoControlFile
ntdll!NtDeviceIoControlFile:
00007ffe`61304f20 4c8bd1          mov     r10,rcx
00007ffe`61304f23 b807000000      mov     eax,7
00007ffe`61304f28 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007ffe`61304f30 7503            jne     ntdll!NtDeviceIoControlFile+0x15 (00007ffe`61304f35)  Branch

ntdll!NtDeviceIoControlFile+0x12:
00007ffe`61304f32 0f05            syscall
00007ffe`61304f34 c3              ret

ntdll!NtDeviceIoControlFile+0x15:
00007ffe`61304f35 cd2e            int     2Eh
00007ffe`61304f37 c3              ret
1: kd> vertarget
Windows 10 Kernel Version 15063 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 15063.0.amd64fre.rs2_release.170317-1834
Machine Name:
Kernel base = 0xfffff803`52406000 PsLoadedModuleList = 0xfffff803`527525a0
Debug session time: Tue Jun 27 15:39:26.892 2017 (UTC + 9:00)
System Uptime: 12 days 7:17:40.907

1: kd> uf ntdll!NtDeviceIoControlFile
ntdll!NtDeviceIoControlFile:
00007ffb`92ca5480 4c8bd1          mov     r10,rcx
00007ffb`92ca5483 b807000000      mov     eax,7
00007ffb`92ca5488 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007ffb`92ca5490 7503            jne     ntdll!NtDeviceIoControlFile+0x15 (00007ffb`92ca5495)  Branch

ntdll!NtDeviceIoControlFile+0x12:
00007ffb`92ca5492 0f05            syscall
00007ffb`92ca5494 c3              ret

ntdll!NtDeviceIoControlFile+0x15:
00007ffb`92ca5495 cd2e            int     2Eh
00007ffb`92ca5497 c3              ret
 これら一連の情報はシステムサービス呼び出しの実装背景とバージョン間の遷移を示しており、比較的新しいWindows 10内部では、実際の呼び出し動作に入る直前に、呼び出し要求が「ユーザー空間からの正当な要求」かどうかを判定しています。つまり、正常なシステム呼び出しシーケンスをチェックし、関数レベルでシステムセキュリティーを向上させようとする意向が示されています。

 古いWindows 10では、「ユーザー空間からの要求」と認められない場合、いずれも割り込み「2E」を発生させることになっています。この割り込み「2E」は、次のようなWinDbgコマンドを実行することにより、その概要を把握することができます。
1: kd> vertarget
Windows 10 Kernel Version 15063 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 15063.0.amd64fre.rs2_release.170317-1834
Machine Name:
Kernel base = 0xfffff803`52406000 PsLoadedModuleList = 0xfffff803`527525a0
Debug session time: Tue Jun 27 15:39:26.892 2017 (UTC + 9:00)
System Uptime: 12 days 7:17:40.907
1: kd> !idt 0x2e

Dumping IDT: ffff9f8140dfc000

1: kd> !idt 0x2f

Dumping IDT: ffff9f8140dfc000

2f:	fffff80352575b00 nt!KiDpcInterrupt
 ご覧のように、割り込み「2E」は対応するハンドラーを持っていません。念のために本「IT談話館」の独自解析コードを実行してみると、割り込み「2E」は確かに割り込みハンドラーを持たないことを確認できます。ただし、古いWindows 10では、次のように、異なるThunkロジックが実装されています。
1: kd> vertarget
Windows 10 Kernel Version 14393 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 14393.103.amd64fre.rs1_release_inmarket.160819-1924
Machine Name:
Kernel base = 0xfffff800`e6e7e000 PsLoadedModuleList = 0xfffff800`e71830a0
Debug session time: Sat Sep 17 04:18:01.076 2016 (UTC + 9:00)
System Uptime: 2 days 16:42:08.801

-No.2C	Trap->0xFFFFF800E6FD2580	nt!KiRaiseAssertion (fffff800`e6fd2580)
-No.2D	Trap->0xFFFFF800E6FD2680	nt!KiDebugServiceTrap (fffff800`e6fd2680)
+No.2E	Thunk->0xFFFFF800E6FCA300	---
-No.2F	Trap->0xFFFFF800E6FCB7C0	nt!KiDpcInterrupt (fffff800`e6fcb7c0)
-No.30	Trap->0xFFFFF800E6FCBA00	nt!KiHvInterrupt (fffff800`e6fcba00)

1: kd> uf /c 0xFFFFF800E6FCA300
Flow analysis was incomplete, some code may be missing
nt!KiIsrThunk+0x170 (fffff800`e6fca300)
  nt!KiIsrLinkage+0x55 (fffff800`e6fca9f5):
    call to nt!KiSaveDebugRegisterState (fffff800`e6fc85e0)
  nt!KiIsrLinkage+0x8b (fffff800`e6fcaa2b):
    call to nt!KeWakeProcessor (fffff800`e6f75250)
  nt!KiIsrLinkage+0xb4 (fffff800`e6fcaa54):
    call to nt!KiCheckForSListAddress (fffff800`e6f54190)
  nt!KiIsrLinkage+0x151 (fffff800`e6fcaaf1):
    call to nt!KiEndThreadAccountingPeriod (fffff800`e6ec9fc0)
  nt!KiIsrLinkage+0x16a (fffff800`e6fcab0a):
    call to nt!PerfInfoLogUnexpectedInterrupt (fffff800`e70a003c)
  nt!KiIsrLinkage+0x192 (fffff800`e6fcab32):
    call to nt!KiBugCheckDispatch (fffff800`e6fd31c0)
  nt!KiIsrLinkage+0x19b (fffff800`e6fcab3b):
    call to nt!HalPerformEndOfInterrupt (fffff800`e6fc3d50)
  nt!KiIsrLinkage+0x1dc (fffff800`e6fcab7c):
    call to nt!KiBeginThreadAccountingPeriod (fffff800`e6f1a650)
  nt!KiIsrLinkage+0x208 (fffff800`e6fcaba8):
    call to nt!KiDpcInterruptBypass (fffff800`e6fcb9c0)
  nt!KiIsrLinkage+0x214 (fffff800`e6fcabb4):
    call to hal!HalRequestSoftwareInterrupt (fffff800`e6e0b1a0)
  nt!KiIsrLinkage+0x25f (fffff800`e6fcabff):
    call to nt!KiInitiateUserApc (fffff800`e6fcb6e0)
  nt!KiIsrLinkage+0x27f (fffff800`e6fcac1f):
    call to nt!KiRestoreSetContextState (fffff800`e6fc8db0)
  nt!KiIsrLinkage+0x29b (fffff800`e6fcac3b):
    call to nt!KiCopyCounters (fffff800`e7053898)
  nt!KiIsrLinkage+0x2b7 (fffff800`e6fcac57):
    call to nt!KiRestoreDebugRegisterState (fffff800`e6fc8570)
 個々の関数の機能説明は割愛させていただきますが、古いWindows 10では最悪の場合には赤色で強調されている関数が実行され、システムクラッシュを発生させます。その後にリリースされたWindows 10ビルドでは、Thunkロジックが次のように強化されています。
1: kd> vertarget
Windows 10 Kernel Version 15063 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 15063.0.amd64fre.rs2_release.170317-1834
Machine Name:
Kernel base = 0xfffff803`52406000 PsLoadedModuleList = 0xfffff803`527525a0
Debug session time: Tue Jun 27 15:39:26.892 2017 (UTC + 9:00)
System Uptime: 12 days 7:17:40.907

-No.2C	Trap->0xFFFFF8035257CB00	nt!KiRaiseAssertion (fffff803`5257cb00)
-No.2D	Trap->0xFFFFF8035257CC00	nt!KiDebugServiceTrap (fffff803`5257cc00)
+No.2E	Thunk->0xFFFFF80352574640		---
-No.2F	Trap->0xFFFFF80352575B00	nt!KiDpcInterrupt (fffff803`52575b00)
-No.30	Trap->0xFFFFF80352575D40	nt!KiHvInterrupt (fffff803`52575d40)

1: kd> uf /c 0xFFFFF80352574640
Flow analysis was incomplete, some code may be missing
nt!KiIsrThunk+0x170 (fffff803`52574640)
  nt!KiIsrLinkage+0x55 (fffff803`52574d35):
    call to nt!KiSaveDebugRegisterState (fffff803`525728f0)
  nt!KiIsrLinkage+0x8b (fffff803`52574d6b):
    call to nt!KeWakeProcessor (fffff803`52604400)
  nt!KiIsrLinkage+0xb4 (fffff803`52574d94):
    call to nt!KiCheckForSListAddress (fffff803`524f5180)
  nt!KiIsrLinkage+0xe2 (fffff803`52574dc2):
    call to nt!guard_check_icall (fffff803`525787e0)
  nt!KiIsrLinkage+0x156 (fffff803`52574e36):
    call to nt!KiEndThreadAccountingPeriod (fffff803`524614a0)
  nt!KiIsrLinkage+0x16f (fffff803`52574e4f):
    call to nt!PerfInfoLogUnexpectedInterrupt (fffff803`52657ff0)
  nt!KiIsrLinkage+0x197 (fffff803`52574e77):
    call to nt!KiBugCheckDispatch (fffff803`5257d740)
  nt!KiIsrLinkage+0x1a0 (fffff803`52574e80):
    call to nt!HalPerformEndOfInterrupt (fffff803`5256a5a0)
  nt!KiIsrLinkage+0x1e1 (fffff803`52574ec1):
    call to nt!KiBeginThreadAccountingPeriod (fffff803`524b2020)
  nt!KiIsrLinkage+0x20d (fffff803`52574eed):
    call to nt!KiDpcInterruptBypass (fffff803`52575d00)
  nt!KiIsrLinkage+0x219 (fffff803`52574ef9):
    call to hal!HalRequestSoftwareInterrupt (fffff803`52c91470)
  nt!KiIsrLinkage+0x264 (fffff803`52574f44):
    call to nt!KiInitiateUserApc (fffff803`52575a20)
  nt!KiIsrLinkage+0x284 (fffff803`52574f64):
    call to nt!KiRestoreSetContextState (fffff803`525730d0)
  nt!KiIsrLinkage+0x2a0 (fffff803`52574f80):
    call to nt!KiCopyCounters (fffff803`52605370)
  nt!KiIsrLinkage+0x2bc (fffff803`52574f9c):
    call to nt!KiRestoreDebugRegisterState (fffff803`52572880)
 赤色で強調されている関数は、次のように、システムクラッシュを発生させます。
1: kd> uf /c fffff803`525787e0
nt!guard_check_icall (fffff803`525787e0)
  nt!guard_icall_bugcheck+0x16 (fffff803`52578796):
    call to nt!KeBugCheckEx (fffff803`525723f0)
 「nt!guard_icall_bugcheck」の動作背景は次のようになっています。
1: kd> uf nt!guard_icall_bugcheck
nt!guard_icall_bugcheck:
fffff803`52578780 4883ec28        sub     rsp,28h
fffff803`52578784 48894c2420      mov     qword ptr [rsp+20h],rcx
fffff803`52578789 b939010000      mov     ecx,139h
fffff803`5257878e 33d2            xor     edx,edx
fffff803`52578790 4d33c0          xor     r8,r8
fffff803`52578793 4d33c9          xor     r9,r9
fffff803`52578796 e8559cffff      call    nt!KeBugCheckEx (fffff803`525723f0)
fffff803`5257879b 90              nop
fffff803`5257879c c3              ret
 赤色の16進数値「139h」は、バグチェックコードであり、次のような緊急事態が発生したことを知らせます。
1: kd> !analyze -show 0x139
KERNEL_SECURITY_CHECK_FAILURE (139)
A kernel component has corrupted a critical data structure.  The corruption
could potentially allow a malicious user to gain control of this machine.
Arguments:
Arg1: 0000000000000000, A stack-based buffer has been overrun.
Arg2: 0000000000000000, Address of the trap frame for the exception that caused the bugcheck
Arg3: 0000000000000000, Address of the exception record for the exception that caused the bugcheck
Arg4: 0000000000000000, Reserved
 このバグチェックコードは、システムが悪意を持つユーザーに乗っ取られる恐れがあることを警告する意味を持っています。システムの突然の停止(システムクラッシュ)は、致命的なシステム障害発生時だけではなく、セキュリティー脅威への警告時にも発生します。

 本稿では、「ntdll!NtDeviceIoControlFile」システムサービスを例に挙げていますが、その他のシステムサービスも、次のように、同様のセキュリティー対策が適応されています。
1: kd> uf nt!NtReadFile
ntdll!NtReadFile:
00007ffb`92ca5460 4c8bd1          mov     r10,rcx
00007ffb`92ca5463 b806000000      mov     eax,6
00007ffb`92ca5468 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007ffb`92ca5470 7503            jne     ntdll!NtReadFile+0x15 (00007ffb`92ca5475)  Branch

ntdll!NtReadFile+0x12:
00007ffb`92ca5472 0f05            syscall
00007ffb`92ca5474 c3              ret

ntdll!NtReadFile+0x15:
00007ffb`92ca5475 cd2e            int     2Eh
00007ffb`92ca5477 c3              ret

1: kd> uf nt!NtWriteFile
ntdll!NtWriteFile:
00007ffb`92ca54a0 4c8bd1          mov     r10,rcx
00007ffb`92ca54a3 b808000000      mov     eax,8
00007ffb`92ca54a8 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007ffb`92ca54b0 7503            jne     ntdll!NtWriteFile+0x15 (00007ffb`92ca54b5)  Branch

ntdll!NtWriteFile+0x12:
00007ffb`92ca54b2 0f05            syscall
00007ffb`92ca54b4 c3              ret

ntdll!NtWriteFile+0x15:
00007ffb`92ca54b5 cd2e            int     2Eh
00007ffb`92ca54b7 c3              ret
 以上のように、カーネル内部では各種のセキュリティー対策がとられています。ところが、「Meltdown and Spectre」を切っ掛けに、カーネル内部はさらに激変しています。次の情報をご覧ください。
0: kd> vertarget
Windows 10 Kernel Version 16299 MP (2 procs) Free x64
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 16299.15.amd64fre.rs3_release.170928-1534
Machine Name:
Kernel base = 0xfffff803`87612000 PsLoadedModuleList = 0xfffff803`87978fd0
Debug session time: Sat Jan  6 15:37:41.466 2018 (UTC + 9:00)
System Uptime: 0 days 0:14:21.130

0: kd> uf ntdll!NtDeviceIoControlFile
ntdll!NtDeviceIoControlFile:
00007ffd`742dff40 4c8bd1          mov     r10,rcx
00007ffd`742dff43 b807000000      mov     eax,7
00007ffd`742dff48 f604250803fe7f01 test    byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007ffd`742dff50 7503            jne     ntdll!NtDeviceIoControlFile+0x15 (00007ffd`742dff55)  Branch

ntdll!NtDeviceIoControlFile+0x12:
00007ffd`742dff52 0f05            syscall
00007ffd`742dff54 c3              ret

ntdll!NtDeviceIoControlFile+0x15:
00007ffd`742dff55 cd2e            int     2Eh
00007ffd`742dff57 c3              ret

0: kd> !idt 2e

Dumping IDT: fffff80389877000

2e:	fffff803878a6370 nt!KiIsrThunkShadow+0x170
 ご覧のように、割り込み番号「2E」に対応するハンドラーが実装されています。このハンドラーは「Meltdown and Spectre」のパッチ時に導入されています。


ビジネスメニュー




「Windowsメモリダンプ解析サービス」のご案内
Windowsメモリダンプ解析技術

Copyright©豊田孝 2004- 2024
本日は2024-04-18です。