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=1796387992; b=jH2+AOaQckO7AbYO+oVpKbDlL1xYuh89LVUJvH8ay3C4bIsa278X9X8ypB3fxcg3Qcz3 Wb8G7kEQwHGqJLlPN/oaQ2CA8WcVIrVMX3gRfCX0/1lQqea1NZqf7MG2xpZD8tawTFwgI bthSLmR4gcW82bTOVOOpDRk0jPitBYGfwBdTGoa8qx+xl5JKw5Kz79y504W9lEQ7dtwl3 jKu45YGS1V38zquye3C/iBFkm/+qSxlkm3QLXPdRjO3Bp/eFNYAO4CzKMIdS/+SgsRGsB mJoKaM64uKObrXjue6MpzFDq+B6J+9brmPygqosbcMz3nV10scNAR7tzZrmAhvAbd7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387992; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=HgOCQj9kSdOQDTMlzKjL67uLwi71j0Z320lPd6OlGBE=; b=vmqDAckIDvuKWLbtTeCvD6QpUD4OkotaZgVsFcCNu5z3I63ThA3B9fivEK3Yt7cfunLB +iejvdIA/Y4HlntvOH1mHjBfZBea5MKX0RWAvSHZWfeByZDK8d2SMViupHwLXR8dn1OuL CHCk4G3p7NI5qT5f+a6oocVgLiiChO9euslYnyBDNSGGuL724mE8SE1CBOq2RnvHgBDsq DsEM68zD1iIOtWx9kp0zbIcj1Mqmquap9/a4LPkvkIFcpzhGlEgMg653ekJb+ekJ19E1R gZx7BPq07RoQUjVtfxXLSYwCfHwZ3Uf9KOjojh4JS+20bEllMaILFdeny8aOYsCCA0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b3ESE5jy; 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 A5FF8606A332 for ; Fri, 4 Dec 2026 12:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b3ESE5jy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 527FF1F000C2; Fri, 4 Dec 2026 12:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796387992; bh=HgOCQj9kSdOQDTMlzKjL67uLwi71j0Z320lPd6OlGBE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=b3ESE5jy8H3Z7vqpfwUuYobdXbxgswHtTaJhdzhC+ashIq+1v3BUr5aVqATyIcqsB XjdMicBHc2kShLAx8ms6aEAxq57iHPr3QfwpQ785h9N/KY/oIBItpEj+0aM53k5nAT A2mwvJ5D9tA8ffMpfGk1644sP2z+vThzPCyoUmrIr27xCT64bwJio+DGRLd1A33pNI 8swS3bGmOUWqoKgY2lAD/dqZAOT71qirdUfR489IZdZP0//baQkXRk+i9L3mkDaGAz z1bV33ZHbZ7zlsnm+Zz7g0XNEPeE//7xd3fY58+dKbhOPuxrlA1slVeGvzGTc0zVzo DyOHzEdd/0/qw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Reply-To: sashiko-reviews@lists.linux.dev To: "Leo Yan" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261204-perf_fix_large_threads-v2-5-a6c077f3037d@arm.com> References: <20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com> <20261204-perf_fix_large_threads-v2-5-a6c077f3037d@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:39:51 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] perf: integer overflow in xyarray__new() with split thread maps -- commit 5da116763d7a7d4ff839c7c950a57030bfbeb322 Author: Leo Yan perf: Assemble split thread maps in script and stat report This commit adds thread_map__append_event() to assemble split thread map records in perf script and perf stat report, keeping the thread map private until the final record arrives before publishing it to the evlist and allocating counter stats. > diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c > index 918ab31802320..4b3e0cd022fb7 100644 > --- a/tools/perf/util/thread_map.c > +++ b/tools/perf/util/thread_map.c > @@ -336,28 +336,57 @@ void thread_map__read_comms(struct perf_thread_map = *threads) > comm_init(threads, i); > } > =20 > -static void thread_map__copy_event(struct perf_thread_map *threads, > - struct perf_record_thread_map *event) > +int thread_map__append_event(struct perf_thread_map **map, > + const struct perf_record_thread_map *event) > { > - unsigned i; > + struct perf_thread_map *threads =3D *map; > + bool new_map =3D !threads; > + u64 old_nr =3D threads ? threads->nr : 0, nr, i; > =20 > - threads->nr =3D (int) event->nr; > + /* > + * Trust event->nr to describe chunks of a valid thread map, whose total > + * count and allocation size are representable without overflow. > + */ > + nr =3D old_nr + event->nr; [Severity: Medium] Can unbounded thread counts across split PERF_RECORD_THREAD_MAP records overflow the allocation size in xyarray__new()? Before this patch, a single PERF_RECORD_THREAD_MAP record held at most 2,729 threads, keeping xyarray__new() below 2^32 bytes even at 32,768 CPUs. Split records remove that ceiling, so set_maps() -> evlist__alloc_stats() -> perf_counts__new() -> xyarray__new() can overflow: tools/lib/perf/xyarray.c:xyarray__new() { size_t row_size =3D ylen * entry_size; struct xyarray *xy =3D zalloc(sizeof(*xy) + xlen * row_size); if (xy !=3D NULL) { xy->entry_size =3D entry_size; xy->row_size =3D row_size; xy->entries =3D xlen * ylen; xy->max_x =3D xlen; xy->max_y =3D ylen; } } On 32-bit builds, xlen * row_size wraps size_t at 3,277 threads across two records (with 32,768 CPUs and 40-byte struct perf_counts_values), producing an undersized buffer while max_x and max_y stay large. Subsequent PERF_RECORD_STAT events then pass xyarray__entry() bounds checks in perf_event__process_stat_event() and write out of bounds on the heap. On 64-bit builds, xlen * ylen overflows signed 32-bit int at 65,536 threads (with 32,768 CPUs), sign-extending xy->entries to a huge size_t in xyarray__reset(). Adding overflow checks in xyarray__new() would protect both paths. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-perf_fix_l= arge_threads-v2-0-a6c077f3037d@arm.com?part=3D5