Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v3 0/3] serial: tegra: fix DMA descriptor use-after-free and stale completions
@ 2026-10-22 21:10 Austin Schlegel via B4 Relay
  2026-10-22 21:10 ` [PATCH v3 1/3] serial: tegra: fix RX DMA descriptor use-after-free Austin Schlegel via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Austin Schlegel via B4 Relay @ 2026-10-22 21:10 UTC (permalink / raw)
  To: Laxman Dewangan, Greg Kroah-Hartman, Jiri Slaby, Thierry Reding,
	Jonathan Hunter, Alan Cox, Stephen Warren
  Cc: linux-kernel, linux-serial, linux-tegra, Austin Schlegel,
	Austin Schlegel, stable

Patches 1 and 2 fix the same bug pattern in
drivers/tty/serial/serial-tegra.c: async_tx_ack() is called on a DMA
descriptor after dmaengine_terminate_all() has terminated it. With the
GPC DMA driver (tegra186-gpc-dma.c, used on Tegra186 and later),
terminating a channel frees the active descriptor synchronously via
vchan_dma_desc_free_list(), so the ack touches freed memory. dmaengine
clients are not allowed to touch a descriptor once it has been
terminated.

Patch 1 (RX) was found via a KFENCE use-after-free report on a Jetson
AGX Orin (Tegra234) under UART loopback traffic. It keeps the
descriptor-leak fix from commit b31245b94207 ("serial: tegra: ack the
rx dma desc after transfer terminated") intact: the ack still happens
for every terminated RX transfer, just before the descriptor is freed
instead of after.

Patch 2 (TX) fixes the same ordering bug in tegra_uart_stop_tx().
It also fixes tegra_uart_flush_buffer(), which terminated the TX
channel without clearing tx_in_progress, so a later
tegra_uart_stop_tx() acked the freed descriptor.

Patch 3 is new in v3. It makes the TX and RX DMA completion callbacks
return early when the transfer they were raised for has already been
stopped, flushed or terminated, instead of accounting for it a second
time.

The bugs fixed by patches 2 and 3 were found in review (Sashiko, on v2)
and have not been reproduced on hardware. In a 10-minute loopback test
with KFENCE sampling every 1 ms, which also stops and flushes TX during
DMA, the unfixed kernel produced 1635 use-after-free KFENCE
errors, all from RX. With this patch series applied there were none.

Testing was done on Tegra234 (Jetson AGX Orin) with GPC DMA only. The
APB DMA driver (Tegra20-Tegra210) recycles descriptors only after they
are acked; the series keeps every ack but has not been tested there.

Signed-off-by: Austin Schlegel <schlegelas@outlook.com>
---
Changes in v3:
- Patch 2: also fix tegra_uart_flush_buffer(), which left
  tx_in_progress set after terminating TX DMA (Sashiko review).
- New patch 3: ignore TX/RX DMA completion callbacks for transfers that
  were already stopped or terminated (Sashiko review).
- Patch 1: no code changes.
- Link to v2: https://lore.kernel.org/r/20261014-serial-tegra-dma-uaf-v2-0-b142b31b67e3@outlook.com

Changes in v2:
- Commit message updates only; no code changes.
- Patch 1: removed an inaccurate statement that the freed descriptor
  is accessed in tegra_uart_rx_dma_complete(); updated the soak test
  duration to 24+ hours.
- Patch 2: removed an inaccurate flush example; added Fixes: tag.
- Switched to my personal email address (v1 was sent from
  austin.schlegel@arthrex.com).
- Link to v1: https://lore.kernel.org/r/20261001-tty-linus-v1-0-ecb8576c802d@arthrex.com

---
Austin Schlegel (3):
      serial: tegra: fix RX DMA descriptor use-after-free
      serial: tegra: fix TX DMA descriptor use-after-free
      serial: tegra: ignore stale DMA completion callbacks

 drivers/tty/serial/serial-tegra.c | 56 +++++++++++++++++++++++++++++++++++----
 1 file changed, 51 insertions(+), 5 deletions(-)
---
base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
change-id: 20261014-serial-tegra-dma-uaf-39ed62701ab6

Best regards,
-- 
Austin Schlegel <schlegelas@outlook.com>



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

end of thread, other threads:[~2026-10-27  6:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 21:10 [PATCH v3 0/3] serial: tegra: fix DMA descriptor use-after-free and stale completions Austin Schlegel via B4 Relay
2026-10-22 21:10 ` [PATCH v3 1/3] serial: tegra: fix RX DMA descriptor use-after-free Austin Schlegel via B4 Relay
2026-10-22 21:17   ` sashiko-bot
2026-10-22 21:10 ` [PATCH v3 2/3] serial: tegra: fix TX " Austin Schlegel via B4 Relay
2026-10-22 21:17   ` sashiko-bot
2026-10-22 21:10 ` [PATCH v3 3/3] serial: tegra: ignore stale DMA completion callbacks Austin Schlegel via B4 Relay
2026-10-22 21:18   ` sashiko-bot
2026-10-27  6:52 ` [PATCH v3 0/3] serial: tegra: fix DMA descriptor use-after-free and stale completions Karl Mehltretter

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