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 5334F16419; Mon, 23 Jun 2025 13:41:36 +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=1750686098; cv=none; b=X73+Z7fWwux6fi4r53h0lwYS5EWTpq6OT1DaQz3CfS6VsIlMbNgIZyL4Q+ecpyYwH/LOAgTFR5XsVfTMDCooeTARo424zgasqYIeYWSNaAJLzNGcPeWL04EsC8qiE8AVvgtUGsZGJ+M83SzGZZUhFFnN/spN9F5zlA1qwXU7V+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750686098; c=relaxed/simple; bh=SNLycSAsaMVzcJld3wvIR1nBoP78HUGWOMEbqj/NBAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=koJi8bd+7v318VQbowRu6lcSGJB0H7e0iU2Vq8eCmnzgNGHJ0lT36YJt2CQapaFnf13tQR0hfoaZaeBURTP47kE3du8iA4KK1hz7Pi+C95TuaAyqMeOfgFPJIUeF2dl96qSoQ7DGQ//ZOr3jpgAUVsdFCkhLo/xfLM/BrlyfR/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Y0GQrPo7; 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="Y0GQrPo7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77752C4CEEA; Mon, 23 Jun 2025 13:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750686096; bh=SNLycSAsaMVzcJld3wvIR1nBoP78HUGWOMEbqj/NBAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0GQrPo7opl5452OYfXFsuGklluwjFn5H/X0eINPS13JRkvmA87+4XAiObuWXNlNL +SwJpRsuKWwvq/MIHbb1awN13PnFPfRD+E0dgWfbnrlTn77K/7JkMR0weaeJZ1F/kI 9DtiN5F8q/n3rcCDzyuthS0lKL2noEUPpCqgLIhA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+65761fc25a137b9c8c6e@syzkaller.appspotmail.com, Phillip Lougher , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 079/411] Squashfs: check return result of sb_min_blocksize Date: Mon, 23 Jun 2025 15:03:43 +0200 Message-ID: <20250623130635.374335677@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130632.993849527@linuxfoundation.org> References: <20250623130632.993849527@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Phillip Lougher [ Upstream commit 734aa85390ea693bb7eaf2240623d41b03705c84 ] Syzkaller reports an "UBSAN: shift-out-of-bounds in squashfs_bio_read" bug. Syzkaller forks multiple processes which after mounting the Squashfs filesystem, issues an ioctl("/dev/loop0", LOOP_SET_BLOCK_SIZE, 0x8000). Now if this ioctl occurs at the same time another process is in the process of mounting a Squashfs filesystem on /dev/loop0, the failure occurs. When this happens the following code in squashfs_fill_super() fails. ---- msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE); msblk->devblksize_log2 = ffz(~msblk->devblksize); ---- sb_min_blocksize() returns 0, which means msblk->devblksize is set to 0. As a result, ffz(~msblk->devblksize) returns 64, and msblk->devblksize_log2 is set to 64. This subsequently causes the UBSAN: shift-out-of-bounds in fs/squashfs/block.c:195:36 shift exponent 64 is too large for 64-bit type 'u64' (aka 'unsigned long long') This commit adds a check for a 0 return by sb_min_blocksize(). Link: https://lkml.kernel.org/r/20250409024747.876480-1-phillip@squashfs.org.uk Fixes: 0aa666190509 ("Squashfs: super block operations") Reported-by: syzbot+65761fc25a137b9c8c6e@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/67f0dd7a.050a0220.0a13.0230.GAE@google.com/ Signed-off-by: Phillip Lougher Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/squashfs/super.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index 60d6951915f44..5108740f9653c 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c @@ -136,6 +136,11 @@ 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_log2 = ffz(~msblk->devblksize); mutex_init(&msblk->meta_index_mutex); -- 2.39.5