Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file()
@ 2025-12-25 15:13 Alper Ak
  2025-12-28 20:48 ` Alex Williamson
  2026-01-07 14:30 ` ✗ LGCI.VerificationFailed: failure for " Patchwork
  0 siblings, 2 replies; 3+ messages in thread
From: Alper Ak @ 2025-12-25 15:13 UTC (permalink / raw)
  To: michal.winiarski
  Cc: Alper Ak, Jason Gunthorpe, Yishai Hadas, Shameer Kolothum,
	Kevin Tian, Alex Williamson, Thomas Hellström, Rodrigo Vivi,
	kvm, intel-xe, linux-kernel

migf->filp is accessed after migf has been freed. Save the error
value before calling kfree() to prevent use-after-free.

Fixes: 1f5556ec8b9e ("vfio/xe: Add device specific vfio_pci driver variant for Intel graphics")
Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
---
 drivers/vfio/pci/xe/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/pci/xe/main.c b/drivers/vfio/pci/xe/main.c
index 0156b53c678b..8e1595e00e18 100644
--- a/drivers/vfio/pci/xe/main.c
+++ b/drivers/vfio/pci/xe/main.c
@@ -250,6 +250,7 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
 	struct xe_vfio_pci_migration_file *migf;
 	const struct file_operations *fops;
 	int flags;
+	int ret;
 
 	migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT);
 	if (!migf)
@@ -259,8 +260,9 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
 	flags = type == XE_VFIO_FILE_SAVE ? O_RDONLY : O_WRONLY;
 	migf->filp = anon_inode_getfile("xe_vfio_mig", fops, migf, flags);
 	if (IS_ERR(migf->filp)) {
+		ret = PTR_ERR(migf->filp);
 		kfree(migf);
-		return ERR_CAST(migf->filp);
+		return ERR_PTR(ret);
 	}
 
 	mutex_init(&migf->lock);
-- 
2.43.0


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

* Re: [PATCH] vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file()
  2025-12-25 15:13 [PATCH] vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file() Alper Ak
@ 2025-12-28 20:48 ` Alex Williamson
  2026-01-07 14:30 ` ✗ LGCI.VerificationFailed: failure for " Patchwork
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2025-12-28 20:48 UTC (permalink / raw)
  To: Alper Ak
  Cc: michal.winiarski, Jason Gunthorpe, Yishai Hadas, Shameer Kolothum,
	Kevin Tian, Thomas Hellström, Rodrigo Vivi, kvm, intel-xe,
	linux-kernel

On Thu, 25 Dec 2025 18:13:49 +0300
Alper Ak <alperyasinak1@gmail.com> wrote:

> migf->filp is accessed after migf has been freed. Save the error
> value before calling kfree() to prevent use-after-free.
> 
> Fixes: 1f5556ec8b9e ("vfio/xe: Add device specific vfio_pci driver variant for Intel graphics")
> Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
> ---
>  drivers/vfio/pci/xe/main.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/pci/xe/main.c b/drivers/vfio/pci/xe/main.c
> index 0156b53c678b..8e1595e00e18 100644
> --- a/drivers/vfio/pci/xe/main.c
> +++ b/drivers/vfio/pci/xe/main.c
> @@ -250,6 +250,7 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
>  	struct xe_vfio_pci_migration_file *migf;
>  	const struct file_operations *fops;
>  	int flags;
> +	int ret;
>  
>  	migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT);
>  	if (!migf)
> @@ -259,8 +260,9 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
>  	flags = type == XE_VFIO_FILE_SAVE ? O_RDONLY : O_WRONLY;
>  	migf->filp = anon_inode_getfile("xe_vfio_mig", fops, migf, flags);
>  	if (IS_ERR(migf->filp)) {
> +		ret = PTR_ERR(migf->filp);
>  		kfree(migf);
> -		return ERR_CAST(migf->filp);
> +		return ERR_PTR(ret);
>  	}
>  
>  	mutex_init(&migf->lock);

Applied to vfio for-linus branch for v6.19.  Thanks,

Alex

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

* ✗ LGCI.VerificationFailed: failure for vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file()
  2025-12-25 15:13 [PATCH] vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file() Alper Ak
  2025-12-28 20:48 ` Alex Williamson
@ 2026-01-07 14:30 ` Patchwork
  1 sibling, 0 replies; 3+ messages in thread
From: Patchwork @ 2026-01-07 14:30 UTC (permalink / raw)
  To: Alper Ak; +Cc: intel-xe

== Series Details ==

Series: vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file()
URL   : https://patchwork.freedesktop.org/series/159740/
State : failure

== Summary ==

Address 'alperyasinak1@gmail.com' is not on the allowlist, which prevents CI from being triggered for this patch.
If you want Intel GFX CI to accept this address, please contact the script maintainers at i915-ci-infra@lists.freedesktop.org.
Exception occurred during validation, bailing out!



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

end of thread, other threads:[~2026-01-07 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-25 15:13 [PATCH] vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file() Alper Ak
2025-12-28 20:48 ` Alex Williamson
2026-01-07 14:30 ` ✗ LGCI.VerificationFailed: failure for " Patchwork

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