From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E459A4C6F13; Thu, 4 Jun 2026 20:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780606185; cv=none; b=EMyIHhO43kiVpJ7imDZWqmUuUx6zGP59jZckKAeYtoUaZl+xEH9NhjfvAD49ueBcGYyA5sltT3vtJWAvbHAigS6ROgVXyqOGMY0l4NJwOFO+/LrbV71M2CHs7Ch/7uX1IiCZ5xeVlchn7qAnEmBqL21aAvZlxmZALm8R0B0/zmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780606185; c=relaxed/simple; bh=UCQpoZtRZQix/YorHPv3+3WJF0dhBiq66RD+C0xocqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sPd/TiSWYYhha6ShCrpbEaYudP2TRfHeWe0ltTp/g8oj/6dBnw9DQlOw+hG/fZnbZZSAvDnn7MXJ94dM19VIiYjRyeI47sV56eOArNXJ+9U9B46iyxAicxQ3meRJQx4j2W/i18iRCFbSsbcg9Npx00J2Zmo6TK5ahkm3fH1kIqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ajHCCxK+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ajHCCxK+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47EDA1F00893; Thu, 4 Jun 2026 20:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780606184; bh=uDdZdq443dw1xqiU/tHBf+lc30Tzb+J6wcTr3uCO5ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ajHCCxK+UzciRNqbD6hKy97J8FjZ11DEM2Kywn8ooj01D3keXAHE+r7Oc9WLdU6wg fnBH2ncbO3cYCh4URpYD5Fb2OWOVcxFMIzOXQv+8Va4zI+bazG6K+vMnOMHMcdfr53 XWD4I+QsA1lgx7eHQII2Glmdnyq6W5/0fpF7rdTZjKGZeNG5SWGBZG5mVHZOVhfxf3 ZRCxNGuS4seAZIjNrS6sEhtQurtwhxnHVW8p1YQlf24VR3v6eJkA29Iwc7haWlb8YK kBr4f36JoyLI9Xoddd4N8CaSbdqc5FV3X6wplMCJ25038LEmL5QM04BSVqqHIVafdU uHdZm8gATdC2A== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , sashiko-bot , "Claude Opus 4.6" Subject: [PATCH 3/4] perf sched: Fix NULL dereference in latency_runtime_event Date: Thu, 4 Jun 2026 17:49:18 -0300 Message-ID: <20260604204921.1707333-4-acme@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260604204921.1707333-1-acme@kernel.org> References: <20260604204921.1707333-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Arnaldo Carvalho de Melo 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: b91fc39f4ad7 ("perf machine: Protect the machine->threads with a rwlock") Reported-by: sashiko-bot Assisted-by: Claude Opus 4.6 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-sched.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 13b801496a01271e..36da451447b5e59f 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -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", -- 2.54.0