* [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
0 siblings, 1 reply; 2+ 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 [flat|nested] 2+ 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
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2025-12-28 20:48 UTC | newest]
Thread overview: 2+ 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
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®