[PATCH -next] firmware: imx: se_ctrl: detect round_up() overflow in iobuf setup
From: pankaj . gupta
Date: Thu Jun 11 2026 - 06:25:39 EST
From: Pankaj Gupta <pankaj.gupta@xxxxxxx>
se_ioctl_setup_iobuf_handler() aligns io.length with round_up(..., 8)
before checking the available shared memory space. On 32-bit builds,
round_up() can overflow for large io.length values and wrap aligned_len
to a smaller value, which can bypass the bounds check while later
memset() still uses the original unbounded io.length.
Detect the overflow by checking whether the aligned value became smaller
than the original length. Valid alignment must never reduce the value,
so this catches wraparound without relying on a SIZE_MAX-based check that
triggers tautological-compare warnings on 64-bit builds
Signed-off-by: Pankaj Gupta <pankaj.gupta@xxxxxxx>
---
drivers/firmware/imx/se_ctrl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
index 8fab3b7767b7..5b23485fe42c 100644
--- a/drivers/firmware/imx/se_ctrl.c
+++ b/drivers/firmware/imx/se_ctrl.c
@@ -666,6 +666,11 @@ static int se_ioctl_setup_iobuf_handler(struct se_if_device_ctx *dev_ctx,
}
aligned_len = round_up((size_t)io.length, 8);
+ if (aligned_len < io.length) {
+ dev_err(dev_ctx->priv->dev, "%s: Invalid buffer length.",
+ dev_ctx->devname);
+ return -EINVAL;
+ }
/* No specific requirement for this buffer. */
shared_mem = &dev_ctx->se_shared_mem_mgmt.non_secure_mem;
--
2.43.0