Skip to content

Commit e2bfb08

Browse files
committed
ext4: don't orphan or truncate the boot loader inode
The boot loader inode (inode raspberrypi#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 raspberrypi#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
1 parent 3e67cfa commit e2bfb08

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

‎fs/ext4/inode.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,15 @@ void ext4_evict_inode(struct inode *inode)
224224
goto no_delete;
225225
}
226226

227-
if (!is_bad_inode(inode))
228-
dquot_initialize(inode);
227+
if (is_bad_inode(inode))
228+
goto no_delete;
229+
dquot_initialize(inode);
229230

230231
if (ext4_should_order_data(inode))
231232
ext4_begin_ordered_truncate(inode, 0);
232233
truncate_inode_pages_final(&inode->i_data);
233234

234235
WARN_ON(atomic_read(&EXT4_I(inode)->i_ioend_count));
235-
if (is_bad_inode(inode))
236-
goto no_delete;
237236

238237
/*
239238
* Protect us against freezing - iput() caller didn't have to have any

‎fs/ext4/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
25442544
int err = 0, rc;
25452545
bool dirty = false;
25462546

2547-
if (!sbi->s_journal)
2547+
if (!sbi->s_journal || is_bad_inode(inode))
25482548
return 0;
25492549

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

0 commit comments

Comments
 (0)