USB: serial: console: fix two use-after-free bugs
Subsystems (3)
Johan Hovold
maintainerPATCH 1/2 USB: serial: console: fix use-after-free on disconnect
In reply to Johan HovoldA clean-up patch removing removing two redundant NULL-checks from the console disconnect handler inadvertently also removed a third check. This could lead to the struct usb_serial being prematurely freed by the console code when a driver accepts but does not register any ports for an interface which also lacks endpoint descriptors.
--- drivers/usb/serial/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/console.c +1 -1
@@ -265,7 +265,7 @@ static struct console usbcons = {void usb_serial_console_disconnect (struct usb_serial *serial) { -if (serial->port[0 ] == usbcons_info.port) { +if (serial->port[0 ] && serial->port[0 ] == usbcons_info.port) {usb_serial_console_exit ();usb_serial_put (serial); }
Signature · 1 line
2.14.2
Johan Hovold
maintainerPATCH 2/2 USB: serial: console: fix use-after-free after failed setup
In reply to Johan HovoldMake sure to reset the USB-console port pointer when console setup fails in order to avoid having the struct usb_serial be prematurely freed by the console code when the device is later disconnected.
--- drivers/usb/serial/console.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/serial/console.c +1 -0
@@ -186,6 +186,7 @@ static int usb_console_setup(struct console *co, char *options)tty_kref_put (tty); reset_open_count: port->port.count =0 ; + info->port =NULL ;usb_autopm_put_interface (serial->interface); error_get_interface:usb_serial_put (serial);
Signature · 1 line
2.14.2
Johan Hovold
maintainercover USB: serial: console: fix two use-after-free bugs
A recent clean-up patch of mine did more than intended and introduced the potential for a use-after-free on disconnect under some very specific circumstances. Fortunately those circumstances were not obscure enough to prevent Andrey's fuzzing from triggering the bug.
While fixing this one I found a related issue through inspection which dates back to 2006.
Johan
Johan Hovold (2):
USB: serial: console: fix use-after-free on disconnect
USB: serial: console: fix use-after-free after failed setup
drivers/usb/serial/console.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.2
Re: [PATCH 2/2] USB: serial: console: fix use-after-free after failed setup
In reply to Johan HovoldQuoted 7 lines · Johan Hovold
Make sure to reset the USB-console port pointer when console setup fails in order to avoid having the struct
usb_serialbe prematurely freed by the console code when the device is later disconnected.Fixes 73e487fdb75f ("[PATCH] USB console: fix disconnection issues")Cc stable <[email protected]> # 2.6.18Signed-off-by Johan Hovold <[email protected]>
Re: [PATCH 1/2] USB: serial: console: fix use-after-free on disconnect
In reply to Johan HovoldQuoted 10 lines · Johan Hovold
A clean-up patch removing removing two redundant NULL-checks from the console disconnect handler inadvertently also removed a third check. This could lead to the struct
usb_serialbeing prematurely freed by the console code when a driver accepts but does not register any ports for an interface which also lacks endpoint descriptors.Fixes 0e517c93dc02 ("USB: serial: console: clean up sanity checks")Cc stable <[email protected]> # 4.11Reported-by Andrey Konovalov <[email protected]>Signed-off-by Johan Hovold <[email protected]>
Re: [PATCH 1/2] USB: serial: console: fix use-after-free on disconnect
In reply to Johan HovoldHi
2017-10-04 18:01 GMT+09:00 Johan Hovold <[email protected]>:
Quoted 1 line
A clean-up patch removing removing two redundant NULL-checks from the
^^^^^^^^^^^^^^^^^^
The word 'removing' was written twice. :)
Quoted 33 lines
console disconnect handler inadvertently also removed a third check. This could lead to the struct
usb_serialbeing prematurely freed by the console code when a driver accepts but does not register any ports for an interface which also lacks endpoint descriptors.Fixes 0e517c93dc02 ("USB: serial: console: clean up sanity checks")Cc stable <[email protected]> # 4.11Reported-by Andrey Konovalov <[email protected]>Signed-off-by Johan Hovold <[email protected]>--- drivers/usb/serial/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/serial/console.c +1
-2@@ -265,7 +265,7 @@ static struct console usbcons = {void usb_serial_console_disconnect (struct usb_serial *serial) { -if (serial->port[0 ] == usbcons_info.port) { +if (serial->port[0 ] && serial->port[0 ] == usbcons_info.port) {usb_serial_console_exit ();usb_serial_put (serial); } --2.14.2
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Johan Hovold
maintainerRe: [PATCH 1/2] USB: serial: console: fix use-after-free on disconnect
Quoted 6 lines · Jaejoong Kim
Hi
2017-10-04 18:01 GMT+09:00 Johan Hovold <[email protected]>:
Quoted 1 line
A clean-up patch removing removing two redundant NULL-checks from the
^^^^^^^^^^^^^^^^^^The word 'removing' was written twice. :)
Thanks for noticing, now fixed up.
Johan
Re: [PATCH 1/2] USB: serial: console: fix use-after-free on disconnect
In reply to Johan HovoldQuoted 9 lines · Johan Hovold
A clean-up patch removing removing two redundant NULL-checks from the console disconnect handler inadvertently also removed a third check. This could lead to the struct
usb_serialbeing prematurely freed by the console code when a driver accepts but does not register any ports for an interface which also lacks endpoint descriptors.Fixes 0e517c93dc02 ("USB: serial: console: clean up sanity checks")Cc stable <[email protected]> # 4.11Reported-by Andrey Konovalov <[email protected]>
This fixes the crash.
Thanks!
Quoted 21 lines
Signed-off-by Johan Hovold <[email protected]>--- drivers/usb/serial/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/serial/console.c +1
-2@@ -265,7 +265,7 @@ static struct console usbcons = {void usb_serial_console_disconnect (struct usb_serial *serial) { -if (serial->port[0 ] == usbcons_info.port) { +if (serial->port[0 ] && serial->port[0 ] == usbcons_info.port) {usb_serial_console_exit ();usb_serial_put (serial); } --2.14.2
Johan Hovold
maintainerRe: [PATCH 1/2] USB: serial: console: fix use-after-free on disconnect
Quoted 7 lines · Andrey Konovalov
Quoted 6 lines · Johan Hovold
A clean-up patch removing removing two redundant NULL-checks from the console disconnect handler inadvertently also removed a third check. This could lead to the struct
usb_serialbeing prematurely freed by the console code when a driver accepts but does not register any ports for an interface which also lacks endpoint descriptors.
Quoted 7 lines
Quoted 3 lines
Fixes 0e517c93dc02 ("USB: serial: console: clean up sanity checks")Cc stable <[email protected]> # 4.11Reported-by Andrey Konovalov <[email protected]>Tested-by Andrey Konovalov <[email protected]>This fixes the crash.
I just forwarded this one in a pull-request to Greg, but thanks for testing nonetheless.
Johan