public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] squashfs: Avoid mem leak in squashfs_fill_super
@ 2025-08-11  6:19 scott_gzh
  2025-08-11  7:02 ` Markus Elfring
  2025-08-11 22:35 ` [PATCH] " Phillip Lougher
  0 siblings, 2 replies; 8+ messages in thread
From: scott_gzh @ 2025-08-11  6:19 UTC (permalink / raw)
  To: phillip; +Cc: linux-kernel, Scott GUO

From: Scott GUO <scottzhguo@tencent.com>

If sb_min_blocksize returns 0, -EINVAL was returned without freeing
sb->s_fs_info, causing mem leak.

Fix it by goto failed_mount.

Fixes: 734aa85390ea ("Squashfs: check return result of sb_min_blocksize")
Signed-off-by: Scott GUO <scottzhguo@tencent.com>
---
 fs/squashfs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 992ea0e37257..7d501083b2e3 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -201,10 +201,12 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	msblk->panic_on_errors = (opts->errors == Opt_errors_panic);
 
+	err = -EINVAL;
+
 	msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE);
 	if (!msblk->devblksize) {
 		errorf(fc, "squashfs: unable to set blocksize\n");
-		return -EINVAL;
+		goto failed_mount;
 	}
 
 	msblk->devblksize_log2 = ffz(~msblk->devblksize);
@@ -227,8 +229,6 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 		goto failed_mount;
 	}
 
-	err = -EINVAL;
-
 	/* Check it is a SQUASHFS superblock */
 	sb->s_magic = le32_to_cpu(sblk->s_magic);
 	if (sb->s_magic != SQUASHFS_MAGIC) {
-- 
2.41.3


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

end of thread, other threads:[~2025-08-12  9:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  6:19 [PATCH] squashfs: Avoid mem leak in squashfs_fill_super scott_gzh
2025-08-11  7:02 ` Markus Elfring
2025-08-12  2:11   ` Scott Guo
2025-08-12  8:18     ` Dan Carpenter
2025-08-12  8:38       ` Markus Elfring
2025-08-12  9:20         ` Dan Carpenter
2025-08-11 22:35 ` [PATCH] " Phillip Lougher
2025-08-12  2:11   ` Scott Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox