diff options
author | Duane Griffin <duaneg@dghda.com> | 2008-07-11 19:27:31 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-07-11 19:27:31 -0400 |
commit | f3b35f063e9a795495fe2f7a2fe55fab11f8ab12 (patch) | |
tree | 6007687f02066794f3d218f710df717f1b72076c /fs/ext4 | |
parent | 71dc8fbcf5f6363342bd636a646eeac7cfef25c3 (diff) |
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: Duane Griffin <duaneg@dghda.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/namei.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index ab16beaa830d..384f1222602a 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -993,19 +993,21 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry, | |||
993 | de = (struct ext4_dir_entry_2 *) bh->b_data; | 993 | de = (struct ext4_dir_entry_2 *) bh->b_data; |
994 | top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize - | 994 | top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize - |
995 | EXT4_DIR_REC_LEN(0)); | 995 | EXT4_DIR_REC_LEN(0)); |
996 | for (; de < top; de = ext4_next_entry(de)) | 996 | for (; de < top; de = ext4_next_entry(de)) { |
997 | if (ext4_match (namelen, name, de)) { | 997 | int off = (block << EXT4_BLOCK_SIZE_BITS(sb)) |
998 | if (!ext4_check_dir_entry("ext4_find_entry", | 998 | + ((char *) de - bh->b_data); |
999 | dir, de, bh, | 999 | |
1000 | (block<<EXT4_BLOCK_SIZE_BITS(sb)) | 1000 | if (!ext4_check_dir_entry(__func__, dir, de, bh, off)) { |
1001 | +((char *)de - bh->b_data))) { | 1001 | brelse(bh); |
1002 | brelse (bh); | ||
1003 | *err = ERR_BAD_DX_DIR; | 1002 | *err = ERR_BAD_DX_DIR; |
1004 | goto errout; | 1003 | goto errout; |
1005 | } | 1004 | } |
1006 | *res_dir = de; | 1005 | |
1007 | dx_release (frames); | 1006 | if (ext4_match(namelen, name, de)) { |
1008 | return bh; | 1007 | *res_dir = de; |
1008 | dx_release(frames); | ||
1009 | return bh; | ||
1010 | } | ||
1009 | } | 1011 | } |
1010 | brelse (bh); | 1012 | brelse (bh); |
1011 | /* Check to see if we should continue to search */ | 1013 | /* Check to see if we should continue to search */ |