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=1796381127; b=L4UGb3Ei94aCWLxQMttVzHN8kJmpexuHOyGgoqEhrpEB/Kcg3DTnU9RwrlTcUZqS9aTt c+aCdH5/e4GDdltBNx34WbOEEBSiAZ8pz2QyDszvWQyuz5VtUX8VnRmmPUnWurUzAL0v8 7sBDPr5QtV0Lim6/xOBZ+tcoJ5OONKkFN8q3fsv19kItJxMwNgmHZfgeqQx7k7zI+aTrd HNQ4Gk/IUzxaLR11Lhl+8NuOQbLjKKrcRhhFvFR2WyskDZU6Y2KVePC9v33L6nb5PLHeU I4AqaAxf5q6cj4DSQtTEogprS52bPL+9iPIxAOdolC/Uup7sG2fLYbNLfKVVFMMnkMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381127; 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=6S64ab6JtozLgPpm+YqUnzWiIf6jsE42GWV30/88iqU=; b=oxQ9ID/x4xJWgRqmILD7QY9pGVmXXtIfcktj+VuxXHA3gtwltLQ1i/7UfZyB6LcHrsJD 71jwVNV+AF0RBja7pMqur7YSTWp7mP9p+deaRNk7hkJxTNQYgA9BPS2d8/LAMEp5F0fF5 +D+7nS1ZLiuZqyLeJEgBT5YoSaDbJG/jcc3xqCLtZJyQFcvqJHEY5npITVwIhGMt123cD 2XTbokVyiUTlclHop58J+ulkuXwintmjAACzPQJ/6VG5AuvnrBr09j2nr4PeQnZcut91l mZTuHvoJrVrl3Nk7dhB5V6oXxL5EwTEy/jcHQlioy7Q/xnPDx1q0T8duFR0YPaaDXuw== 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=lODlbWIu; 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 6AAB6606A322; Fri, 4 Dec 2026 10:45:27 +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=lODlbWIu Received: by smtp.kernel.org (Postfix) with ESMTPSA id D54E71F000C2; Fri, 4 Dec 2026 10:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381127; bh=6S64ab6JtozLgPpm+YqUnzWiIf6jsE42GWV30/88iqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lODlbWIuqo7P01bGNvHkJ2qoJ0ZOz9fFmlJs6gJQDdgY5pdPOnrqoroafWUC3M5E/ TTtpLuFLpPDrUjySl+xfkuUAZLqX4mC8h1eUI6KHqXRtx4E56NseuBv4BGyOWNOveV J0pSpHR1ir1PEJFCu7w9PZd356zV3+jahmyfeMm4= 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 7.3 568/742] perf record: Reject CPU indices equal to the mask size Date: Fri, 4 Dec 2026 19:07:12 +0900 Message-ID: <20261204100650.232449394@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 @@ -3704,8 +3704,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); }