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=1795022859; b=YP5C9455pxCsOmORClzDpzt9uOYvm7mBmLvcZ+jRrV1XPSwq+6oUIB7hcWaBgPxe2VK8 QDwMy/aMSvxurwiLzpXdwOKseYlLTDyqn+qBOwCr06qpCueIj63GFCc2aUD1xm8YMsUdS 28/HMr7C5LfensTsmm5/YuFDsLjIGq4f0rxOdSF1/YHrnQFDFmjj6xXK7kastmQU/ODvd /SFqZfzCotE/b3HzMoQXOWFIUkAW42QzoWVV8bZ7IcdZIUcU0mRKuM5+df2OzgvM3pI2O 1Rmo0DEKnXRUfeTq0E2Kiop6QCePoY2eKjV01A6GXUvZXJuPQzbrUZyE3NtW/JGvYdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795022859; 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-Type:Content-Transfer-Encoding; bh=l9QveARuY9lHRgqztYTgAfn7JcT5qeMhVCLhG6OFfPQ=; b=eqaC0mFrudHSROV9nC7x95uHCLYBpw1IKUXbN+XfCXfWBuiHiSkbGX7Od7gcQfdUy8Et LPPZRA6EBmSAJm86RRd5HbPoOkxIpUgC13ldfTwKzFB9OC1Lw10zCsx+dfu2VowQHOP9s omETvvB+D50SqNaGQXt70O0NLy0pWlcpZntBSYc9wxQsoukj1SSwMKimLflC+fbfh/sKj pI8zIvz+6tCU+2PGGIVSCEy7a0FJYD6biSaM9TxrBvGnKokxAPLMB+UWscbOmZ/Nn0ET2 T9v4W0PmWf5+4fCS1I+UoHRzssE3oqkKZ+gbGPORMXUkTQOkfOKy5AgHELMWy+hmXvA== 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=nuG5G7Qm; 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 2EE1A606B3EA; Wed, 18 Nov 2026 17:27:38 +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=nuG5G7Qm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E4E31F000C4; Wed, 18 Nov 2026 17:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795022858; bh=l9QveARuY9lHRgqztYTgAfn7JcT5qeMhVCLhG6OFfPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nuG5G7QmJxftWtapH4ukaRMmgn2Fvid1MdPHH6ZBmn7pDnrolsGauCxkdQvkVMsf8 5u03H6dClXVtuxxqylzxXNwKuHvX+k1ltnRyuM0HUiZfJnMyZl0mkkhy9EPMTT43EL qApvn2R1VCLdRWo2JUJg3a/CZ9yCfuu8/5cZkfT8= 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 6.18 0163/2151] perf jitdump: Bounds-check debug entry byte-swap loop Date: Wed, 18 Nov 2026 15:31:38 +0100 Message-ID: <20261118150127.685395716@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit ede3cd8151675c2983cd49104b1e9b25a3712ed8 ] The byte-swap loop for JIT_CODE_DEBUG_INFO uses array indexing (jr->info.entries[n]) to iterate debug entries. struct debug_entry has a flexible array member name[], so each entry has a different size. Array indexing computes offsets assuming fixed-size elements, landing inside variable-length name strings after the first entry and byte-swapping garbage. Additionally, nr_entry is read from untrusted jitdump input without validation against total_size, so a crafted value causes OOB reads. Replace the array indexing with debug_entry_next() pointer arithmetic (which correctly accounts for the variable-length name) and bounds-check each entry against the record's total_size before byte-swapping. 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 | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index e1f0e01b851b1..5174946ffe870 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -319,14 +319,32 @@ jit_get_next_entry(struct jit_buf_desc *jd) switch(id) { case JIT_CODE_DEBUG_INFO: if (jd->needs_bswap) { + void *end = (void *)jr + jr->prefix.total_size; + struct debug_entry *ent; uint64_t n; + jr->info.code_addr = bswap_64(jr->info.code_addr); jr->info.nr_entry = bswap_64(jr->info.nr_entry); - for (n = 0 ; n < jr->info.nr_entry; n++) { - jr->info.entries[n].addr = bswap_64(jr->info.entries[n].addr); - jr->info.entries[n].lineno = bswap_32(jr->info.entries[n].lineno); - jr->info.entries[n].discrim = bswap_32(jr->info.entries[n].discrim); + + /* + * debug_entry has a variable-length name[], so array + * indexing would compute wrong offsets — use + * debug_entry_next() and bounds-check each entry. + */ + ent = &jr->info.entries[0]; + for (n = 0; n < jr->info.nr_entry; n++) { + if ((void *)ent + sizeof(*ent) > end) + break; + /* name must be NUL-terminated within the record */ + if (!memchr(ent->name, '\0', (char *)end - ent->name)) + break; + ent->addr = bswap_64(ent->addr); + ent->lineno = bswap_32(ent->lineno); + ent->discrim = bswap_32(ent->discrim); + ent = debug_entry_next(ent); } + /* clamp so downstream consumers don't overrun */ + jr->info.nr_entry = n; } break; case JIT_CODE_UNWINDING_INFO: -- 2.53.0