Skip to content

Commit 105c78e

Browse files
ebiggerstytso
authored andcommitted
ext4: don't allow journal inode to have encrypt flag
Mounting a filesystem whose journal inode has the encrypt flag causes a NULL dereference in fscrypt_limit_io_blocks() when the 'inlinecrypt' mount option is used. The problem is that when jbd2_journal_init_inode() calls bmap(), it eventually finds its way into ext4_iomap_begin(), which calls fscrypt_limit_io_blocks(). fscrypt_limit_io_blocks() requires that if the inode is encrypted, then its encryption key must already be set up. That's not the case here, since the journal inode is never "opened" like a normal file would be. Hence the crash. A reproducer is: mkfs.ext4 -F /dev/vdb debugfs -w /dev/vdb -R "set_inode_field <8> flags 0x80808" mount /dev/vdb /mnt -o inlinecrypt To fix this, make ext4 consider journal inodes with the encrypt flag to be invalid. (Note, maybe other flags should be rejected on the journal inode too. For now, this is just the minimal fix for the above issue.) I've marked this as fixing the commit that introduced the call to fscrypt_limit_io_blocks(), since that's what made an actual crash start being possible. But this fix could be applied to any version of ext4 that supports the encrypt feature. Reported-by: [email protected] Fixes: 38ea50d ("ext4: support direct I/O with fscrypt using blk-crypto") Cc: [email protected] Signed-off-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent 3bf678a commit 105c78e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/ext4/super.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5723,7 +5723,7 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb,
57235723

57245724
ext4_debug("Journal inode found at %p: %lld bytes\n",
57255725
journal_inode, journal_inode->i_size);
5726-
if (!S_ISREG(journal_inode->i_mode)) {
5726+
if (!S_ISREG(journal_inode->i_mode) || IS_ENCRYPTED(journal_inode)) {
57275727
ext4_msg(sb, KERN_ERR, "invalid journal inode");
57285728
iput(journal_inode);
57295729
return NULL;

0 commit comments

Comments
 (0)