Skip to content

tty: n_gsm: fix gsm_queue() UAF and add a base regression test

Weiming Shi linux-kselftest linux-serial lkml stable 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 0 repliesNew
  2. v22 patches 6 repliesSuperseded

Changes in v3 from the cover letter

- Drop the cmpxchg() in gsm_dlci_free(); the pin alone fixes the UAF (Greg).
- Keep the addr bounds check at each call site, not in the helper (Daniel).
- Correct the Fixes: tag to the refcount commit (Daniel).
- Add the AI-assist tag to patch 1 and trim the comments (Daniel).

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tty: n_gsm: fix use-after-free in gsm_queue() control frame dispatchdrivers/tty/n_gsm.c+67 -60 replies
2/2selftests: tty: add base regression test for n_gsm line disciplinetools/testing/selftests/tty/.gitignore tools/testing/selftests/tty/Makefile tools/testing/selftests/tty/config +1 more+347 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/2] tty: n_gsm: fix gsm_queue() UAF and add a base regression test

The receive worker walks gsm->dlci[] without gsm->mutex while a concurrent GSMIOC_SETCONF -> gsm_cleanup_mux() frees the DLCIs, so the control handlers can dereference a freed gsm_dlci. v1's NULL check only narrowed the window; this series fixes the use-after-free itself by pinning each DLCI the dispatch dereferences with its existing tty_port reference (dlci_get/put), so the data path stays lock-free.

v3:
- Drop the cmpxchg() in gsm_dlci_free(); the pin alone fixes the UAF (Greg).
- Keep the addr bounds check at each call site, not in the helper (Daniel).
- Correct the Fixes: tag to the refcount commit (Daniel).
- Add the AI-assist tag to patch 1 and trim the comments (Daniel).

Verification (KASAN, panic_on_warn=1): a reproducer targeting the MSC handler crashes the unpatched kernel and survives 200+ race rounds on this series. The selftest passes on both the clean and patched kernel (pass:3 fail:0 skip:0).

Weiming Shi (2):
tty: n_gsm: fix use-after-free in gsm_queue() control frame dispatch
selftests: tty: add base regression test for n_gsm line discipline

 drivers/tty/n_gsm.c                          |  73 +++-
 tools/testing/selftests/tty/.gitignore       |   1 +
 tools/testing/selftests/tty/Makefile         |   2 +-
 tools/testing/selftests/tty/config           |   1 +
 tools/testing/selftests/tty/tty_n_gsm_test.c | 344 +++++++++++++++++++
 5 files changed, 414 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/tty/tty_n_gsm_test.c
Signature · 1 line
2.43.0