Changeset 80218 in vbox for trunk/src/VBox/HostDrivers/Support/win
- Timestamp:
- Aug 11, 2019 11:48:46 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r80217 r80218 408 408 DECLASM(void) supR3HardenedEarlyProcessInitThunk(void); 409 409 DECLASM(void) supR3HardenedMonitor_KiUserApcDispatcher(void); 410 extern "C" void __stdcall suplibHardenedWindowsMain(void); 410 411 411 412 … … 4107 4108 supR3HardenedWinKillChild(pThis, "supR3HardenedWinSetupChildInit", rcNt, 4108 4109 "NtProtectVirtualMemory/LdrInitializeThunk[restore] failed: %#x", rcNt); 4110 4111 /* 4112 * Check the sanity of the thread context. 4113 */ 4114 CONTEXT Ctx; 4115 RT_ZERO(Ctx); 4116 Ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; 4117 rcNt = NtGetContextThread(pThis->hThread, &Ctx); 4118 if (NT_SUCCESS(rcNt)) 4119 { 4120 #ifdef RT_ARCH_AMD64 4121 SUP_DPRINTF(("supR3HardenedWinSetupChildInit: Initial context:\n" 4122 " RAX=%016RX64 RBX=%016RX64 RCX=%016RX64 RDX=%016RX64\n" 4123 " RSI=%016RX64 RDI=%016RX64 R8=%016RX64 R9=%016RX64\n" 4124 " R10=%016RX64 R11=%016RX64 R12=%016RX64 R13=%016RX64\n" 4125 " R14=%016RX64 R15=%016RX64\n" 4126 " RIP=%016RX64 RSP=%016RX64 RBP=%016RX64 RFLAGS=%08RX32\n" 4127 " P1=%016RX64 P2=%016RX64 P3=%016RX64 P4=%016RX64\n" 4128 " P5=%016RX64 P6=%016RX64\n" 4129 " CS=%04RX16 DS=%04RX16 ES=%04RX16 FS=%04RX16 GS=%04RX16 SS=%04RX16\n" 4130 " DR0=%016RX64 DR1=%016RX64 DR2=%016RX64 DR3=%016RX64\n" 4131 " DR6=%016RX64 DR7=%016RX64\n", 4132 Ctx.Rax, Ctx.Rbx, Ctx.Rcx, Ctx.Rdx, 4133 Ctx.Rsi, Ctx.Rdi, Ctx.R8, Ctx.R9, 4134 Ctx.R10, Ctx.R11, Ctx.R12, Ctx.R13, 4135 Ctx.R14, Ctx.R15, 4136 Ctx.Rip, Ctx.Rsp, Ctx.Rbp, Ctx.EFlags, 4137 Ctx.P1Home, Ctx.P2Home, Ctx.P3Home, 4138 Ctx.P4Home, Ctx.P5Home, Ctx.P6Home, 4139 Ctx.SegCs, Ctx.SegDs, Ctx.SegEs, Ctx.SegFs, Ctx.SegGs, Ctx.SegSs, 4140 Ctx.Dr0, Ctx.Dr1, Ctx.Dr2, Ctx.Dr3, 4141 Ctx.Dr6, Ctx.Dr7)); 4142 DWORD64 *pPC = &Ctx.Rip; 4143 #elif defined(RT_ARCH_X86) 4144 SUP_DPRINTF(("supR3HardenedWinSetupChildInit: Initial context:\n" 4145 " EAX=%08RX32 EBX=%08RX32 ECX=%08RX32 EDX=%08RX32 ESI=%08RX64 EDI=%08RX32\n" 4146 " EIP=%08RX32 ESP=%08RX32 EBP=%08RX32 EFLAGS=%08RX32\n" 4147 " CS=%04RX16 DS=%04RX16 ES=%04RX16 FS=%04RX16 GS=%04RX16\n" 4148 " DR0=%08RX32 DR1=%08RX32 DR2=%08RX32 DR3=%08RX32 DR6=%08RX32 DR7=%08RX32\n", 4149 Ctx.Eax, Ctx.Ebx, Ctx.Ecx, Ctx.Edx, Ctx.Esi, Ctx.Edi, 4150 Ctx.Eip, Ctx.Esp, Ctx.Ebp, Ctx.EFlags, 4151 Ctx.SegCs, Ctx.SegDs, Ctx.SegEs, Ctx.SegFs, Ctx.SegGs, 4152 Ctx.Dr0, Ctx.Dr1, Ctx.Dr2, Ctx.Dr3, Ctx.Dr6, Ctx.Dr7)); 4153 DWORD *pPC = &Ctx.Eip; 4154 #else 4155 # error "Unsupported arch." 4156 #endif 4157 size_t const cbNtDll = RTLdrSize(pLdrEntry->hLdrMod); 4158 uintptr_t const uChildMain = uChildExeAddr + ( (uintptr_t)&suplibHardenedWindowsMain 4159 - (uintptr_t)NtCurrentPeb()->ImageBaseAddress); 4160 RTLDRADDR uLdrRtlUserThreadStart; 4161 rc = RTLdrGetSymbolEx(pLdrEntry->hLdrMod, pbChildNtDllBits, pThis->uNtDllAddr, UINT32_MAX, 4162 "RtlUserThreadStart", &uLdrRtlUserThreadStart); 4163 if (RT_FAILURE(rc)) 4164 uLdrRtlUserThreadStart = 0; 4165 4166 bool fUpdateContext = false; 4167 4168 /* Check if the RIP looks half sane, correct it if it isn't. 4169 It should point to RtlUserThreadStart (Vista and later it seem), though only 4170 tested on win10. The first parameter is the executable entrypoint, the 2nd 4171 is probably the PEB. */ 4172 if ( ( uLdrRtlUserThreadStart 4173 ? *pPC == uLdrRtlUserThreadStart 4174 : *pPC - pThis->uNtDllAddr <= cbNtDll) 4175 || *pPC == uChildMain) 4176 { } 4177 else 4178 { 4179 SUP_DPRINTF(("Warning! Bogus RIP: %016RX64\n", *pPC)); 4180 if (uLdrRtlUserThreadStart) 4181 { 4182 SUP_DPRINTF(("Correcting RIP from to %016RX64 hoping that it might work...\n", (uintptr_t)uLdrRtlUserThreadStart)); 4183 *pPC = uLdrRtlUserThreadStart; 4184 fUpdateContext = true; 4185 } 4186 } 4187 #ifdef RT_ARCH_AMD64 4188 if (Ctx.SegDs != 0) 4189 SUP_DPRINTF(("Warning! Bogus DS: %04x, expected zero\n", Ctx.SegDs)); 4190 if (Ctx.SegEs != 0) 4191 SUP_DPRINTF(("Warning! Bogus ES: %04x, expected zero\n", Ctx.SegEs)); 4192 if (Ctx.SegFs != 0) 4193 SUP_DPRINTF(("Warning! Bogus FS: %04x, expected zero\n", Ctx.SegFs)); 4194 if (Ctx.SegGs != 0) 4195 SUP_DPRINTF(("Warning! Bogus GS: %04x, expected zero\n", Ctx.SegGs)); 4196 if (Ctx.Rcx != uChildMain) 4197 SUP_DPRINTF(("Warning! Bogus RCX: %016RX64, expected %016RX64\n", Ctx.Rcx, uChildMain)); 4198 if ((Ctx.Rsp & 15) != 8) 4199 SUP_DPRINTF(("Warning! Misaligned RSP: %016RX64\n", Ctx.Rsp)); 4200 #endif 4201 if (Ctx.SegCs != ASMGetCS()) 4202 SUP_DPRINTF(("Warning! Bogus CS: %04x, expected %04x\n", Ctx.SegCs, ASMGetCS())); 4203 if (Ctx.SegSs != ASMGetSS()) 4204 SUP_DPRINTF(("Warning! Bogus SS: %04x, expected %04x\n", Ctx.SegSs, ASMGetSS())); 4205 if (Ctx.Dr0 != 0) 4206 SUP_DPRINTF(("Warning! Bogus DR0: %016RX64, expected zero\n", Ctx.Dr0)); 4207 if (Ctx.Dr1 != 0) 4208 SUP_DPRINTF(("Warning! Bogus DR1: %016RX64, expected zero\n", Ctx.Dr1)); 4209 if (Ctx.Dr2 != 0) 4210 SUP_DPRINTF(("Warning! Bogus DR2: %016RX64, expected zero\n", Ctx.Dr2)); 4211 if (Ctx.Dr3 != 0) 4212 SUP_DPRINTF(("Warning! Bogus DR3: %016RX64, expected zero\n", Ctx.Dr3)); 4213 if (Ctx.Dr6 != 0) 4214 SUP_DPRINTF(("Warning! Bogus DR6: %016RX64, expected zero\n", Ctx.Dr6)); 4215 if (Ctx.Dr7 != 0) 4216 { 4217 SUP_DPRINTF(("Warning! Bogus DR7: %016RX64, expected zero\n", Ctx.Dr7)); 4218 Ctx.Dr7 = 0; 4219 fUpdateContext = true; 4220 } 4221 4222 if (fUpdateContext) 4223 { 4224 rcNt = NtSetContextThread(pThis->hThread, &Ctx); 4225 if (!NT_SUCCESS(rcNt)) 4226 SUP_DPRINTF(("Error! NtSetContextThread failed: %#x\n", rcNt)); 4227 } 4228 } 4109 4229 4110 4230 /* Caller starts child execution. */ … … 6561 6681 char **papszArgs = suplibCommandLineToArgvWStub(CmdLineStr.Buffer, CmdLineStr.Length / sizeof(WCHAR), &cArgs); 6562 6682 supR3HardenedOpenLog(&cArgs, papszArgs); 6563 SUP_DPRINTF(("supR3HardenedVmProcessInit: uNtDllAddr=%p g_uNtVerCombined=%#x\n", uNtDllAddr, g_uNtVerCombined)); 6683 SUP_DPRINTF(("supR3HardenedVmProcessInit: uNtDllAddr=%p g_uNtVerCombined=%#x (stack ~%p)\n", 6684 uNtDllAddr, g_uNtVerCombined, &Timeout)); 6564 6685 6565 6686 /*
Note:
See TracChangeset
for help on using the changeset viewer.