Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Omar Elghoul <oelghoul@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v9 4/4] vfio-pci/zdev: Add VFIO FMB device features
Date: Wed, 7 Oct 2026 10:24:51 -0400	[thread overview]
Message-ID: <cecdfa03-3898-4059-a818-762599269531@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-163087@kernel.org>

On 10/7/26 10:07 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] vfio_pci: NULL pointer deref in fmb_read on fmb allocation failure
> - [High] vfio_pci: stack buffer overflow in fmb_read via unbounded fmb_length
> --
> 
> commit 759143700fb3898fd78661e48f994eff036f8cf5
> Author: Omar Elghoul <oelghoul@linux.ibm.com>
> 
> vfio-pci/zdev: Add VFIO FMB device features
> 
> This commit introduces new VFIO features for zPCI devices to provide FMB
> passthrough to userspace. It allows enabling or disabling the FMB using a SET
> feature, and reading the latest FMB using a GET feature.
> 
>> diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c
>> index f47f36314a1cc..1a66f455545ab 100644
>> --- a/drivers/vfio/pci/vfio_pci_zdev.c
>> +++ b/drivers/vfio/pci/vfio_pci_zdev.c
> [ ... ]
>> +int vfio_pci_zdev_feature_fmb_enable(struct vfio_pci_core_device *vdev, u32 flags,
>> +				     void __user *arg, size_t argsz)
>> +{
> [ ... ]
>> +	if (fmb_enable.enabled) {
>> +		zdev->fmb_requested = true;
>> +		return zpci_fmb_reenable_device(zdev);
> 
> [Severity: High]
> If zpci_fmb_reenable_device() fails (for example, if kmem_cache_zalloc()
> returns -ENOMEM), does zdev->fmb_requested remain set to true?
> 
> Since the failure doesn't revert the flag to false, could this leave the
> device state inconsistent for future FMB reads?

This flag is intentionally kept true and is documented in patch 2/4 to
track the desired FMB state, which is not necessarily the actual FMB
enablement state in firmware. In hindsight, the liveness check should've
been zdev->fmb_requested && zdev->fmb rather than just one or the other.
The "inconsistent" device state isn't an issue either because the FMB
sample includes a timestamp, so a consumer would know when it's reading
stale data.

> 
> [Severity: High]
> Is it intentional to bypass the zdev->fmb_length bounds check here?
> 
> The standard enablement path typically validates that zdev->fmb_length fits
> within the structure boundaries. By calling zpci_fmb_reenable_device()
> directly, it appears a hardware-supplied length greater than the size of
> struct zpci_fmb could be accepted and saved.

In practice this shouldn't be an issue, but it would've been a good idea
to move the sizeof(*zdev->fmb) < zdev->fmb_length check into
zpci_fmb_reenable_device() as well to prevent this issue from existing
even in theory.

> 
>> +	}
>> +
>> +	return zpci_fmb_disable_device(zdev);
>> +}
>> +
>> +int vfio_pci_zdev_feature_fmb_read(struct vfio_pci_core_device *vdev, u32 flags,
>> +				   void __user *arg, size_t argsz)
>> +{
>> +	struct zpci_dev *zdev;
>> +	struct vfio_device_feature_zpci_fmb_read fmb_read;
>> +	struct zpci_fmb fmb_bounce;
> [ ... ]
>> +	scoped_guard(mutex, &zdev->fmb_lock) {
>> +		if (!zdev->fmb_requested)
>> +			return -ENOMSG;
>> +		memcpy(&fmb_bounce, zdev->fmb, zdev->fmb_length);
> 
> [Severity: High]
> If a previous call to vfio_pci_zdev_feature_fmb_enable() failed during
> allocation but left zdev->fmb_requested = true, this check will pass.
> 
> Will this result in a NULL pointer dereference when accessing zdev->fmb in
> this memcpy()?

Admittedly I did miss this one, sorry about that. I will address it in
the next iteration.

> 
> [Severity: High]
> Can zdev->fmb_length be larger than sizeof(struct zpci_fmb)?
> 
> If an oversized fmb_length is reported by the hardware or firmware and was not
> validated during enablement, could copying up to that length into the
> fixed-size local stack variable fmb_bounce result in a stack buffer overflow?

See above

> 
>> +	}
>> +
>> +	if (copy_to_user(u64_to_user_ptr(fmb_read.data), &fmb_bounce, zdev->fmb_length))
>> +		return -EFAULT;
>> +	return 0;
>> +}
> 


      reply	other threads:[~2026-10-07 14:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 13:59 [PATCH v9 0/4] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-10-07 13:59 ` [PATCH v9 1/4] s390/pci: Hold fmb_lock when enabling or disabling PCI devices Omar Elghoul
2026-10-07 14:13   ` sashiko-bot
2026-10-07 13:59 ` [PATCH v9 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement Omar Elghoul
2026-10-07 14:11   ` sashiko-bot
2026-10-07 13:59 ` [PATCH v9 3/4] s390/pci: Fence FMB enable/disable via debugfs for passthrough devices Omar Elghoul
2026-10-07 14:06   ` sashiko-bot
2026-10-07 13:59 ` [PATCH v9 4/4] vfio-pci/zdev: Add VFIO FMB device features Omar Elghoul
2026-10-07 14:07   ` sashiko-bot
2026-10-07 14:24     ` Omar Elghoul [this message]

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=cecdfa03-3898-4059-a818-762599269531@linux.ibm.com \
    --to=oelghoul@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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