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

Configure Feed

Select the types of activity you want to include in your feed.

usb: gadget: u_serial: Add null pointer check in gserial_suspend

Consider a case where gserial_disconnect has already cleared
gser->ioport. And if gserial_suspend gets called afterwards,
it will lead to accessing of gser->ioport and thus causing
null pointer dereference.

Avoid this by adding a null pointer check. Added a static
spinlock to prevent gser->ioport from becoming null after
the newly added null pointer check.

Fixes: aba3a8d01d62 ("usb: gadget: u_serial: add suspend resume callbacks")
Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
Link: https://lore.kernel.org/r/1683278317-11774-1-git-send-email-quic_prashk@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Prashanth K and committed by
Greg Kroah-Hartman
2f6ecb89 24520e51

+11 -2
+11 -2
drivers/usb/gadget/function/u_serial.c
··· 1420 1420 1421 1421 void gserial_suspend(struct gserial *gser) 1422 1422 { 1423 - struct gs_port *port = gser->ioport; 1423 + struct gs_port *port; 1424 1424 unsigned long flags; 1425 1425 1426 - spin_lock_irqsave(&port->port_lock, flags); 1426 + spin_lock_irqsave(&serial_port_lock, flags); 1427 + port = gser->ioport; 1428 + 1429 + if (!port) { 1430 + spin_unlock_irqrestore(&serial_port_lock, flags); 1431 + return; 1432 + } 1433 + 1434 + spin_lock(&port->port_lock); 1435 + spin_unlock(&serial_port_lock); 1427 1436 port->suspended = true; 1428 1437 spin_unlock_irqrestore(&port->port_lock, flags); 1429 1438 }