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 6B70D42DA53; Tue, 21 Jul 2026 19:36:42 +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=1784662603; cv=none; b=GRx0zn2zp9LVionTSQzCiOa4nE6uhfuOUSaLY+cyltOQDgbuLkLLqVhlnd9T3TmDLqGVg/wiX1FsDtf/pH381nlc318LEEz/s0PswSNIDD7opn7qM35p5a+IcmJKqm8XjWRo4WYzdQFLteAftCSzDW2I7k3Ia+IKHha3p4ttbsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662603; c=relaxed/simple; bh=6rAF723tflUXvEe9P+KkpzVBXC8I3/kLQv6ZahS83rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nA/W6ANnivgElaiN5yYGD8Oher+XnQbCFGFQJoQ/HQMw1YzZnuLMWeTrp91FL43rQlRkhpG8/Hxm829iVDGJTSZCvDSIEE7XGuzpJHwe9af+qULtTkI/zmaNnLod0NcP1yCAZIQvkK9+1FHOhDWXEcR28SePvSHWOC9vJK4tkUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=W0uQ2y1L; 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="W0uQ2y1L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D21301F000E9; Tue, 21 Jul 2026 19:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784662602; bh=Ty6syGw6ymPmIYKGieLRcvpRkEGPq7Q4TK2dv+jmE1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W0uQ2y1LkEK82vUfR1aYaycSJ7c+sLfo58fNGZkdMuXv4qUfYoOzGU1Owj2PZf1uN 4YQPGqgTSGD7OOb7IqqQjgrpKdgnemlg5BZBh9goLO3rXBsy4y3C/7MiBBTpPrz1Ra /iz2IirwYpyEaiu7iYxSLcpo3Z95yRY6WrKmVRUM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Alexey Budankov , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.12 0464/1276] perf mmap: Guard cpu__get_node() return in aio_bind() Date: Tue, 21 Jul 2026 17:15:07 +0200 Message-ID: <20260721152456.485897816@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@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-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit f32dc302a090f48893477ef297a888db109ec0bd ] perf_mmap__aio_bind() passes the cpu__get_node() return value directly to an unsigned long variable (node_index). When cpu__get_node() returns -1 for an unknown CPU, the implicit int-to-unsigned-long conversion sign-extends it to ULONG_MAX. This causes bitmap_zalloc(ULONG_MAX + 1) which wraps to bitmap_zalloc(0), returning a zero-sized allocation. The subsequent __set_bit(ULONG_MAX, node_mask) then writes massively out of bounds. Check the return value in a signed temporary before assigning to node_index, and skip the NUMA binding when the node is unknown. Fixes: c44a8b44ca9f ("perf record: Bind the AIO user space buffers to nodes") Reported-by: sashiko-bot Cc: Alexey Budankov Cc: Jiri Olsa Cc: Namhyung Kim Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/mmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 43b02293f1d2da..5d2685d9ab4ea6 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -103,9 +103,15 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, struct perf_cpu cpu, i int err = 0; if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) { + int node; + data = map->aio.data[idx]; mmap_len = mmap__mmap_len(map); - node_index = cpu__get_node(cpu); + node = cpu__get_node(cpu); + /* -1 sign-extends to ULONG_MAX, wrapping bitmap_zalloc(0) and OOB __set_bit */ + if (node < 0) + return 0; + node_index = node; node_mask = bitmap_zalloc(node_index + 1); if (!node_mask) { pr_err("Failed to allocate node mask for mbind: error %m\n"); -- 2.53.0