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=1795028945; b=2EDZ/7RdHEivFBdL/Yu1fyWh9ZWNaoHwZ+gAwDdJaR7FIV8J7kTaC0c/2R5Fl8kchPrf lLnB9S7vZ84n0LgIERMw1vLKzVW5NGdES8+smdg0FyO0fa/qD9tdhozRoGt3nDy+LOetn scKXl0JFctq6YE8PeX/u2WgCwS+0frTiLocP+SNJov0LH67cNvRjhBGHRTIsZNfIza1hg dwdB39ColjMtk7Y9higgwGQX5FQYh1VSpLyguObkITtVVSmFc0wH8Hk75ykzIHl2BYGpx HLJ3Skjb5f6PAuNSUQfwMO1OmmrOT2WvJhPvreVuxDPhzvLXUE6HOGXHML+1k88rTnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795028945; 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=L8ewblOExfgXzHQWQ/2i0E6Ezc9P/mzecoxZNitcDb8=; b=GuFY64GVmmutlqMR24VU6fIWi1bNdeEw6jBfVFuJ4dc3cI+A2Pm2Ohz2w7VcQqUK0kkC aN8NjMY6HjH61P3cfX4WhI0821NxkTC9k+NuVeQKmfK7vCzE+gem0ZgcRT1/im2vxC122 f8mDj1zQIstVIe6AkGUsjeelR50kcTL8vGsZTKbZycWbfR20eQb5WPqD0N8ZwK1Qh8S+9 miIDTwnBYDewqCTfvDB2EQK0LqtbSGLmjSwqJLvnV+M2xzlri3ftbcmS3OOAnXZUJ90wK 6Hd5beTgA8Ek96Jvei/PXzdY7nDy7OmX3tDekznV5vRzc74YEkjgS80sS20/7ApnwUg== 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="OF/RYmQr"; 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 734AA606A330; Wed, 18 Nov 2026 19:09: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=OF/RYmQr Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA0531F000C6; Wed, 18 Nov 2026 19:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795028945; bh=L8ewblOExfgXzHQWQ/2i0E6Ezc9P/mzecoxZNitcDb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OF/RYmQrTo3ZS6Zc0N/6VMvHvdX5ugAreMr6ci16B7lb5RRspjEQhhpQKd0hK9FDs 0hFbftsDZNuFqTgKCfCmcOMc/qz5wSgcto6c+dIFZSekPMHHwHTvCa6g+XPnzffaR7 8hRoFf0wHRxAGb25ebicND4oYG6Hvo3rJNSQdy+Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Ian Rogers , Stefano Sanfilippo , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.12 0176/1756] perf jitdump: Validate unwinding sizes against record payload Date: Wed, 18 Nov 2026 15:38:23 +0100 Message-ID: <20261118150015.462585122@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150007.957976754@linuxfoundation.org> References: <20261118150007.957976754@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 92d50319b4f0c0bbee8a236a09063272cd22faab ] jit_repipe_unwinding_info() copies unwinding_size and eh_frame_hdr_size from the jitdump record into jd-> fields without checking them against the actual payload size. Downstream, jit_add_eh_frame_info() in genelf.c computes unwinding_table_size = unwinding_size - eh_frame_hdr_size, which underflows when eh_frame_hdr_size > unwinding_size. The result is passed as d->d_size to libelf, causing an OOB heap read into the output ELF file. Validate that unwinding_size fits within the record payload and that eh_frame_hdr_size does not exceed unwinding_size before allocating or storing the values, so a bogus record cannot force a large allocation that is then discarded. mapped_size is likewise taken from the record and was narrowed into an int for the mmap2 len computation in jit_repipe_code_load() and jit_repipe_code_move(); values above INT_MAX would turn negative, producing a wrong mmap2 length. Use uint64_t for usize so the value cannot truncate. Fixes: 0284fecd13b6db3e ("perf jit: Add unwinding support") Reported-by: sashiko-bot Reviewed-by: Ian Rogers Cc: Stefano Sanfilippo Cc: Stephane Eranian Assisted-by: LLM Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/jitdump.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index 4cbae8a02d2d9..ea2440a5fbcb1 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -461,7 +461,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) u16 idr_size; const char *sym; uint64_t count; - int ret, csize, usize; + int ret, csize; + uint64_t usize; pid_t nspid, pid, tid; struct { u32 pid, tid; @@ -542,7 +543,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET; event->mmap2.start = addr; - event->mmap2.len = usize ? ALIGN_8(csize) + usize : csize; + event->mmap2.len = usize ? ALIGN_8((uint64_t)csize) + usize : (uint64_t)csize; event->mmap2.pid = pid; event->mmap2.tid = tid; event->mmap2.ino = st.st_ino; @@ -596,7 +597,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) char *filename; size_t size; struct stat st; - int usize; + uint64_t usize; u16 idr_size; int ret; pid_t nspid, pid, tid; @@ -745,6 +746,18 @@ jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr) return -1; unwinding_data_size = jr->prefix.total_size - sizeof(jr->unwinding); + + /* + * Validate sizes before allocating — jit_add_eh_frame_info() + * computes unwinding_size - eh_frame_hdr_size and uses the + * result as a buffer length for libelf. + */ + if (jr->unwinding.unwinding_size > unwinding_data_size || + jr->unwinding.eh_frame_hdr_size > jr->unwinding.unwinding_size) { + pr_warning("jitdump: invalid unwinding sizes in unwinding_info record\n"); + return -1; + } + unwinding_data = malloc(unwinding_data_size); if (!unwinding_data) return -1; -- 2.53.0