Skip to content

Commit

Permalink
ext4: don't orphan or truncate the boot loader inode
Browse files Browse the repository at this point in the history
The boot loader inode (inode #5) should never be visible in the
directory hierarchy, but it's possible if the file system is corrupted
that there will be a directory entry that points at inode #5.  In
order to avoid accidentally trashing it, when such a directory inode
is opened, the inode will be marked as a bad inode, so that it's not
possible to modify (or read) the inode from userspace.

Unfortunately, when we unlink this (invalid/illegal) directory entry,
we will put the bad inode on the ophan list, and then when try to
unlink the directory, we don't actually remove the bad inode from the
orphan list before freeing in-memory inode structure.  This means the
in-memory orphan list is corrupted, leading to a kernel oops.

In addition, avoid truncating a bad inode in ext4_destroy_inode(),
since truncating the boot loader inode is not a smart thing to do.

Reported-by: Sami Liedes <sami.liedes@iki.fi>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
  • Loading branch information
Theodore Ts'o committed Oct 6, 2014
1 parent 3e67cfa commit e2bfb08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,15 @@ void ext4_evict_inode(struct inode *inode)
goto no_delete;
}

if (!is_bad_inode(inode))
dquot_initialize(inode);
if (is_bad_inode(inode))
goto no_delete;
dquot_initialize(inode);

if (ext4_should_order_data(inode))
ext4_begin_ordered_truncate(inode, 0);
truncate_inode_pages_final(&inode->i_data);

WARN_ON(atomic_read(&EXT4_I(inode)->i_ioend_count));
if (is_bad_inode(inode))
goto no_delete;

/*
* Protect us against freezing - iput() caller didn't have to have any
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
int err = 0, rc;
bool dirty = false;

if (!sbi->s_journal)
if (!sbi->s_journal || is_bad_inode(inode))
return 0;

WARN_ON_ONCE(!(inode->i_state & (I_NEW | I_FREEING)) &&
Expand Down

0 comments on commit e2bfb08

Please sign in to comment.