Commit 884b167
committed
perf: Fix event leak upon exit
jira LE-2157
cve CVE-2024-43870
Rebuild_History Non-Buildable kernel-5.14.0-503.14.1.el9_5
commit-author Frederic Weisbecker <frederic@kernel.org>
commit 2fd5ad3
When a task is scheduled out, pending sigtrap deliveries are deferred
to the target task upon resume to userspace via task_work.
However failures while adding an event's callback to the task_work
engine are ignored. And since the last call for events exit happen
after task work is eventually closed, there is a small window during
which pending sigtrap can be queued though ignored, leaking the event
refcount addition such as in the following scenario:
TASK A
-----
do_exit()
exit_task_work(tsk);
<IRQ>
perf_event_overflow()
event->pending_sigtrap = pending_id;
irq_work_queue(&event->pending_irq);
</IRQ>
=========> PREEMPTION: TASK A -> TASK B
event_sched_out()
event->pending_sigtrap = 0;
atomic_long_inc_not_zero(&event->refcount)
// FAILS: task work has exited
task_work_add(&event->pending_task)
[...]
<IRQ WORK>
perf_pending_irq()
// early return: event->oncpu = -1
</IRQ WORK>
[...]
=========> TASK B -> TASK A
perf_event_exit_task(tsk)
perf_event_exit_event()
free_event()
WARN(atomic_long_cmpxchg(&event->refcount, 1, 0) != 1)
// leak event due to unexpected refcount == 2
As a result the event is never released while the task exits.
Fix this with appropriate task_work_add()'s error handling.
Fixes: 517e6a3 ("perf: Fix perf_pending_task() UaF")
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240621091601.18227-4-frederic@kernel.org
(cherry picked from commit 2fd5ad3)
Signed-off-by: Jonathan Maple <jmaple@ciq.com>1 parent 600045f commit 884b167
1 file changed
+5
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2284 | 2284 | | |
2285 | 2285 | | |
2286 | 2286 | | |
2287 | | - | |
2288 | | - | |
2289 | 2287 | | |
2290 | 2288 | | |
2291 | | - | |
2292 | | - | |
2293 | | - | |
| 2289 | + | |
| 2290 | + | |
2294 | 2291 | | |
2295 | | - | |
2296 | | - | |
2297 | | - | |
| 2292 | + | |
| 2293 | + | |
2298 | 2294 | | |
| 2295 | + | |
2299 | 2296 | | |
2300 | 2297 | | |
2301 | 2298 | | |
| |||
0 commit comments