Commit f4bb2981 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: add ext4_iget_normal() which is to be used for dir tree lookups

If there is a corrupted file system which has directory entries that
point at reserved, metadata inodes, prohibit them from being used by
treating them the same way we treat Boot Loader inodes --- that is,
mark them to be bad inodes.  This prohibits them from being opened,
deleted, or modified via chmod, chown, utimes, etc.

In particular, this prevents a corrupted file system which has a
directory entry which points at the journal inode from being deleted
and its blocks released, after which point Much Hilarity Ensues.
Reported-by: default avatarSami Liedes <sami.liedes@iki.fi>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
parent e2bfb088
...@@ -2109,6 +2109,7 @@ int do_journal_get_write_access(handle_t *handle, ...@@ -2109,6 +2109,7 @@ int do_journal_get_write_access(handle_t *handle,
#define CONVERT_INLINE_DATA 2 #define CONVERT_INLINE_DATA 2
extern struct inode *ext4_iget(struct super_block *, unsigned long); extern struct inode *ext4_iget(struct super_block *, unsigned long);
extern struct inode *ext4_iget_normal(struct super_block *, unsigned long);
extern int ext4_write_inode(struct inode *, struct writeback_control *); extern int ext4_write_inode(struct inode *, struct writeback_control *);
extern int ext4_setattr(struct dentry *, struct iattr *); extern int ext4_setattr(struct dentry *, struct iattr *);
extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
......
...@@ -4104,6 +4104,13 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) ...@@ -4104,6 +4104,13 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
struct inode *ext4_iget_normal(struct super_block *sb, unsigned long ino)
{
if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
return ERR_PTR(-EIO);
return ext4_iget(sb, ino);
}
static int ext4_inode_blocks_set(handle_t *handle, static int ext4_inode_blocks_set(handle_t *handle,
struct ext4_inode *raw_inode, struct ext4_inode *raw_inode,
struct ext4_inode_info *ei) struct ext4_inode_info *ei)
......
...@@ -1417,7 +1417,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi ...@@ -1417,7 +1417,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
dentry); dentry);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
inode = ext4_iget(dir->i_sb, ino); inode = ext4_iget_normal(dir->i_sb, ino);
if (inode == ERR_PTR(-ESTALE)) { if (inode == ERR_PTR(-ESTALE)) {
EXT4_ERROR_INODE(dir, EXT4_ERROR_INODE(dir,
"deleted inode referenced: %u", "deleted inode referenced: %u",
...@@ -1450,7 +1450,7 @@ struct dentry *ext4_get_parent(struct dentry *child) ...@@ -1450,7 +1450,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino)); return d_obtain_alias(ext4_iget_normal(child->d_inode->i_sb, ino));
} }
/* /*
......
...@@ -1001,7 +1001,7 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb, ...@@ -1001,7 +1001,7 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
* Currently we don't know the generation for parent directory, so * Currently we don't know the generation for parent directory, so
* a generation of 0 means "accept any" * a generation of 0 means "accept any"
*/ */
inode = ext4_iget(sb, ino); inode = ext4_iget_normal(sb, ino);
if (IS_ERR(inode)) if (IS_ERR(inode))
return ERR_CAST(inode); return ERR_CAST(inode);
if (generation && inode->i_generation != generation) { if (generation && inode->i_generation != generation) {
......
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