Commit f3b35f06 authored by Duane Griffin's avatar Duane Griffin Committed by Theodore Ts'o

ext4: validate directory entry data before use

ext4_dx_find_entry uses ext4_next_entry without verifying that the entry is
valid. If its rec_len == 0 this causes an infinite loop. Refactor the loop
to check the validity of entries before checking whether they match and
moving onto the next one.

There are other uses of ext4_next_entry in this file which also look
problematic. They should be reviewed and fixed if/when we have a test-case
that triggers them.

This patch fixes the first case (image hdb.25.softlockup.gz) reported in
http://bugzilla.kernel.org/show_bug.cgi?id=10882.
Signed-off-by: default avatarDuane Griffin <duaneg@dghda.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 71dc8fbc
...@@ -993,19 +993,21 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry, ...@@ -993,19 +993,21 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
de = (struct ext4_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize - top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
EXT4_DIR_REC_LEN(0)); EXT4_DIR_REC_LEN(0));
for (; de < top; de = ext4_next_entry(de)) for (; de < top; de = ext4_next_entry(de)) {
if (ext4_match (namelen, name, de)) { int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
if (!ext4_check_dir_entry("ext4_find_entry", + ((char *) de - bh->b_data);
dir, de, bh,
(block<<EXT4_BLOCK_SIZE_BITS(sb)) if (!ext4_check_dir_entry(__func__, dir, de, bh, off)) {
+((char *)de - bh->b_data))) { brelse(bh);
brelse (bh);
*err = ERR_BAD_DX_DIR; *err = ERR_BAD_DX_DIR;
goto errout; goto errout;
} }
*res_dir = de;
dx_release (frames); if (ext4_match(namelen, name, de)) {
return bh; *res_dir = de;
dx_release(frames);
return bh;
}
} }
brelse (bh); brelse (bh);
/* Check to see if we should continue to search */ /* Check to see if we should continue to search */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment