vduse_domain_create() creates the anon-inode file before initializing stream_iovad and consistent_iovad. If rcache initialization fails, the error path calls fput(file) and frees domain synchronously, while the deferred __fput() later runs vduse_domain_release() on the freed domain, causing a use-after-free and double-free. Move anon_inode_getfile() after both IOVA domains are initialized so failures clean up synchronously without calling fput(). Fixes: 32e92d9f6f87 ("iommu/iova: Separate out rcache init") Cc: stable@vger.kernel.org Signed-off-by: Xiang Lei --- drivers/vdpa/vdpa_user/iova_domain.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c index 28a977248a0d..f3f12a0b875f 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -659,12 +659,6 @@ vduse_domain_create(unsigned long iova_limit, size_t bounce_size) map = &domain->bounce_maps[pfn]; map->orig_phys = INVALID_PHYS_ADDR; } - file = anon_inode_getfile("[vduse-domain]", &vduse_domain_fops, - domain, O_RDWR); - if (IS_ERR(file)) - goto err_file; - - domain->file = file; rwlock_init(&domain->bounce_lock); spin_lock_init(&domain->iotlb_lock); init_iova_domain(&domain->stream_iovad, @@ -678,12 +672,19 @@ vduse_domain_create(unsigned long iova_limit, size_t bounce_size) if (ret) goto err_iovad_consistent; + file = anon_inode_getfile("[vduse-domain]", &vduse_domain_fops, + domain, O_RDWR); + if (IS_ERR(file)) + goto err_file; + + domain->file = file; + return domain; +err_file: + put_iova_domain(&domain->consistent_iovad); err_iovad_consistent: put_iova_domain(&domain->stream_iovad); err_iovad_stream: - fput(file); -err_file: vfree(domain->bounce_maps); err_map: vhost_iotlb_free(domain->iotlb); -- 2.53.0