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 6042E29D26A; Tue, 26 Aug 2025 11:26:44 +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=1756207604; cv=none; b=uAd+Ez/aWy0vJBUqcizyvZCd38JpkZYjatYoi+zF62vNZplOPM1fuTbkh+DOVhDiTazPdgKb6iX2U8E6JxoREA9sUdWsNAFCtaVSLFCMKf0vuSBZlI3+3h2m3rC5WLNvcd2mGEjopVjzE8PkLiLLYfnjmjs5NmVY2XI7pkMcACc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756207604; c=relaxed/simple; bh=gTU5j94/sX4b3IaFo3J/ZXAPU3ushUN7Y/tktBrK7qE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unTE5AIoa8W8Qjp0QrybIpF7/OEopy2U0SNgBFpXg2cMa91UVTAf6UQG32JUauBato+P2fwr33dCIwOX3Hjy5NSQ/uN6miX0Gldd6XC/5GtQNte+/kAYCZy7XBeo3QpMbSHcqCW7s77y2ia33PM4ZqyJv7QnQb8eLLV2bmU2NrY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eR+SpkDQ; 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="eR+SpkDQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E17ECC4CEF1; Tue, 26 Aug 2025 11:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756207604; bh=gTU5j94/sX4b3IaFo3J/ZXAPU3ushUN7Y/tktBrK7qE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eR+SpkDQmWfrH2gp+h5BfNlEpzkGvmKry6E2Fa3C+2/L0HFwrfYPNcQmoYxzPgPro b81LTH66m+4d0qtZyKkJlRCMEg5uHJ2qcW7y1LxRfmfV8yvnqNBYFsyZDiaoLrGsUE iXRYM50TWDf17KqiSQZPxFetNBcuO2tuBq3jGAO0= 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.16 245/457] squashfs: fix memory leak in squashfs_fill_super Date: Tue, 26 Aug 2025 13:08:49 +0200 Message-ID: <20250826110943.425790182@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110937.289866482@linuxfoundation.org> References: <20250826110937.289866482@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.16-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 @@ -187,10 +187,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"); @@ -201,12 +206,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);