public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io"
@ 2025-06-17  5:07 Kuen-Han Tsai
  2025-06-17  5:07 ` [PATCH v2 2/2] usb: gadget: u_serial: Fix race condition in TTY wakeup Kuen-Han Tsai
  2025-06-18 12:28 ` [PATCH v2 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io" Prashanth K
  0 siblings, 2 replies; 5+ messages in thread
From: Kuen-Han Tsai @ 2025-06-17  5:07 UTC (permalink / raw)
  To: gregkh, prashanth.k, khtsai, hulianqin, krzysztof.kozlowski,
	mwalle, jirislaby
  Cc: linux-usb, linux-kernel

This reverts commit ffd603f214237e250271162a5b325c6199a65382.

Commit ffd603f21423 ("usb: gadget: u_serial: Add null pointer check in
gs_start_io") adds null pointer checks at the beginning of the
gs_start_io() function to prevent a null pointer dereference. However,
these checks are redundant because the function's comment already
requires callers to hold the port_lock and ensure port.tty and port_usb
are not null. All existing callers already follow these rules.

The true cause of the null pointer dereference is a race condition. When
gs_start_io() calls either gs_start_rx() or gs_start_tx(), the port_lock
is temporarily released for usb_ep_queue(). This allows port.tty and
port_usb to be cleared.

Fixes: ffd603f21423 ("usb: gadget: u_serial: Add null pointer check in gs_start_io")
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
---
v2:
- Remove Cc: stable

---
 drivers/usb/gadget/function/u_serial.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index ab544f6824be..c043bdc30d8a 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -544,20 +544,16 @@ static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
 static int gs_start_io(struct gs_port *port)
 {
 	struct list_head	*head = &port->read_pool;
-	struct usb_ep		*ep;
+	struct usb_ep		*ep = port->port_usb->out;
 	int			status;
 	unsigned		started;

-	if (!port->port_usb || !port->port.tty)
-		return -EIO;
-
 	/* Allocate RX and TX I/O buffers.  We can't easily do this much
 	 * earlier (with GFP_KERNEL) because the requests are coupled to
 	 * endpoints, as are the packet sizes we'll be using.  Different
 	 * configurations may use different endpoints with a given port;
 	 * and high speed vs full speed changes packet sizes too.
 	 */
-	ep = port->port_usb->out;
 	status = gs_alloc_requests(ep, head, gs_read_complete,
 		&port->read_allocated);
 	if (status)
--
2.50.0.rc2.692.g299adb8693-goog


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

end of thread, other threads:[~2025-06-18 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17  5:07 [PATCH v2 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io" Kuen-Han Tsai
2025-06-17  5:07 ` [PATCH v2 2/2] usb: gadget: u_serial: Fix race condition in TTY wakeup Kuen-Han Tsai
2025-06-18 12:26   ` Prashanth K
2025-06-18 14:44     ` Kuen-Han Tsai
2025-06-18 12:28 ` [PATCH v2 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io" Prashanth K

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox