All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xiang Mei" <xmei5@asu.edu>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] vfio/pci: clear vdev->msi_perm after freeing it on init failure
Date: Sun, 05 Jul 2026 01:54:21 +0000	[thread overview]
Message-ID: <20260705015421.C9E3C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260705014010.1297885-1-xmei5@asu.edu>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Heap buffer overflow in vfio_cap_init() and vfio_ecap_init() due to missing bounds check on capability length.
--

commit 5867deb8ee022404d313dea6794c1dc0a44460cb
Author: Xiang Mei <xmei5@asu.edu>

vfio/pci: clear vdev->msi_perm after freeing it on init failure

This commit clears the vdev->msi_perm pointer after freeing it during an
init_pci_cap_msi_perm() failure. This prevents a use-after-free and a double
free of the MSI permission table when vfio_config_init() fails.

> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index a10ed733f0e3a..9914f3ac69aef 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1272,6 +1272,7 @@ static int vfio_msi_cap_len(struct vfio_pci_core_device *vdev, u8 pos)
>  	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
>  	if (ret) {
>  		kfree(vdev->msi_perm);
> +		vdev->msi_perm = NULL;
>  		return ret;
>  	}

[Severity: Critical]
This is a pre-existing issue, but there appears to be a heap buffer overflow
due to missing bounds checks on capability lengths.

In vfio_cap_init(), if a PCI device advertises a capability where the offset
'pos' plus length 'len' exceeds 'pdev->cfg_size', can this memset() write out
of bounds on the heap?

drivers/vfio/pci/vfio_pci_config.c:vfio_cap_init() {
    ...
		memset(map + pos, cap, len);
		ret = vfio_fill_vconfig_bytes(vdev, pos, len);
    ...
}

Similarly, in vfio_ecap_init(), extended capabilities are not bounds-checked
against the buffer size:

drivers/vfio/pci/vfio_pci_config.c:vfio_ecap_init() {
    ...
		memset(map + epos, ecap, len);
		ret = vfio_fill_vconfig_bytes(vdev, epos, len);
    ...
}

This out-of-bounds write would then continue into vfio_fill_vconfig_bytes():

drivers/vfio/pci/vfio_pci_config.c:vfio_fill_vconfig_bytes() {
    ...
			*dwordp = cpu_to_le32(dword);
    ...
}

Should we validate that the capability length fits within the configuration
space buffer before performing these writes?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260705014010.1297885-1-xmei5@asu.edu?part=1

  reply	other threads:[~2026-07-05  1:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-05  1:40 [PATCH] vfio/pci: clear vdev->msi_perm after freeing it on init failure Xiang Mei
2026-07-05  1:54 ` sashiko-bot [this message]
2026-07-17 15:43 ` Alex Williamson

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=20260705015421.C9E3C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xmei5@asu.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.