SUPDrv-win.cpp revision d4a75d7464ec56c5a0d53b3841e9cfd83ba80f4f
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxDrv - The VirtualBox Support Driver - Windows NT specifics.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2012 Oracle Corporation
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Header Files *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Defined Constants And Macros *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
b34f0f200ed0778053a2a1d93381c2c6b60cb2d5vboxsync/** The support service name. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync/** The Pool tag (VBox). */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync/** Win32 device name for system access. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync/** NT device name for system access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Win Symlink name for system access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#define DEVICE_NAME_DOS_SYS L"\\DosDevices\\VBoxDrv"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Win32 device name for user access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** NT device name for user access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Win Symlink name for user access. */
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync#define DEVICE_NAME_DOS_USR L"\\DosDevices\\VBoxDrvU"
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync/** Win32 device name for hardened stub access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** NT device name for hardened stub access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync# define DEVICE_NAME_NT_STUB L"\\Device\\VBoxDrvStub"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync///** Win Symlink name for hardened stub access. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync//# define DEVICE_NAME_DOS_STUB L"\\DosDevices\\VBoxDrvStub"
6a767f9e41ad3ab67a2d0a376ae0a9404a283626vboxsync/** Macro for checking for deflecting calls to the stub device. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync# define VBOXDRV_COMPLETE_IRP_AND_RETURN_IF_STUB_DEV(a_pDevObj, a_pIrp) \
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync do { if ((a_pDevObj) == g_pDevObjStub) supdrvNtCompleteRequest(STATUS_ACCESS_DENIED, a_pIrp); } while (0)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync# define VBOXDRV_COMPLETE_IRP_AND_RETURN_IF_STUB_DEV(a_pDevObj, a_pIrp) do {} while (0)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Enables the fast I/O control code path. */
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/*******************************************************************************
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync* Structures and Typedefs *
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync*******************************************************************************/
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * Device extension used by VBoxDrvU.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** Global cookie (same location as in SUPDRVDEVEXT, different value). */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** Pointer to the main driver extension. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsyncAssertCompileMembersAtSameOffset(SUPDRVDEVEXT, u32Cookie, SUPDRVDEVEXTUSR, u32Cookie);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Pointer to the VBoxDrvU device extension. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Value of SUPDRVDEVEXTUSR::u32Cookie. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Get the main device extension. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync : ((PSUPDRVDEVEXTUSR)pDevObj->DeviceExtension)->pMainDrvExt )
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync * Device extension used by VBoxDrvS.
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Common header. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync/** Pointer to the VBoxDrvS device extension. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Value of SUPDRVDEVEXTSTUB::Common.u32Cookie. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#define SUPDRVDEVEXTSTUB_COOKIE UINT32_C(0x90abcdef)
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * The kind of process we're protecting.
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Stub process protection while performing process verification.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Next: StubSpawning (or free) */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync /** Stub process protection before it creates the VM process.
ad81f667a6be22bee5e7628bf8cfb849723734c6vboxsync * Next: StubParent, StubDead. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Stub process protection while having a VM process as child.
7f857bf87e6836b7359e38b75ef7408dd2886c7cvboxsync * Next: StubDead */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** Dead stub process. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** Potential VM process.
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * Next: VmProcessConfirmed, VmProcessDead. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Confirmed VM process.
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * Next: VmProcessDead. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync /** Dead VM process. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** End of valid protection kinds. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync * A NT process protection structure.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** The AVL node core structure. The process ID is the pid. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** Magic value (SUPDRVNTPROTECT_MAGIC). */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Reference counter. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** The kind of process we're protecting. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /** Vista, 7 & 8: Hack to allow more rights to the handle returned by
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * NtCreateUserProcess. Only applicable to VmProcessUnconfirmed. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync /** Vista, 7 & 8: Hack to allow more rights to the handle returned by
fc0e1701814ea969173fadb20fef6833b04fb2bcvboxsync * NtCreateUserProcess. Only applicable to VmProcessUnconfirmed. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /** 8.1: Hack to allow more rights to the handle returned by
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync * NtCreateUserProcess. Only applicable to VmProcessUnconfirmed. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync /** Vista, 7 & 8: Hack to allow more rights to the handle duplicated by CSR
fc0e1701814ea969173fadb20fef6833b04fb2bcvboxsync * during process creation. Only applicable to VmProcessUnconfirmed. */
7f857bf87e6836b7359e38b75ef7408dd2886c7cvboxsync /** 7,: Hack to allow the supid themes service duplicate handle privileges to
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * our process. */
typedef NTSTATUS (NTAPI *PFNPSSETCREATEPROCESSNOTIFYROUTINEEX)(PCREATE_PROCESS_NOTIFY_ROUTINE_EX, BOOLEAN);
#ifdef VBOXDRV_WITH_FAST_IO
static BOOLEAN _stdcall VBoxDrvNtFastIoDeviceControl(PFILE_OBJECT pFileObj, BOOLEAN fWait, PVOID pvInput, ULONG cbInput,
static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
static VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2);
#ifdef VBOX_WITH_HARDENING
static void supdrvNtProtectTerm(void);
static bool supdrvNtIsDebuggerAttached(void);
#ifdef VBOXDRV_WITH_FAST_IO
#ifdef VBOX_WITH_HARDENING
# ifdef RT_ARCH_AMD64
NTSTATUS rcNt = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_pDevObjSys);
rcNt = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXTUSR), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_pDevObjUsr);
#ifdef VBOX_WITH_HARDENING
rcNt = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXTSTUB), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_pDevObjStub);
return rcNt;
#ifdef VBOX_WITH_HARDENING
return rcNt;
static void vboxdrvNtDestroyDevices(void)
#ifdef VBOX_WITH_HARDENING
if (g_pDevObjUsr)
#ifdef VBOX_WITH_HARDENING
if (g_pDevObjStub)
#ifdef VBOX_WITH_HARDENING
#ifdef VBOXDRV_WITH_FAST_IO
return STATUS_INTERNAL_ERROR;
#ifdef VBOX_WITH_HARDENING
if (!vrc)
#ifdef VBOXDRV_WITH_FAST_IO
return STATUS_SUCCESS;
#ifdef VBOX_WITH_HARDENING
RTR0Term();
return rcNt;
#ifdef VBOX_WITH_HARDENING
RTR0Term();
return rcNt;
#ifdef VBOX_WITH_HARDENING
LogRel(("vboxdrv: Declined %p access to VBoxDrvStub: rc=%d\n", PsGetProcessId(PsGetCurrentProcess()), rc));
if (pNtProtect)
&pSession);
rc = supdrvCreateSession(pDevExt, true /*fUser*/, pDevObj == g_pDevObjSys /*fUnrestricted*/, &pSession);
return supdrvNtCompleteRequest(rcNt, pIrp); /* Note. the IoStatus is completely ignored on error. */
#ifdef VBOX_WITH_HARDENING
if (pNtProtect)
if (pSession)
#ifdef VBOX_WITH_HARDENING
if (pNtProtect)
if (pSession)
#ifdef VBOXDRV_WITH_FAST_IO
static BOOLEAN _stdcall VBoxDrvNtFastIoDeviceControl(PFILE_OBJECT pFileObj, BOOLEAN fWait, PVOID pvInput, ULONG cbInput,
if (!pSession)
return TRUE;
if (supdrvNtIsDebuggerAttached())
return TRUE;
return TRUE;
unsigned cbOut = 0;
int rc = 0;
Log2(("VBoxDrvNtFastIoDeviceControl(%p): ioctl=%#x pvIn=%p cbIn=%#x pvOut=%p cbOut=%#x pSession=%p\n",
# ifdef RT_ARCH_AMD64
if (pHdr)
if (cbOut)
# ifdef RT_ARCH_AMD64
if (supdrvNtIsDebuggerAttached())
int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
unsigned cbOut = 0;
int rc = 0;
#ifdef RT_ARCH_AMD64
if (!rc)
#ifdef RT_ARCH_AMD64
return rcNt;
unsigned cbOut = 0;
int rc = 0;
: !pSession
if (!rc)
return rcNt;
return STATUS_NOT_SUPPORTED;
if ((unsigned)pArgument2 == 0)
#ifdef VBOX_WITH_HARDENING
void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
typedef struct MYSYSTEMGDIDRIVERINFO
int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
# ifndef RT_ARCH_X86
return VERR_NOT_SUPPORTED;
return rc;
if (!pwcsFilename)
return VERR_NO_TMP_MEMORY;
NTSTATUS rcNt = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer));
# ifdef DEBUG_bird
Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer);
rc = RTR0MemObjLockKernel(&pImage->hMemLock, pImage->pvImage, pImage->cbImageBits, RTMEM_PROT_READ);
switch (rcNt)
# ifdef RT_ARCH_AMD64
return rc;
int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
return VINF_SUCCESS;
static int supdrvNtCompare(PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, uint32_t uRva, uint32_t cb)
if (iDiff)
return iDiff;
int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
return VINF_SUCCESS;
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size >= sizeof(IMAGE_IMPORT_DESCRIPTOR)
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress > sizeof(IMAGE_NT_HEADERS)
&& pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress < pImage->cbImageBits
struct MyRegion
unsigned cExcludeRgns = 0;
/ sizeof(IMAGE_IMPORT_DESCRIPTOR);
while ( cImpsLeft-- > 0
cThunks++;
for (; i < cExcludeRgns; i++)
if (i != cExcludeRgns)
cExcludeRgns++;
pImp++;
int iDiff = 0;
if (!iDiff)
return VINF_SUCCESS;
return VERR_LDR_MISMATCH_NATIVE;
return VERR_INTERNAL_ERROR_4;
#ifdef SUPDRV_WITH_MSR_PROBER
typedef struct SUPDRVNTMSPROBERARGS
bool fGp;
return rc;
return VERR_ACCESS_DENIED;
return VINF_SUCCESS;
return rc;
return VERR_ACCESS_DENIED;
return VINF_SUCCESS;
bool fBeforeGp = true;
bool fModifyGp = true;
bool fAfterGp = true;
bool fRestoreGp = true;
if (!fFaster)
fBeforeGp = false;
fBeforeGp = true;
if (!fBeforeGp)
fModifyGp = false;
fModifyGp = true;
fAfterGp = false;
fAfterGp = true;
fRestoreGp = false;
fRestoreGp = true;
if (!fFaster)
ASMReloadCR3();
ASMNopPause();
return VINF_SUCCESS;
switch (rc)
if (rc < 0)
return STATUS_UNSUCCESSFUL;
#ifdef VBOX_WITH_HARDENING
if (!pszImageFile)
} Buf;
if (!chRight)
int rc;
if (uSessionId == 0)
&pvApiPortObj);
return VERR_SUPDRV_APIPORT_OPEN_ERROR;
if (!pbBuf)
cbNeeded = 0;
if ( pbBuf
bool fThatsIt = false;
ppPortProc++;
fThatsIt = false;
if (fThatsIt)
return rc;
static bool supdrvNtProtectIsFrigginThemesService(PSUPDRVNTPROTECT pNtProtect, PEPROCESS pAnnoyingProcess)
static bool supdrvNtProtectIsSpawningStubProcess(PSUPDRVNTPROTECT pNtStub, HANDLE hParentPid, HANDLE hChildPid)
bool fRc = false;
return fRc;
int rc = supdrvNtProtectCreate(&pNtChild, hChildPid, kSupDrvNtProtectKind_VmProcessUnconfirmed, false /*fLink*/);
if (fSuccess)
return VINF_SUCCESS;
return rc;
if (pNtProtect)
if (g_pDevObjSys)
if (pSession)
static void supdrvNtProtectVerifyNewChildProtection(PSUPDRVNTPROTECT pNtStub, PSUPDRVNTPROTECT pNtVm, bool fCallerChecks)
if ( fCallerChecks
LogRel(("vboxdrv: Misdetected vm stub; hParentPid=%p hChildPid=%p\n", pNtStub->AvlCore.Key, pNtVm->AvlCore.Key));
if (fCreated)
if (pNtStub)
if (!pNtVm)
supdrvNtProtectCallback_ProcessCreateNotifyEx(PEPROCESS pNewProcess, HANDLE hNewPid, PPS_CREATE_NOTIFY_INFO pInfo)
if (pInfo)
pInfo->FileOpenNameAvailable && pInfo->ImageFileName ? (size_t)pInfo->ImageFileName->Length / 2 : 0,
if (pNtStub)
if (!pNtVm)
# define SUPDRV_NT_ALLOW_PROCESS_RIGHTS \
| PROCESS_VM_READ \
| DELETE \
| READ_CONTROL \
| SYNCHRONIZE)
# define SUPDRV_NT_EVIL_PROCESS_RIGHTS \
| PROCESS_VM_WRITE \
Assert(pOpInfo->Operation == OB_OPERATION_HANDLE_CREATE || pOpInfo->Operation == OB_OPERATION_HANDLE_DUPLICATE);
if (!pNtProtect)
if (pNtStub)
if (pNtProtect)
&& pOpInfo->Parameters->CreateHandleInformation.DesiredAccess == 0x1478 /* 6.1.7600.16385 (win7_rtm.090713-1255) */
Log(("vboxdrv/ProcessHandlePre: ctx=%04zx/%p wants %#x to %p/pid=%04zx [%d], allow %#x => %#x; %s\n",
Log(("vboxdrv/ProcessHandlePre: ctx=%04zx/%p[%p] dup from %04zx/%p with %#x to %p in pid=%04zx [%d] %s\n",
Log(("vboxdrv/ProcessHandlePre: ctx=%04zx/%p[%p] dup from %04zx/%p with %#x to %p in pid=%04zx [%d] %s\n",
return OB_PREOP_SUCCESS;
Assert(pOpInfo->Operation == OB_OPERATION_HANDLE_CREATE || pOpInfo->Operation == OB_OPERATION_HANDLE_DUPLICATE);
/* From ntifs.h */
# define SUPDRV_NT_ALLOWED_THREAD_RIGHTS \
( THREAD_TERMINATE \
| DELETE \
| READ_CONTROL \
| SYNCHRONIZE)
# define SUPDRV_NT_EVIL_THREAD_RIGHTS \
Assert(pOpInfo->Operation == OB_OPERATION_HANDLE_CREATE || pOpInfo->Operation == OB_OPERATION_HANDLE_DUPLICATE);
if (pNtProtect)
Log(("vboxdrv/ThreadHandlePre: ctx=%04zx/%p wants %#x to %p in pid=%04zx [%d], allow %#x => %#x; %s\n",
Log(("vboxdrv/ThreadHandlePre: ctx=%04zx/%p[%p] dup from %04zx/%p with %#x to %p in pid=%04zx [%d] self\n",
Log(("vboxdrv/ThreadHandlePre: ctx=%04zx/%p[%p] dup from %04zx/%p with %#x to %p in pid=%04zx [%d], allow %#x => %#x; %s\n",
return OB_PREOP_SUCCESS;
Assert(pOpInfo->Operation == OB_OPERATION_HANDLE_CREATE || pOpInfo->Operation == OB_OPERATION_HANDLE_DUPLICATE);
fGrantedAccess, SUPDRV_NT_ALLOWED_THREAD_RIGHTS, fGrantedAccess & ~SUPDRV_NT_ALLOWED_THREAD_RIGHTS));
static int supdrvNtProtectCreate(PSUPDRVNTPROTECT *ppNtProtect, HANDLE hPid, SUPDRVNTPROTECTKIND enmProcessKind, bool fLink)
if (!pNtProtect)
return VERR_NO_MEMORY;
if (fLink)
if (!fSuccess)
return VERR_ACCESS_DENIED;
return VINF_SUCCESS;
if (!pNtProtect)
if (cRefs != 0)
PSUPDRVNTPROTECT pRemoved = (PSUPDRVNTPROTECT)RTAvlPVRemove(&g_NtProtectTree, pNtProtect->AvlCore.Key);
if (pChild)
if (!cChildRefs)
if (pChild)
if (pFound)
return pFound;
if (!pbBuf)
return VERR_NO_MEMORY;
const char *pszType;
# ifndef VBOX_WITH_VISTA_NO_SP
return rc;
AssertReturn(PsGetProcessId(PsGetCurrentProcess()) == pNtProtect->AvlCore.Key, VERR_INTERNAL_ERROR_3);
pNtProtect->enmProcessKind = RT_SUCCESS(rc) ? kSupDrvNtProtectKind_StubSpawning : kSupDrvNtProtectKind_StubDead;
return rc;
# ifndef VBOX_WITHOUT_DEBUGGER_CHECKS
static bool supdrvNtIsDebuggerAttached(void)
static void supdrvNtProtectTerm(void)
rcNt = g_pfnPsSetCreateProcessNotifyRoutineEx(supdrvNtProtectCallback_ProcessCreateNotifyEx, TRUE /*fRemove*/);
rcNt = PsSetCreateProcessNotifyRoutine(supdrvNtProtectCallback_ProcessCreateNotify, TRUE /*fRemove*/);
# ifdef RT_ARCH_X86
g_pfnPsSetCreateProcessNotifyRoutineEx = (PFNPSSETCREATEPROCESSNOTIFYROUTINEEX)MmGetSystemRoutineAddress(&RoutineName);
g_pfnPsReferenceProcessFilePointer = (PFNPSREFERENCEPROCESSFILEPOINTER)MmGetSystemRoutineAddress(&RoutineName);
g_pfnPsIsProtectedProcessLight = (PFNPSISPROTECTEDPROCESSLIGHT)MmGetSystemRoutineAddress(&RoutineName);
# ifdef RT_ARCH_X86
case 0xb0: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xAF; break; /* just in case */
case 0xb1: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB0; break; /* just in case */
case 0xb2: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB1; break; /* just in case */
case 0xb3: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB2; break; /* XP SP3 */
case 0xb4: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB2; break; /* just in case */
case 0xb5: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB3; break; /* just in case */
case 0xb6: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB4; break; /* just in case */
case 0xb7: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB5; break; /* just in case */
case 0xb8: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB6; break; /* just in case */
case 0xb9: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB7; break; /* just in case */
case 0xba: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xB8; break; /* just in case */
case 0xbb: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBA; break; /* W2K3 R2 SP2 */
case 0xbc: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBB; break; /* just in case */
case 0xbd: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBC; break; /* just in case */
case 0xbe: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBD; break; /* just in case */
case 0xbf: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBE; break; /* just in case */
case 0x1e: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0x1F; break;
case 0x1f: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0x20; break;
case 0x20: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0x21; break;
case 0x21: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0x22; break;
case 0x22: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0x23; break;
LogRel(("vboxdrv: Cannot locate ZwQueryVirtualMemory in ntoskrnl, nor were we able to cook up a replacement.\n"));
return STATUS_PROCEDURE_NOT_FOUND;
rcNt = g_pfnPsSetCreateProcessNotifyRoutineEx(supdrvNtProtectCallback_ProcessCreateNotifyEx, FALSE /*fRemove*/);
rcNt = PsSetCreateProcessNotifyRoutine(supdrvNtProtectCallback_ProcessCreateNotify, FALSE /*fRemove*/);
for (uint32_t i = 0; i < RT_ELEMENTS(s_apwszAltitudes) && rcNt == STATUS_FLT_INSTANCE_ALTITUDE_COLLISION; i++)
return STATUS_SUCCESS;
# ifndef VBOX_WITH_VISTA_NO_SP
DbgPrint("vboxdrv: ObRegisterCallbacks was not found. Please make sure you got the latest updates and service packs installed\n");
g_pfnPsSetCreateProcessNotifyRoutineEx(supdrvNtProtectCallback_ProcessCreateNotifyEx, TRUE /*fRemove*/);
return rcNt;