Commit 2fb78222 authored by Randy Dunlap's avatar Randy Dunlap Committed by Zizhi Wo
Browse files

fs/ntfs3: validate BOOT sectors_per_clusters

stable inclusion
from stable-v5.15.45
commit 58cf68a1886d14ffdc5c892ce483a82156769e88
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBP6TI
CVE: CVE-2022-49553

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=58cf68a1886d14ffdc5c892ce483a82156769e88

--------------------------------

commit a3b77434 upstream.

When the NTFS BOOT sectors_per_clusters field is > 0x80, it represents a
shift value.  Make sure that the shift value is not too large before using
it (NTFS max cluster size is 2MB).  Return -EVINVAL if it too large.

This prevents negative shift values and shift values that are larger than
the field size.

Prevents this UBSAN error:

 UBSAN: shift-out-of-bounds in ../fs/ntfs3/super.c:673:16
 shift exponent -192 is negative

Link: https://lkml.kernel.org/r/20220502175342.20296-1-rdunlap@infradead.org


Fixes: 82cae269 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Reported-by: default avatar <syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com>
Reviewed-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Cc: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Kari Argillander <kari.argillander@stargateuniverse.net>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
parent 261e0bd2
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -668,9 +668,11 @@ static u32 format_size_gb(const u64 bytes, u32 *mb)

static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
{
	return boot->sectors_per_clusters <= 0x80
		       ? boot->sectors_per_clusters
		       : (1u << (0 - boot->sectors_per_clusters));
	if (boot->sectors_per_clusters <= 0x80)
		return boot->sectors_per_clusters;
	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
		return 1U << (0 - boot->sectors_per_clusters);
	return -EINVAL;
}

/*
@@ -713,6 +715,8 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,

	/* cluster size: 512, 1K, 2K, 4K, ... 2M */
	sct_per_clst = true_sectors_per_clst(boot);
	if ((int)sct_per_clst < 0)
		goto out;
	if (!is_power_of_2(sct_per_clst))
		goto out;