USB: serial: keyspan: Fixing use-after-free in usa49_glocont_callback()
Subsystems (2)
PATCH 1/1 USB: serial: keyspan: Fixing use-after-free in usa49_glocont_callback()
usa49_glocont_callback() obtains the private data from all ports of a serial device using usb_get_serial_port_data(). This can happen during keyspan_port_remove() which frees the private data which can cause UAF.
Fix this by calling usb_set_serial_port_data(port, NULL) inside keyspan_port_remove() right before kfree() of private data. This in turn allows "if (!p_priv) continue;" condition within usa49_glocont_callback() to execute properly.
--- drivers/usb/serial/keyspan.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/serial/keyspan.c +2 -0
@@ -2997,6 +2997,8 @@ static void keyspan_port_remove(struct usb_serial_port *port)for (i =0 ; i <ARRAY_SIZE (p_priv->in_buffer); ++i)kfree (p_priv->in_buffer[i]); +usb_set_serial_port_data (port,NULL ); +kfree (p_priv); }
Signature · 1 line
2.43.0
Johan Hovold
maintainerQuoted 5 lines · Rafael Alejandro Diaz Cruz
usa49_glocont_callback()obtains the private data from all ports of a serial device usingusb_get_serial_port_data(). This can happen duringkeyspan_port_remove()which frees the private data which can cause UAF.
Quoted 7 lines
Fix this by calling
usb_set_serial_port_data(port, NULL)insidekeyspan_port_remove()right beforekfree()of private data. This in turn allows "if (!p_priv) continue;" condition withinusa49_glocont_callback()to execute properly.Reported-by [email protected]
Please include a Link to the report as well (and a Fixes tag).
Quoted 10 lines
Signed-off-by Rafael Alejandro Diaz Cruz <[email protected]>--- drivers/usb/serial/keyspan.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/serial/keyspan.c +0
-0
drivers/usb/serial/keyspan.c static void keyspan_port_remove(struct usb_serial_port *port) · line 3001
Quoted 5 lines
drivers/usb/serial/keyspan.c +2
-0@@ -2997,6 +2997,8 @@ static void keyspan_port_remove(struct usb_serial_port *port)for (i =0 ; i <ARRAY_SIZE (p_priv->in_buffer); ++i)kfree (p_priv->in_buffer[i]); +usb_set_serial_port_data (port,NULL ); +
This doesn't work as nothing prevents the completion handler from loading the pointer just before you set it to NULL here.
drivers/usb/serial/keyspan.c static void keyspan_port_remove(struct usb_serial_port *port) · line 3003
Quoted 2 lines
drivers/usb/serial/keyspan.c +0
-0kfree (p_priv); }
The UAF syzbot reported is a symptom of a general problem with the disconnect handling. I've just sent a fix to address this here:
https://lore.kernel.org/all/[email protected]/
Johan