From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 316D0137932; Tue, 26 Aug 2025 13:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215123; cv=none; b=tegNLuoOSxBS684OjSOHZMFR9cj9GnOzaPbK2sW/mNgMsumqYKImVyuM1bl+TmSqqpRzIin8PwzemY4dXpuYQq6I1wCKfH7N3VSq0dDy+tyBR3qXunPFQw85InCtagdRTYzFcWIZt2t5yDLbtYQMO6huCQXAPQta8D1mdsyDS0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215123; c=relaxed/simple; bh=HOwS783ENCBr19Da1REGL6c13N91U3zefcVYMedDLKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jWImjx3cSnp2vDVV18AJ5WN/ZOkvQnAfjpltRHcR6kmpmg0N4u1Rzquv7a+dk7gF57kY4zuZAG8HnEGjSM5/FzsSCJMgtsYRcFJSpthqeG0R1OYc4SX936XMjsM71nNKVOgjMFyQTSTUmdamLHMmtcAaUnzDKaCSn0CkxQohGRg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Xz5RvFuA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Xz5RvFuA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0896C4CEF1; Tue, 26 Aug 2025 13:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756215123; bh=HOwS783ENCBr19Da1REGL6c13N91U3zefcVYMedDLKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xz5RvFuAG7DN2LCFZWUoUmSzI5U3u/5aMPMjd3IwWcOxVhtzC7JxtnOOH+z49ggmO rMn/UJMe183QWUNyR6fKmzARtjRavwhbOLxbp3qxR+nR60TKCTK0uzupHUiXWDfS07 xy7/oNIaxJjFKP2ysf4w079Y4rUS/a2GE7CQVAGc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Phillip Lougher , Scott GUO , Andrew Morton Subject: [PATCH 6.1 396/482] squashfs: fix memory leak in squashfs_fill_super Date: Tue, 26 Aug 2025 13:10:49 +0200 Message-ID: <20250826110940.611823493@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110930.769259449@linuxfoundation.org> References: <20250826110930.769259449@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Phillip Lougher commit b64700d41bdc4e9f82f1346c15a3678ebb91a89c upstream. If sb_min_blocksize returns 0, squashfs_fill_super exits without freeing allocated memory (sb->s_fs_info). Fix this by moving the call to sb_min_blocksize to before memory is allocated. Link: https://lkml.kernel.org/r/20250811223740.110392-1-phillip@squashfs.org.uk Fixes: 734aa85390ea ("Squashfs: check return result of sb_min_blocksize") Signed-off-by: Phillip Lougher Reported-by: Scott GUO Closes: https://lore.kernel.org/all/20250811061921.3807353-1-scott_gzh@163.com Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/squashfs/super.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c @@ -123,10 +123,15 @@ static int squashfs_fill_super(struct su unsigned short flags; unsigned int fragments; u64 lookup_table_start, xattr_id_table_start, next_table; - int err; + int err, devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE); TRACE("Entered squashfs_fill_superblock\n"); + 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"); @@ -136,12 +141,7 @@ static int squashfs_fill_super(struct su 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);