Commit 8bffa95
perf: Fix perf_pending_task() UaF
[ Upstream commit 517e6a3 ]
Per syzbot it is possible for perf_pending_task() to run after the
event is free()'d. There are two related but distinct cases:
- the task_work was already queued before destroying the event;
- destroying the event itself queues the task_work.
The first cannot be solved using task_work_cancel() since
perf_release() itself might be called from a task_work (____fput),
which means the current->task_works list is already empty and
task_work_cancel() won't be able to find the perf_pending_task()
entry.
The simplest alternative is extending the perf_event lifetime to cover
the task_work.
The second is just silly, queueing a task_work while you know the
event is going away makes no sense and is easily avoided by
re-arranging how the event is marked STATE_DEAD and ensuring it goes
through STATE_OFF on the way down.
Reported-by: syzbot+9228d6098455bb209ec8@syzkaller.appspotmail.com
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Marco Elver <elver@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 825bd2a commit 8bffa95
1 file changed
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2367 | 2367 | | |
2368 | 2368 | | |
2369 | 2369 | | |
| 2370 | + | |
2370 | 2371 | | |
2371 | 2372 | | |
2372 | 2373 | | |
| |||
2412 | 2413 | | |
2413 | 2414 | | |
2414 | 2415 | | |
| 2416 | + | |
2415 | 2417 | | |
2416 | 2418 | | |
2417 | 2419 | | |
| |||
2432 | 2434 | | |
2433 | 2435 | | |
2434 | 2436 | | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
2435 | 2443 | | |
2436 | 2444 | | |
2437 | 2445 | | |
2438 | 2446 | | |
2439 | 2447 | | |
2440 | 2448 | | |
| 2449 | + | |
| 2450 | + | |
2441 | 2451 | | |
2442 | 2452 | | |
2443 | 2453 | | |
| |||
5212 | 5222 | | |
5213 | 5223 | | |
5214 | 5224 | | |
5215 | | - | |
5216 | 5225 | | |
5217 | | - | |
5218 | 5226 | | |
5219 | 5227 | | |
5220 | 5228 | | |
| |||
5226 | 5234 | | |
5227 | 5235 | | |
5228 | 5236 | | |
5229 | | - | |
5230 | | - | |
| 5237 | + | |
5231 | 5238 | | |
5232 | 5239 | | |
5233 | 5240 | | |
| |||
6662 | 6669 | | |
6663 | 6670 | | |
6664 | 6671 | | |
| 6672 | + | |
| 6673 | + | |
6665 | 6674 | | |
6666 | 6675 | | |
6667 | 6676 | | |
| |||
0 commit comments