Skip to content

Commit 5fbabc9

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: io_edgeport: fix epic-descriptor handling
commit e4457d9798adb96272468e93da663de9bd0a4198 upstream. Use a dedicated buffer for the DMA transfer and make sure to detect short transfers to avoid parsing a corrupt descriptor. Fixes: 6e8cf77 ("USB: add EPIC support to the io_edgeport driver") Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aece86f commit 5fbabc9

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

drivers/usb/serial/io_edgeport.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,24 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
492492
int result;
493493
struct usb_serial *serial = ep->serial;
494494
struct edgeport_product_info *product_info = &ep->product_info;
495-
struct edge_compatibility_descriptor *epic = &ep->epic_descriptor;
495+
struct edge_compatibility_descriptor *epic;
496496
struct edge_compatibility_bits *bits;
497497
struct device *dev = &serial->dev->dev;
498498

499499
ep->is_epic = 0;
500+
501+
epic = kmalloc(sizeof(*epic), GFP_KERNEL);
502+
if (!epic)
503+
return -ENOMEM;
504+
500505
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
501506
USB_REQUEST_ION_GET_EPIC_DESC,
502507
0xC0, 0x00, 0x00,
503-
&ep->epic_descriptor,
504-
sizeof(struct edge_compatibility_descriptor),
508+
epic, sizeof(*epic),
505509
300);
506-
507-
if (result > 0) {
510+
if (result == sizeof(*epic)) {
508511
ep->is_epic = 1;
512+
memcpy(&ep->epic_descriptor, epic, sizeof(*epic));
509513
memset(product_info, 0, sizeof(struct edgeport_product_info));
510514

511515
product_info->NumPorts = epic->NumPorts;
@@ -534,8 +538,16 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
534538
dev_dbg(dev, " IOSPWriteLCR : %s\n", bits->IOSPWriteLCR ? "TRUE": "FALSE");
535539
dev_dbg(dev, " IOSPSetBaudRate : %s\n", bits->IOSPSetBaudRate ? "TRUE": "FALSE");
536540
dev_dbg(dev, " TrueEdgeport : %s\n", bits->TrueEdgeport ? "TRUE": "FALSE");
541+
542+
result = 0;
543+
} else if (result >= 0) {
544+
dev_warn(&serial->interface->dev, "short epic descriptor received: %d\n",
545+
result);
546+
result = -EIO;
537547
}
538548

549+
kfree(epic);
550+
539551
return result;
540552
}
541553

@@ -2789,7 +2801,7 @@ static int edge_startup(struct usb_serial *serial)
27892801
dev_info(&serial->dev->dev, "%s detected\n", edge_serial->name);
27902802

27912803
/* Read the epic descriptor */
2792-
if (get_epic_descriptor(edge_serial) <= 0) {
2804+
if (get_epic_descriptor(edge_serial) < 0) {
27932805
/* memcpy descriptor to Supports structures */
27942806
memcpy(&edge_serial->epic_descriptor.Supports, descriptor,
27952807
sizeof(struct edge_compatibility_bits));

0 commit comments

Comments
 (0)