Forwarded: [PATCH] gfs2: fix memory leak of kernel threads on mount failure

syzbot posted 1 patch 1 week ago
fs/gfs2/ops_fstype.c | 2 ++
1 file changed, 2 insertions(+)
Forwarded: [PATCH] gfs2: fix memory leak of kernel threads on mount failure
Posted by syzbot 1 week ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] gfs2: fix memory leak of kernel threads on mount failure
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

Syzbot reported a memory leak in GFS2 when mounting fails after
init_threads() has successfully created kernel threads. The issue
occurs when gfs2_freeze_lock_shared() fails - the error path jumps
to fail_per_node without cleaning up the threads created by
init_threads().

The leak includes the thread name string, task_struct, credentials,
and other thread-related allocations that are never freed when the
mount operation fails at this point.

Fix this by ensuring gfs2_destroy_threads() is called in the
fail_per_node error path for read-write mounts, matching the
condition used when creating the threads.

Reported-by: syzbot+aac438d7a1c44071e04b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=aac438d7a1c44071e04b
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 fs/gfs2/ops_fstype.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index e7a88b717991..163dd7132957 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1286,6 +1286,8 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
 
 fail_per_node:
 	init_per_node(sdp, UNDO);
+	if (!sb_rdonly(sb))
+		gfs2_destroy_threads(sdp);
 fail_inodes:
 	init_inodes(sdp, UNDO);
 fail_sb:
-- 
2.43.0