public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] vfio/cdx: Fix NULL pointer dereference in interrupt trigger path
@ 2026-03-20 10:19 Prasanna Kumar T S M
  2026-03-20 10:21 ` [PATCH 2/2] cdx: Fix double free when sysfs file creation fails Prasanna Kumar T S M
  0 siblings, 1 reply; 2+ messages in thread
From: Prasanna Kumar T S M @ 2026-03-20 10:19 UTC (permalink / raw)
  To: ptsm, nipun.gupta, nikhil.agarwal, alex, pieter.jansen-van-vuuren,
	kvm, linux-kernel
  Cc: stable

Add validation to ensure MSI is configured before accessing cdx_irqs
array in vfio_cdx_set_msi_trigger(). Without this check, userspace
can trigger a NULL pointer dereference by calling VFIO_DEVICE_SET_IRQS
with VFIO_IRQ_SET_DATA_BOOL or VFIO_IRQ_SET_DATA_NONE flags before
ever setting up interrupts via VFIO_IRQ_SET_DATA_EVENTFD.

The vfio_cdx_msi_enable() function allocates the cdx_irqs array and
sets config_msi to 1 only when called through the EVENTFD path. The
trigger loop (for DATA_BOOL/DATA_NONE) assumed this had already been
done, but there was no enforcement of this call ordering.

This matches the protection used in the PCI VFIO driver where
vfio_pci_set_msi_trigger() checks irq_is() before the trigger loop.

Fixes: 848e447e000c ("vfio/cdx: add interrupt support")
Cc: stable@vger.kernel.org
Signed-off-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
---
 drivers/vfio/cdx/intr.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/vfio/cdx/intr.c b/drivers/vfio/cdx/intr.c
index 8f4402cec9c5..c0eed065e8ef 100644
--- a/drivers/vfio/cdx/intr.c
+++ b/drivers/vfio/cdx/intr.c
@@ -175,6 +175,10 @@ static int vfio_cdx_set_msi_trigger(struct vfio_cdx_device *vdev,
 		return ret;
 	}
 
+	/* Ensure MSI is configured before accessing cdx_irqs */
+	if (!vdev->config_msi)
+		return -EINVAL;
+
 	for (i = start; i < start + count; i++) {
 		if (!vdev->cdx_irqs[i].trigger)
 			continue;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] cdx: Fix double free when sysfs file creation fails
  2026-03-20 10:19 [PATCH 1/2] vfio/cdx: Fix NULL pointer dereference in interrupt trigger path Prasanna Kumar T S M
@ 2026-03-20 10:21 ` Prasanna Kumar T S M
  0 siblings, 0 replies; 2+ messages in thread
From: Prasanna Kumar T S M @ 2026-03-20 10:21 UTC (permalink / raw)
  To: ptsm, nipun.gupta, nikhil.agarwal, abhijit.gangurde, puneet.gupta,
	gregkh, linux-kernel
  Cc: stable

In cdx_create_res_attr(), if sysfs_create_bin_file() fails, the code
frees res_attr but doesn't set cdx_dev->res_attr[num] to NULL. This
leaves a dangling pointer in the array. Then cdx_destroy_res_attr()
frees the already-freed memory. Fix the double free by initializing
cdx_dev->res_attr[num] after sysfs_create_bin_file() completes.

Fixes: aeda33ab8160 ("cdx: create sysfs bin files for cdx resources")
Cc: stable@vger.kernel.org
Signed-off-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
---
 drivers/cdx/cdx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index 9196dc50a48d..a4e03fb07c4c 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -768,7 +768,6 @@ static int cdx_create_res_attr(struct cdx_device *cdx_dev, int num)
 
 	sysfs_bin_attr_init(res_attr);
 
-	cdx_dev->res_attr[num] = res_attr;
 	sprintf(res_attr_name, "resource%d", num);
 
 	res_attr->mmap = cdx_mmap_resource;
@@ -777,8 +776,12 @@ static int cdx_create_res_attr(struct cdx_device *cdx_dev, int num)
 	res_attr->size = cdx_resource_len(cdx_dev, num);
 	res_attr->private = (void *)(unsigned long)num;
 	ret = sysfs_create_bin_file(&cdx_dev->dev.kobj, res_attr);
-	if (ret)
+	if (ret) {
 		kfree(res_attr);
+		return ret;
+	}
+
+	cdx_dev->res_attr[num] = res_attr;
 
 	return ret;
 }
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-20 10:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 10:19 [PATCH 1/2] vfio/cdx: Fix NULL pointer dereference in interrupt trigger path Prasanna Kumar T S M
2026-03-20 10:21 ` [PATCH 2/2] cdx: Fix double free when sysfs file creation fails Prasanna Kumar T S M

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox