[PATCH 2/2] staging: vc04_services: vc-sm-cma: add address validation in clean_invalid_contig_2d()
Sebastian Josue Alba Vives
sebasjosue84 at gmail.com
Sat Mar 28 23:18:46 PDT 2026
From: Sebastián Alba Vives <sebasjosue84 at gmail.com>
clean_invalid_contig_2d() performs cache maintenance operations
(dmac_inv_range, dmac_clean_range, dmac_flush_range) on a user-supplied
virtual address without verifying that it falls within the user address
space. A local attacker can pass a kernel virtual address via the
VC_SM_CMA_CMD_CLEAN_INVALID2 ioctl, causing the kernel to execute cache
maintenance operations on arbitrary kernel memory, potentially leading
to data corruption or information disclosure.
Add access_ok() validation to verify the entire address range falls
within userspace before performing any cache operations. Also add
overflow checks using check_mul_overflow()/check_add_overflow() for the
range computation to prevent size_t wraparound.
The /dev/vc-sm-cma device is world-accessible (mode 0666), so this is
reachable by any unprivileged local user on 32-bit Raspberry Pi
kernels.
Fixes: dfdc7a773374 ("staging: vc04_services: Add new vc-sm-cma driver")
Signed-off-by: Sebastián Alba Vives <sebasjosue84 at gmail.com>
---
.../staging/vc04_services/vc-sm-cma/vc_sm.c | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
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 d597d41b4..29aa5a939 100644
--- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
+++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
@@ -40,6 +40,7 @@
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/of_device.h>
+#include <linux/overflow.h>
#include <linux/platform_device.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
@@ -1263,6 +1264,8 @@ static int clean_invalid_contig_2d(const void __user *addr,
const unsigned int cache_op)
{
size_t i;
+ size_t last_block_offset;
+ size_t total_range;
void (*op_fn)(const void *start, const void *end);
if (!block_size) {
@@ -1270,11 +1273,27 @@ static int clean_invalid_contig_2d(const void __user *addr,
return -EINVAL;
}
+ if (!block_count)
+ return 0;
+
op_fn = cache_op_to_func(cache_op);
if (!op_fn)
return -EINVAL;
- for (i = 0; i < block_count; i ++, addr += stride)
+ /*
+ * Validate that the entire user-supplied address range falls
+ * within userspace. Without this check, an attacker could
+ * invoke cache maintenance operations on kernel addresses.
+ */
+ if (check_mul_overflow((size_t)(block_count - 1), stride,
+ &last_block_offset))
+ return -EOVERFLOW;
+ if (check_add_overflow(last_block_offset, block_size, &total_range))
+ return -EOVERFLOW;
+ if (!access_ok(addr, total_range))
+ return -EFAULT;
+
+ for (i = 0; i < block_count; i++, addr += stride)
op_fn(addr, addr + block_size);
return 0;
--
2.43.0
More information about the linux-rpi-kernel
mailing list