mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] squashfs: Avoid mem leak in squashfs_fill_super()
@ 2025-08-12  3:04 scott_gzh
  2025-08-12 15:57 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: scott_gzh @ 2025-08-12  3:04 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 calling and checking result of sb_min_blocksize() before
kzalloc.

Fixes: 734aa85390ea ("Squashfs: check return result of sb_min_blocksize")
Signed-off-by: Scott GUO <scottzhguo@tencent.com>

---

v2:
  Adjust commit message based on Markus' advice, and refine fix
  following Phillip's comment.
---
 fs/squashfs/super.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 992ea0e37257..073462b098c5 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -188,9 +188,16 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	unsigned int fragments;
 	u64 lookup_table_start, xattr_id_table_start, next_table;
 	int err;
+	int devblksize;
 
 	TRACE("Entered squashfs_fill_superblock\n");
 
+	devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE);
+	if (!devblksize) {
+		errorf(fc, "squashfs: unable to set blocksize\n");
+		return -EINVAL;
+	}
+
 	sb->s_fs_info = kzalloc(sizeof(*msblk), GFP_KERNEL);
 	if (sb->s_fs_info == NULL) {
 		ERROR("Failed to allocate squashfs_sb_info\n");
@@ -201,12 +208,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	msblk->panic_on_errors = (opts->errors == Opt_errors_panic);
 
-	msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE);
-	if (!msblk->devblksize) {
-		errorf(fc, "squashfs: unable to set blocksize\n");
-		return -EINVAL;
-	}
-
+	msblk->devblksize = devblksize;
 	msblk->devblksize_log2 = ffz(~msblk->devblksize);
 
 	mutex_init(&msblk->meta_index_mutex);
-- 
2.41.3


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

* Re: [PATCH v2] squashfs: Avoid mem leak in squashfs_fill_super()
  2025-08-12  3:04 [PATCH v2] squashfs: Avoid mem leak in squashfs_fill_super() scott_gzh
@ 2025-08-12 15:57 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-08-12 15:57 UTC (permalink / raw)
  To: Scott Guo, Phillip Lougher; +Cc: Scott Guo, LKML, kernel-janitors

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

                         memory?


> Fix it by calling and checking result of sb_min_blocksize() before
> kzalloc.

         () call?

Regards,
Markus

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-12  3:04 [PATCH v2] squashfs: Avoid mem leak in squashfs_fill_super() scott_gzh
2025-08-12 15:57 ` Markus Elfring

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

all inboxes | Powered by JetHome®