Changeset 80242 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Aug 13, 2019 2:02:58 AM (5 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support/win
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h
r80216 r80242 169 169 /** Set if verified. */ 170 170 bool fVerified; 171 /** Whether we've got valid cacheable image bit .s*/171 /** Whether we've got valid cacheable image bits. */ 172 172 bool fValidBits; 173 173 /** The image base address. */ -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r80218 r80242 4155 4155 # error "Unsupported arch." 4156 4156 #endif 4157 size_t const cbNtDll = RTLdrSize(pLdrEntry->hLdrMod);4157 /* Entrypoint for the executable: */ 4158 4158 uintptr_t const uChildMain = uChildExeAddr + ( (uintptr_t)&suplibHardenedWindowsMain 4159 4159 - (uintptr_t)NtCurrentPeb()->ImageBaseAddress); 4160 RTLDRADDR uLdrRtlUserThreadStart; 4160 4161 /* NtDll size and the more recent default thread start entrypoint (Vista+?): */ 4162 RTLDRADDR uSystemThreadStart; 4161 4163 rc = RTLdrGetSymbolEx(pLdrEntry->hLdrMod, pbChildNtDllBits, pThis->uNtDllAddr, UINT32_MAX, 4162 "RtlUserThreadStart", &u LdrRtlUserThreadStart);4164 "RtlUserThreadStart", &uSystemThreadStart); 4163 4165 if (RT_FAILURE(rc)) 4164 uLdrRtlUserThreadStart = 0; 4166 uSystemThreadStart = 0; 4167 4168 /* Kernel32 for thread start of older windows version, only XP64/W2K3-64 has an actual 4169 export for it. Unfortunately, it is not yet loaded into the child, so we have to 4170 assume same location as in the parent (safe): */ 4171 PSUPHNTLDRCACHEENTRY pLdrEntryKernel32; 4172 int rc = supHardNtLdrCacheOpen("kernel32.dll", &pLdrEntryKernel32, NULL /*pErrInfo*/); 4173 if (RT_FAILURE(rc)) 4174 supR3HardenedWinKillChild(pThis, "supR3HardenedWinSetupChildInit", rc, 4175 "supHardNtLdrCacheOpen failed on KERNEL32: %Rrc\n", rc); 4176 size_t const cbKernel32 = RTLdrSize(pLdrEntryKernel32->hLdrMod); 4177 4178 #ifdef RT_ARCH_AMD64 4179 if (!uSystemThreadStart) 4180 { 4181 rc = RTLdrGetSymbolEx(pLdrEntry->hLdrMod, pbChildNtDllBits, pLdrEntryKernel32->uImageBase, UINT32_MAX, 4182 "BaseProcessStart", &uSystemThreadStart); 4183 if (RT_FAILURE(rc)) 4184 uSystemThreadStart = 0; 4185 } 4186 #endif 4165 4187 4166 4188 bool fUpdateContext = false; 4167 4189 4168 /* Check if the RIP looks half sane, correct it if it isn't.4190 /* Check if the RIP looks half sane, try correct it if it isn't. 4169 4191 It should point to RtlUserThreadStart (Vista and later it seem), though only 4170 4192 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) 4193 is probably the PEB. Before Vista it should point to Kernel32!BaseProcessStart, 4194 though the symbol is only exported in 5.2/AMD64. */ 4195 if ( ( uSystemThreadStart 4196 ? *pPC == uSystemThreadStart 4197 : *pPC - ( pLdrEntryKernel32->uImageBase != ~(uintptr_t)0 ? pLdrEntryKernel32->uImageBase 4198 : (uintptr_t)GetModuleHandleW(L"kernel32.dll")) <= cbKernel32) 4175 4199 || *pPC == uChildMain) 4176 4200 { } 4177 4201 else 4178 4202 { 4179 SUP_DPRINTF(("Warning! Bogus RIP: %016RX64\n", *pPC)); 4180 if (uLdrRtlUserThreadStart) 4203 SUP_DPRINTF(("Warning! Bogus RIP: %p (uSystemThreadStart=%p; kernel32 %p LB %p; uChildMain=%p)\n", 4204 *pPC, uSystemThreadStart, pLdrEntryKernel32->uImageBase, cbKernel32, uChildMain)); 4205 if (uSystemThreadStart) 4181 4206 { 4182 SUP_DPRINTF(("Correcting RIP from to % 016RX64 hoping that it might work...\n", (uintptr_t)uLdrRtlUserThreadStart));4183 *pPC = u LdrRtlUserThreadStart;4207 SUP_DPRINTF(("Correcting RIP from to %p hoping that it might work...\n", (uintptr_t)uSystemThreadStart)); 4208 *pPC = uSystemThreadStart; 4184 4209 fUpdateContext = true; 4185 4210 } 4186 4211 } 4187 4212 #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)); 4213 if (g_uNtVerCombined >= SUP_MAKE_NT_VER_SIMPLE(10, 0)) /* W2K3: CS=33 SS=DS=ES=GS=2b FS=53 */ 4214 { 4215 if (Ctx.SegDs != 0) 4216 SUP_DPRINTF(("Warning! Bogus DS: %04x, expected zero\n", Ctx.SegDs)); 4217 if (Ctx.SegEs != 0) 4218 SUP_DPRINTF(("Warning! Bogus ES: %04x, expected zero\n", Ctx.SegEs)); 4219 if (Ctx.SegFs != 0) 4220 SUP_DPRINTF(("Warning! Bogus FS: %04x, expected zero\n", Ctx.SegFs)); 4221 if (Ctx.SegGs != 0) 4222 SUP_DPRINTF(("Warning! Bogus GS: %04x, expected zero\n", Ctx.SegGs)); 4223 } 4196 4224 if (Ctx.Rcx != uChildMain) 4197 4225 SUP_DPRINTF(("Warning! Bogus RCX: %016RX64, expected %016RX64\n", Ctx.Rcx, uChildMain)); 4226 if (Ctx.Rdx & PAGE_OFFSET_MASK) 4227 SUP_DPRINTF(("Warning! Bogus RDX: %016RX64, expected page aligned\n", Ctx.Rdx)); /* PEB */ 4198 4228 if ((Ctx.Rsp & 15) != 8) 4199 4229 SUP_DPRINTF(("Warning! Misaligned RSP: %016RX64\n", Ctx.Rsp));
Note:
See TracChangeset
for help on using the changeset viewer.