Skip to content

Commit 07a9293

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: keyspan_pda: fix receive sanity checks
commit c528fcb116e61afc379a2e0a0f70906b937f1e2c upstream. Make sure to check for short transfers before parsing the receive buffer to avoid acting on stale data. 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 2428776 commit 07a9293

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/usb/serial/keyspan_pda.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
139139
{
140140
struct usb_serial_port *port = urb->context;
141141
unsigned char *data = urb->transfer_buffer;
142+
unsigned int len = urb->actual_length;
142143
int retval;
143144
int status = urb->status;
144145
struct keyspan_pda_private *priv;
@@ -159,18 +160,26 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
159160
goto exit;
160161
}
161162

163+
if (len < 1) {
164+
dev_warn(&port->dev, "short message received\n");
165+
goto exit;
166+
}
167+
162168
/* see if the message is data or a status interrupt */
163169
switch (data[0]) {
164170
case 0:
165171
/* rest of message is rx data */
166-
if (urb->actual_length) {
167-
tty_insert_flip_string(&port->port, data + 1,
168-
urb->actual_length - 1);
169-
tty_flip_buffer_push(&port->port);
170-
}
172+
if (len < 2)
173+
break;
174+
tty_insert_flip_string(&port->port, data + 1, len - 1);
175+
tty_flip_buffer_push(&port->port);
171176
break;
172177
case 1:
173178
/* status interrupt */
179+
if (len < 3) {
180+
dev_warn(&port->dev, "short interrupt message received\n");
181+
break;
182+
}
174183
dev_dbg(&port->dev, "rx int, d1=%d, d2=%d\n", data[1], data[2]);
175184
switch (data[1]) {
176185
case 1: /* modemline change */

0 commit comments

Comments
 (0)