diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2014-07-28 19:06:26 +0200 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-07-28 19:06:26 +0200 |
commit | 40b163f1c45f52752677e66d2fd273dbfd273a22 (patch) | |
tree | 9047b84d0ab4086388c351d2f49e3ed1fba576d0 /fs/ext4/dir.c | |
parent | ext4: fix incorrect locking in move_extent_per_page (diff) | |
download | linux-40b163f1c45f52752677e66d2fd273dbfd273a22.tar.xz linux-40b163f1c45f52752677e66d2fd273dbfd273a22.zip |
ext4: check inline directory before converting
Before converting an inline directory to a regular directory, check
the directory entries to make sure they're not obviously broken.
This helps us to avoid a BUG_ON if one of the dirents is trashed.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Diffstat (limited to 'fs/ext4/dir.c')
-rw-r--r-- | fs/ext4/dir.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index ef1bed66c14f..0bb3f9ea0832 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -571,6 +571,31 @@ static int ext4_release_dir(struct inode *inode, struct file *filp) return 0; } +int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf, + int buf_size) +{ + struct ext4_dir_entry_2 *de; + int nlen, rlen; + unsigned int offset = 0; + char *top; + + de = (struct ext4_dir_entry_2 *)buf; + top = buf + buf_size; + while ((char *) de < top) { + if (ext4_check_dir_entry(dir, NULL, de, bh, + buf, buf_size, offset)) + return -EIO; + nlen = EXT4_DIR_REC_LEN(de->name_len); + rlen = ext4_rec_len_from_disk(de->rec_len, buf_size); + de = (struct ext4_dir_entry_2 *)((char *)de + rlen); + offset += rlen; + } + if ((char *) de > top) + return -EIO; + + return 0; +} + const struct file_operations ext4_dir_operations = { .llseek = ext4_dir_llseek, .read = generic_read_dir, |