mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] remoteproc: core: fix integer overflow in rproc_da_to_va() bounds check
@ 2026-10-31 16:11 Atul Akella
  2026-11-05 16:40 ` Mathieu Poirier
  0 siblings, 1 reply; 2+ messages in thread
From: Atul Akella @ 2026-10-31 16:11 UTC (permalink / raw)
  To: andersson, mathieu.poirier; +Cc: linux-remoteproc, linux-kernel, Atul Akella

offset is calculated as da - carveout->da and stored in a 32 bit
signed int, while da and carveout->da are both u64. For a
sufficiently small da, the 64bit difference is truncated into the
32 bit int, bypassing the offset < 0 underflow check with a small
positive value. Additionally, offset + len > carveout->len can
itself overflow when offset and len are both large, providing a
second bypass.

Rewrite the bounds check entirely in u64 arithmetic. Reject
underflow before computing offset (da < carveout->da). Replace the
addition-based overflow check with a subtraction-based one
(len > carveout->len - offset) so no intermediate sum can wrap.

Signed-off-by: Atul Akella <atul.akella@gmail.com>
---
 drivers/remoteproc/remoteproc_core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 23f8539a99bd..d5fa9d23bd5c 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -198,18 +198,20 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
 	}
 
 	list_for_each_entry(carveout, &rproc->carveouts, node) {
-		int offset = da - carveout->da;
+		u64 offset;
 
 		/*  Verify that carveout is allocated */
 		if (!carveout->va)
 			continue;
 
 		/* try next carveout if da is too small */
-		if (offset < 0)
+		if (da < carveout->da)
 			continue;
 
-		/* try next carveout if da is too large */
-		if (offset + len > carveout->len)
+		offset = da - carveout->da;
+
+		/* try next carveout if da or len is too large */
+		if (offset > carveout->len || len > carveout->len - offset)
 			continue;
 
 		ptr = carveout->va + offset;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] remoteproc: core: fix integer overflow in rproc_da_to_va() bounds check
  2026-10-31 16:11 [PATCH] remoteproc: core: fix integer overflow in rproc_da_to_va() bounds check Atul Akella
@ 2026-11-05 16:40 ` Mathieu Poirier
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Poirier @ 2026-11-05 16:40 UTC (permalink / raw)
  To: Atul Akella; +Cc: andersson, linux-remoteproc, linux-kernel

On Sat, Oct 31, 2026 at 09:41:30PM +0530, Atul Akella wrote:
> offset is calculated as da - carveout->da and stored in a 32 bit
> signed int, while da and carveout->da are both u64. For a
> sufficiently small da, the 64bit difference is truncated into the
> 32 bit int, bypassing the offset < 0 underflow check with a small
> positive value. Additionally, offset + len > carveout->len can
> itself overflow when offset and len are both large, providing a
> second bypass.
> 
> Rewrite the bounds check entirely in u64 arithmetic. Reject
> underflow before computing offset (da < carveout->da). Replace the
> addition-based overflow check with a subtraction-based one
> (len > carveout->len - offset) so no intermediate sum can wrap.
> 
> Signed-off-by: Atul Akella <atul.akella@gmail.com>
> ---
>  drivers/remoteproc/remoteproc_core.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>

Applied.

Thanks,
Mathieu
 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 23f8539a99bd..d5fa9d23bd5c 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -198,18 +198,20 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
>  	}
>  
>  	list_for_each_entry(carveout, &rproc->carveouts, node) {
> -		int offset = da - carveout->da;
> +		u64 offset;
>  
>  		/*  Verify that carveout is allocated */
>  		if (!carveout->va)
>  			continue;
>  
>  		/* try next carveout if da is too small */
> -		if (offset < 0)
> +		if (da < carveout->da)
>  			continue;
>  
> -		/* try next carveout if da is too large */
> -		if (offset + len > carveout->len)
> +		offset = da - carveout->da;
> +
> +		/* try next carveout if da or len is too large */
> +		if (offset > carveout->len || len > carveout->len - offset)
>  			continue;
>  
>  		ptr = carveout->va + offset;
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-05 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 16:11 [PATCH] remoteproc: core: fix integer overflow in rproc_da_to_va() bounds check Atul Akella
2026-11-05 16:40 ` Mathieu Poirier

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®