diff options
| author | Phat Dinh <phatdt1116@gmail.com> | 2026-11-03 15:56:41 +0700 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2026-11-23 10:37:47 +0100 |
| commit | 4aa81df6bb45e9cf693c86849fe90d4e3dd85bbc (patch) | |
| tree | e0f323ea68b0d020570b5edb5d593c6a0116cd43 /tools/lib | |
| parent | dd1e556d9a5aef3e731fbe31ae43d9b4eaf05c1b (diff) | |
perf/core: Fix UAF from remove_on_exec with perf_event_open()
perf_event_open() installs the event into the target context and then
drops the target's exec_update_lock before linking event->owner_entry
into current->perf_event_list. This leaves a window in which the
target can exec() while the event is live in its context but not yet
on the owner's list.
If the event has attr.remove_on_exec set, perf_event_remove_on_exec()
detaches it in that window through perf_remove_from_owner(), which
does list_del_init(&event->owner_entry) on the not-yet-linked entry
and clears event->owner. perf_event_open() then continues and adds
the now ownerless event to current->perf_event_list:
CPU 0: perf_event_open() CPU 1: target task exec()
------------------------ -------------------------
perf_install_in_context(event)
event->owner = current
up_read(exec_update_lock)
down_write(exec_update_lock)
perf_event_remove_on_exec()
perf_remove_from_owner(event)
list_del_init(&event->owner_entry)
event->owner = NULL
up_write(exec_update_lock)
list_add_tail(&event->owner_entry,
¤t->perf_event_list)
When the event fd is closed, perf_release() sees event->owner == NULL,
skips unlinking owner_entry and frees the event, leaving a dangling
entry on the opener's perf_event_list. The next walk of that list,
e.g. perf_event_exit_task() or PR_TASK_PERF_EVENTS_{EN,DIS}ABLE,
is a use-after-free.
Fix this by linking the event into current->perf_event_list before
releasing exec_update_lock, so exec() cannot observe the event until
it is fully published. Lock order is exec_update_lock ->
perf_event_mutex, the same as perf_event_exit_task() called from
exec, so no new dependency is introduced.
Fixes: 2e498d0a74e5 ("perf: Add support for event removal on exec")
Signed-off-by: Phat Dinh <phatdt1116@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261103085641.3686424-1-phatdt1116@gmail.com
Diffstat (limited to 'tools/lib')
0 files changed, 0 insertions, 0 deletions
