mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ziheng Wei <zihengw03@163.com>
To: Hans de Goede <hansg@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] virt: vboxguest: fix out-of-bounds access and invalid kfree in vbg_hgcm_call32()
Date: Mon, 30 Nov 2026 18:13:49 +0800	[thread overview]
Message-ID: <20261130101349.1379461-1-zihengw03@163.com> (raw)

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


             reply	other threads:[~2026-11-30 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:13 Ziheng Wei [this message]
2026-11-30 12:14 ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130101349.1379461-1-zihengw03@163.com \
    --to=zihengw03@163.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®