Skip to content

Commit c34360b

Browse files
xiaoguangwulijinxia
authored andcommitted
DM USB: Fix potential crash issues.
This patch fix some potential crash issues, like wild pointers access, buffer overflow and etc. Change-Id: Iddd8e1820da426adc6b9b4d9da9e44017d9f365c Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Yu Wang <yu1.wang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent e334675 commit c34360b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

devicemodel/hw/pci/xhci.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ pci_xhci_dev_destroy(struct pci_xhci_dev_emu *de)
748748
if (ue->ue_deinit)
749749
ue->ue_deinit(ud);
750750
}
751-
}
751+
} else
752+
return;
752753

753754
if (ue->ue_devtype == USB_DEV_PORT_MAPPER)
754755
free(ue);
@@ -3314,7 +3315,8 @@ pci_xhci_parse_bus_port(struct pci_xhci_vdev *xdev, char *opts)
33143315

33153316
/* 'bus-port' format */
33163317
cnt = sscanf(opts, "%u-%u", &bus, &port);
3317-
if (cnt == EOF || cnt < 2) {
3318+
if (cnt == EOF || cnt < 2 || bus >= USB_NATIVE_NUM_BUS ||
3319+
port >= USB_NATIVE_NUM_PORT) {
33183320
rc = -1;
33193321
goto errout;
33203322
}
@@ -3534,7 +3536,10 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts)
35343536
xdev->portregs = NULL;
35353537
}
35363538
UPRINTF(LFTL, "fail to parse xHCI options, rc=%d\r\n", rc);
3537-
pci_xhci_device_usage(opts);
3539+
3540+
if (opts)
3541+
pci_xhci_device_usage(opts);
3542+
35383543
return rc;
35393544
}
35403545

devicemodel/hw/platform/usb_pmapper.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ usb_dev_prepare_xfer(struct usb_data_xfer *xfer, int *count, int *size)
149149
found = 0;
150150
first = -1;
151151
c = s = 0;
152-
if (!count || !size)
152+
if (!count || !size || idx < 0 || idx >= USB_MAX_XFER_BLOCKS)
153153
return -1;
154154

155155
for (i = 0; i < xfer->ndata; i++) {
@@ -452,6 +452,10 @@ usb_dev_prepare_ctrl_xfer(struct usb_data_xfer *xfer)
452452
struct usb_data_xfer_block *blk = NULL;
453453

454454
idx = xfer->head;
455+
456+
if (idx < 0 || idx >= USB_MAX_XFER_BLOCKS)
457+
return NULL;
458+
455459
for (i = 0; i < xfer->ndata; i++) {
456460
/*
457461
* find out the data block and set every

0 commit comments

Comments
 (0)