mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Paul <p@1g4.org>
Cc: acme@kernel.org, peterz@infradead.org, mingo@redhat.com,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
	james.clark@linaro.org, atrajeev@linux.vnet.ibm.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] perf record: reject CPU indices equal to the mask size
Date: Thu, 5 Nov 2026 23:20:03 -0800	[thread overview]
Message-ID: <au1_ow_duqzf7nyY@google.com> (raw)
In-Reply-To: <20261030064825.2156317-1-p@1g4.org>

On Fri, Oct 30, 2026 at 06:48:50AM +0000, Paul wrote:
> From: Paul Moses <p@1g4.org>
> 
> 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.

What's the exact command line?

> 
> ==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: cbd7bfc7fd99 ("tools/perf: Fix out of bound access to cpu mask array")
> Cc: stable@vger.kernel.org
> Signed-off-by: Paul Moses <p@1g4.org>

Arnaldo, do you want to take it for 7.4?

Thanks,
Namhyung

> ---
>  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 d7c8f490cb62..80aaad7d51ec 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -3689,8 +3689,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.56.GIT
> 
> 

      reply	other threads:[~2026-11-06  7:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  6:48 Paul
2026-11-06  7:20 ` Namhyung Kim [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=au1_ow_duqzf7nyY@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=p@1g4.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®