The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] remoteproc: k3-r5: Fix integer overflow in SRAM address translation
@ 2026-12-02 18:55 Atul Akella
  0 siblings, 0 replies; only message in thread
From: Atul Akella @ 2026-12-02 18:55 UTC (permalink / raw)
  To: andersson, mathieu.poirier, s-anna, b-padhi
  Cc: linux-remoteproc, linux-kernel, Atul Akella

The SRAM address translation path in k3_r5_rproc_da_to_va()
checks the requested range using da + len. This addition can
overflow, allowing an out of bounds range to pass the check.

The offset is also stored in a u32, which can truncate the
difference when da is greater than the 32bit device address.

Use a u64 for the offset and validate the range using
subtraction-based bounds checks to avoid both issues.

Fixes: ea47c6887b6d ("remoteproc: k3-r5: Add loading support for on-chip SRAM regions")

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

diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c
index d7d9756afed0..13795c753441 100644
--- a/drivers/remoteproc/ti_k3_r5_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c
@@ -567,7 +567,8 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
 	struct k3_rproc *kproc = rproc->priv;
 	struct k3_r5_core *core = kproc->priv;
 	void __iomem *va = NULL;
-	u32 dev_addr, offset;
+	u32 dev_addr;
+	u64 offset;
 	size_t size;
 	int i;
 
@@ -579,10 +580,12 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool
 		dev_addr = core->sram[i].dev_addr;
 		size = core->sram[i].size;
 
-		if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
+		if (da >= dev_addr) {
 			offset = da - dev_addr;
-			va = core->sram[i].cpu_addr + offset;
-			return (__force void *)va;
+			if (offset <= size && len <= size - offset) {
+				va = core->sram[i].cpu_addr + offset;
+				return (__force void *)va;
+			}
 		}
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 18:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:55 [PATCH] remoteproc: k3-r5: Fix integer overflow in SRAM address translation Atul Akella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox