* [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32()
@ 2026-11-30 10:13 Ziheng Wei
2026-11-30 12:14 ` Hans de Goede
0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-11-30 10:13 UTC (permalink / raw)
To: Hans de Goede, Arnd Bergmann, Greg Kroah-Hartman; +Cc: linux-kernel
The copy-back loop in vbg_hgcm_call32() advances parm32 and parm64 in
the for-loop increment while also indexing both arrays with [i]:
for (i = 0; i < parm_count; i++, parm32++, parm64++)
parm32[i]... = parm64[i]...
Because each iteration advances the pointers and also adds [i], iteration
i accesses element 2*i. This goes out of bounds once 2*i >= parm_count
(for parm_count >= 2) and leaves parm64 pointing past the start of the
kzalloc() buffer when out_free passes it to kfree() for any parm_count > 0.
On user space reaching VBG_IOCTL_HGCM_CALL_32 via /dev/vboxuser (root-only
0600 by default after VBG_IOCTL_HGCM_CONNECT), this causes invalid frees
and out-of-bounds copy-back accesses.
Remove the pointer increments from the loop header so indexing uses [i]
against the original base pointers, matching the copy-in loop above.
Found by LLM-assisted static analysis. Compile-tested on x86_64 with
CONFIG_COMPAT=y and CONFIG_VBOXGUEST=m, and runtime-tested in QEMU+KASAN
via a kernel module harness exercising vbg_hgcm_call32() for
parm_count=0..4 (invalid-free and slab-out-of-bounds before the fix;
0 KASAN findings after).
Fixes: 579db9d45cb4 ("virt: Add vboxguest VMMDEV communication code")
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
drivers/virt/vboxguest/vboxguest_utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c
index 1c02b3c0d..f9e1d1fea 100644
--- a/drivers/virt/vboxguest/vboxguest_utils.c
+++ b/drivers/virt/vboxguest/vboxguest_utils.c
@@ -717,7 +717,7 @@ int vbg_hgcm_call32(
goto out_free;
/* Copy back. */
- for (i = 0; i < parm_count; i++, parm32++, parm64++) {
+ for (i = 0; i < parm_count; i++) {
switch (parm64[i].type) {
case VMMDEV_HGCM_PARM_TYPE_32BIT:
parm32[i].u.value32 = parm64[i].u.value32;
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32()
2026-11-30 10:13 [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32() Ziheng Wei
@ 2026-11-30 12:14 ` Hans de Goede
0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2026-11-30 12:14 UTC (permalink / raw)
To: Ziheng Wei, Arnd Bergmann, Greg Kroah-Hartman; +Cc: linux-kernel
Hi,
On 30-Nov-26 11:13, Ziheng Wei wrote:
> The copy-back loop in vbg_hgcm_call32() advances parm32 and parm64 in
> the for-loop increment while also indexing both arrays with [i]:
>
> for (i = 0; i < parm_count; i++, parm32++, parm64++)
> parm32[i]... = parm64[i]...
>
> Because each iteration advances the pointers and also adds [i], iteration
> i accesses element 2*i. This goes out of bounds once 2*i >= parm_count
> (for parm_count >= 2) and leaves parm64 pointing past the start of the
> kzalloc() buffer when out_free passes it to kfree() for any parm_count > 0.
> On user space reaching VBG_IOCTL_HGCM_CALL_32 via /dev/vboxuser (root-only
> 0600 by default after VBG_IOCTL_HGCM_CONNECT), this causes invalid frees
> and out-of-bounds copy-back accesses.
>
> Remove the pointer increments from the loop header so indexing uses [i]
> against the original base pointers, matching the copy-in loop above.
>
> Found by LLM-assisted static analysis. Compile-tested on x86_64 with
> CONFIG_COMPAT=y and CONFIG_VBOXGUEST=m, and runtime-tested in QEMU+KASAN
> via a kernel module harness exercising vbg_hgcm_call32() for
> parm_count=0..4 (invalid-free and slab-out-of-bounds before the fix;
> 0 KASAN findings after).
>
> Fixes: 579db9d45cb4 ("virt: Add vboxguest VMMDEV communication code")
> Signed-off-by: Ziheng Wei <zihengw03@163.com>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Regards,
Hans
> ---
> drivers/virt/vboxguest/vboxguest_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c
> index 1c02b3c0d..f9e1d1fea 100644
> --- a/drivers/virt/vboxguest/vboxguest_utils.c
> +++ b/drivers/virt/vboxguest/vboxguest_utils.c
> @@ -717,7 +717,7 @@ int vbg_hgcm_call32(
> goto out_free;
>
> /* Copy back. */
> - for (i = 0; i < parm_count; i++, parm32++, parm64++) {
> + for (i = 0; i < parm_count; i++) {
> switch (parm64[i].type) {
> case VMMDEV_HGCM_PARM_TYPE_32BIT:
> parm32[i].u.value32 = parm64[i].u.value32;
>
> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 12:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 10:13 [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32() Ziheng Wei
2026-11-30 12:14 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®