Changeset 97023 in vbox for trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
- Timestamp:
- Oct 6, 2022 8:23:59 AM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 153956
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r96407 r97023 4943 4943 4944 4944 4945 static const char *supdrvNtProtectHandleTypeIndexToName(ULONG idxType, char *pszName, size_t cbName) 4946 { 4947 /* 4948 * Query the object types. 4949 */ 4950 uint32_t cbBuf = _8K; 4951 uint8_t *pbBuf = (uint8_t *)RTMemAllocZ(_8K); 4952 ULONG cbNeeded = cbBuf; 4953 NTSTATUS rcNt = NtQueryObject(NULL, ObjectTypesInformation, pbBuf, cbBuf, &cbNeeded); 4954 while (rcNt == STATUS_INFO_LENGTH_MISMATCH) 4955 { 4956 cbBuf = RT_ALIGN_32(cbNeeded + 256, _64K); 4957 RTMemFree(pbBuf); 4958 pbBuf = (uint8_t *)RTMemAllocZ(cbBuf); 4959 if (pbBuf) 4960 rcNt = NtQueryObject(NULL, ObjectTypesInformation, pbBuf, cbBuf, &cbNeeded); 4961 else 4962 break; 4963 } 4964 if (NT_SUCCESS(rcNt)) 4965 { 4966 Assert(cbNeeded <= cbBuf); 4967 4968 POBJECT_TYPES_INFORMATION pObjTypes = (OBJECT_TYPES_INFORMATION *)pbBuf; 4969 POBJECT_TYPE_INFORMATION pCurType = &pObjTypes->FirstType; 4970 ULONG cLeft = pObjTypes->NumberOfTypes; 4971 while (cLeft-- > 0 && (uintptr_t)&pCurType[1] - (uintptr_t)pbBuf < cbNeeded) 4972 { 4973 if (pCurType->TypeIndex == idxType) 4974 { 4975 PCRTUTF16 const pwszSrc = pCurType->TypeName.Buffer; 4976 AssertBreak(pwszSrc); 4977 size_t idxName = pCurType->TypeName.Length / sizeof(RTUTF16); 4978 AssertBreak(idxName > 0); 4979 AssertBreak(idxName < 128); 4980 if (idxName >= cbName) 4981 idxName = cbName - 1; 4982 pszName[idxName] = '\0'; 4983 while (idxName-- > 0) 4984 pszName[idxName] = (char )pwszSrc[idxName]; 4985 RTMemFree(pbBuf); 4986 return pszName; 4987 } 4988 4989 /* next */ 4990 pCurType = (POBJECT_TYPE_INFORMATION)( (uintptr_t)pCurType->TypeName.Buffer 4991 + RT_ALIGN_32(pCurType->TypeName.MaximumLength, sizeof(uintptr_t))); 4992 } 4993 } 4994 4995 RTMemFree(pbBuf); 4996 return "unknown"; 4997 } 4998 4999 4945 5000 /** 4946 5001 * Worker for supdrvNtProtectVerifyProcess that verifies the handles to a VM … … 5009 5064 uint32_t cBenignThreadHandles = 0; 5010 5065 5066 uint32_t cEvilInheritableHandles = 0; 5067 uint32_t cBenignInheritableHandles = 0; 5068 char szTmpName[32]; 5069 5011 5070 SYSTEM_HANDLE_INFORMATION_EX const *pInfo = (SYSTEM_HANDLE_INFORMATION_EX const *)pbBuf; 5012 5071 ULONG_PTR i = pInfo->NumberOfHandles; … … 5070 5129 cEvilThreadHandles++; 5071 5130 pszType = "thread"; 5131 } 5132 else if ( (pHandleInfo->HandleAttributes & OBJ_INHERIT) 5133 && pHandleInfo->UniqueProcessId == hProtectedPid) 5134 { 5135 /* No handles should be marked inheritable, except files and two events. 5136 Handles to NT 'directory' objects are especially evil, because of 5137 KnownDlls faking. See bugref{10294} for details. 5138 5139 Correlating the ObjectTypeIndex to a type is complicated, so instead 5140 we try referecing the handle and check the type that way. So, only 5141 file and events objects are allowed to be marked inheritable at the 5142 moment. Add more in whitelist fashion if needed. */ 5143 void *pvObject = NULL; 5144 rcNt = ObReferenceObjectByHandle(pHandleInfo->HandleValue, 0, *IoFileObjectType, KernelMode, &pvObject, NULL); 5145 if (rcNt == STATUS_OBJECT_TYPE_MISMATCH) 5146 rcNt = ObReferenceObjectByHandle(pHandleInfo->HandleValue, 0, *ExEventObjectType, KernelMode, &pvObject, NULL); 5147 if (NT_SUCCESS(rcNt)) 5148 { 5149 ObDereferenceObject(pvObject); 5150 cBenignInheritableHandles++; 5151 continue; 5152 } 5153 5154 if (rcNt != STATUS_OBJECT_TYPE_MISMATCH) 5155 { 5156 cBenignInheritableHandles++; 5157 continue; 5158 } 5159 5160 cEvilInheritableHandles++; 5161 pszType = supdrvNtProtectHandleTypeIndexToName(pHandleInfo->ObjectTypeIndex, szTmpName, sizeof(szTmpName)); 5072 5162 } 5073 5163 else … … 5100 5190 || g_pfnObRegisterCallbacks) 5101 5191 { 5102 LogRel(("vboxdrv: Found evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s \n",5192 LogRel(("vboxdrv: Found evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s (%u)\n", 5103 5193 pHandleInfo->UniqueProcessId, pHandleInfo->HandleValue, 5104 pHandleInfo->GrantedAccess, pHandleInfo->HandleAttributes, pszType ));5194 pHandleInfo->GrantedAccess, pHandleInfo->HandleAttributes, pszType, pHandleInfo->ObjectTypeIndex)); 5105 5195 rc = RTErrInfoAddF(pErrInfo, VERR_SUPDRV_HARDENING_EVIL_HANDLE, 5106 5196 *pErrInfo->pszMsg 5107 ? "\nFound evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s "5108 : "Found evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s ",5197 ? "\nFound evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s (%u)" 5198 : "Found evil handle to budding VM process: pid=%p h=%p acc=%#x attr=%#x type=%s (%u)", 5109 5199 pHandleInfo->UniqueProcessId, pHandleInfo->HandleValue, 5110 pHandleInfo->GrantedAccess, pHandleInfo->HandleAttributes, pszType );5200 pHandleInfo->GrantedAccess, pHandleInfo->HandleAttributes, pszType, pHandleInfo->ObjectTypeIndex); 5111 5201 5112 5202 /* Try add the process name. */
Note:
See TracChangeset
for help on using the changeset viewer.