[PATCH 01/10] remoteproc: core: Fix integer overflow in rproc_check_carveout_da()

From: Lee Jones

Date: Mon Nov 23 2026 - 12:22:02 EST


rproc_check_carveout_da() subtracts two unsigned 32-bit device addresses
and stores the difference in a signed int variable before checking the
carveout bounds. When da exceeds mem->da by 0x80000000 or more, delta
wraps negative; conversely, when da is less than mem->da by more than
0x80000000, delta wraps to a positive integer and bypasses the lower
bound check. Furthermore, delta + len is evaluated in 32-bit unsigned
arithmetic before promotion to size_t, allowing large da and len values
to wrap around 32 bits and bypass the upper bound check as well.

Since len > mem->len is already rejected upfront, compare da < mem->da
directly and check da - mem->da > mem->len - len using subtraction to
eliminate signedness bugs and integer wraparound.

Fixes: c874bf59add0 ("remoteproc: add helper function to check carveout device address")
Closes: https://sashiko.dev/#/bug/linux-8c4ef7d2-a95d-4267-b41e-9023431eba23
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/remoteproc/remoteproc_core.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 23f8539a99bd..2b2ebf39a40a 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -287,7 +287,6 @@ static int rproc_check_carveout_da(struct rproc *rproc,
struct rproc_mem_entry *mem, u32 da, u32 len)
{
struct device *dev = &rproc->dev;
- int delta;

/* Check requested resource length */
if (len > mem->len) {
@@ -299,16 +298,14 @@ static int rproc_check_carveout_da(struct rproc *rproc,
/* Address doesn't match registered carveout configuration */
return -EINVAL;
} else if (da != FW_RSC_ADDR_ANY && mem->da != FW_RSC_ADDR_ANY) {
- delta = da - mem->da;
-
/* Check requested resource belongs to registered carveout */
- if (delta < 0) {
+ if (da < mem->da) {
dev_err(dev,
"Registered carveout doesn't fit da request\n");
return -EINVAL;
}

- if (delta + len > mem->len) {
+ if (da - mem->da > mem->len - len) {
dev_err(dev,
"Registered carveout doesn't fit len request\n");
return -EINVAL;
--
2.56.1.750.gf70dc682cf-goog