From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382555; b=jeJV9ZnzR18MXGBVAr/11JbgortsA16rTzHsgUBJHRNDyKvz0SqxBXyt7VVoa3m2CIvF /rKhw0pqvVC7PELhM7tt5YPq3lOBuiL5D8tXPitXNokhmEwANC49COeGsmstokDSkGQyQ yD3N6KUUNqJPGOlb2TMX/zsgs+XLRH8Y9rJgOwMgShmedDBzED8f1mOAG0h+yI4g2ZYX9 tlbVzepFVxMos88dm7x4Z4rVbaELVCugi/xCW5dTBu/XdUWpV7dNg7UchZcn9/UKK1T8s GvAk4pkKcMGvK+eIx582Cqw/uYmhmav7blY9QKdrllCTsrz48JZdC0HyppcVX54aaqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382555; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=enVxGLgbiFDngObYN+62eVm6jieM5hQ3573Zghn8luU=; b=3y1mR7qL1pevxjb96mPE/F8Seb0ox4xKcLQlxJ7X9xo4oioRXsyP+eMCSR33HiNY6zdd eb2t6IRQoMt/MKcr+LTwsCoqf3srkmn+MtwtsqnP+AxucLJuyayl2KOMhwkylq4wOurrN askSDH47HzbROxHZB62jhfdwhL2+QXIpaj1bq3i7xDxGJH5wMH2F+r09S1N12uwlhEnrG CR0BbtACqogHHlLB4Ijm7Dbg/GNkcH0+Il5TfLFeD/NrDoc5wrgUz9s1UIDP5C8wr5wzj raZUNXQRmFUvKZcLtzxkt6ubuxHBM+j2oEQgUX5dZr93vBG6svg5iP3pfxu5VPjI90g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2N2KFQFk; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC5C606A32F; Fri, 4 Dec 2026 11:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2N2KFQFk Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0CBF1F000C2; Fri, 4 Dec 2026 11:09:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382555; bh=enVxGLgbiFDngObYN+62eVm6jieM5hQ3573Zghn8luU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2N2KFQFkm+JUfStqwqQn1YvO7BPaOaDEfkB6OUZSdWeGMr+xykOmFHW+YfB+SZ31U CJd0/m9zXEW2UIJiMB0GXk8gyvLHDIzrjw0okAwt4hzUQxCcD7KjPu9l8jvhKFXvrX LKNER+mMap8H+eK6/PFXcP1V7aXNARiVYdbWUw5M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, 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 Subject: [PATCH 6.18 505/703] perf record: Reject CPU indices equal to the mask size Date: Fri, 4 Dec 2026 19:06:44 +0900 Message-ID: <20261204100641.233025441@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Moses commit 82b4a28e758816365405e01d9ed09027d13ef77a upstream. 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 Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Athira Rajeev Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: stable@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/builtin-record.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3638,8 +3638,8 @@ static int record__mmap_cpu_mask_init(st 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); }