mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
perf sched: Fix NULL dereference in latency_runtime_event
latency_runtime_event() passes the return value of
machine__findnew_thread() directly to thread_atoms_search() at line
1216, before checking for NULL at line 1220. thread_atoms_search()
calls pid_cmp() which dereferences the thread pointer via
thread__tid(), causing a NULL pointer dereference if the allocation
fails.
All other callers of thread_atoms_search() in this file
(latency_switch_event, latency_wakeup_event,
latency_migrate_task_event) correctly check for NULL first.
Move the atoms assignment after the NULL check to match the pattern
used by the other callers.
Fixes: b91fc39f4a ("perf machine: Protect the machine->threads with a rwlock")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
66ea9de603
commit
8cbca8a480
|
|
@ -1213,13 +1213,15 @@ static int latency_runtime_event(struct perf_sched *sched,
|
|||
const u32 pid = perf_sample__intval(sample, "pid");
|
||||
const u64 runtime = perf_sample__intval(sample, "runtime");
|
||||
struct thread *thread = machine__findnew_thread(machine, -1, pid);
|
||||
struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid);
|
||||
struct work_atoms *atoms;
|
||||
u64 timestamp = sample->time;
|
||||
int cpu = sample->cpu, err = -1;
|
||||
|
||||
if (thread == NULL)
|
||||
return -1;
|
||||
|
||||
atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid);
|
||||
|
||||
/* perf.data is untrusted input — CPU may be absent or corrupted */
|
||||
if (cpu >= MAX_CPUS || cpu < 0) {
|
||||
pr_warning("WARNING: at offset %#" PRIx64 ": out-of-bound sample CPU %d, skipping sample\n",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user