Skip to content

Commit acf44a2

Browse files
alperakawilliam
authored andcommitted
vfio/xe: Fix use-after-free in xe_vfio_pci_alloc_file()
migf->filp is accessed after migf has been freed. Save the error value before calling kfree() to prevent use-after-free. Fixes: 1f5556e ("vfio/xe: Add device specific vfio_pci driver variant for Intel graphics") Signed-off-by: Alper Ak <alperyasinak1@gmail.com> Link: https://lore.kernel.org/r/20251225151349.360870-1-alperyasinak1@gmail.com Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent 665077d commit acf44a2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/vfio/pci/xe/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
250250
struct xe_vfio_pci_migration_file *migf;
251251
const struct file_operations *fops;
252252
int flags;
253+
int ret;
253254

254255
migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT);
255256
if (!migf)
@@ -259,8 +260,9 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
259260
flags = type == XE_VFIO_FILE_SAVE ? O_RDONLY : O_WRONLY;
260261
migf->filp = anon_inode_getfile("xe_vfio_mig", fops, migf, flags);
261262
if (IS_ERR(migf->filp)) {
263+
ret = PTR_ERR(migf->filp);
262264
kfree(migf);
263-
return ERR_CAST(migf->filp);
265+
return ERR_PTR(ret);
264266
}
265267

266268
mutex_init(&migf->lock);

0 commit comments

Comments
 (0)