1 ext4: add ext4_iget_normal() which is to be used for dir tree lookups
3 If there is a corrupted file system which has directory entries that
4 point at reserved, metadata inodes, prohibit them from being used by
5 treating them the same way we treat Boot Loader inodes --- that is,
6 mark them to be bad inodes. This prohibits them from being opened,
7 deleted, or modified via chmod, chown, utimes, etc.
9 In particular, this prevents a corrupted file system which has a
10 directory entry which points at the journal inode from being deleted
11 and its blocks released, after which point Much Hilarity Ensues.
13 Reported-by: Sami Liedes <sami.liedes@iki.fi>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 Cc: stable@vger.kernel.org
19 fs/ext4/inode.c | 7 +++++++
20 fs/ext4/namei.c | 4 ++--
21 fs/ext4/super.c | 2 +-
22 4 files changed, 11 insertions(+), 3 deletions(-)
24 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
25 index 1eb5b7b..012e89b 100644
28 @@ -2109,6 +2109,7 @@ int do_journal_get_write_access(handle_t *handle,
29 #define CONVERT_INLINE_DATA 2
31 extern struct inode *ext4_iget(struct super_block *, unsigned long);
32 +extern struct inode *ext4_iget_normal(struct super_block *, unsigned long);
33 extern int ext4_write_inode(struct inode *, struct writeback_control *);
34 extern int ext4_setattr(struct dentry *, struct iattr *);
35 extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
36 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
37 index 59983b2..e204d8a 100644
40 @@ -4104,6 +4104,13 @@ bad_inode:
44 +struct inode *ext4_iget_normal(struct super_block *sb, unsigned long ino)
46 + if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
47 + return ERR_PTR(-EIO);
48 + return ext4_iget(sb, ino);
51 static int ext4_inode_blocks_set(handle_t *handle,
52 struct ext4_inode *raw_inode,
53 struct ext4_inode_info *ei)
54 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
55 index a2a9d40..7037ecf 100644
58 @@ -1417,7 +1417,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
62 - inode = ext4_iget(dir->i_sb, ino);
63 + inode = ext4_iget_normal(dir->i_sb, ino);
64 if (inode == ERR_PTR(-ESTALE)) {
66 "deleted inode referenced: %u",
67 @@ -1450,7 +1450,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
71 - return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino));
72 + return d_obtain_alias(ext4_iget_normal(child->d_inode->i_sb, ino));
76 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
77 index 1070d6e..a0811cc 100644
80 @@ -1001,7 +1001,7 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
81 * Currently we don't know the generation for parent directory, so
82 * a generation of 0 means "accept any"
84 - inode = ext4_iget(sb, ino);
85 + inode = ext4_iget_normal(sb, ino);
87 return ERR_CAST(inode);
88 if (generation && inode->i_generation != generation) {