Changeset 51770 in vbox for trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/bird/hardenedwindows (added) merged: 92692-94610
- Property svn:mergeinfo changed
-
trunk/src/VBox
- Property svn:mergeinfo changed
/branches/bird/hardenedwindows/src/VBox (added) merged: 92692-94610
- Property svn:mergeinfo changed
-
trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp
r49213 r51770 31 31 #ifdef IN_SUP_HARDENED_R3 32 32 # undef DEBUG /* Warning: disables RT_STRICT */ 33 # undef LOG_DISABLED 33 34 # define LOG_DISABLED 34 35 /** @todo RTLOGREL_DISABLED */ … … 39 40 40 41 #define USE_NT_DEVICE_IO_CONTROL_FILE 41 #ifdef USE_NT_DEVICE_IO_CONTROL_FILE 42 # include <iprt/nt/nt-and-windows.h> 43 #else 44 # include <Windows.h> 45 #endif 42 #include <iprt/nt/nt-and-windows.h> 46 43 47 44 #include <VBox/sup.h> … … 55 52 #include "../SUPLibInternal.h" 56 53 #include "../SUPDrvIOC.h" 54 #ifdef VBOX_WITH_HARDENING 55 # include "win/SUPHardenedVerify-win.h" 56 #endif 57 57 58 58 … … 75 75 * Internal Functions * 76 76 *******************************************************************************/ 77 #ifndef IN_SUP_HARDENED_R3 77 78 static int suplibOsCreateService(void); 78 79 //unused: static int suplibOsUpdateService(void); … … 80 81 static int suplibOsStartService(void); 81 82 static int suplibOsStopService(void); 83 #endif 82 84 #ifdef USE_NT_DEVICE_IO_CONTROL_FILE 83 85 static int suplibConvertNtStatus(NTSTATUS rcNt); … … 87 89 88 90 89 90 91 91 int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted) 92 92 { 93 93 /* 94 * Nothing to do if pre-inited.94 * Almost nothing to do if pre-inited. 95 95 */ 96 96 if (fPreInited) 97 { 98 #if defined(VBOX_WITH_HARDENING) && !defined(IN_SUP_HARDENED_R3) 99 # ifdef IN_SUP_R3_STATIC 100 return VERR_NOT_SUPPORTED; 101 # else 102 supR3HardenedWinInitVersion(); 103 return supHardenedWinInitImageVerifier(NULL); 104 # endif 105 #else 97 106 return VINF_SUCCESS; 107 #endif 108 } 98 109 99 110 /* 100 111 * Try open the device. 101 112 */ 102 HANDLE hDevice = CreateFile(fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR,103 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,104 NULL,105 OPEN_EXISTING,106 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,107 NULL);108 if (hDevice == INVALID_HANDLE_VALUE)109 {110 113 #ifndef IN_SUP_HARDENED_R3 111 /* 112 * Try start the service and retry opening it. 113 */ 114 suplibOsStartService(); 115 116 hDevice = CreateFile(fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, 117 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 118 NULL, 119 OPEN_EXISTING, 120 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 121 NULL); 122 if (hDevice == INVALID_HANDLE_VALUE) 123 #endif /* !IN_SUP_HARDENED_R3 */ 124 { 125 int rc = GetLastError(); 126 switch (rc) 114 uint32_t cTry = 0; 115 #endif 116 HANDLE hDevice; 117 for (;;) 118 { 119 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 120 121 static const WCHAR s_wszName[] = L"\\Device\\VBoxDrvU"; 122 UNICODE_STRING NtName; 123 NtName.Buffer = (PWSTR)s_wszName; 124 NtName.Length = sizeof(s_wszName) - sizeof(WCHAR) * (fUnrestricted ? 2 : 1); 125 NtName.MaximumLength = NtName.Length; 126 127 OBJECT_ATTRIBUTES ObjAttr; 128 InitializeObjectAttributes(&ObjAttr, &NtName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/); 129 130 hDevice = RTNT_INVALID_HANDLE_VALUE; 131 132 NTSTATUS rcNt = NtCreateFile(&hDevice, 133 GENERIC_READ | GENERIC_WRITE, 134 &ObjAttr, 135 &Ios, 136 NULL /* Allocation Size*/, 137 FILE_ATTRIBUTE_NORMAL, 138 FILE_SHARE_READ | FILE_SHARE_WRITE, 139 FILE_OPEN, 140 FILE_NON_DIRECTORY_FILE, 141 NULL /*EaBuffer*/, 142 0 /*EaLength*/); 143 if (NT_SUCCESS(rcNt)) 144 rcNt = Ios.Status; 145 if (!NT_SUCCESS(rcNt)) 146 { 147 #ifndef IN_SUP_HARDENED_R3 148 /* 149 * Failed to open, try starting the service and reopen the device 150 * exactly once. 151 */ 152 if (cTry == 0 && !NT_SUCCESS(rcNt)) 153 { 154 cTry++; 155 suplibOsStartService(); 156 continue; 157 } 158 #endif 159 switch (rcNt) 127 160 { 128 161 /** @todo someone must test what is actually returned. */ 129 case ERROR_DEV_NOT_EXIST:130 case ERROR_DEVICE_NOT_CONNECTED:131 case ERROR_BAD_DEVICE:132 case ERROR_DEVICE_REMOVED:133 case ERROR_DEVICE_NOT_AVAILABLE:162 case STATUS_DEVICE_DOES_NOT_EXIST: 163 case STATUS_DEVICE_NOT_CONNECTED: 164 //case ERROR_BAD_DEVICE: 165 case STATUS_DEVICE_REMOVED: 166 //case ERROR_DEVICE_NOT_AVAILABLE: 134 167 return VERR_VM_DRIVER_LOAD_ERROR; 135 case ERROR_PATH_NOT_FOUND: 136 case ERROR_FILE_NOT_FOUND: 168 case STATUS_OBJECT_PATH_NOT_FOUND: 169 case STATUS_NO_SUCH_DEVICE: 170 case STATUS_NO_SUCH_FILE: 171 case STATUS_OBJECT_NAME_NOT_FOUND: 137 172 return VERR_VM_DRIVER_NOT_INSTALLED; 138 case ERROR_ACCESS_DENIED:139 case ERROR_SHARING_VIOLATION:173 case STATUS_ACCESS_DENIED: 174 case STATUS_SHARING_VIOLATION: 140 175 return VERR_VM_DRIVER_NOT_ACCESSIBLE; 176 case STATUS_UNSUCCESSFUL: 177 return VERR_SUPLIB_NT_PROCESS_UNTRUSTED_0; 178 case STATUS_TRUST_FAILURE: 179 return VERR_SUPLIB_NT_PROCESS_UNTRUSTED_1; 180 case STATUS_TOO_LATE: 181 return VERR_SUPDRV_HARDENING_EVIL_HANDLE; 141 182 default: 183 184 return rcNt; 142 185 return VERR_VM_DRIVER_OPEN_ERROR; 143 186 } 144 145 return -1 /** @todo define proper error codes for suplibOsInit failure. */; 146 } 187 } 188 break; 147 189 } 148 190 … … 154 196 return VINF_SUCCESS; 155 197 } 156 157 198 158 199 #ifndef IN_SUP_HARDENED_R3 … … 440 481 fRc = StartService(hService, 0, NULL); 441 482 DWORD LastError = GetLastError(); NOREF(LastError); 483 #ifndef DEBUG_bird 442 484 AssertMsg(fRc, ("StartService failed with LastError=%Rwa\n", LastError)); 485 #endif 443 486 } 444 487 … … 652 695 } 653 696 697 /* See VBoxDrvNtErr2NtStatus. */ 698 if (((uint32_t)rcNt & 0xffff0000) == UINT32_C(0xe9860000)) /** @todo defines for these? */ 699 return (int)((uint32_t)rcNt | UINT32_C(0xffff0000)); 700 654 701 /* Fall back on IPRT for the rest. */ 655 702 return RTErrConvertFromNtStatus(rcNt);
Note:
See TracChangeset
for help on using the changeset viewer.