Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] USB: serial: keyspan: fix NULL-derefs on open() and write()
@ 2019-10-03 13:49 Johan Hovold
  2019-10-04  8:54 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2019-10-03 13:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Greg Kroah-Hartman, Rainer Weikusat, Johan Hovold, stable

Fix NULL-pointer dereferences on open() and write() which can be
triggered by a malicious USB device.

The current URB allocation helper would fail to initialise the newly
allocated URB if the device has unexpected endpoint descriptors,
something which could lead NULL-pointer dereferences in a number of
open() and write() paths when accessing the URB. For example:

	BUG: kernel NULL pointer dereference, address: 0000000000000000
	...
	RIP: 0010:usb_clear_halt+0x11/0xc0
	...
	Call Trace:
	 ? tty_port_open+0x4d/0xd0
	 keyspan_open+0x70/0x160 [keyspan]
	 serial_port_activate+0x5b/0x80 [usbserial]
	 tty_port_open+0x7b/0xd0
	 ? check_tty_count+0x43/0xa0
	 tty_open+0xf1/0x490

	BUG: kernel NULL pointer dereference, address: 0000000000000000
	...
	RIP: 0010:keyspan_write+0x14e/0x1f3 [keyspan]
	...
	Call Trace:
	 serial_write+0x43/0xa0 [usbserial]
	 n_tty_write+0x1af/0x4f0
	 ? do_wait_intr_irq+0x80/0x80
	 ? process_echoes+0x60/0x60
	 tty_write+0x13f/0x2f0

	BUG: kernel NULL pointer dereference, address: 0000000000000000
	...
	RIP: 0010:keyspan_usa26_send_setup+0x298/0x305 [keyspan]
	...
	Call Trace:
	 keyspan_open+0x10f/0x160 [keyspan]
	 serial_port_activate+0x5b/0x80 [usbserial]
	 tty_port_open+0x7b/0xd0
	 ? check_tty_count+0x43/0xa0
	 tty_open+0xf1/0x490

Fixes: fdcba53e2d58 ("fix for bugzilla #7544 (keyspan USB-to-serial converter)")
Cc: stable <stable@vger.kernel.org>	# 2.6.21
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/keyspan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index d34779fe4a8d..e66a59ef43a1 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1741,8 +1741,8 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
 
 	ep_desc = find_ep(serial, endpoint);
 	if (!ep_desc) {
-		/* leak the urb, something's wrong and the callers don't care */
-		return urb;
+		usb_free_urb(urb);
+		return NULL;
 	}
 	if (usb_endpoint_xfer_int(ep_desc)) {
 		ep_type_name = "INT";
-- 
2.23.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] USB: serial: keyspan: fix NULL-derefs on open() and write()
  2019-10-03 13:49 [PATCH] USB: serial: keyspan: fix NULL-derefs on open() and write() Johan Hovold
@ 2019-10-04  8:54 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2019-10-04  8:54 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, Rainer Weikusat, stable

On Thu, Oct 03, 2019 at 03:49:58PM +0200, Johan Hovold wrote:
> Fix NULL-pointer dereferences on open() and write() which can be
> triggered by a malicious USB device.
> 
> The current URB allocation helper would fail to initialise the newly
> allocated URB if the device has unexpected endpoint descriptors,
> something which could lead NULL-pointer dereferences in a number of
> open() and write() paths when accessing the URB. For example:
> 
> 	BUG: kernel NULL pointer dereference, address: 0000000000000000
> 	...
> 	RIP: 0010:usb_clear_halt+0x11/0xc0
> 	...
> 	Call Trace:
> 	 ? tty_port_open+0x4d/0xd0
> 	 keyspan_open+0x70/0x160 [keyspan]
> 	 serial_port_activate+0x5b/0x80 [usbserial]
> 	 tty_port_open+0x7b/0xd0
> 	 ? check_tty_count+0x43/0xa0
> 	 tty_open+0xf1/0x490
> 
> 	BUG: kernel NULL pointer dereference, address: 0000000000000000
> 	...
> 	RIP: 0010:keyspan_write+0x14e/0x1f3 [keyspan]
> 	...
> 	Call Trace:
> 	 serial_write+0x43/0xa0 [usbserial]
> 	 n_tty_write+0x1af/0x4f0
> 	 ? do_wait_intr_irq+0x80/0x80
> 	 ? process_echoes+0x60/0x60
> 	 tty_write+0x13f/0x2f0
> 
> 	BUG: kernel NULL pointer dereference, address: 0000000000000000
> 	...
> 	RIP: 0010:keyspan_usa26_send_setup+0x298/0x305 [keyspan]
> 	...
> 	Call Trace:
> 	 keyspan_open+0x10f/0x160 [keyspan]
> 	 serial_port_activate+0x5b/0x80 [usbserial]
> 	 tty_port_open+0x7b/0xd0
> 	 ? check_tty_count+0x43/0xa0
> 	 tty_open+0xf1/0x490
> 
> Fixes: fdcba53e2d58 ("fix for bugzilla #7544 (keyspan USB-to-serial converter)")
> Cc: stable <stable@vger.kernel.org>	# 2.6.21
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03 13:49 [PATCH] USB: serial: keyspan: fix NULL-derefs on open() and write() Johan Hovold
2019-10-04  8:54 ` Greg Kroah-Hartman

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git