From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, "Bjorn Andersson" <andersson@kernel.org>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
"HyeongJun An" <sammiee5311@gmail.com>,
"Ohad Ben-Cohen" <ohad@wizery.com>,
"Brian Swetland" <swetland@google.com>,
"Mark Grosen" <mgrosen@ti.com>,
"Guzman Lugo" <fernando.lugo@ti.com>,
"Suman Anna" <s-anna@ti.com>, "Robert Tivy" <rtivy@ti.com>,
"De Leon" <x0095078@ti.com>,
"Sjur Brændeland" <sjur.brandeland@stericsson.com>,
"Clement Leger" <cleger@kalray.eu>,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 04/10] remoteproc: elf_loader: Fix overflow in rproc_elf_load_segments()
Date: Mon, 23 Nov 2026 17:20:48 +0000 [thread overview]
Message-ID: <20261123172140.3547896-5-lee@kernel.org> (raw)
In-Reply-To: <20261123172140.3547896-1-lee@kernel.org>
For 64-bit ELF firmware images, rproc_elf_load_segments() reads 64-bit
p_offset and p_filesz fields and checks offset + filesz > fw->size. A
malformed segment header where offset + filesz wraps around 64 bits
bypasses this truncation check, causing the subsequent segment copy
from elf_data + offset to read out of bounds outside the firmware
buffer.
Replace the addition with an overflow-safe subtraction check and log
offset and filesz individually when rejecting a truncated image.
Fixes: f31e339f1b9b ("remoteproc: Add elf64 support in elf loader")
Closes: https://sashiko.dev/#/bug/linux-754a0c40-c150-42df-9c0d-bbb2c3846fa7
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/remoteproc/remoteproc_elf_loader.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
index da3cddbe7d4c..6b9de0627768 100644
--- a/drivers/remoteproc/remoteproc_elf_loader.c
+++ b/drivers/remoteproc/remoteproc_elf_loader.c
@@ -213,9 +213,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
break;
}
- if (offset + filesz > fw->size) {
- dev_err(dev, "truncated fw: need 0x%llx avail 0x%zx\n",
- offset + filesz, fw->size);
+ if (offset > fw->size || filesz > fw->size - offset) {
+ dev_err(dev, "truncated fw: offset 0x%llx filesz 0x%llx avail 0x%zx\n",
+ offset, filesz, fw->size);
ret = -EINVAL;
break;
}
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 17:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:20 [PATCH 00/10] remoteproc: Assorted bug fixes across remoteproc core and drivers Lee Jones
2026-11-23 17:20 ` [PATCH 01/10] remoteproc: core: Fix integer overflow in rproc_check_carveout_da() Lee Jones
2026-11-23 17:20 ` [PATCH 02/10] remoteproc: k3: Fix integer overflow in k3_rproc_da_to_va() Lee Jones
2026-11-23 17:20 ` [PATCH 03/10] remoteproc: omap: Fix integer overflow in omap_rproc_da_to_va() Lee Jones
2026-11-23 17:20 ` Lee Jones [this message]
2026-11-23 17:20 ` [PATCH 05/10] remoteproc: imx_rproc: Avoid stale mailbox pointers on request failure Lee Jones
2026-11-23 17:20 ` [PATCH 06/10] remoteproc: imx_rproc: Register SCU cleanup after resource acquisition Lee Jones
2026-11-23 17:20 ` [PATCH 07/10] remoteproc: qcom: Clear glink->node on allocation failure Lee Jones
2026-11-23 17:20 ` [PATCH 08/10] remoteproc: qcom: Skip unregistering uninitialised SSR subdevice Lee Jones
2026-11-23 17:20 ` [PATCH 09/10] remoteproc: imx_dsp_rproc: Fix pointer stride in imx_dsp_rproc_memset() Lee Jones
2026-11-23 17:20 ` [PATCH 10/10] remoteproc: imx_dsp_rproc: Fix off-by-one bitmask for trailing bytes Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123172140.3547896-5-lee@kernel.org \
--to=lee@kernel.org \
--cc=andersson@kernel.org \
--cc=cleger@kalray.eu \
--cc=fernando.lugo@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mgrosen@ti.com \
--cc=ohad@wizery.com \
--cc=rtivy@ti.com \
--cc=s-anna@ti.com \
--cc=sammiee5311@gmail.com \
--cc=sjur.brandeland@stericsson.com \
--cc=stable@vger.kernel.org \
--cc=swetland@google.com \
--cc=x0095078@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®