All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vduse: allocate anon inode file after domain initialization
@ 2026-12-01  6:25 Xiang Lei
  2026-12-01  6:27 ` sashiko-bot
  2026-12-01 10:39 ` Eugenio Perez Martin
  0 siblings, 2 replies; 3+ messages in thread
From: Xiang Lei @ 2026-12-01  6:25 UTC (permalink / raw)
  Cc: Xiang Lei, stable, Michael S. Tsirkin, Jason Wang,
	Eugenio Pérez, Xuan Zhuo, Xie Yongji, chenglong.ma,
	Linfeng Sun, John Garry, Robin Murphy, Joerg Roedel,
	virtualization

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 <leixiang@kylinos.cn>
---
 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


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

end of thread, other threads:[~2026-12-01 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  6:25 [PATCH] vduse: allocate anon inode file after domain initialization Xiang Lei
2026-12-01  6:27 ` sashiko-bot
2026-12-01 10:39 ` Eugenio Perez Martin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.