From 5914ad4c7f8ccb1cb9f7227d7712bd3e676dd825 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Aug 2022 13:16:55 +0200 Subject: [PATCH] 5.10-stable patches added patches: ext4-check-if-directory-block-is-within-i_size.patch --- ...-if-directory-block-is-within-i_size.patch | 51 +++++++++++++++++++ queue-5.10/series | 1 + 2 files changed, 52 insertions(+) create mode 100644 queue-5.10/ext4-check-if-directory-block-is-within-i_size.patch diff --git a/queue-5.10/ext4-check-if-directory-block-is-within-i_size.patch b/queue-5.10/ext4-check-if-directory-block-is-within-i_size.patch new file mode 100644 index 00000000000..39424c3838e --- /dev/null +++ b/queue-5.10/ext4-check-if-directory-block-is-within-i_size.patch @@ -0,0 +1,51 @@ +From 65f8ea4cd57dbd46ea13b41dc8bac03176b04233 Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Mon, 4 Jul 2022 16:27:20 +0200 +Subject: ext4: check if directory block is within i_size + +From: Lukas Czerner + +commit 65f8ea4cd57dbd46ea13b41dc8bac03176b04233 upstream. + +Currently ext4 directory handling code implicitly assumes that the +directory blocks are always within the i_size. In fact ext4_append() +will attempt to allocate next directory block based solely on i_size and +the i_size is then appropriately increased after a successful +allocation. + +However, for this to work it requires i_size to be correct. If, for any +reason, the directory inode i_size is corrupted in a way that the +directory tree refers to a valid directory block past i_size, we could +end up corrupting parts of the directory tree structure by overwriting +already used directory blocks when modifying the directory. + +Fix it by catching the corruption early in __ext4_read_dirblock(). + +Addresses Red-Hat-Bugzilla: #2070205 +CVE: CVE-2022-1184 +Signed-off-by: Lukas Czerner +Cc: stable@vger.kernel.org +Reviewed-by: Andreas Dilger +Link: https://lore.kernel.org/r/20220704142721.157985-1-lczerner@redhat.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/namei.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +--- a/fs/ext4/namei.c ++++ b/fs/ext4/namei.c +@@ -109,6 +109,13 @@ static struct buffer_head *__ext4_read_d + struct ext4_dir_entry *dirent; + int is_dx_block = 0; + ++ if (block >= inode->i_size) { ++ ext4_error_inode(inode, func, line, block, ++ "Attempting to read directory block (%u) that is past i_size (%llu)", ++ block, inode->i_size); ++ return ERR_PTR(-EFSCORRUPTED); ++ } ++ + if (ext4_simulate_fail(inode->i_sb, EXT4_SIM_DIRBLOCK_EIO)) + bh = ERR_PTR(-EIO); + else diff --git a/queue-5.10/series b/queue-5.10/series index c3f69209f74..42bbe9fc244 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -520,3 +520,4 @@ xen-blkfront-apply-feature_persistent-parameter-when-connect.patch keys-asymmetric-enforce-sm2-signature-use-pkey-algo.patch tpm-eventlog-fix-section-mismatch-for-debug_section_mismatch.patch tracing-use-a-struct-alignof-to-determine-trace-event-field-alignment.patch +ext4-check-if-directory-block-is-within-i_size.patch -- 2.47.3