add patch fail-unalloc-root-dir-in-ext4_iget
[ext4-patch-queue.git] / fail-unalloc-root-dir-in-ext4_iget
blob4f980d802b3b8132ddfa8b145b2bb08543c43454
1 ext4: fail ext4_iget for root directory if unallocated
3 If the root directory has an i_links_count of zero, then when the file
4 system is mounted, then when ext4_fill_super() notices the problem and
5 tries to call iput() the root directory in the error return path,
6 ext4_evict_inode() will try to free the inode on disk, before all of
7 the file system structures are set up, and this will result in an OOPS
8 caused by a NULL pointer dereference.
10 https://bugzilla.kernel.org/show_bug.cgi?id=199179
12 Reported-by: Wen Xu <wen.xu@gatech.edu>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Cc: stable@vger.kernel.org
15 ---
16  fs/ext4/inode.c | 6 ++++++
17  1 file changed, 6 insertions(+)
19 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
20 index 951a3d69ed17..5adfd0980c71 100644
21 --- a/fs/ext4/inode.c
22 +++ b/fs/ext4/inode.c
23 @@ -4745,6 +4745,12 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
24                 goto bad_inode;
25         raw_inode = ext4_raw_inode(&iloc);
27 +       if ((ino == EXT4_ROOT_INO) && (raw_inode->i_links_count == 0)) {
28 +               EXT4_ERROR_INODE(inode, "root inode unallocated");
29 +               ret = -EFSCORRUPTED;
30 +               goto bad_inode;
31 +       }
33         if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
34                 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
35                 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >