Skip to content

Commit a655b21

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: digi_acceleport: fix incomplete rx sanity check
commit 1b0aed2b1600f6e5c7b9acfbd610a4e351ef5232 upstream. Make sure the received data has the required headers before parsing it. Also drop the redundant urb-status check, which has already been handled by the caller. Fixes: 1da177e ("Linux-2.6.12-rc2") 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 07a9293 commit a655b21

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

drivers/usb/serial/digi_acceleport.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,25 +1399,30 @@ static int digi_read_inb_callback(struct urb *urb)
13991399
{
14001400
struct usb_serial_port *port = urb->context;
14011401
struct digi_port *priv = usb_get_serial_port_data(port);
1402-
int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1403-
int len = ((unsigned char *)urb->transfer_buffer)[1];
1404-
int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1405-
unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1402+
unsigned char *buf = urb->transfer_buffer;
1403+
int opcode;
1404+
int len;
1405+
int port_status;
1406+
unsigned char *data;
14061407
int flag, throttled;
1407-
int status = urb->status;
1408-
1409-
/* do not process callbacks on closed ports */
1410-
/* but do continue the read chain */
1411-
if (urb->status == -ENOENT)
1412-
return 0;
14131408

14141409
/* short/multiple packet check */
1410+
if (urb->actual_length < 2) {
1411+
dev_warn(&port->dev, "short packet received\n");
1412+
return -1;
1413+
}
1414+
1415+
opcode = buf[0];
1416+
len = buf[1];
1417+
14151418
if (urb->actual_length != len + 2) {
1416-
dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, "
1417-
"status=%d, port=%d, opcode=%d, len=%d, "
1418-
"actual_length=%d, status=%d\n", __func__, status,
1419-
priv->dp_port_num, opcode, len, urb->actual_length,
1420-
port_status);
1419+
dev_err(&port->dev, "malformed packet received: port=%d, opcode=%d, len=%d, actual_length=%u\n",
1420+
priv->dp_port_num, opcode, len, urb->actual_length);
1421+
return -1;
1422+
}
1423+
1424+
if (opcode == DIGI_CMD_RECEIVE_DATA && len < 1) {
1425+
dev_err(&port->dev, "malformed data packet received\n");
14211426
return -1;
14221427
}
14231428

@@ -1431,6 +1436,9 @@ static int digi_read_inb_callback(struct urb *urb)
14311436

14321437
/* receive data */
14331438
if (opcode == DIGI_CMD_RECEIVE_DATA) {
1439+
port_status = buf[2];
1440+
data = &buf[3];
1441+
14341442
/* get flag from port_status */
14351443
flag = 0;
14361444

0 commit comments

Comments
 (0)