Skip to content

Commit 91a4b1e

Browse files
fs/ntfs3: Fix shift-out-of-bounds in ntfs_fill_super
Reported-by: [email protected] Signed-off-by: Konstantin Komarov <[email protected]>
1 parent bfbe5b3 commit 91a4b1e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

fs/ntfs3/ntfs_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ enum utf16_endian;
4242
#define MINUS_ONE_T ((size_t)(-1))
4343
/* Biggest MFT / smallest cluster */
4444
#define MAXIMUM_BYTES_PER_MFT 4096
45+
#define MAXIMUM_SHIFT_BYTES_PER_MFT 12
4546
#define NTFS_BLOCKS_PER_MFT_RECORD (MAXIMUM_BYTES_PER_MFT / 512)
4647

4748
#define MAXIMUM_BYTES_PER_INDEX 4096
49+
#define MAXIMUM_SHIFT_BYTES_PER_INDEX 12
4850
#define NTFS_BLOCKS_PER_INODE (MAXIMUM_BYTES_PER_INDEX / 512)
4951

5052
/* NTFS specific error code when fixup failed. */

fs/ntfs3/super.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,17 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
899899
goto out;
900900
}
901901

902-
sbi->record_size = record_size =
903-
boot->record_size < 0 ? 1 << (-boot->record_size) :
904-
(u32)boot->record_size << cluster_bits;
902+
if (boot->record_size >= 0) {
903+
record_size = (u32)boot->record_size << cluster_bits;
904+
} else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) {
905+
record_size = 1u << (-boot->record_size);
906+
} else {
907+
ntfs_err(sb, "%s: invalid record size %d.", hint,
908+
boot->record_size);
909+
goto out;
910+
}
911+
912+
sbi->record_size = record_size;
905913
sbi->record_bits = blksize_bits(record_size);
906914
sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes
907915

@@ -918,9 +926,15 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
918926
goto out;
919927
}
920928

921-
sbi->index_size = boot->index_size < 0 ?
922-
1u << (-boot->index_size) :
923-
(u32)boot->index_size << cluster_bits;
929+
if (boot->index_size >= 0) {
930+
sbi->index_size = (u32)boot->index_size << cluster_bits;
931+
} else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) {
932+
sbi->index_size = 1u << (-boot->index_size);
933+
} else {
934+
ntfs_err(sb, "%s: invalid index size %d.", hint,
935+
boot->index_size);
936+
goto out;
937+
}
924938

925939
/* Check index record size. */
926940
if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) {

0 commit comments

Comments
 (0)