Changeset 90587 in vbox for trunk/src/VBox/Devices/Security
- Timestamp:
- Aug 10, 2021 9:39:57 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 146198
- Location:
- trunk/src/VBox/Devices/Security
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Security/DevTpm.cpp
r90580 r90587 29 29 #include <iprt/string.h> 30 30 #include <iprt/uuid.h> 31 32 #include <iprt/formats/tpm.h> 31 33 32 34 #include "VBoxDD.h" … … 348 350 /** Locality response buffer size register. */ 349 351 #define TPM_CRB_LOCALITY_REG_CTRL_RSP_SZ 0x64 350 /** Locality response buffer sizeregister. */352 /** Locality response buffer address register. */ 351 353 #define TPM_CRB_LOCALITY_REG_CTRL_RSP_ADDR 0x68 352 354 /** Locality data buffer. */ … … 452 454 typedef struct DEVTPMR3 453 455 { 456 /** Pointer to the device instance. */ 457 PPDMDEVINS pDevIns; 454 458 /** The base interface for LUN\#0. */ 455 459 PDMIBASE IBase; … … 936 940 break; 937 941 if ( (u32 & TPM_CRB_LOCALITY_REG_CTRL_REQ_CMD_RDY) 938 && pThis->enmState == DEVTPMSTATE_IDLE) 942 && ( pThis->enmState == DEVTPMSTATE_IDLE 943 || pThis->enmState == DEVTPMSTATE_CMD_COMPLETION)) 939 944 { 940 945 pThis->enmState = DEVTPMSTATE_READY; … … 967 972 && u32 == 0x1) 968 973 { 969 pThis->enmState = =DEVTPMSTATE_CMD_EXEC;974 pThis->enmState = DEVTPMSTATE_CMD_EXEC; 970 975 rc = PDMDevHlpTaskTrigger(pDevIns, pThis->hTpmCmdTask); 971 976 } … … 1008 1013 Assert(!(off & (cb - 1))); 1009 1014 1010 LogFlowFunc((": %RGp %#x\n", off, cb));1011 1015 VBOXSTRICTRC rc = VINF_SUCCESS; 1012 1016 uint32_t uReg = tpmGetRegisterFromOffset(off); 1013 1017 uint8_t bLoc = tpmGetLocalityFromOffset(off); 1014 1018 PDEVTPMLOCALITY pLoc = &pThis->aLoc[bLoc]; 1015 1016 1019 1017 1020 uint64_t u64; … … 1020 1023 else 1021 1024 rc = tpmMmioFifoRead(pDevIns, pThis, pLoc, bLoc, uReg, &u64); 1025 1026 LogFlowFunc((": %RGp %#x %#llx\n", off, cb, u64)); 1022 1027 1023 1028 if (rc == VINF_SUCCESS) … … 1085 1090 LogFlowFunc(("\n")); 1086 1091 1087 /** @todo */ 1088 RT_NOREF(pThis, pThisCC); 1089 pThis->enmState = DEVTPMSTATE_CMD_COMPLETION; 1092 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, pDevIns->pCritSectRoR3, VERR_IGNORED); 1093 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, pDevIns->pCritSectRoR3, rcLock); 1094 1095 if (pThisCC->pDrvTpm) 1096 { 1097 size_t cbCmd = RTTpmReqGetSz((PCTPMREQHDR)&pThis->abCmdResp[0]); 1098 int rc = pThisCC->pDrvTpm->pfnCmdExec(pThisCC->pDrvTpm, pThis->bLoc, &pThis->abCmdResp[0], cbCmd, 1099 &pThis->abCmdResp[0], sizeof(pThis->abCmdResp)); 1100 if (RT_SUCCESS(rc)) 1101 { 1102 pThis->enmState = DEVTPMSTATE_CMD_COMPLETION; 1103 tpmLocSetIntSts(pThisCC->pDevIns, pThis, &pThis->aLoc[pThis->bLoc], TPM_CRB_LOCALITY_REG_INT_STS_START); 1104 } 1105 else 1106 { 1107 /* Set fatal error. */ 1108 pThis->enmState = DEVTPMSTATE_FATAL_ERROR; 1109 } 1110 } 1111 1112 PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3); 1090 1113 } 1091 1114 … … 1171 1194 1172 1195 /** 1196 * @interface_method_impl{PDMDEVREG,pfnPowerOff} 1197 */ 1198 static DECLCALLBACK(void) tpmR3PowerOff(PPDMDEVINS pDevIns) 1199 { 1200 PDEVTPMCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVTPMCC); 1201 1202 if (pThisCC->pDrvTpm) 1203 { 1204 int rc = pThisCC->pDrvTpm->pfnShutdown(pThisCC->pDrvTpm); 1205 AssertRC(rc); 1206 } 1207 } 1208 1209 1210 /** 1173 1211 * @interface_method_impl{PDMDEVREG,pfnReset} 1174 1212 */ … … 1218 1256 1219 1257 pThis->hTpmCmdTask = NIL_PDMTASKHANDLE; 1258 1259 pThisCC->pDevIns = pDevIns; 1220 1260 1221 1261 /* IBase */ … … 1275 1315 pThisCC->pDrvTpm = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMITPMCONNECTOR); 1276 1316 AssertLogRelMsgReturn(pThisCC->pDrvTpm, ("TPM#%d: Driver is missing the TPM interface.\n", iInstance), VERR_PDM_MISSING_INTERFACE); 1317 1318 /* Startup the TPM here instead of in the power on callback as we can convey errors here to the upper layer. */ 1319 rc = pThisCC->pDrvTpm->pfnStartup(pThisCC->pDrvTpm, sizeof(pThis->abCmdResp)); 1320 if (RT_FAILURE(rc)) 1321 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to startup the TPM")); 1277 1322 } 1278 1323 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) … … 1353 1398 /* .pfnQueryInterface = */ NULL, 1354 1399 /* .pfnInitComplete = */ NULL, 1355 /* .pfnPowerOff = */ NULL,1400 /* .pfnPowerOff = */ tpmR3PowerOff, 1356 1401 /* .pfnSoftReset = */ NULL, 1357 1402 /* .pfnReserved0 = */ NULL, -
trunk/src/VBox/Devices/Security/DrvTpmEmu.cpp
r90580 r90587 35 35 #include <iprt/uuid.h> 36 36 #include <iprt/json.h> 37 38 #include <iprt/formats/tpm.h> 37 39 38 40 #include "VBoxDD.h" … … 258 260 RTSOCKET hSockData; 259 261 262 #if 0 260 263 /** Poll set used to wait for I/O events. */ 261 264 RTPOLLSET hPollSet; … … 269 272 /** Flag to signal whether the thread was woken up from external. */ 270 273 bool volatile fWokenUp; 274 #endif 275 271 276 /** Currently set locality. */ 272 277 uint8_t bLoc; … … 411 416 return drvTpmEmuExecCtrlCmdEx(pThis, enmCmd, pvCmd, cbCmd, pu32Resp, 412 417 NULL /*pvResp*/, 0 /*cbResp*/, cMillies); 418 } 419 420 421 /** 422 * Executes the given command over the control connection to the TPM emulator - variant with no command payload. 423 * 424 * @returns VBox status code. 425 * @retval VERR_NET_IO_ERROR if the executed command returned an error in the response status field. 426 * @param pThis Pointer to the TPM emulator driver instance data. 427 * @param enmCmd The command to execute. 428 * @param pvResp Where to store additional resposne data. 429 * @param cbResp Size of the Response data in bytes (excluding the response status code which is implicit). 430 * @param cMillies Number of milliseconds to wait before aborting the command with a timeout error. 431 */ 432 static int drvTpmEmuExecCtrlCmdNoPayloadAndResp(PDRVTPMEMU pThis, SWTPMCMD enmCmd, RTMSINTERVAL cMillies) 433 { 434 uint32_t u32Resp = 0; 435 int rc = drvTpmEmuExecCtrlCmdEx(pThis, enmCmd, NULL /*pvCmd*/, 0 /*cbCmd*/, &u32Resp, 436 NULL /*pvResp*/, 0 /*cbResp*/, cMillies); 437 if (RT_SUCCESS(rc)) 438 { 439 if (u32Resp != 0) 440 rc = VERR_NET_IO_ERROR; 441 } 442 443 return rc; 413 444 } 414 445 … … 523 554 rc = VERR_NET_IO_ERROR; 524 555 556 if (RT_SUCCESS(rc)) 557 pThis->bLoc = bLoc; 558 525 559 return rc; 526 560 } … … 612 646 if (RT_SUCCESS(rc)) 613 647 { 614 RT_NOREF(pInterface, bLoc, pvCmd, cbCmd, pvResp, cbResp); 648 rc = RTSocketWrite(pThis->hSockData, pvCmd, cbCmd); 649 if (RT_SUCCESS(rc)) 650 { 651 rc = RTSocketSelectOne(pThis->hSockData, RT_MS_10SEC); 652 if (RT_SUCCESS(rc)) 653 { 654 /* Read the response header in first. */ 655 TPMRESPHDR RespHdr; 656 rc = RTSocketRead(pThis->hSockData, &RespHdr, sizeof(RespHdr), NULL /*pcbRead*/); 657 if (RT_SUCCESS(rc)) 658 { 659 size_t cbHdrResp = RTTpmRespGetSz(&RespHdr); 660 if (cbHdrResp <= cbResp - sizeof(RespHdr)) 661 { 662 memcpy(pvResp, &RespHdr, sizeof(RespHdr)); 663 664 if (cbHdrResp > sizeof(RespHdr)) 665 rc = RTSocketRead(pThis->hSockData, (uint8_t *)pvResp + sizeof(RespHdr), cbHdrResp - sizeof(RespHdr), 666 NULL /*pcbRead*/); 667 } 668 else 669 rc = VERR_BUFFER_OVERFLOW; 670 } 671 } 672 } 615 673 } 616 674 … … 622 680 static DECLCALLBACK(int) drvTpmEmuCmdCancel(PPDMITPMCONNECTOR pInterface) 623 681 { 624 RT_NOREF(pInterface); 625 return VERR_NOT_IMPLEMENTED; 682 PDRVTPMEMU pThis = RT_FROM_MEMBER(pInterface, DRVTPMEMU, ITpmConnector); 683 684 return drvTpmEmuExecCtrlCmdNoPayloadAndResp(pThis, SWTPMCMD_CANCEL_TPM_CMD, RT_MS_10SEC); 626 685 } 627 686 … … 649 708 if (pThis->hSockCtrl != NIL_RTSOCKET) 650 709 { 710 #if 0 651 711 int rc = RTPollSetRemove(pThis->hPollSet, DRVTPMEMU_POLLSET_ID_SOCKET_CTRL); 652 712 AssertRC(rc); 653 654 rc = RTSocketShutdown(pThis->hSockCtrl, true /* fRead */, true /* fWrite */); 713 #endif 714 715 int rc = RTSocketShutdown(pThis->hSockCtrl, true /* fRead */, true /* fWrite */); 655 716 AssertRC(rc); 656 717 … … 663 724 if (pThis->hSockData != NIL_RTSOCKET) 664 725 { 726 #if 0 665 727 int rc = RTPollSetRemove(pThis->hPollSet, DRVTPMEMU_POLLSET_ID_SOCKET_DATA); 666 728 AssertRC(rc); 667 668 rc = RTSocketShutdown(pThis->hSockData, true /* fRead */, true /* fWrite */); 729 #endif 730 731 int rc = RTSocketShutdown(pThis->hSockData, true /* fRead */, true /* fWrite */); 669 732 AssertRC(rc); 670 733 … … 675 738 } 676 739 740 #if 0 677 741 if (pThis->hPipeWakeR != NIL_RTPIPE) 678 742 { … … 698 762 pThis->hPollSet = NIL_RTPOLLSET; 699 763 } 764 #endif 700 765 } 701 766 … … 717 782 pThis->bLoc = TPM_NO_LOCALITY_SELECTED; 718 783 784 #if 0 719 785 pThis->hPollSet = NIL_RTPOLLSET; 720 786 pThis->hPipeWakeR = NIL_RTPIPE; 721 787 pThis->hPipeWakeW = NIL_RTPIPE; 788 #endif 722 789 723 790 /* IBase */ … … 744 811 N_("Configuration error: querying \"Location\" resulted in %Rrc"), rc); 745 812 813 #if 0 746 814 rc = RTPipeCreate(&pThis->hPipeWakeR, &pThis->hPipeWakeW, 0 /* fFlags */); 747 815 if (RT_FAILURE(rc)) … … 761 829 N_("DrvTpmEmu#%d failed to add wakeup pipe for %s to poll set"), 762 830 pDrvIns->iInstance, szLocation); 831 #endif 763 832 764 833 /* … … 783 852 if (RT_FAILURE(rc)) 784 853 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 785 N_("DrvTpmEmu#%d failed to connect to socket %s"),854 N_("DrvTpmEmu#%d failed to connect to control socket %s"), 786 855 pDrvIns->iInstance, szLocation); 787 856 857 #if 0 788 858 rc = RTPollSetAddSocket(pThis->hPollSet, pThis->hSockCtrl, 789 859 RTPOLL_EVT_READ | RTPOLL_EVT_WRITE | RTPOLL_EVT_ERROR, … … 793 863 N_("DrvTpmEmu#%d failed to add socket for %s to poll set"), 794 864 pDrvIns->iInstance, szLocation); 865 #endif 795 866 796 867 rc = drvTpmEmuQueryCaps(pThis); … … 839 910 N_("DrvTpmEmu#%d Emulated TPM version of %s does not offer required set of capabilities (%#x requested vs. %#x offered)"), 840 911 pDrvIns->iInstance, szLocation, fCapsReq, pThis->fCaps); 912 913 /* Connect the data channel now. */ 914 /** @todo Allow configuring a different port. */ 915 *pszPort = '\0'; /* Overwrite temporarily to avoid copying the hostname into a temporary buffer. */ 916 rc = RTTcpClientConnect(szLocation, uPort + 1, &pThis->hSockData); 917 *pszPort = ':'; /* Restore delimiter before checking the status. */ 918 if (RT_FAILURE(rc)) 919 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 920 N_("DrvTpmEmu#%d failed to connect to data socket %s"), 921 pDrvIns->iInstance, szLocation); 841 922 842 923 LogRel(("DrvTpmEmu#%d: Connected to %s, emulating TPM version %s\n", pDrvIns->iInstance, szLocation, pszTpmVers));
Note:
See TracChangeset
for help on using the changeset viewer.