From: Cheng Yongkang <teel4res@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] tty: n_gsm: tx_work can be queued after gsm_cleanup_mux() flushed it
Date: Sun, 15 Nov 2026 08:36:46 -0800 [thread overview]
Message-ID: <20261115163646.226207-1-teel4res@gmail.com> (raw)
Hi Greg, Jiri,
Before anything else, a question. In September you said that n_gsm
should only be touched by people who can test it and have a system
that uses it. I do not have such hardware; I only tested with a pty.
Does that still apply to bug reports like this one? If it does, please
ignore this mail and I will not send more n_gsm reports.
The issue needs CAP_NET_ADMIN to attach N_GSM and a gsmtty close
racing with the ldisc being removed from the base tty. The window is a
few instructions and I could only hit it after adding delays, so it
may not matter much in practice.
gsm_send() adds the frame to tx_ctrl_list under tx_lock, drops the
lock, and then calls gsmld_write_trigger(), which checks
dlci[0]->dead and calls schedule_work(&gsm->tx_work). If
gsm_cleanup_mux() runs between that check and schedule_work(), it sets
dlci[0]->dead and calls flush_work(&gsm->tx_work) while nothing is
queued yet. The work is queued after that, nothing cancels it before
gsm_free_mux() frees the mux, and gsmld_write_task() then runs on
freed memory.
On v7.3 with KASAN I added a udelay() between the check and
schedule_work() in gsmld_write_trigger(), and an msleep() at the start
of gsmld_write_task() so that the worker runs after the free.
Closing /dev/gsmtty1, which sends DISC through gsm_send(), while
another thread set the base tty back to N_TTY gave:
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x40/0x60
Read of size 1 at addr ffff888111b183d8 by task kworker/0:2/791
Workqueue: events gsmld_write_task
_raw_spin_lock_irqsave
gsmld_write_task
process_scheduled_works
worker_thread
Allocated by task 9384:
gsmld_open
tty_ldisc_open
tty_set_ldisc
Freed by task 10:
kfree
mux_put
release_one_tty
Last potentially related work creation:
queue_work_on
gsmtty_close
tty_release
That was one hit in 85 attempts over 60 seconds. Without the delays I
did not hit it. n_gsm.c is the same in next-20261113.
cancel_work_sync() cannot go into gsm_free_mux(), because mux_put()
calls it under gsm_mux_lock with interrupts disabled. One option is to
set dlci[0]->dead under tx_lock in gsm_cleanup_mux(), and to make the
dead check and schedule_work() happen under tx_lock too, so that the
flush_work() after it is the last one. __gsm_data_queue() already
calls gsmld_write_trigger() with tx_lock held, but gsm_send(), the
CMD_FCON and XOFF paths and gsmld_write_wakeup() do not, so the lock
cannot simply be taken inside gsmld_write_trigger(). I have not
written or tested a fix.
Thanks,
Cheng Yongkang
reply other threads:[~2026-11-15 16:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261115163646.226207-1-teel4res@gmail.com \
--to=teel4res@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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