提交 d26377a7 编写于 作者: S Shreyansh Chouhan 提交者: Zheng Zengkai

reiserfs: check directory items on read from disk

stable inclusion
from stable-5.10.58
commit ecd8614809eb97dc48cf70c3bebeb7ddeb08c137
bugzilla: 176984 https://gitee.com/openeuler/kernel/issues/I4E2P4

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

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

[ Upstream commit 13d25750 ]

While verifying the leaf item that we read from the disk, reiserfs
doesn't check the directory items, this could cause a crash when we
read a directory item from the disk that has an invalid deh_location.

This patch adds a check to the directory items read from the disk that
does a bounds check on deh_location for the directory entries. Any
directory entry header with a directory entry offset greater than the
item length is considered invalid.

Link: https://lore.kernel.org/r/20210709152929.766363-1-chouhan.shreyansh630@gmail.com
Reported-by: syzbot+c31a48e6702ccb3d64c9@syzkaller.appspotmail.com
Signed-off-by: NShreyansh Chouhan <chouhan.shreyansh630@gmail.com>
Signed-off-by: NJan Kara <jack@suse.cz>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 0839acfc
...@@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path) ...@@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path)
search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
} }
static int has_valid_deh_location(struct buffer_head *bh, struct item_head *ih)
{
struct reiserfs_de_head *deh;
int i;
deh = B_I_DEH(bh, ih);
for (i = 0; i < ih_entry_count(ih); i++) {
if (deh_location(&deh[i]) > ih_item_len(ih)) {
reiserfs_warning(NULL, "reiserfs-5094",
"directory entry location seems wrong %h",
&deh[i]);
return 0;
}
}
return 1;
}
static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
{ {
struct block_head *blkh; struct block_head *blkh;
...@@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) ...@@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
"(second one): %h", ih); "(second one): %h", ih);
return 0; return 0;
} }
if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) { if (is_direntry_le_ih(ih)) {
reiserfs_warning(NULL, "reiserfs-5093", if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) {
"item entry count seems wrong %h", reiserfs_warning(NULL, "reiserfs-5093",
ih); "item entry count seems wrong %h",
return 0; ih);
return 0;
}
return has_valid_deh_location(bh, ih);
} }
prev_location = ih_location(ih); prev_location = ih_location(ih);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册