From: Greg Kroah-Hartman Date: Sun, 16 Oct 2022 13:13:41 +0000 (+0200) Subject: 6.0-stable patches X-Git-Tag: v5.4.219~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ea56834b94679eb656df0482c731683780d9fc6;p=thirdparty%2Fkernel%2Fstable-queue.git 6.0-stable patches added patches: ext2-add-sanity-checks-for-group-and-filesystem-size.patch ext4-avoid-crash-when-inline-data-creation-follows-dio-write.patch --- diff --git a/queue-6.0/ext2-add-sanity-checks-for-group-and-filesystem-size.patch b/queue-6.0/ext2-add-sanity-checks-for-group-and-filesystem-size.patch new file mode 100644 index 00000000000..6510033d73a --- /dev/null +++ b/queue-6.0/ext2-add-sanity-checks-for-group-and-filesystem-size.patch @@ -0,0 +1,56 @@ +From d766f2d1e3e3bd44024a7f971ffcf8b8fbb7c5d2 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Wed, 14 Sep 2022 17:24:42 +0200 +Subject: ext2: Add sanity checks for group and filesystem size + +From: Jan Kara + +commit d766f2d1e3e3bd44024a7f971ffcf8b8fbb7c5d2 upstream. + +Add sanity check that filesystem size does not exceed the underlying +device size and that group size is big enough so that metadata can fit +into it. This avoid trying to mount some crafted filesystems with +extremely large group counts. + +Reported-by: syzbot+0f2f7e65a3007d39539f@syzkaller.appspotmail.com +Reported-by: kernel test robot # Test fixup +CC: stable@vger.kernel.org +Signed-off-by: Jan Kara +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext2/super.c | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +--- a/fs/ext2/super.c ++++ b/fs/ext2/super.c +@@ -1052,6 +1052,13 @@ static int ext2_fill_super(struct super_ + sbi->s_blocks_per_group); + goto failed_mount; + } ++ /* At least inode table, bitmaps, and sb have to fit in one group */ ++ if (sbi->s_blocks_per_group <= sbi->s_itb_per_group + 3) { ++ ext2_msg(sb, KERN_ERR, ++ "error: #blocks per group smaller than metadata size: %lu <= %lu", ++ sbi->s_blocks_per_group, sbi->s_inodes_per_group + 3); ++ goto failed_mount; ++ } + if (sbi->s_frags_per_group > sb->s_blocksize * 8) { + ext2_msg(sb, KERN_ERR, + "error: #fragments per group too big: %lu", +@@ -1065,9 +1072,14 @@ static int ext2_fill_super(struct super_ + sbi->s_inodes_per_group); + goto failed_mount; + } ++ if (sb_bdev_nr_blocks(sb) < le32_to_cpu(es->s_blocks_count)) { ++ ext2_msg(sb, KERN_ERR, ++ "bad geometry: block count %u exceeds size of device (%u blocks)", ++ le32_to_cpu(es->s_blocks_count), ++ (unsigned)sb_bdev_nr_blocks(sb)); ++ goto failed_mount; ++ } + +- if (EXT2_BLOCKS_PER_GROUP(sb) == 0) +- goto cantfind_ext2; + sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) - + le32_to_cpu(es->s_first_data_block) - 1) + / EXT2_BLOCKS_PER_GROUP(sb)) + 1; diff --git a/queue-6.0/ext4-avoid-crash-when-inline-data-creation-follows-dio-write.patch b/queue-6.0/ext4-avoid-crash-when-inline-data-creation-follows-dio-write.patch new file mode 100644 index 00000000000..b9fd031a457 --- /dev/null +++ b/queue-6.0/ext4-avoid-crash-when-inline-data-creation-follows-dio-write.patch @@ -0,0 +1,78 @@ +From 4bb26f2885ac6930984ee451b952c5a6042f2c0e Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Wed, 27 Jul 2022 17:57:53 +0200 +Subject: ext4: avoid crash when inline data creation follows DIO write + +From: Jan Kara + +commit 4bb26f2885ac6930984ee451b952c5a6042f2c0e upstream. + +When inode is created and written to using direct IO, there is nothing +to clear the EXT4_STATE_MAY_INLINE_DATA flag. Thus when inode gets +truncated later to say 1 byte and written using normal write, we will +try to store the data as inline data. This confuses the code later +because the inode now has both normal block and inline data allocated +and the confusion manifests for example as: + +kernel BUG at fs/ext4/inode.c:2721! +invalid opcode: 0000 [#1] PREEMPT SMP KASAN +CPU: 0 PID: 359 Comm: repro Not tainted 5.19.0-rc8-00001-g31ba1e3b8305-dirty #15 +Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-1.fc36 04/01/2014 +RIP: 0010:ext4_writepages+0x363d/0x3660 +RSP: 0018:ffffc90000ccf260 EFLAGS: 00010293 +RAX: ffffffff81e1abcd RBX: 0000008000000000 RCX: ffff88810842a180 +RDX: 0000000000000000 RSI: 0000008000000000 RDI: 0000000000000000 +RBP: ffffc90000ccf650 R08: ffffffff81e17d58 R09: ffffed10222c680b +R10: dfffe910222c680c R11: 1ffff110222c680a R12: ffff888111634128 +R13: ffffc90000ccf880 R14: 0000008410000000 R15: 0000000000000001 +FS: 00007f72635d2640(0000) GS:ffff88811b000000(0000) knlGS:0000000000000000 +CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +CR2: 0000565243379180 CR3: 000000010aa74000 CR4: 0000000000150eb0 +Call Trace: + + do_writepages+0x397/0x640 + filemap_fdatawrite_wbc+0x151/0x1b0 + file_write_and_wait_range+0x1c9/0x2b0 + ext4_sync_file+0x19e/0xa00 + vfs_fsync_range+0x17b/0x190 + ext4_buffered_write_iter+0x488/0x530 + ext4_file_write_iter+0x449/0x1b90 + vfs_write+0xbcd/0xf40 + ksys_write+0x198/0x2c0 + __x64_sys_write+0x7b/0x90 + do_syscall_64+0x3d/0x90 + entry_SYSCALL_64_after_hwframe+0x63/0xcd + + +Fix the problem by clearing EXT4_STATE_MAY_INLINE_DATA when we are doing +direct IO write to a file. + +Cc: stable@kernel.org +Reported-by: Tadeusz Struk +Reported-by: syzbot+bd13648a53ed6933ca49@syzkaller.appspotmail.com +Link: https://syzkaller.appspot.com/bug?id=a1e89d09bbbcbd5c4cb45db230ee28c822953984 +Signed-off-by: Jan Kara +Reviewed-by: Lukas Czerner +Tested-by: Tadeusz Struk +Link: https://lore.kernel.org/r/20220727155753.13969-1-jack@suse.cz +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/file.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/fs/ext4/file.c ++++ b/fs/ext4/file.c +@@ -528,6 +528,12 @@ static ssize_t ext4_dio_write_iter(struc + ret = -EAGAIN; + goto out; + } ++ /* ++ * Make sure inline data cannot be created anymore since we are going ++ * to allocate blocks for DIO. We know the inode does not have any ++ * inline data now because ext4_dio_supported() checked for that. ++ */ ++ ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); + + offset = iocb->ki_pos; + count = ret; diff --git a/queue-6.0/series b/queue-6.0/series index bbf6c07665d..a1558380d20 100644 --- a/queue-6.0/series +++ b/queue-6.0/series @@ -131,3 +131,5 @@ jbd2-wake-up-journal-waiters-in-fifo-order-not-lifo.patch jbd2-fix-potential-buffer-head-reference-count-leak.patch jbd2-fix-potential-use-after-free-in-jbd2_fc_wait_bufs.patch jbd2-add-miss-release-buffer-head-in-fc_do_one_pass.patch +ext2-add-sanity-checks-for-group-and-filesystem-size.patch +ext4-avoid-crash-when-inline-data-creation-follows-dio-write.patch