Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial/keyspan_pda, fix potential tty NULL dereferences

Make sure that we check the return value of tty_port_tty_get.
Sometimes it may return NULL and we later dereference that.

There are several places to check. For easier handling,
tty_port_tty_get is moved directly to the palce where needed in
keyspan_pda_rx_interrupt.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
f7d7aedf 7adc14b1

+8 -7
+8 -7
drivers/usb/serial/keyspan_pda.c
··· 173 173 container_of(work, struct keyspan_pda_private, wakeup_work); 174 174 struct usb_serial_port *port = priv->port; 175 175 struct tty_struct *tty = tty_port_tty_get(&port->port); 176 - tty_wakeup(tty); 176 + if (tty) 177 + tty_wakeup(tty); 177 178 tty_kref_put(tty); 178 179 } 179 180 ··· 207 206 static void keyspan_pda_rx_interrupt(struct urb *urb) 208 207 { 209 208 struct usb_serial_port *port = urb->context; 210 - struct tty_struct *tty = tty_port_tty_get(&port->port); 209 + struct tty_struct *tty; 211 210 unsigned char *data = urb->transfer_buffer; 212 211 int retval; 213 212 int status = urb->status; ··· 224 223 /* this urb is terminated, clean up */ 225 224 dbg("%s - urb shutting down with status: %d", 226 225 __func__, status); 227 - goto out; 226 + return; 228 227 default: 229 228 dbg("%s - nonzero urb status received: %d", 230 229 __func__, status); ··· 234 233 /* see if the message is data or a status interrupt */ 235 234 switch (data[0]) { 236 235 case 0: 237 - /* rest of message is rx data */ 238 - if (urb->actual_length) { 236 + tty = tty_port_tty_get(&port->port); 237 + /* rest of message is rx data */ 238 + if (tty && urb->actual_length) { 239 239 tty_insert_flip_string(tty, data + 1, 240 240 urb->actual_length - 1); 241 241 tty_flip_buffer_push(tty); 242 242 } 243 + tty_kref_put(tty); 243 244 break; 244 245 case 1: 245 246 /* status interrupt */ ··· 268 265 dev_err(&port->dev, 269 266 "%s - usb_submit_urb failed with result %d", 270 267 __func__, retval); 271 - out: 272 - tty_kref_put(tty); 273 268 } 274 269 275 270