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=1795054638; b=mbT77aURdXWCguymQVwkcBKcNviX8dAcnekmdaNewNU/k72G5QMUtMbw7/Y/eVcocxTS DY/rMp/k4+7ScuEibU1W8tBsQ9zZuEIs3QATinRCH2UTrf7EMoDvlr6mshFSd6jmXf2TH L82K5dUrmJZi+D6osVf634hEVGSmZeZRJUwLPuoT3K8cQrcp70h2TOHftlWJgCM1r6IgM kUGgvjvWGF5ZeffDOSsvR1SONUxYXgmQNIW0OkFgzRS9Pl7aHvQ72pZI9ppwpQ+5HrlRU 9GuruuDMtqJU5SN3/27XoPqljeKzGi5gEWJhkXwALwmOR3Z07b4LxX8Ef0EPPlw4Skw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795054638; 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=2upQr5IHSFX0SLp1Zp5EcNdzD+qi1jQ28wACXe0kvy8=; b=DycAscBpgIk40v6qTwFQcJNSqcAyytFXR+9pN3FBb5GYatExqKps18exexIZhqM0ISyK AuhDmoaGNpvZ+t5bswsL76RDrac+MckceABdagngNgfgqfpvAOevbpLUxLOkx2qvN6nIw DoxOyH7Eygk6sAv0QUcTpjvfCNONmRfM/g43V80y3Jc1N6ACYjKg8Z01J2gvVxOM/vgTB hFxnyI/T+K2u0GQ2DsbvM5rkcbp2YGm9uQTyeWR/7GD9K6HIBMwDPiM3zKNDMhcgj/N/n aXrMuB1WTJUhxHPAZQXTw7CID0MeZA0eQcH4DjU1ISsSQ/wZrSR7pUXt9c0TTBulZsw== 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=e1qXo2l0; 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 BA031606A31C; Thu, 19 Nov 2026 02:17:18 +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=e1qXo2l0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 198E61F000C4; Thu, 19 Nov 2026 02:17:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795054638; bh=2upQr5IHSFX0SLp1Zp5EcNdzD+qi1jQ28wACXe0kvy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e1qXo2l06VE+gTWAFntla4Gi4JgzwBtUulniVSeLSTbxfUrU03CQqTwptWySfIoiC +KvrM2+RVcpeLfyTmADOUe/FhIiHby6Iht69Cl3OYAcWPEjP/Rw8toJsxtfZjkFWfK d4Nc7uxnN0nKdq+I1TQ2umwN8N0OBA1Q3RJ7Kd5Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Ian Rogers , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.15 1347/2214] perf jitdump: Check snprintf return before computing header size Date: Wed, 18 Nov 2026 15:50:23 +0100 Message-ID: <20261118150105.340859471@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 0155f05ea6e133c18a04b8b5945cac59870da156 ] snprintf() returns the would-have-been length on truncation. When the jitted filename exceeds PATH_MAX, the unclamped 'size' value inflates sizeof(event->mmap2.filename) - size into a massive underflow, causing the header.size computation to write an oversized header. The subsequent write to 'id = event + header.size - idr_size' then corrupts the heap. Clamp size to PATH_MAX - 1 after snprintf in both jit_repipe_code_load() and jit_repipe_code_move(). Fixes: 9b07e27f88b9 ("perf inject: Add jitdump mmap injection support") Reported-by: sashiko-bot Reviewed-by: Ian Rogers Cc: Stephane Eranian Assisted-by: LLM Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/jitdump.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index 12337ff564ece..bf87e32f4bbe8 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -498,6 +498,9 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, nspid, count); + /* snprintf returns would-be length on truncation, clamp to buffer */ + if (size >= sizeof(event->mmap2.filename)) + size = sizeof(event->mmap2.filename) - 1; size++; /* for \0 */ @@ -610,6 +613,9 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, nspid, jr->move.code_index); + /* snprintf returns would-be length on truncation, clamp to buffer */ + if (size >= sizeof(event->mmap2.filename)) + size = sizeof(event->mmap2.filename) - 1; size++; /* for \0 */ -- 2.53.0