Skip to content

tracing/user_events: fix use-after-free in user_event_mm_dup()

Michael Bommarito linux-trace-kernel lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tracing/user_events: fix use-after-free in user_event_mm_dup()kernel/trace/trace_events_user.c+32 -70 replies
2/2selftests/user_events: wait for deferred event teardown after unregistertools/testing/selftests/user_events/abi_test.c tools/testing/selftests/user_events/perf_test.c+46 -41 reply

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/2] tracing/user_events: fix use-after-free in user_event_mm_dup()

This replaces the earlier single patch "tracing/user_events: fix use-after-free of enabler in user_event_mm_dup()" that is in the tracing for-linus branch; Steven agreed to drop that one and take this instead.

user_event_enabler_destroy() removes an enabler from the mm enabler list that user_event_mm_dup() walks locklessly under rcu_read_lock() during fork(), then drops the enabler's event reference and frees the enabler without waiting for a grace period. A concurrent fork() walker can therefore both dereference the freed enabler and take a reference on a user_event that the put has already freed -- two use-after-frees, one on the enabler and one on the user_event. The enabler use-after-free was found first; XIAO WU then reported the user_event one, with a PoC and a KASAN slab-use-after-free (write) in user_event_mm_dup(), and the enabler-only fix did not address it.

Patch 1 holds both the enabler and its event reference until an RCU grace period has elapsed, by deferring the put and the free to a work item queued with queue_rcu_work(). The approach was suggested by Beau Belgrave; it supersedes the enabler-only fix.

Patch 2 adjusts two user_events selftests that assumed the event is torn down the instant an unregister returns; with the deferred put, DIAG_IOCSDEL can briefly return -EBUSY, so they now wait for the delete to take effect.

Verified under KASAN on x86-64: the race faults on the unpatched kernel (and panics with kasan.fault=panic), a benign serialized control is clean, and the patched kernel is clean across repeated runs. The user_events selftests pass on both kernels with patch 2 applied.

Michael Bommarito (2):
tracing/user_events: fix use-after-free in user_event_mm_dup() selftests/user_events: wait for deferred event teardown after
unregister

 kernel/trace/trace_events_user.c              | 39 +++++++++++++++----
 .../testing/selftests/user_events/abi_test.c  | 24 +++++++++++-
 .../testing/selftests/user_events/perf_test.c | 26 +++++++++++--
 3 files changed, 78 insertions(+), 11 deletions(-)

base-commit: f24ca6729076623c9a0547ecc71e4fc1c4b65c3c

Signature · 1 line
2.53.0