remoteproc: Assorted bug fixes across remoteproc core and drivers
Subsystems (4)
cover remoteproc: Assorted bug fixes across remoteproc core and drivers
These issues were reported by Sashiko.
None of these changes have been tested on physical hardware.
Lee Jones (10):
remoteproc: core: Fix integer overflow in rproc_check_carveout_da()
remoteproc: k3: Fix integer overflow in k3_rproc_da_to_va()
remoteproc: omap: Fix integer overflow in omap_rproc_da_to_va()
remoteproc: elf_loader: Fix overflow in rproc_elf_load_segments()
remoteproc: imx_rproc: Avoid stale mailbox pointers on request failure
remoteproc: imx_rproc: Register SCU cleanup after resource acquisition
remoteproc: qcom: Clear glink->node on allocation failure
remoteproc: qcom: Skip unregistering uninitialised SSR subdevice
remoteproc: imx_dsp_rproc: Fix pointer stride in
imx_dsp_rproc_memset()
remoteproc: imx_dsp_rproc: Fix off-by-one bitmask for trailing bytes
drivers/remoteproc/imx_dsp_rproc.c | 10 ++++--- drivers/remoteproc/imx_rproc.c | 33 ++++++++++++++-------- drivers/remoteproc/omap_remoteproc.c | 11 +++++--- drivers/remoteproc/qcom_common.c | 5 ++++ drivers/remoteproc/remoteproc_core.c | 7 ++--- drivers/remoteproc/remoteproc_elf_loader.c | 6 ++-- drivers/remoteproc/ti_k3_common.c | 27 +++++++++++------- 7 files changed, 61 insertions(+), 38 deletions(-)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 1/10 remoteproc: core: Fix integer overflow in rproc_check_carveout_da()
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.
--- drivers/remoteproc/remoteproc_core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/remoteproc/remoteproc_core.c +2 -5
@@ -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 ;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 2/10 remoteproc: k3: Fix integer overflow in k3_rproc_da_to_va()
In reply to Lee Jonesk3_rproc_da_to_va() validates memory regions using (da + len) <= (base + size) and stores da - base in a 32-bit unsigned offset variable. Because da is u64 and len is size_t, a malformed firmware segment or resource entry with a large da value causes da + len to wrap around 64 bits and pass the upper bound check. Subsequent assignment to the u32 offset variable truncates the 64-bit difference, returning an out-of-bounds kernel virtual address to callers such as the ELF segment loader.
Widen offset to u64 and rewrite the range checks across all three memory loops using overflow-safe subtraction.
--- drivers/remoteproc/ti_k3_common.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/remoteproc/ti_k3_common.c +17 -10
@@ -356,7 +356,8 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)struct k3_rproc *kproc = rproc->priv;void __iomem *va =NULL ;phys_addr_t bus_addr; -u32 dev_addr, offset; +u32 dev_addr; +u64 offset;size_t size;int i;
@@ -369,17 +370,21 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) size = kproc->mem[i].size;/* handle rproc-view addresses */ -if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { +if (da >= dev_addr) { offset = da - dev_addr; - va = kproc->mem[i].cpu_addr + offset; -return (__force void *)va; +if (offset <= size && len <= size - offset) { + va = kproc->mem[i].cpu_addr + offset; +return (__force void *)va; + } }/* handle SoC-view addresses */ -if (da >= bus_addr && (da + len) <= (bus_addr + size)) { +if (da >= bus_addr) { offset = da - bus_addr; - va = kproc->mem[i].cpu_addr + offset; -return (__force void *)va; +if (offset <= size && len <= size - offset) { + va = kproc->mem[i].cpu_addr + offset; +return (__force void *)va; + } } }
@@ -388,10 +393,12 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) dev_addr = kproc->rmem[i].dev_addr; size = kproc->rmem[i].size; -if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { +if (da >= dev_addr) { offset = da - dev_addr; - va = kproc->rmem[i].cpu_addr + offset; -return (__force void *)va; +if (offset <= size && len <= size - offset) { + va = kproc->rmem[i].cpu_addr + offset; +return (__force void *)va; + } } }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 3/10 remoteproc: omap: Fix integer overflow in omap_rproc_da_to_va()
In reply to Lee Jonesomap_rproc_da_to_va() checks da + len <= dev_addr + size using 64-bit unsigned addition and stores da - dev_addr in a 32-bit unsigned offset variable. A crafted firmware segment or resource entry with a large da value can wrap da + len around 64 bits, bypassing the upper bound check, while truncating da - dev_addr to 32 bits yields an out-of-bounds pointer offset into kernel memory.
Widen offset to u64 and validate both offset <= size and len <= size - offset without addition overflow.
--- drivers/remoteproc/omap_remoteproc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/remoteproc/omap_remoteproc.c +7 -4
@@ -735,7 +735,7 @@ static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool * {struct omap_rproc *oproc = rproc->priv;int i; -u32 offset; +u64 offset;if (len <=0 )return NULL ;
@@ -744,9 +744,12 @@ static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *return NULL ;for (i =0 ; i < oproc->num_mems; i++) { -if (da >= oproc->mem[i].dev_addr && da + len <= - oproc->mem[i].dev_addr + oproc->mem[i].size) { - offset = da - oproc->mem[i].dev_addr; +if (da < oproc->mem[i].dev_addr) +continue ; + + offset = da - oproc->mem[i].dev_addr; +if (offset <= oproc->mem[i].size && + len <= oproc->mem[i].size - offset) {/* __force to make sparse happy with type conversion */ return (__force void *)(oproc->mem[i].cpu_addr + offset);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 4/10 remoteproc: elf_loader: Fix overflow in rproc_elf_load_segments()
In reply to Lee JonesFor 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.
--- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/remoteproc/remoteproc_elf_loader.c +3 -3
@@ -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 ; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 5/10 remoteproc: imx_rproc: Avoid stale mailbox pointers on request failure
In reply to Lee Jonesimx_rproc_xtr_mbox_init() stores the result of mbox_request_channel_byname() directly into priv->tx_ch and priv->rx_ch. Because mailbox channels are freed on stop() and detach() and re-requested on start(), attach(), and system shutdown, a failure while requesting "tx" leaves an ERR_PTR in priv->tx_ch, which is later dereferenced by imx_rproc_kick() and imx_rproc_free_mbox(). If "rx" fails after "tx" succeeds, priv->tx_ch is freed without being cleared while priv->rx_ch retains an ERR_PTR, causing subsequent calls to see both pointers as non-NULL and skip initialisation, leading to a use-after-free on priv->tx_ch and an ERR_PTR dereference on priv->rx_ch.
Request both channels into local variables and assign priv->tx_ch and priv->rx_ch only after both requests succeed.
--- drivers/remoteproc/imx_rproc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/remoteproc/imx_rproc.c +11 -7
@@ -875,6 +875,7 @@ static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)static int imx_rproc_xtr_mbox_init (struct rproc *rproc,bool tx_block) {struct imx_rproc *priv = rproc->priv; +struct mbox_chan *tx_ch, *rx_ch;struct device *dev = priv->dev;struct mbox_client *cl;
@@ -900,18 +901,21 @@ static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block) cl->knows_txdone = false; cl->rx_callback = imx_rproc_rx_callback; - priv->tx_ch =mbox_request_channel_byname (cl,"tx" ); -if (IS_ERR (priv->tx_ch)) -return dev_err_probe (cl->dev,PTR_ERR (priv->tx_ch), + tx_ch =mbox_request_channel_byname (cl,"tx" ); +if (IS_ERR (tx_ch)) +return dev_err_probe (cl->dev,PTR_ERR (tx_ch),"failed to request tx mailbox channel\n" ); - priv->rx_ch =mbox_request_channel_byname (cl,"rx" ); -if (IS_ERR (priv->rx_ch)) { -mbox_free_channel (priv->tx_ch); -return dev_err_probe (cl->dev,PTR_ERR (priv->rx_ch), + rx_ch =mbox_request_channel_byname (cl,"rx" ); +if (IS_ERR (rx_ch)) { +mbox_free_channel (tx_ch); +return dev_err_probe (cl->dev,PTR_ERR (rx_ch),"failed to request rx mailbox channel\n" ); } + priv->tx_ch = tx_ch; + priv->rx_ch = rx_ch; +return 0 ; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 6/10 remoteproc: imx_rproc: Register SCU cleanup after resource acquisition
In reply to Lee Jonesimx_rproc_scu_api_detect_mode() registers the imx_rproc_put_scu() devres cleanup action before attaching power domains or registering the SCU partition reboot notifier and enabling its interrupt group. If imx_sc_rm_get_resource_owner() or imx_scu_irq_register_notifier() fails, imx_rproc_put_scu() runs during failure unwind and unregisters an unregistered notifier block while disabling an unconfigured interrupt bit. Worse, if imx_scu_irq_group_enable() fails, the error path explicitly unregisters priv->rproc_nb and devres subsequently invokes imx_rproc_put_scu() to unregister the same notifier block a second time.
Defer devm_add_action_or_reset() until power-domain attachment or SCU notifier and interrupt setup have completed.
--- drivers/remoteproc/imx_rproc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +10 -5
@@ -1083,10 +1083,6 @@ static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)else priv->core_index =0 ; - ret =devm_add_action_or_reset (dev, imx_rproc_put_scu, priv); -if (ret) -return dev_err_probe (dev, ret,"Failed to add action for put scu\n" ); -/* * If Mcore resource is not owned by Acore partition, It is kicked by ROM, * and Linux could only do IPC with Mcore and nothing else.
@@ -1095,7 +1091,11 @@ static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)if (of_property_read_u32 (dev->of_node,"fsl,entry-address" , &priv->entry))return -EINVAL ; -return imx_rproc_attach_pd (priv); + ret =imx_rproc_attach_pd (priv); +if (ret) +return ret; + + goto add_scu_action; } priv->rproc->state =RPROC_DETACHED ;
@@ -1126,6 +1126,11 @@ static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)return ret; } +add_scu_action: + ret =devm_add_action_or_reset (dev, imx_rproc_put_scu, priv); +if (ret) +return dev_err_probe (dev, ret,"Failed to add action for put scu\n" ); +return 0 ; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 7/10 remoteproc: qcom: Clear glink->node on allocation failure
In reply to Lee JonesWhen kstrdup_const() fails in qcom_add_glink_subdev(), the error path drops the device-node reference via of_node_put(glink->node) and returns before registering the GLINK subdevice, leaving glink->node non-NULL. During subsequent teardown, qcom_remove_glink_subdev() checks glink->node, calls rproc_remove_subdev() on an uninitialised list node resulting in a NULL pointer dereference, and drops the device-node reference a second time.
Reset glink->node to NULL when releasing the node reference so teardown leaves an unregistered subdevice untouched.
--- drivers/remoteproc/qcom_common.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/remoteproc/qcom_common.c +2 -0
@@ -255,6 +255,7 @@ void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink, glink->ssr_name =kstrdup_const (ssr_name,GFP_KERNEL );if (!glink->ssr_name) {of_node_put (glink->node); + glink->node =NULL ;return ; }
@@ -280,6 +281,7 @@ void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glinrproc_remove_subdev (rproc, &glink->subdev);kfree_const (glink->ssr_name);of_node_put (glink->node); + glink->node =NULL ; }EXPORT_SYMBOL_GPL (qcom_remove_glink_subdev);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 8/10 remoteproc: qcom: Skip unregistering uninitialised SSR subdevice
In reply to Lee JonesIf qcom_ssr_get_subsys() fails in qcom_add_ssr_subdev(), the function logs an error and returns early without calling rproc_add_subdev(), leaving ssr->info NULL and ssr->subdev.node uninitialised. When driver probe unwinds or the device is later removed, qcom_remove_ssr_subdev() unconditionally calls rproc_remove_subdev(), dereferencing a NULL list pointer in list_del().
Guard qcom_remove_ssr_subdev() on ssr->info being non-NULL, matching the GLINK and SMD subdevice teardown helpers.
--- drivers/remoteproc/qcom_common.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/remoteproc/qcom_common.c +3 -0
@@ -537,6 +537,9 @@ EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);*/ void qcom_remove_ssr_subdev (struct rproc *rproc,struct qcom_rproc_ssr *ssr) { +if (!ssr->info) +return ; +rproc_remove_subdev (rproc, &ssr->subdev); ssr->info =NULL ; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 9/10 remoteproc: imx_dsp_rproc: Fix pointer stride in imx_dsp_rproc_memset()
In reply to Lee JonesCommit 3c497f624d40 ("remoteproc: imx_dsp_rproc: Fix kernel test robot sparse warning") changed tmp_dst from u32 * to void __iomem *. In GNU C, incrementing a void pointer advances it by 1 byte rather than 4 bytes. Consequently, the word-fill loop in imx_dsp_rproc_memset() steps by 1 byte per 32-bit writel(), triggering unaligned 32-bit MMIO accesses on Device-mapped DSP IRAM, mispositioning tmp_dst for the trailing-byte read-modify-write, and leaving roughly three quarters of the target region uninitialised.
Advance tmp_dst by 4 bytes per 32-bit word write.
--- drivers/remoteproc/imx_dsp_rproc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_dsp_rproc.c +4 -2
@@ -843,8 +843,10 @@ static int imx_dsp_rproc_memset(void *addr, u8 value, size_t size) q = size /4 ; r = size %4 ; -while (q--) -writel (tmp_val, tmp_dst++); +while (q--) { +writel (tmp_val, tmp_dst); + tmp_dst +=4 ; + }if (r) { affected_mask =GENMASK (8 * r,0 );
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 10/10 remoteproc: imx_dsp_rproc: Fix off-by-one bitmask for trailing bytes
In reply to Lee JonesWhen size is not a multiple of 4, both imx_dsp_rproc_memcpy() and imx_dsp_rproc_memset() compute affected_mask as GENMASK(8 * r, 0) for the remaining r bytes (1 <= r <= 3). Because GENMASK(h, l) is inclusive of bit h, GENMASK(8 * r, 0) sets 8 * r + 1 bits and clears or overwrites the least-significant bit of the first byte past the end of the target region during the 32-bit read-modify-write.
Use GENMASK(8 * r - 1, 0) to mask exclusively the r trailing bytes.
--- drivers/remoteproc/imx_dsp_rproc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_dsp_rproc.c +2 -2
@@ -799,7 +799,7 @@ static int imx_dsp_rproc_memcpy(void *dst, const void *src, size_t size)writel (source[i], dest + i *4 );if (r) { - affected_mask =GENMASK (8 * r,0 ); + affected_mask =GENMASK (8 * r -1 ,0 );/* * first read the 32bit data of dest, then change affected
@@ -849,7 +849,7 @@ static int imx_dsp_rproc_memset(void *addr, u8 value, size_t size) }if (r) { - affected_mask =GENMASK (8 * r,0 ); + affected_mask =GENMASK (8 * r -1 ,0 );/* * first read the 32bit data of addr, then change affected
Signature · 1 line
2.56.1.750.gf70dc682cf-goog