ext4: check inline directory before converting
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 28 Jul 2014 17:06:26 +0000 (13:06 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 28 Jul 2014 17:06:26 +0000 (13:06 -0400)
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>
fs/ext4/dir.c
fs/ext4/ext4.h
fs/ext4/inline.c

index ef1bed66c14f393f9ad2025177b4b98f6c53bd9b..0bb3f9ea08329a46d27f75160a6b42718fed6042 100644 (file)
@@ -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,
index 321760d6b353c7da4f4a888c635d68b5bba2bf8a..5b19760b1de59ddc6340f8845832c031a272a4db 100644 (file)
@@ -2028,6 +2028,8 @@ static inline  unsigned char get_dtype(struct super_block *sb, int filetype)
 
        return ext4_filetype_table[filetype];
 }
+extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh,
+                            void *buf, int buf_size);
 
 /* fsync.c */
 extern int ext4_sync_file(struct file *, loff_t, loff_t, int);
index 141b6acbc51c3665e25b0fa6b9e4b9c01d8f3517..bea662bd0ca6b921b15c1bda0aab950a2fec2c78 100644 (file)
@@ -1172,6 +1172,18 @@ static int ext4_convert_inline_data_nolock(handle_t *handle,
        if (error < 0)
                goto out;
 
+       /*
+        * Make sure the inline directory entries pass checks before we try to
+        * convert them, so that we avoid touching stuff that needs fsck.
+        */
+       if (S_ISDIR(inode->i_mode)) {
+               error = ext4_check_all_de(inode, iloc->bh,
+                                       buf + EXT4_INLINE_DOTDOT_SIZE,
+                                       inline_size - EXT4_INLINE_DOTDOT_SIZE);
+               if (error)
+                       goto out;
+       }
+
        error = ext4_destroy_inline_data_nolock(handle, inode);
        if (error)
                goto out;
This page took 0.031782 seconds and 5 git commands to generate.