staging: vc04_services: vc-sm-cma: fix security issues in clean_invalid2 ioctl
Subsystems (2)
cover staging: vc04_services: vc-sm-cma: fix security issues in clean_invalid2 ioctl
This series fixes two security issues in the VideoCore shared memory CMA driver (vc-sm-cma), accessible via /dev/vc-sm-cma which is created with mode 0666 (world-accessible, no authentication required).
Both bugs are in vc_sm_cma_clean_invalid2(), reachable via the VC_SM_CMA_CMD_CLEAN_INVALID2 ioctl on 32-bit ARM kernels.
Patch 1: Integer overflow in kmalloc size computation Patch 2: Missing address validation in cache maintenance operations
Both issues affect 32-bit Raspberry Pi kernels (RPi 1/2/3/Zero and 32-bit RPi 4/5 configurations) running the rpi-6.6.y kernel series.
Both issues were found through manual source code auditing.
I would like to request separate CVE assignments for each patch as they are independent vulnerabilities.
PATCH 1/2 staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
From: Sebastián Alba Vives <[email protected]>
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.
--- drivers/staging/vc04_services/vc-sm-cma/vc_sm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c +6 -2
@@ -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 ) {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
Quoted 9 lines · Sebastian Josue Alba Vives
From: Sebastián Alba Vives <[email protected]>
vc_sm_cma_clean_invalid2()uses 'ioparam.op_count *sizeof(*block)' to compute the allocation size passed tokmalloc(). Since ioparam.op_count is a__u32supplied 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 largecopy_from_user()and out-of-bounds heap reads in the subsequent loop.
Quoted 4 lines
Replace
kmalloc()withkmalloc_array(), which returns NULL on overflow. Also add an early return forop_count== 0 to avoid a zero-size allocation, and return-ENOMEM(not-EFAULT) on allocation failure to correctly indicate out of memory.
Why not use kmalloc_array() instead?
Quoted 5 lines
The
/dev/vc-sm-cmadevice 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")
I do not see that git id anywhere, what tree is it in?
thanks,
greg k-h
Re: [PATCH 1/2] staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
Hi Greg, Thanks for the quick review.
Regarding kmalloc_array(): the patch does replace kmalloc() with kmalloc_array() - perhaps the question is about the remaining ioparam.op_count * sizeof(*block) in the copy_from_user() call below? That multiplication is now safe because kmalloc_array() already verified that op_count * sizeof(*block) does not overflow(if it did, kmalloc_array would have returned NULL and we'd have exited). Happy to add a comment clarifying this if you prefer.
Regarding the Fixes tag: the commit dfdc7a773374 is from the raspberrypi/linux tree (branch rpi-6.6.y). This driver (vc-sm-cma) appears to only exist in the Raspberry Pi kernel fork and has not been merged into mainline staging.
I apologize for sending this to the wrong tree. Should these patches go directly to the Raspberry Pi kernel maintainers ([email protected]) instead?
Quoted 29 lines · Greg Kroah-Hartman
Quoted 9 lines · Sebastian Josue Alba Vives
From: Sebastián Alba Vives <[email protected]>
vc_sm_cma_clean_invalid2()uses 'ioparam.op_count *sizeof(*block)' to compute the allocation size passed tokmalloc(). Since ioparam.op_count is a__u32supplied 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 largecopy_from_user()and out-of-bounds heap reads in the subsequent loop.Quoted 4 lines
Replace
kmalloc()withkmalloc_array(), which returns NULL on overflow. Also add an early return forop_count== 0 to avoid a zero-size allocation, and return-ENOMEM(not-EFAULT) on allocation failure to correctly indicate out of memory.Why not use
kmalloc_array()instead?Quoted 5 lines
The
/dev/vc-sm-cmadevice 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")I do not see that git id anywhere, what tree is it in?
thanks,
greg k-h
Signature · 1 line
Sebastián Alba
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
Quoted 9 lines · Sebastián Alba
Hi Greg, Thanks for the quick review.
Regarding
kmalloc_array(): the patch does replacekmalloc()withkmalloc_array()- perhaps the question is about the remaining ioparam.op_count *sizeof(*block)in thecopy_from_user()call below? That multiplication is now safe becausekmalloc_array()already verified thatop_count*sizeof(*block)does notoverflow(if it did, kmalloc_array would have returned NULL and we'd have exited). Happy to add a comment clarifying this if you prefer.
Sorry, my fault, I meant alloc_objs(), coffee hadn't kicked in yet.
And please do not top-post:
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
Quoted 4 lines
Regarding the Fixes tag: the commit
dfdc7a773374is from the raspberrypi/linux tree (branch rpi-6.6.y). This driver (vc-sm-cma) appears to only exist in the Raspberry Pi kernel fork and has not been merged into mainline staging.
Then we can't do anything with it here :(
Quoted 3 lines
I apologize for sending this to the wrong tree. Should these patches go directly to the Raspberry Pi kernel maintainers ([email protected]) instead?
No idea how that out-of-tree driver is managed, sorry.
good luck,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CAMEGJJ0zgab3WN=rb2o+UgEq_coX5LnkyPj3UNrBSMQbTGU7Zw@mail.gmail.com
Re: [PATCH 1/2] staging: vc04_services: vc-sm-cma: fix integer overflow in vc_sm_cma_clean_invalid2()
Hi Phil,
Thanks for the pointer. I've opened PR #7294 against rpi-6.6.y:
https://github.com/raspberrypi/linux/pull/7294
Sebastián
Quoted 67 lines · Phil Elwell
Quoted 11 lines · On Sun, 29 Mar 2026, 08:05 Sebastián Alba, <[email protected]> wrote:
Hi Greg, Thanks for the quick review.
Regarding
kmalloc_array(): the patch does replacekmalloc()withkmalloc_array()- perhaps the question is about the remaining ioparam.op_count *sizeof(*block)in thecopy_from_user()call below? That multiplication is now safe becausekmalloc_array()already verified thatop_count*sizeof(*block)does notoverflow(if it did, kmalloc_array would have returned NULL and we'd have exited). Happy to add a comment clarifying this if you prefer.Quoted 8 lines
Regarding the Fixes tag: the commit
dfdc7a773374is from the raspberrypi/linux tree (branch rpi-6.6.y). This driver (vc-sm-cma) appears to only exist in the Raspberry Pi kernel fork and has not been merged into mainline staging.I apologize for sending this to the wrong tree. Should these patches go directly to the Raspberry Pi kernel maintainers ([email protected]) instead?
Open a Pull Request at our Linux repo:
https://github com/raspberrypi/linux/
Phil
Quoted 36 lines
Quoted 22 lines · Greg Kroah-Hartman
Quoted 9 lines · Sebastian Josue Alba Vives
From: Sebastián Alba Vives <[email protected]>
vc_sm_cma_clean_invalid2()uses 'ioparam.op_count *sizeof(*block)' to compute the allocation size passed tokmalloc(). Since ioparam.op_count is a__u32supplied 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 largecopy_from_user()and out-of-bounds heap reads in the subsequent loop.Quoted 4 lines
Replace
kmalloc()withkmalloc_array(), which returns NULL on overflow. Also add an early return forop_count== 0 to avoid a zero-size allocation, and return-ENOMEM(not-EFAULT) on allocation failure to correctly indicate out of memory.Why not use
kmalloc_array()instead?Quoted 4 lines
The
/dev/vc-sm-cmadevice is world-accessible (mode 0666), so this is reachable by any unprivileged local user.Quoted 7 lines
Quoted 1 line
Fixes dfdc7a773374 ("staging: vc04_services: Add new vc-sm-cma driver")I do not see that git id anywhere, what tree is it in?
thanks,
greg k-h
--
Sebastián Alba
Signature · 1 line
Sebastián Alba
PATCH 2/2 staging: vc04_services: vc-sm-cma: add address validation in clean_invalid_contig_2d()
In reply to Sebastian Josue Alba VivesFrom: Sebastián Alba Vives <[email protected]>
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.
--- .../staging/vc04_services/vc-sm-cma/vc_sm.c | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c +20 -1
@@ -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 ;
Signature · 1 line
2.43.0