Skip to content

serial: fix console lifetime bugs on failed bind and removal

Karl Mehltretter imx linux-arm-kernel linux-serial lkml stable 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 1 replyIn review
  2. v35 patches 1 replySuperseded
  3. v24 patches 11 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v14 patches1 replySuperseded

Changes in v4 from the cover letter

- No code changes. v3 was accidentally sent as individual mails. Resending as a single thread.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5serial: core: do fallible allocations before the console can be registereddrivers/tty/serial/serial_core.c+16 -140 replies
2/5serial: core: clear freed pointers on uart_register_driver() failuredrivers/tty/serial/serial_core.c+2 -00 replies
3/5tty: skip cdev_del() when no cdev is registereddrivers/tty/tty_io.c+1 -10 replies
4/5tty: clear cdev pointer after cdev_add() failuredrivers/tty/tty_io.c+3 -10 replies
5/5serial: imx: serialize imx_uart_ports[] lifetimedrivers/tty/serial/imx.c+17 -31 reply

Reviews trailers per patch

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

Read the v4 thread

Cover letter [PATCH v4 0/5] serial: fix console lifetime bugs on failed bind and removal

This series fixes four serial/tty error-path bugs and an i.MX console port-table lifetime bug. The fixes were found with failslab fail-nth sweeps and sysfs bind/unbind sequences under KASAN on QEMU's raspi1ap and mcimx6ul-evk machines.

Patches 1-4 fix shared serial/tty core code. They move fallible allocations before console registration, clear pointers after uart_driver registration fails, and make a non-NULL tty cdev slot mean that the cdev is live.

Patch 5 clears i.MX's devm-allocated port-table entry after failed probe and removal. It keeps the entry valid through console unregistration, rejects duplicate lines and serializes table updates against other port probes.

Validation includes fail-nth sweeps on both boards. The i.MX tests also cover the sibling-probe race, sequential unbind/rebind and CONFIG_PROVE_LOCKING=y.

Changes in v4:
- No code changes. v3 was accidentally sent as individual mails. Resending as a single thread.

Changes in v3:
- Drop Cc: stable from patches 1-4.
- Patch 1: remove redundant uport->name clearing and credit Sashiko's report with Reported-by and Closes trailers.
- Split v2 patch 3 into two patches with corresponding Fixes tags.
- Shorten the changelogs.
- Patch 5: use scoped guards, reject occupied slots, remove the unnecessary line variable, document the console-callback locking constraint and add a backport note.

Changes in v2:
- Patch 4: serialize port registration and removal with imx_uart_ports[] updates to close the reported sibling-probe race.
- Patches 1-3 are unchanged.

v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]

Karl Mehltretter (5):
serial: core: do fallible allocations before the console can be
registered
serial: core: clear freed pointers on uart_register_driver() failure
tty: skip cdev_del() when no cdev is registered
tty: clear cdev pointer after cdev_add() failure
serial: imx: serialize imx_uart_ports[] lifetime

 drivers/tty/serial/imx.c         | 20 +++++++++++++++++---
 drivers/tty/serial/serial_core.c | 32 ++++++++++++++++++--------------
 drivers/tty/tty_io.c             |  6 ++++--
 3 files changed, 39 insertions(+), 19 deletions(-)
Signature · 1 line
2.53.0