remoteproc: ti_k3: fix DA to VA bounds checks
cover remoteproc: ti_k3: fix DA to VA bounds checks
The TI K3 DSP and M4 remoteproc drivers use addition based range checks in their DA to VA callbacks. These checks can overflow when evaluating the requested address range or the end of a memory region.
Replace them with subtraction based checks. Verify that the requested address is not below the region base, calculate its offset, and check that the requested length fits within the remaining region size.
Use u64 for the offset to avoid truncating wider address offsets. Both drivers are updated in the same way while preserving their existing mapping and return behavior.
Atul Akella (2):
remoteproc: ti_k3_dsp: make bounds check overflow safe
remoteproc: ti_k3_m4: make bounds check overflow safe
drivers/remoteproc/ti_k3_dsp_rproc.c | 12 +++++++----- drivers/remoteproc/ti_k3_m4_rproc.c | 18 +++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 remoteproc: ti_k3_dsp: make bounds check overflow safe
k3_dsp_da_to_va() callback uses addition based checks to validate device and bus address ranges. These checks can overflow while evaluating da + len or the end of a memory region, potentially allowing an out of bounds range to pass validation.
Use subtraction based bounds checks instead. First verify that the requested address is not below the region base, then calculate its offset and ensure that the requested length fits within the remaining region size.
Also use u64 for the offset to avoid truncating wider address offsets.
--- drivers/remoteproc/ti_k3_dsp_rproc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/remoteproc/ti_k3_dsp_rproc.c +7 -5
@@ -266,7 +266,7 @@ static void *k3_dsp_da_to_va(struct udevice *dev, ulong da, ulong len, bool *is_struct k3_dsp_privdata *dsp =dev_get_priv (dev);phys_addr_t bus_addr, dev_addr;size_t size; -u32 offset; +u64 offset;int i;dev_dbg (dev,"%s\n" , __func__);
@@ -289,14 +289,16 @@ static void *k3_dsp_da_to_va(struct udevice *dev, ulong da, ulong len, bool *is_ dev_addr = dsp->mem[i].dev_addr; size = dsp->mem[i].size; -if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { +if (da >= dev_addr) { offset = da - dev_addr; - dsp->cached_addr = dsp->mem[i].cpu_addr + offset; +if (offset <= size && len <= size - offset) + dsp->cached_addr = dsp->mem[i].cpu_addr + offset; } -if (da >= bus_addr && (da + len) <= (bus_addr + size)) { +if (da >= bus_addr) { offset = da - bus_addr; - dsp->cached_addr = dsp->mem[i].cpu_addr + offset; +if (offset <= size && len <= size - offset) + dsp->cached_addr = dsp->mem[i].cpu_addr + offset; } }
Signature · 1 line
2.43.0
PATCH 2/2 remoteproc: ti_k3_m4: make bounds check overflow safe
In reply to Atul Akellak3_m4_da_to_va() callback uses addition based checks to validate device and bus address ranges. These checks can overflow while evaluating da + len or the end of a memory region, potentially allowing an out of bounds range to pass validation.
Use subtraction based bounds checks instead. First verify that the requested address is not below the region base, then calculate its offset and ensure that the requested length fits within the remaining region size.
Also use u64 for the offset to avoid truncating wider address offsets.
--- drivers/remoteproc/ti_k3_m4_rproc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/remoteproc/ti_k3_m4_rproc.c +11 -7
@@ -187,7 +187,7 @@ static void *k3_m4_da_to_va(struct udevice *dev, ulong da, ulong len, bool *is_iphys_addr_t bus_addr, dev_addr;void __iomem *va =NULL ;size_t size; -u32 offset; +u64 offset;int i;if (len <=0 )
@@ -198,16 +198,20 @@ static void *k3_m4_da_to_va(struct udevice *dev, ulong da, ulong len, bool *is_i dev_addr = m4->mem[i].dev_addr; size = m4->mem[i].size; -if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { +if (da >= dev_addr) { offset = da - dev_addr; - va = m4->mem[i].cpu_addr + offset; -return (__force void *)va; +if (offset <= size && len <= size - offset) { + va = m4->mem[i].cpu_addr + offset; +return (__force void *)va; + } } -if (da >= bus_addr && (da + len) <= (bus_addr + size)) { +if (da >= bus_addr) { offset = da - bus_addr; - va = m4->mem[i].cpu_addr + offset; -return (__force void *)va; +if (offset <= size && len <= size - offset) { + va = m4->mem[i].cpu_addr + offset; +return (__force void *)va; + } } }
Signature · 1 line
2.43.0