linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fuse: Fix a potential double free in virtio_fs_get_tree
@ 2021-03-23  5:18 Lv Yunlong
  2021-03-23 14:33 ` Connor Kuehl
  2021-03-23 17:10 ` Vivek Goyal
  0 siblings, 2 replies; 4+ messages in thread
From: Lv Yunlong @ 2021-03-23  5:18 UTC (permalink / raw)
  To: vgoyal, stefanha, miklos
  Cc: virtualization, linux-fsdevel, linux-kernel, Lv Yunlong

In virtio_fs_get_tree, fm is allocated by kzalloc() and
assigned to fsc->s_fs_info by fsc->s_fs_info=fm statement.
If the kzalloc() failed, it will goto err directly, so that
fsc->s_fs_info must be non-NULL and fm will be freed.

But later fm is freed again when virtio_fs_fill_super() fialed.
I think the statement if (fsc->s_fs_info) {kfree(fm);} is
misplaced.

My patch puts this statement in the correct palce to avoid
double free.

Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 fs/fuse/virtio_fs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 8868ac31a3c0..727cf436828f 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1437,10 +1437,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
 
 	fsc->s_fs_info = fm;
 	sb = sget_fc(fsc, virtio_fs_test_super, set_anon_super_fc);
-	if (fsc->s_fs_info) {
-		fuse_conn_put(fc);
-		kfree(fm);
-	}
+
 	if (IS_ERR(sb))
 		return PTR_ERR(sb);
 
@@ -1457,6 +1454,11 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
 		sb->s_flags |= SB_ACTIVE;
 	}
 
+	if (fsc->s_fs_info) {
+		fuse_conn_put(fc);
+		kfree(fm);
+	}
+
 	WARN_ON(fsc->root);
 	fsc->root = dget(sb->s_root);
 	return 0;
-- 
2.25.1



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

end of thread, other threads:[~2021-03-25  5:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  5:18 [PATCH] fuse: Fix a potential double free in virtio_fs_get_tree Lv Yunlong
2021-03-23 14:33 ` Connor Kuehl
2021-03-23 17:10 ` Vivek Goyal
2021-03-25  5:04   ` lyl2019

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).