Hillf Danton
unread,Jun 22, 2020, 10:11:02 AM6/22/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Kyungtae Kim, Felipe Balbi, Greg KH, Michał Mirosław, Sergey Organov, Fabrice Gasnier, USB list, LKML, syzkaller, Dave Tian, Markus Elfring, Hillf Danton
Without being aware of the reasons behind the race incuring the UAF,
though, the race itself can be cured by checking tty valid on flushing it.
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -767,13 +767,29 @@ static void gs_flush_chars(struct tty_st
{
struct gs_port *port = tty->driver_data;
unsigned long flags;
+ unsigned int port_num;
+ /* check port valid against gserial_free_line() */
+ for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) {
+ if (port != ports[port_num].port)
+ continue;
+ mutex_lock(&ports[port_num].lock);
+ if (port == ports[port_num].port)
+ goto valid_port;
+ mutex_unlock(&ports[port_num].lock);
+ return;
+ }
+ return;
+
+valid_port:
pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty);
spin_lock_irqsave(&port->port_lock, flags);
if (port->port_usb)
gs_start_tx(port);
spin_unlock_irqrestore(&port->port_lock, flags);
+
+ mutex_unlock(&ports[port_num].lock);
}
static int gs_write_room(struct tty_struct *tty)