瀏覽代碼

[xhci] Leak memory if controller fails to disable slot

If the Disable Slot command fails then the hardware may continue to
write to the slot context.  Leak the memory used by the slot context
to avoid future memory corruption.

This situation has been observed in practice when a Set Address
command fails, causing the command ring to become temporarily
unresponsive.

Note that there is no need to similarly leak memory on the failure
path in xhci_device_open(), since in the event of a failure the
hardware is never informed of the slot context address.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 年之前
父節點
當前提交
88448de720
共有 1 個檔案被更改,包括 18 行新增3 行删除
  1. 18
    3
      src/drivers/usb/xhci.c

+ 18
- 3
src/drivers/usb/xhci.c 查看文件

2587
 	struct xhci_device *xhci = slot->xhci;
2587
 	struct xhci_device *xhci = slot->xhci;
2588
 	size_t len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
2588
 	size_t len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
2589
 	unsigned int id = slot->id;
2589
 	unsigned int id = slot->id;
2590
+	int rc;
2590
 
2591
 
2591
 	/* Disable slot */
2592
 	/* Disable slot */
2592
-	xhci_disable_slot ( xhci, id );
2593
+	if ( ( rc = xhci_disable_slot ( xhci, id ) ) != 0 ) {
2594
+		/* Slot is still enabled.  Leak the slot context,
2595
+		 * since the controller may still write to this
2596
+		 * memory, and leave the DCBAA entry intact.
2597
+		 *
2598
+		 * If the controller later reports that this same slot
2599
+		 * has been re-enabled, then some assertions will be
2600
+		 * triggered.
2601
+		 */
2602
+		DBGC ( xhci, "XHCI %p slot %d leaking context memory\n",
2603
+		      xhci, slot->id );
2604
+		slot->context = NULL;
2605
+	}
2593
 
2606
 
2594
 	/* Free slot */
2607
 	/* Free slot */
2595
-	free_dma ( slot->context, len );
2596
-	xhci->dcbaa[id] = 0;
2608
+	if ( slot->context ) {
2609
+		free_dma ( slot->context, len );
2610
+		xhci->dcbaa[id] = 0;
2611
+	}
2597
 	xhci->slot[id] = NULL;
2612
 	xhci->slot[id] = NULL;
2598
 	free ( slot );
2613
 	free ( slot );
2599
 }
2614
 }

Loading…
取消
儲存