Changeset 87161 in vbox for trunk/src/VBox
- Timestamp:
- Jan 4, 2021 12:45:18 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/USB/usbip/USBProxyDevice-usbip.cpp
r82968 r87161 820 820 static int usbProxyUsbIpDisconnect(PUSBPROXYDEVUSBIP pProxyDevUsbIp) 821 821 { 822 int rc = VINF_SUCCESS; 822 int rc = RTPollSetRemove(pProxyDevUsbIp->hPollSet, USBIP_POLL_ID_SOCKET); 823 Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND); 823 824 824 825 rc = RTTcpClientCloseEx(pProxyDevUsbIp->hSocket, false /*fGracefulShutdown*/); … … 964 965 case USBPROXYUSBIPRECVSTATE_HDR_RESIDUAL: 965 966 { 966 /** @todo Verify that the directions match, verify that the length doesn't exceed the buffer. */967 968 967 switch (RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32ReqRet)) 969 968 { … … 980 979 { 981 980 uint8_t *pbData = NULL; 981 size_t cbRet = 0; 982 982 983 983 AssertPtr(pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb); … … 986 986 /* Preserve the setup request. */ 987 987 pbData = &pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->abData[sizeof(VUSBSETUP)]; 988 pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData= pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength + sizeof(VUSBSETUP);988 cbRet = pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength + sizeof(VUSBSETUP); 989 989 } 990 990 else 991 991 { 992 992 pbData = &pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->abData[0]; 993 pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData= pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength;993 cbRet = pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength; 994 994 } 995 995 996 996 if (pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength) 997 usbProxyUsbIpRecvStateAdvance(pProxyDevUsbIp, USBPROXYUSBIPRECVSTATE_URB_BUFFER, 998 pbData, pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength); 997 { 998 if (RT_LIKELY(pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData >= cbRet)) 999 { 1000 pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData = cbRet; 1001 usbProxyUsbIpRecvStateAdvance(pProxyDevUsbIp, USBPROXYUSBIPRECVSTATE_URB_BUFFER, 1002 pbData, pProxyDevUsbIp->BufRet.RetSubmit.u32ActualLength); 1003 } 1004 else 1005 { 1006 /* 1007 * Bogus length returned from the USB/IP remote server. 1008 * Error out because there is no way to find the end of the current 1009 * URB and the beginning of the next one. The error will cause closing the 1010 * connection to the rogue remote and all URBs get completed with an error. 1011 */ 1012 LogRelMax(10, ("USB/IP: Received reply with sequence number %u contains invalid length %zu (max %zu)\n", 1013 pProxyDevUsbIp->BufRet.Hdr.u32SeqNum, cbRet, 1014 pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData)); 1015 rc = VERR_NET_PROTOCOL_ERROR; 1016 } 1017 } 999 1018 else 1000 1019 { … … 1015 1034 RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32SeqNum))); 1016 1035 usbProxyUsbIpResetRecvState(pProxyDevUsbIp); 1036 rc = VERR_NET_PROTOCOL_ERROR; 1017 1037 } 1018 1038 break; … … 1049 1069 { 1050 1070 PVUSBURBISOCPTK pIsocPkt = &pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->aIsocPkts[i]; 1051 usbProxyUsbIpIsocPktDescN2H(&pProxyDevUsbIp->aIsocPktDesc[i]); 1052 pIsocPkt->enmStatus = usbProxyUsbIpVUsbStatusConvertFromStatus(pProxyDevUsbIp->aIsocPktDesc[i].i32Status); 1053 pIsocPkt->off = pProxyDevUsbIp->aIsocPktDesc[i].u32Offset; 1054 pIsocPkt->cb = pProxyDevUsbIp->aIsocPktDesc[i].u32ActualLength; 1071 PUsbIpIsocPktDesc pIsocPktUsbIp = &pProxyDevUsbIp->aIsocPktDesc[i]; 1072 1073 usbProxyUsbIpIsocPktDescN2H(pIsocPktUsbIp); 1074 pIsocPkt->enmStatus = usbProxyUsbIpVUsbStatusConvertFromStatus(pIsocPktUsbIp->i32Status); 1075 1076 if (RT_LIKELY( pIsocPktUsbIp->u32Offset < pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData 1077 && pProxyDevUsbIp->pUrbUsbIp->pVUsbUrb->cbData - pIsocPktUsbIp->u32Offset >= pIsocPktUsbIp->u32ActualLength)) 1078 { 1079 pIsocPkt->off = pIsocPktUsbIp->u32Offset; 1080 pIsocPkt->cb = pIsocPktUsbIp->u32ActualLength; 1081 } 1082 else 1083 { 1084 /* 1085 * The offset and length value in the isoc packet descriptor are bogus and would cause a buffer overflow later on, leave an 1086 * error message and disconnect from the rogue remote end. 1087 */ 1088 LogRelMax(10, ("USB/IP: Received reply with sequence number %u contains invalid isoc packet descriptor %u (offset=%u length=%u)\n", 1089 pProxyDevUsbIp->BufRet.Hdr.u32SeqNum, i, 1090 pIsocPktUsbIp->u32Offset, pIsocPktUsbIp->u32ActualLength)); 1091 rc = VERR_NET_PROTOCOL_ERROR; 1092 break; 1093 } 1055 1094 } 1056 1095 … … 1063 1102 } 1064 1103 } 1065 else1066 {1067 /** @todo Complete all URBs with DNR error and mark device as unplugged. */1068 #if 01069 pUrbUsbIp = pProxyDevUsbIp->pUrbUsbIp;1070 pUrbUsbIp->pVUsbUrb->enmStatus = VUSBSTATUS_DNR;1071 usbProxyUsbIpResetRecvState(pProxyDevUsbIp);1072 #endif1073 }1074 1104 1075 1105 if (RT_SUCCESS(rc)) 1076 1106 *ppUrbUsbIp = pUrbUsbIp; 1107 else 1108 { 1109 /* Complete all URBs with DNR error and mark device as unplugged, the current one is still in the in flight list. */ 1110 pProxyDevUsbIp->pUrbUsbIp = NULL; 1111 usbProxyUsbIpResetRecvState(pProxyDevUsbIp); 1112 usbProxyUsbIpDisconnect(pProxyDevUsbIp); 1113 1114 rc = RTSemFastMutexRequest(pProxyDevUsbIp->hMtxLists); 1115 AssertRC(rc); 1116 PUSBPROXYURBUSBIP pIt; 1117 PUSBPROXYURBUSBIP pItNext; 1118 RTListForEachSafe(&pProxyDevUsbIp->ListUrbsInFlight, pIt, pItNext, USBPROXYURBUSBIP, NodeList) 1119 { 1120 if (pIt->pVUsbUrb) /* can be NULL for requests created by usbProxyUsbIpCtrlUrbExchangeSync(). */ 1121 pIt->pVUsbUrb->enmStatus = VUSBSTATUS_CRC; 1122 RTListNodeRemove(&pIt->NodeList); 1123 RTListAppend(&pProxyDevUsbIp->ListUrbsLanded, &pIt->NodeList); 1124 } 1125 RTSemFastMutexRelease(pProxyDevUsbIp->hMtxLists); 1126 } 1077 1127 1078 1128 return rc; … … 1171 1221 break; 1172 1222 default: 1173 usbProxyUsbIpUrbFree(pProxyDevUsbIp, pUrbUsbIp);1174 1223 return VERR_INVALID_PARAMETER; /** @todo better status code. */ 1175 1224 } … … 1216 1265 if (RT_FAILURE(rc)) 1217 1266 { 1218 /** @todo Complete the URB with an error. */ 1219 usbProxyUsbIpUrbFree(pProxyDevUsbIp, pIter); 1267 /* Complete URB with an error and place into landed list. */ 1268 pIter->pVUsbUrb->enmStatus = VUSBSTATUS_DNR; 1269 usbProxyUsbIpLinkUrb(pProxyDevUsbIp, &pProxyDevUsbIp->ListUrbsLanded, pIter); 1220 1270 } 1221 1271 } … … 1475 1525 1476 1526 PUSBPROXYDEVUSBIP pDevUsbIp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVUSBIP); 1527 if (pDevUsbIp->hSocket != NIL_RTSOCKET) 1528 usbProxyUsbIpDisconnect(pDevUsbIp); 1529 1477 1530 /* Destroy the pipe and pollset if necessary. */ 1478 1531 if (pDevUsbIp->hPollSet != NIL_RTPOLLSET) 1479 1532 { 1480 if (pDevUsbIp->hSocket != NIL_RTSOCKET)1481 {1482 rc = RTPollSetRemove(pDevUsbIp->hPollSet, USBIP_POLL_ID_SOCKET);1483 Assert(RT_SUCCESS(rc) || rc == VERR_POLL_HANDLE_ID_NOT_FOUND);1484 }1485 1533 rc = RTPollSetRemove(pDevUsbIp->hPollSet, USBIP_POLL_ID_PIPE); 1486 1534 AssertRC(rc); … … 1493 1541 } 1494 1542 1495 if (pDevUsbIp->hSocket != NIL_RTSOCKET)1496 usbProxyUsbIpDisconnect(pDevUsbIp);1497 1543 if (pDevUsbIp->pszHost) 1498 1544 RTStrFree(pDevUsbIp->pszHost);
Note:
See TracChangeset
for help on using the changeset viewer.