From: Greg KH <gregkh@linuxfoundation.org>
To: Kuen-Han Tsai <khtsai@google.com>
Cc: prashanth.k@oss.qualcomm.com, hulianqin@vivo.com,
krzysztof.kozlowski@linaro.org, mwalle@kernel.org,
jirislaby@kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: gadget: u_serial: Fix race condition in TTY wakeup
Date: Mon, 16 Jun 2025 16:17:30 +0200 [thread overview]
Message-ID: <2025061634-heavily-outrage-603a@gregkh> (raw)
In-Reply-To: <20250616132152.1544096-2-khtsai@google.com>
On Mon, Jun 16, 2025 at 09:21:47PM +0800, Kuen-Han Tsai wrote:
> A race condition occurs when gs_start_io() calls either gs_start_rx() or
> gs_start_tx(), as those functions briefly drop the port_lock for
> usb_ep_queue(). This allows gs_close() and gserial_disconnect() to clear
> port.tty and port_usb, respectively.
>
> Use the null-safe TTY Port helper function to wake up TTY.
>
> Cc: stable@vger.kernel.org
> Fixes: 35f95fd7f234 ("TTY: usb/u_serial, use tty from tty_port")
> Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
> ---
> Explanation:
> CPU1: CPU2:
> gserial_connect() // lock
> gs_close() // await lock
> gs_start_rx() // unlock
> usb_ep_queue()
> gs_close() // lock, reset port_tty and unlock
> gs_start_rx() // lock
> tty_wakeup() // dereference
Why isn't this up in the changelog?
>
> Stack traces:
> [ 51.494375][ T278] ttyGS1: shutdown
> [ 51.494817][ T269] android_work: sent uevent USB_STATE=DISCONNECTED
> [ 52.115792][ T1508] usb: [dm_bind] generic ttyGS1: super speed IN/ep1in OUT/ep1out
> [ 52.516288][ T1026] android_work: sent uevent USB_STATE=CONNECTED
> [ 52.551667][ T1533] gserial_connect: start ttyGS1
> [ 52.565634][ T1533] [khtsai] enter gs_start_io, ttyGS1, port->port.tty=0000000046bd4060
> [ 52.565671][ T1533] [khtsai] gs_start_rx, unlock port ttyGS1
> [ 52.591552][ T1533] [khtsai] gs_start_rx, lock port ttyGS1
> [ 52.619901][ T1533] [khtsai] gs_start_rx, unlock port ttyGS1
> [ 52.638659][ T1325] [khtsai] gs_close, lock port ttyGS1
> [ 52.656842][ T1325] gs_close: ttyGS1 (0000000046bd4060,00000000be9750a5) ...
> [ 52.683005][ T1325] [khtsai] gs_close, clear ttyGS1
> [ 52.683007][ T1325] gs_close: ttyGS1 (0000000046bd4060,00000000be9750a5) done!
> [ 52.708643][ T1325] [khtsai] gs_close, unlock port ttyGS1
> [ 52.747592][ T1533] [khtsai] gs_start_rx, lock port ttyGS1
> [ 52.747616][ T1533] [khtsai] gs_start_io, ttyGS1, going to call tty_wakeup(), port->port.tty=0000000000000000
> [ 52.747629][ T1533] Unable to handle kernel NULL pointer dereference at virtual address 00000000000001f8
What is [khtsai] from?
thanks,
greg k-h
next prev parent reply other threads:[~2025-06-16 14:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 13:21 [PATCH 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io" Kuen-Han Tsai
2025-06-16 13:21 ` [PATCH 2/2] usb: gadget: u_serial: Fix race condition in TTY wakeup Kuen-Han Tsai
2025-06-16 14:17 ` Greg KH [this message]
2025-06-17 3:31 ` Kuen-Han Tsai
2025-06-16 14:18 ` [PATCH 1/2] Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io" Greg KH
2025-06-17 3:41 ` Kuen-Han Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025061634-heavily-outrage-603a@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=hulianqin@vivo.com \
--cc=jirislaby@kernel.org \
--cc=khtsai@google.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mwalle@kernel.org \
--cc=prashanth.k@oss.qualcomm.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox