mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] tty: n_gsm: tx_work can be queued after gsm_cleanup_mux() flushed it
@ 2026-11-15 16:36 Cheng Yongkang
  2026-11-16  9:38 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Cheng Yongkang @ 2026-11-15 16:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-serial, linux-kernel

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

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

end of thread, other threads:[~2026-11-16  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 16:36 [BUG] tty: n_gsm: tx_work can be queued after gsm_cleanup_mux() flushed it Cheng Yongkang
2026-11-16  9:38 ` Greg Kroah-Hartman

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

all inboxes | Powered by JetHome®