From: Mehmet Fide <mehmet.fide@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
mehmet.fide@screeningeagle.com
Subject: Re: [PATCH] usb: gadget: u_serial: implement flush_buffer
Date: Thu, 15 Oct 2026 21:41:28 +0200 [thread overview]
Message-ID: <20261015194128.2545029-1-mehmet.fide@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-173201@kernel.org>
The window is real, but the use-after-free in it is older than this
patch.
I reproduced it on a Verdin AM62 with 6.12.113 and KASAN, with a 3 s
delay added at the top of gs_close() to widen the window. At shutdown
systemd closes ttyGS0 while the configfs teardown unbinds the gadget
and removes the acm function:
BUG: KASAN: slab-use-after-free in check_tty_count+0x230/0x278
Workqueue: events do_tty_hangup
__tty_hangup.part.0
do_tty_hangup
Allocated by: gserial_alloc_line_no_console <- acm_alloc_instance
Freed by: gserial_free_port <- gserial_free_line <- acm_free_instance
In one of the runs the closing task then faulted in release_tty() ->
tty_buffer_cancel_work(). The KASAN report is the same with this patch
not applied.
gserial_free_port() frees the gs_port, and with it the embedded
tty_port, while a tty still refers to it: the tty core keeps using
tty->port until release_tty(), and u_serial has no install/cleanup pair
that holds a reference on the port meanwhile. I will send a v2 as a
series: first keep the gs_port alive through the tty_port reference
count (get in install, put in cleanup, free in the destructor), then
flush_buffer on top of it.
Greg, please drop this version.
Thanks,
Mehmet
prev parent reply other threads:[~2026-10-15 19:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 16:27 [PATCH] usb: gadget: u_serial: implement flush_buffer Mehmet Fide
2026-10-15 16:42 ` sashiko-bot
2026-10-15 19:41 ` Mehmet Fide [this message]
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=20261015194128.2545029-1-mehmet.fide@gmail.com \
--to=mehmet.fide@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mehmet.fide@screeningeagle.com \
/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