]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vfio/pds: Fix memory leak in pds_vfio_dirty_enable()
authorZilin Guan <zilin@seu.edu.cn>
Thu, 25 Dec 2025 14:31:50 +0000 (14:31 +0000)
committerAlex Williamson <alex@shazbot.org>
Sun, 28 Dec 2025 19:33:40 +0000 (12:33 -0700)
pds_vfio_dirty_enable() allocates memory for region_info. If
interval_tree_iter_first() returns NULL, the function returns -EINVAL
immediately without freeing the allocated memory, causing a memory leak.

Fix this by jumping to the out_free_region_info label to ensure
region_info is freed.

Fixes: 2e7c6feb4ef52 ("vfio/pds: Add multi-region support")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Link: https://lore.kernel.org/r/20251225143150.1117366-1-zilin@seu.edu.cn
Signed-off-by: Alex Williamson <alex@shazbot.org>
drivers/vfio/pci/pds/dirty.c

index 481992142f79016106964e4e6dccd995a84b56e7..4915a7c1c4916d9934fd27a5f65ee77abba16cd7 100644 (file)
@@ -292,8 +292,11 @@ static int pds_vfio_dirty_enable(struct pds_vfio_pci_device *pds_vfio,
        len = num_ranges * sizeof(*region_info);
 
        node = interval_tree_iter_first(ranges, 0, ULONG_MAX);
-       if (!node)
-               return -EINVAL;
+       if (!node) {
+               err = -EINVAL;
+               goto out_free_region_info;
+       }
+
        for (int i = 0; i < num_ranges; i++) {
                struct pds_lm_dirty_region_info *ri = &region_info[i];
                u64 region_size = node->last - node->start + 1;