[PATCH 1/2] staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
Sebastian Josue Alba Vives
sebasjosue84 at gmail.com
Sat Mar 28 23:18:45 PDT 2026
From: Sebastián Alba Vives <sebasjosue84 at gmail.com>
vc_sm_cma_clean_invalid2() uses 'ioparam.op_count * sizeof(*block)' to
compute the allocation size passed to kmalloc(). Since ioparam.op_count
is a __u32 supplied directly by userspace via ioctl, an attacker can
choose a value that causes the multiplication to overflow on 32-bit
platforms, resulting in a small allocation followed by a large
copy_from_user() and out-of-bounds heap reads in the subsequent loop.
Replace kmalloc() with kmalloc_array(), which returns NULL on overflow.
Also add an early return for op_count == 0 to avoid a zero-size
allocation, and return -ENOMEM (not -EFAULT) on allocation failure to
correctly indicate out of memory.
The /dev/vc-sm-cma device is world-accessible (mode 0666), so this is
reachable by any unprivileged local user.
Fixes: dfdc7a773374 ("staging: vc04_services: Add new vc-sm-cma driver")
Signed-off-by: Sebastián Alba Vives <sebasjosue84 at gmail.com>
---
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
index 34155d62a..d597d41b4 100644
--- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
+++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
@@ -1292,9 +1292,13 @@ static int vc_sm_cma_clean_invalid2(unsigned int cmdnr, unsigned long arg)
__func__, cmdnr);
return -EFAULT;
}
- block = kmalloc(ioparam.op_count * sizeof(*block), GFP_KERNEL);
+
+ if (!ioparam.op_count)
+ return 0;
+
+ block = kmalloc_array(ioparam.op_count, sizeof(*block), GFP_KERNEL);
if (!block)
- return -EFAULT;
+ return -ENOMEM;
if (copy_from_user(block, (void *)(arg + sizeof(ioparam)),
ioparam.op_count * sizeof(*block)) != 0) {
--
2.43.0
More information about the linux-rpi-kernel
mailing list