提交 d9dc377b 编写于 作者: L Lukas Czerner 提交者: Yongqiang Liu

ext4: check if directory block is within i_size

mainline inclusion
from mainline-v6.0-rc1
commit 65f8ea4c
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I58WSQ
CVE: CVE-2022-1184

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

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: NLukas Czerner <lczerner@redhat.com>
Cc: stable@vger.kernel.org
Reviewed-by: NAndreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/20220704142721.157985-1-lczerner@redhat.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>

Conflicts:
	fs/ext4/namei.c
Signed-off-by: NBaokun Li <libaokun1@huawei.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 01b1ec1d
...@@ -124,6 +124,13 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, ...@@ -124,6 +124,13 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
struct ext4_dir_entry *dirent; struct ext4_dir_entry *dirent;
int is_dx_block = 0; 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);
}
bh = ext4_bread(NULL, inode, block, 0); bh = ext4_bread(NULL, inode, block, 0);
if (IS_ERR(bh)) { if (IS_ERR(bh)) {
__ext4_warning(inode->i_sb, func, line, __ext4_warning(inode->i_sb, func, line,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册