[PATCH v2 0/3] tracing: Fix readonly backup instance blocking reads and autoremove races

From: Masami Hiramatsu (Google)

Date: Thu Dec 03 2026 - 04:54:02 EST


Hi,

This is v2 of the series fixing three issues in read-only backup trace
instances introduced by commits 2c79da099aac ("tracing: Make the backup
instance non-reusable") and eca33fdab47b ("tracing: Remove the backup
instance automatically after read").

The previous version is here:
https://lore.kernel.org/all/179622391385.9100.2915051158917183404.stgit@xxxxxxxxxxxxxxxxxxxxxxx/

Changes in v2:
- [1/3] Check trace_array_is_readonly() before O_NONBLOCK /
SPLICE_F_NONBLOCK so non-blocking reads and splices return EOF
instead of -EAGAIN, and return EPOLLIN | EPOLLRDNORM in trace_poll().
- [3/3] Consolidate trace_array_destroy() and instance_rmdir() via
try_remove_instance(), and keep returning -ENODEV after
flush_workqueue() to avoid double d_delete_notify() in vfs_rmdir().

1. Empty read-only backup instances block indefinitely (or return
-EAGAIN on non-blocking reads/splices, or never wake in poll()) when
update_last_data_if_empty() returns false. Patch 1 returns EOF
(or -ENODEV for TRACE_MMAP_IOCTL_GET_READER) for both blocking and
non-blocking callers, and returns EPOLLIN | EPOLLRDNORM in
trace_poll().

2. __trace_array_get() rejects opens with -ENODEV as soon as
tr->free_on_close is set, breaking multi-fd consumers that still hold
open pipes while reading stats or truncating the trace file. Patch 2
tracks queued autoremove work in tr->autoremove_queued and rejects
opens only once autoremove is queued.

3. __remove_instance() calls cancel_work_sync() on autoremove_work while
holding event_mutex and trace_types_lock, causing an ABBA deadlock or
UAF/ABA race when rmdir or trace_array_destroy() races with
autoremove. Patch 3 lets trace_array_autoremove() exclusively destroy
tr once queued, and consolidates trace_array_destroy() and
instance_rmdir() so external callers drop the locks, flush
autoremove_wq, and return -ENODEV.


Thank you,

Masami Hiramatsu (Google) (3):
tracing: Return EOF on empty readonly instances
tracing: Reject backup instance opens only after autoremove is queued
tracing: Fix deadlock and UAF when rmdir races with backup autoremove

kernel/trace/trace.c | 110 ++++++++++++++++++++++++++++---------------
kernel/trace/trace.h | 4 ++
2 files changed, 77 insertions(+), 37 deletions(-)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.56.1.911.g883d8bcb20-goog