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 BA8AF2D8376; Tue, 21 Jul 2026 20:38: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=1784666325; cv=none; b=O24myzOwmeTmoAG0O6jKC+nptaXHOXUoh7Ri3kckQYhU8Cgu0N6uSp2hUXuH8OhKoIHZbAmFZr7K11Z2PSFbjOhqcAZEqki9oQMDkKp6mrt2rGwpGzH/cVklUwr8m7ZT8kGGQUTkkr/0O6x+pnN76Sy3tJhpn6xJUq7XZ9EsuXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784666325; c=relaxed/simple; bh=NaR6J2582Lmq9Ndhj3GmeJXbQWzbLeRrnnuQ7f44UEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NxpRymbdQ3XaP51fr5dlRmsK9UkUX0EcHQF91KNBuwJyRYth8eKMNCnCfqW36CbhQugDH5EPMbaR2Gb5d6sQKTHujb4XezBG3Q1W92bqN/geR05QgRo0jkhkYsrmJJtaU8HagcsfVD6vZACwAnDKixStpo+tZHMaqPZraMAhHko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jtGfBcvZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jtGfBcvZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 258E51F000E9; Tue, 21 Jul 2026 20:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784666324; bh=8PBNZ6VISr5ikmUCDjyefxxlZmCBGW74IL9leKRDbNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jtGfBcvZC0Yn07RwMcL/YXwSMYgUeC7eichZw7+2roDVUSr8N9fVRZRlvBiAD3bL4 XCxYc/IcB0Jhhwdgtp0GXNsOfbTV+kEydHhv1Pco/8oiRZQI/MdxuSVtJ3MftaNp8H yeDo0LuQrPLx48lbwDUfjVWSwCxE7eX7DDI9JDyo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.6 0638/1266] perf sched: Fix NULL dereference in latency_runtime_event Date: Tue, 21 Jul 2026 17:17:55 +0200 Message-ID: <20260721152456.132752457@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 8cbca8a480e15f6326ce94287570993f27a4b2d5 ] 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:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 9e9bb19f0bc98b..6df0d1252f197f 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1223,13 +1223,15 @@ static int latency_runtime_event(struct perf_sched *sched, const u32 pid = evsel__intval(evsel, sample, "pid"); const u64 runtime = evsel__intval(evsel, 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.53.0