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=1795015265; b=nSQKvp6T4sqqs3cT24Qn/lsjnjtaMhHrs68XDDpTm+vCVwEZaqo9/Gx6nYkL6pbRiYFf 98RmXy3ynPTGHV+y7qs7j1btuT2o3TK8Xoks+SNaIvkyUbA/rStYBARIEqdt/VN9VILTe 13KA2XKPvjYENeypahrM3lHWvjG8yM57D1U0PNLeipo6/5ukqDjLQOsbslyRX4QuEaSbT 4B8CweSY87zz67jv11sCOxWDQiqaTNLhwDq1ZavqF349iVgUAQZNMGWg3L+E+dsQY55Vs QU8RustKbfkxxFU2HjP/8hX0qXIXOPiUTVz7MSwxC0c3Z9a5jKYLpLXq1ZHvdTxSvDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795015265; 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=nM6bhtmMsvK5NXezMdsILFaVFY5YaOHG5sYolDuaHxk=; b=a8zIhzPHwoEJmCZZyDiE0Er8H1HxhtDq6zAic+BPHyUApkxyKAFChdF4p/mFwsqHvfIm R6hXu2DPIdbBaeV96EK2ndDlROk9jwtBC9LxTQVLtGjN6p9nOQ9utv6OKyDTWUpCEEdNR qwq5qgHc4aeNStTaFOmzCqAyXbPIO0tTOuN9run4X0BWHUgs6VmnMHe/eANitxVKrqVL7 E7oJtJS019Ncuj045ci9r+wlTGiomV9cnyaSTkAHTBRB4luntv8MdNERvH39uInsccryZ 27GV1Yb6C6NNde+C3RGWOrMpar5q1CxRmp91ECN7Imqx1AAFg2nlMxCT+7LZnUL4cWg== 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=qkxohApI; 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 D3712606A325; Wed, 18 Nov 2026 15:21:05 +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=qkxohApI Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD0EC1F00936; Wed, 18 Nov 2026 15:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795015265; bh=nM6bhtmMsvK5NXezMdsILFaVFY5YaOHG5sYolDuaHxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qkxohApI3OoxjrICq1b/jd48oxasaPv4u6Q8Il+79qBDpIfMTnlzoKffuICQwK5JO Q3jHrSR1cBCyAowxgHh/xkflfZNa5qGYZ/FFrUblVdSxkuEMpVFxtQQxV/Mp20bzGz BKLKPrewfhBDDS575GXzNQs3582fBp95SOnoKV30= 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 7.3 0110/2651] perf jitdump: Bounds-check debug entry byte-swap loop Date: Wed, 18 Nov 2026 15:22:30 +0100 Message-ID: <20261118150251.845207837@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@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 7.3-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 f79e9420c6bd7..7efbaa07f1ba7 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -320,14 +320,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