Changeset 75052 in vbox for trunk/src/VBox/HostDrivers/Support/darwin
- Timestamp:
- Oct 24, 2018 4:40:28 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 126099
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r75050 r75052 34 34 #include "../SUPDrvInternal.h" 35 35 #include <VBox/version.h> 36 #include <iprt/assert.h> 36 37 #include <iprt/asm.h> 37 38 #include <iprt/asm-amd64-x86.h> 39 #include <iprt/ctype.h> 40 #include <iprt/dbg.h> 38 41 #include <iprt/initterm.h> 39 #include <iprt/assert.h> 42 #include <iprt/file.h> 43 #include <iprt/ldr.h> 44 #include <iprt/mem.h> 45 #include <iprt/power.h> 46 #include <iprt/process.h> 40 47 #include <iprt/spinlock.h> 41 48 #include <iprt/semaphore.h> 42 #include <iprt/process.h>43 #include <iprt/alloc.h>44 #include <iprt/power.h>45 #include <iprt/dbg.h>46 49 #include <iprt/x86.h> 50 #include <iprt/crypto/applecodesign.h> 51 #include <iprt/crypto/store.h> 52 #include <iprt/crypto/pkcs7.h> 53 #include <iprt/crypto/x509.h> 47 54 #include <VBox/err.h> 48 55 #include <VBox/log.h> … … 94 101 static kern_return_t VBoxDrvDarwinStart(struct kmod_info *pKModInfo, void *pvData); 95 102 static kern_return_t VBoxDrvDarwinStop(struct kmod_info *pKModInfo, void *pvData); 103 #ifdef SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION 104 static int supdrvDarwinInitCertStores(PSUPDRVDEVEXT pDevExt); 105 static void supdrvDarwinDestroyCertStores(PSUPDRVDEVEXT pDevExt); 106 #endif 96 107 97 108 static int VBoxDrvDarwinOpen(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess); … … 275 286 if (RT_SUCCESS(rc)) 276 287 { 288 #ifdef SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION 289 supdrvDarwinInitCertStores(&g_DevExt); 290 #endif 291 277 292 /* 278 293 * Initialize the session hash table. … … 338 353 LogRel(("VBoxDrv: cdevsw_add failed (%d)\n", g_iMajorDeviceNo)); 339 354 } 355 #ifdef SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION 356 supdrvDarwinDestroyCertStores(&g_DevExt); 357 #endif 340 358 RTSpinlockDestroy(g_Spinlock); 341 359 g_Spinlock = NIL_RTSPINLOCK; … … 421 439 422 440 441 #ifdef SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION 442 443 /** 444 * Initalizes the certificate stores (code signing) in the device extension. 445 */ 446 static int supdrvDarwinInitCertStores(PSUPDRVDEVEXT pDevExt) 447 { 448 pDevExt->hAdditionalStore = NIL_RTCRSTORE; 449 450 pDevExt->hRootStore = NIL_RTCRSTORE; 451 int rc = RTCrStoreCreateInMem(&pDevExt->hRootStore, g_cSUPTrustedTAs + 1); 452 if (RT_SUCCESS(rc)) 453 { 454 for (uint32_t i = 0; i < g_cSUPTrustedTAs; i++) 455 { 456 int rc2 = RTCrStoreCertAddEncoded(pDevExt->hRootStore, RTCRCERTCTX_F_ENC_TAF_DER, 457 g_aSUPTrustedTAs[i].pch, g_aSUPTrustedTAs[i].cb, NULL); 458 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 459 { 460 printf("VBoxDrv: Error loading g_aSUPTrustedTAs[%u]: %d\n", i, rc); 461 rc = rc2; 462 } 463 } 464 465 /* We implicitly trust the build certificate. */ 466 int rc2 = RTCrStoreCertAddEncoded(pDevExt->hRootStore, RTCRCERTCTX_F_ENC_X509_DER, 467 g_abSUPBuildCert, g_cbSUPBuildCert, NULL); 468 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 469 { 470 printf("VBoxDrv: Error loading g_cbSUPBuildCert: %d\n", rc); 471 rc = rc2; 472 } 473 } 474 return rc; 475 } 476 477 478 /** 479 * Releases the certificate stores in the device extension. 480 */ 481 static void supdrvDarwinDestroyCertStores(PSUPDRVDEVEXT pDevExt) 482 { 483 if (pDevExt->hRootStore != NIL_RTCRSTORE) 484 { 485 uint32_t cRefs = RTCrStoreRelease(pDevExt->hRootStore); 486 Assert(cRefs == 0); RT_NOREF(cRefs); 487 pDevExt->hRootStore = NIL_RTCRSTORE; 488 } 489 if (pDevExt->hAdditionalStore != NIL_RTCRSTORE) 490 { 491 uint32_t cRefs = RTCrStoreRelease(pDevExt->hAdditionalStore); 492 Assert(cRefs == 0); RT_NOREF(cRefs); 493 pDevExt->hAdditionalStore = NIL_RTCRSTORE; 494 } 495 } 496 497 #endif /* SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION */ 498 423 499 /** 424 500 * Stop the kernel module. … … 457 533 AssertRC(rc); 458 534 g_Spinlock = NIL_RTSPINLOCK; 535 536 #ifdef SUPDRV_WITH_DARWIN_IMAGE_VERIFICATION 537 supdrvDarwinDestroyCertStores(&g_DevExt); 538 #endif 459 539 460 540 RTR0TermForced(); … … 1167 1247 * Check already loaded modules. 1168 1248 */ 1169 for (PSUPDRVLDRIMAGE pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) ;1249 for (PSUPDRVLDRIMAGE pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) 1170 1250 if ( pImage->uState == SUP_IOCTL_LDR_LOAD 1171 1251 && pImage->hLdrMod != NIL_RTLDRMOD) … … 1180 1260 */ 1181 1261 printf("VBoxDrv: Unable to resolve symbol '%s'.\n", pszSymbol); 1262 RT_NOREF(hLdrMod, pszModule, uSymbol); 1182 1263 return VERR_SYMBOL_NOT_FOUND; 1183 1264 } … … 1236 1317 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, 1237 1318 "Certificate is missing the 'Dev ID Application' extension"); 1238 if (cDevIdKext == 0 && pState->fKernel)1319 if (cDevIdKext == 0) 1239 1320 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, 1240 1321 "Certificate is missing the 'Dev ID kext' extension"); … … 1254 1335 { 1255 1336 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pvUser; 1337 RT_NOREF_PV(hLdrMod); RT_NOREF_PV(cbSignature); 1338 1256 1339 switch (enmSignature) 1257 1340 { … … 1261 1344 PCRTCRPKCS7CONTENTINFO pContentInfo = (PCRTCRPKCS7CONTENTINFO)pvSignature; 1262 1345 RTTIMESPEC ValidationTime; 1263 RTTimeNow(&ValidationTime) 1346 RTTimeNow(&ValidationTime); 1264 1347 1265 1348 return RTCrPkcs7VerifySignedDataWithExternalData(pContentInfo, … … 1268 1351 | RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT, 1269 1352 pDevExt->hAdditionalStore, pDevExt->hRootStore, &ValidationTime, 1270 supdrvDarwinLdrOpenVerifyCertificatCallback, pDevExt 1353 supdrvDarwinLdrOpenVerifyCertificatCallback, pDevExt, 1271 1354 pvExternalData, cbExternalData, pErrInfo); 1272 1355 } … … 1274 1357 1275 1358 default: 1276 RT_NOREF_PV(hLdrMod); RT_NOREF_PV(cbSignature);1277 1359 return RTErrInfoSetF(pErrInfo, VERR_NOT_SUPPORTED, "Unsupported signature type: %d", enmSignature); 1278 1360 } … … 1298 1380 * freed via the RTFileReadAllFree callback when the loader module is closed. 1299 1381 */ 1300 void *pvFile 1301 size_t *pcbFile = 0;1382 void *pvFile = NULL; 1383 size_t cbFile = 0; 1302 1384 int rc = RTFileReadAllEx(pszFilename, 0, _32M, RTFILE_RDALL_O_DENY_WRITE, &pvFile, &cbFile); 1303 1385 if (RT_SUCCESS(rc)) … … 1343 1425 } 1344 1426 1345 RTR0MemObjFree(hMem Obj, true /*fFreeMappings*/);1427 RTR0MemObjFree(hMemAlloc, true /*fFreeMappings*/); 1346 1428 } 1347 1429 else 1348 printf("VBoxDrv: Failed to allocate %u bytes for %s: %d\n", (unsigned)cbImage, rc);1430 printf("VBoxDrv: Failed to allocate %u bytes for %s: %d\n", (unsigned)cbImage, pszFilename, rc); 1349 1431 } 1350 1432 else 1351 1433 { 1352 1434 printf("VBoxDrv: Image size mismatch for %s: %#x, ring-3 says %#x\n", 1353 pszFilename, cbImage,pImage->cbImageBits);1435 pszFilename, (unsigned)cbImage, (unsigned)pImage->cbImageBits); 1354 1436 rc = VERR_LDR_MISMATCH_NATIVE; 1355 1437 } … … 1384 1466 { 1385 1467 RT_NOREF(hLdrMod, pszSymbol, uSymbol); 1386 if ( uValue == (uintptr_t)pvUser)1468 if (Value == (uintptr_t)pvUser) 1387 1469 return VINF_CALLBACK_RETURN; 1388 1470 return VINF_SUCCESS; … … 1417 1499 } 1418 1500 else 1419 SUPR0Printf("SUPDrv: No export named %s (%p) in %s!\n", pszSymbol, uRvaToValidate, pImage->szName);1501 SUPR0Printf("SUPDrv: No export named %s (%p) in %s!\n", pszSymbol, pv, pImage->szName); 1420 1502 } 1421 1503 /* … … 1459 1541 if (!memcmp(pImage->pvImage, pbImageBits, pImage->cbImageBits)) 1460 1542 return VINF_SUCCESS; 1543 1544 RT_NOREF(pDevExt, pReq); 1461 1545 return VERR_LDR_MISMATCH_NATIVE; 1462 1546
Note:
See TracChangeset
for help on using the changeset viewer.