Re: [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32()
From: Hans de Goede
Date: Mon Nov 30 2026 - 07:14:11 EST
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@xxxxxxx>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@xxxxxxxxxxxxxxxx>
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