* FAILED: patch "[PATCH] perf record: Reject CPU indices equal to the mask size" failed to apply to 6.1-stable tree
@ 2026-12-02 13:39 gregkh
2026-12-04 4:21 ` [PATCH 6.1.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-12-02 13:39 UTC (permalink / raw)
To: p, acme, adrian.hunter, alexander.shishkin, atrajeev, irogers,
james.clark, jolsa, mark.rutland, mingo, namhyung, peterz
Cc: stable
The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 82b4a28e758816365405e01d9ed09027d13ef77a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120243-tricking-diabetes-c833@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 82b4a28e758816365405e01d9ed09027d13ef77a Mon Sep 17 00:00:00 2001
From: Paul Moses <p@1g4.org>
Date: Fri, 30 Oct 2026 06:48:50 +0000
Subject: [PATCH] perf record: Reject CPU indices equal to the mask size
record__mmap_cpu_mask_init() rejects CPU indices greater than nbits but
accepts nbits itself. Valid indices end at nbits - 1. When nbits is a
multiple of BITS_PER_LONG, __set_bit() accesses the word immediately past
the bitmap allocation.
User specified recording thread masks reach this write before they are
intersected with the selected CPU mask. For example, an affinity mask
containing CPU 64 overruns a bitmap allocated for 64 possible CPUs.
==40343==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7bbab4000018 at pc 0x6195de57af45 bp 0x7ffe25545d20 sp 0x7ffe25545d18
READ of size 8 at 0x7bbab4000018 thread T0
Reject indices greater than or equal to nbits before setting a bit.
Fixes: cbd7bfc7fd99acdd ("tools/perf: Fix out of bound access to cpu mask array")
Signed-off-by: Paul Moses <p@1g4.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ad81458989b5..0e98a613c37d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -3704,8 +3704,8 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp
return 0;
perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) {
- /* Return ENODEV is input cpu is greater than max cpu */
- if ((unsigned long)cpu.cpu > mask->nbits)
+ /* Return ENODEV if the CPU index is outside the mask. */
+ if ((unsigned long)cpu.cpu >= mask->nbits)
return -ENODEV;
__set_bit(cpu.cpu, mask->bits);
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 6.1.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case 2026-12-02 13:39 FAILED: patch "[PATCH] perf record: Reject CPU indices equal to the mask size" failed to apply to 6.1-stable tree gregkh @ 2026-12-04 4:21 ` Sasha Levin 2026-12-04 4:21 ` [PATCH 6.1.y 2/2] perf record: Reject CPU indices equal to the mask size Sasha Levin 0 siblings, 1 reply; 3+ messages in thread From: Sasha Levin @ 2026-12-04 4:21 UTC (permalink / raw) To: stable Cc: Ian Rogers, James Clark, Adrian Hunter, Alexander Shishkin, Alexandre Ghiti, Andrew Jones, André Almeida, Athira Jajeev, Atish Patra, Changbin Du, Darren Hart, Davidlohr Bueso, Huacai Chen, Ingo Molnar, Jiri Olsa, John Garry, K Prateek Nayak, Kajol Jain, Kan Liang, Leo Yan, Mark Rutland, Mike Leach, Namhyung Kim, Nick Desaulniers, Paolo Bonzini, Paran Lee, Peter Zijlstra, Ravi Bangoria, Sandipan Das, Sean Christopherson, Steinar H. Gunderson, Suzuki Poulouse, Thomas Gleixner, Will Deacon, Yang Jihong, Yang Li, Yanteng Si, bpf, coresight, linux-arm-kernel, Arnaldo Carvalho de Melo, Sasha Levin From: Ian Rogers <irogers@google.com> [ Upstream commit 5805c82513c444333efb086017be8d666336858a ] When iterating CPUs in a CPU map it is often desirable to skip the "any CPU" (aka dummy) case. Add a helper for this and use in builtin-record. Reviewed-by: James Clark <james.clark@arm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: André Almeida <andrealmeid@igalia.com> Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Cc: Atish Patra <atishp@rivosinc.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Paran Lee <p4ranlee@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Steinar H. Gunderson <sesse@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will@kernel.org> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Yang Li <yang.lee@linux.alibaba.com> Cc: Yanteng Si <siyanteng@loongson.cn> Cc: bpf@vger.kernel.org Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20231129060211.1890454-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Stable-dep-of: 82b4a28e7588 ("perf record: Reject CPU indices equal to the mask size") Signed-off-by: Sasha Levin <sashal@kernel.org> --- tools/lib/perf/include/perf/cpumap.h | 6 ++++++ tools/perf/builtin-record.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 03aceb72a783c..60c4e05470102 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -31,6 +31,12 @@ LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_c (idx) < perf_cpu_map__nr(cpus); \ (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx)) +#define perf_cpu_map__for_each_cpu_skip_any(_cpu, idx, cpus) \ + for ((idx) = 0, (_cpu) = perf_cpu_map__cpu(cpus, idx); \ + (idx) < perf_cpu_map__nr(cpus); \ + (idx)++, (_cpu) = perf_cpu_map__cpu(cpus, idx)) \ + if ((_cpu).cpu != -1) + #define perf_cpu_map__for_each_idx(idx, cpus) \ for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index fa2a066005ad0..eac672d02e94b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3545,9 +3545,7 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp if (cpu_map__is_dummy(cpus)) return 0; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu.cpu == -1) - continue; + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) { /* Return ENODEV is input cpu is greater than max cpu */ if ((unsigned long)cpu.cpu > mask->nbits) return -ENODEV; -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.1.y 2/2] perf record: Reject CPU indices equal to the mask size 2026-12-04 4:21 ` [PATCH 6.1.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case Sasha Levin @ 2026-12-04 4:21 ` Sasha Levin 0 siblings, 0 replies; 3+ messages in thread From: Sasha Levin @ 2026-12-04 4:21 UTC (permalink / raw) To: stable Cc: Paul Moses, Namhyung Kim, Adrian Hunter, Alexander Shishkin, Athira Rajeev, Ian Rogers, Ingo Molnar, James Clark, Jiri Olsa, Mark Rutland, Peter Zijlstra, Arnaldo Carvalho de Melo, Sasha Levin From: Paul Moses <p@1g4.org> [ Upstream commit 82b4a28e758816365405e01d9ed09027d13ef77a ] record__mmap_cpu_mask_init() rejects CPU indices greater than nbits but accepts nbits itself. Valid indices end at nbits - 1. When nbits is a multiple of BITS_PER_LONG, __set_bit() accesses the word immediately past the bitmap allocation. User specified recording thread masks reach this write before they are intersected with the selected CPU mask. For example, an affinity mask containing CPU 64 overruns a bitmap allocated for 64 possible CPUs. ==40343==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7bbab4000018 at pc 0x6195de57af45 bp 0x7ffe25545d20 sp 0x7ffe25545d18 READ of size 8 at 0x7bbab4000018 thread T0 Reject indices greater than or equal to nbits before setting a bit. Fixes: cbd7bfc7fd99acdd ("tools/perf: Fix out of bound access to cpu mask array") Signed-off-by: Paul Moses <p@1g4.org> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: stable@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> --- tools/perf/builtin-record.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index eac672d02e94b..19291f060e70e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3546,8 +3546,8 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp return 0; perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) { - /* Return ENODEV is input cpu is greater than max cpu */ - if ((unsigned long)cpu.cpu > mask->nbits) + /* Return ENODEV if the CPU index is outside the mask. */ + if ((unsigned long)cpu.cpu >= mask->nbits) return -ENODEV; set_bit(cpu.cpu, mask->bits); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 4:21 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 13:39 FAILED: patch "[PATCH] perf record: Reject CPU indices equal to the mask size" failed to apply to 6.1-stable tree gregkh 2026-12-04 4:21 ` [PATCH 6.1.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case Sasha Levin 2026-12-04 4:21 ` [PATCH 6.1.y 2/2] perf record: Reject CPU indices equal to the mask size Sasha Levin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox