fscrypt: remove checks for encryption key after file open
Subsystems (5)
cover fscrypt: remove checks for encryption key after file open
From: Eric Biggers <[email protected]>
This series removes checks for a regular file's encryption key that occur after we've already opened the file. We're guaranteed to already have the key in such places, since we require it in ->open(). open() fails with ENOKEY otherwise, and a file descriptor is never made available.
This pertains to regular files only. (Directories can be opened with or without their key.)
Eric Biggers (4):
ext4: don't bother checking for encryption key in ->mmap()
f2fs: don't bother checking for encryption key in ->mmap()
ubifs: don't bother checking for encryption key in ->mmap()
f2fs: don't bother checking for encryption key in ->write_iter()
fs/ext4/file.c | 7 ------- fs/f2fs/file.c | 13 ------------- fs/ubifs/file.c | 9 --------- 3 files changed, 29 deletions(-)
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 1/4 ext4: don't bother checking for encryption key in ->mmap()
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each mmap().
--- fs/ext4/file.c | 7 ------- 1 file changed, 7 deletions(-)
fs/ext4/file.c +0 -7
@@ -345,13 +345,6 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb))))return -EIO ; -if (ext4_encrypted_inode (inode)) { -int err =fscrypt_get_encryption_info (inode); -if (err) -return 0 ; -if (!fscrypt_has_encryption_key (inode)) -return -ENOKEY ; - }file_accessed (file);if (IS_DAX (file_inode (file))) { vma->vm_ops = &ext4_dax_vm_ops;
Signature · 1 line
2.13.0.303.g4ebf302169-goog
Re: [PATCH 1/4] ext4: don't bother checking for encryption key in ->mmap()
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().Signed-off-by Eric Biggers <[email protected]>
Thanks, applied.
- Ted
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 2/4 f2fs: don't bother checking for encryption key in ->mmap()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each mmap().
This f2fs copy of this code was also broken in that it wouldn't actually have failed if the key was in fact unavailable.
--- fs/f2fs/file.c | 8 -------- 1 file changed, 8 deletions(-)
fs/f2fs/file.c +0 -7
@@ -415,14 +415,6 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)struct inode *inode =file_inode (file);int err; -if (f2fs_encrypted_inode (inode)) { - err =fscrypt_get_encryption_info (inode); -if (err) -return 0 ; -if (!f2fs_encrypted_inode (inode)) -return -ENOKEY ; - }
Re: [f2fs-dev] [PATCH 2/4] f2fs: don't bother checking for encryption key in ->mmap()
Quoted 10 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().This f2fs copy of this code was also broken in that it wouldn't actually have failed if the key was in fact unavailable.
Signed-off-by Eric Biggers <[email protected]>
Thanks,
Quoted 24 lines
--- fs/f2fs/file.c | 8 -------- 1 file changed, 8 deletions(-)fs/f2fs/file.c +0
-8@@ -415,14 +415,6 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)struct inode *inode =file_inode (file);int err; -if (f2fs_encrypted_inode (inode)) { - err =fscrypt_get_encryption_info (inode); -if (err) -return 0 ; -if (!f2fs_encrypted_inode (inode)) -return -ENOKEY ; - } -/* we don't need to use inline_data strictly */ err =f2fs_convert_inline_inode (inode);if (err)
PATCH 3/4 ubifs: don't bother checking for encryption key in ->mmap()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each mmap().
--- fs/ubifs/file.c | 9 --------- 1 file changed, 9 deletions(-)
fs/ubifs/file.c +0 -1
@@ -1607,15 +1607,6 @@ static const struct vm_operations_struct ubifs_file_vm_ops = {static int ubifs_file_mmap (struct file *file,struct vm_area_struct *vma) {int err; -struct inode *inode = file->f_mapping->host;
Re: [PATCH 3/4] ubifs: don't bother checking for encryption key in ->mmap()
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().Signed-off-by Eric Biggers <[email protected]>
Signature · 2 lines
Thanks, //richard
Theodore Ts'o
maintainerRe: [PATCH 3/4] ubifs: don't bother checking for encryption key in ->mmap()
Quoted 10 lines · Richard Weinberger
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().Signed-off-by Eric Biggers <[email protected]>
There are some patches that were sent to linux-fscrypt (including this one) that are specific to ubifs that don't appear to be in linux-next as of this writing.
I can include them in the fscrypt tree (which I am updating somewhat belatedly; sorry, crazy travel schedule has made me be late attending to fscrypt), but it probably makes more sense for the change to go in via the ubifs tree. The f2fs version of the "don't bother checking for encryption key" is already in linux-next, via the f2fs tree, for example.
So I'm planning on NOT taking the ubifs-specific patches that are in the linux-fscrypto patch queue; unless Richard, you want to specifically ask me to do so.
Cheers,
- Ted
Re: [PATCH 3/4] ubifs: don't bother checking for encryption key in ->mmap()
Ted + Richard,
Quoted 23 lines · Theodore Ts'o
Quoted 10 lines · Richard Weinberger
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().Signed-off-by Eric Biggers <[email protected]>There are some patches that were sent to linux-fscrypt (including this one) that are specific to ubifs that don't appear to be in linux-next as of this writing.
I can include them in the fscrypt tree (which I am updating somewhat belatedly; sorry, crazy travel schedule has made me be late attending to fscrypt), but it probably makes more sense for the change to go in via the ubifs tree. The f2fs version of the "don't bother checking for encryption key" is already in linux-next, via the f2fs tree, for example.
Quoted 4 lines
So I'm planning on NOT taking the ubifs-specific patches that are in the linux-fscrypto patch queue; unless Richard, you want to specifically ask me to do so.
The mmap and truncate patches were basically the same for each filesystem, but yes it's fine for them to go in separately. Richard, can you take for ubifs:
ubifs: don't bother checking for encryption key in ->mmap() ubifs: require key for truncate(2) of encrypted file
and Ted can you take for ext4:
ext4: don't bother checking for encryption key in ->mmap() ext4: require key for truncate(2) of encrypted file
- Eric
Richard Weinberger
maintainerRe: [PATCH 3/4] ubifs: don't bother checking for encryption key in ->mmap()
Ted, Eric,
Am 23.06.2017 um 19:18 schrieb Eric Biggers:
Quoted 31 lines
Ted + Richard,
Quoted 23 lines · Theodore Ts'o
Quoted 10 lines · Richard Weinberger
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be mmap'ed, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each
mmap().Signed-off-by Eric Biggers <[email protected]>There are some patches that were sent to linux-fscrypt (including this one) that are specific to ubifs that don't appear to be in linux-next as of this writing.
I can include them in the fscrypt tree (which I am updating somewhat belatedly; sorry, crazy travel schedule has made me be late attending to fscrypt), but it probably makes more sense for the change to go in via the ubifs tree. The f2fs version of the "don't bother checking for encryption key" is already in linux-next, via the f2fs tree, for example.
Quoted 4 lines
So I'm planning on NOT taking the ubifs-specific patches that are in the linux-fscrypto patch queue; unless Richard, you want to specifically ask me to do so.
Quoted 5 lines
The mmap and truncate patches were basically the same for each filesystem, but yes it's fine for them to go in separately. Richard, can you take for ubifs:
ubifs: don't bother checking for encryption key in ->mmap() ubifs: require key for truncate(2) of encrypted file
Alright, I'll carry them. :-)
The plan is that the fscrypt tree will just contain fscrypt "core" patches and global changes/cleanups go thought the individual filesystem trees, right?
Thanks,
//richard
Theodore Ts'o
maintainerRe: [PATCH 3/4] ubifs: don't bother checking for encryption key in ->mmap()
Quoted 3 lines · Richard Weinberger
The plan is that the fscrypt tree will just contain fscrypt "core" patches and global changes/cleanups go thought the individual filesystem trees, right?
Yes, it minimizes potential conflicts against other individual file system trees if we keep patches that are file system specific in their own tree.
There will be times when we can't do that --- for example, if we need to make a change in the fscrypt directory that requires matching changes in all of the users of fscrypt at the same time. But when we do that there is always the chance that there will be merge conflicts that have to be manually reconciled by both Stephen Rothwell for linux-next and Linus during the merge window. But if we can avoid needing to do that, it's generally easier for all concerned.
Cheers,
- Ted
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 4/4 f2fs: don't bother checking for encryption key in ->write_iter()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Since only an open file can be written to, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each ->write_iter().
This code was also broken in that it wouldn't actually have failed if the key was in fact unavailable.
--- fs/f2fs/file.c | 5 ----- 1 file changed, 5 deletions(-)
fs/f2fs/file.c +0 -4
@@ -2318,11 +2318,6 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)struct blk_plug plug;ssize_t ret; -if (f2fs_encrypted_inode (inode) && - !fscrypt_has_encryption_key (inode) && -fscrypt_get_encryption_info (inode)) -return -EACCES ;
Re: [PATCH 4/4] f2fs: don't bother checking for encryption key in ->write_iter()
Quoted 10 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since only an open file can be written to, and we only allow open()ing an encrypted file when its key is available, there is no need to check for the key again before permitting each ->write_iter().
This code was also broken in that it wouldn't actually have failed if the key was in fact unavailable.
Signed-off-by Eric Biggers <[email protected]>
Thanks,
Quoted 11 lines
--- fs/f2fs/file.c | 5 ----- 1 file changed, 5 deletions(-)fs/f2fs/file.c +0
-0@@ -2318,11 +2318,6 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)struct blk_plug plug;
fs/f2fs/file.c static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · line 2323
Quoted 10 lines
fs/f2fs/file.c +0
-5ssize_t ret; -if (f2fs_encrypted_inode (inode) && - !fscrypt_has_encryption_key (inode) && -fscrypt_get_encryption_info (inode)) -return -EACCES ; -inode_lock (inode); ret =generic_write_checks (iocb, from);if (ret >0 ) {
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Eric,
Quoted 18 lines · Eric Biggers
From: Eric Biggers <[email protected]>
This series removes checks for a regular file's encryption key that occur after we've already opened the file. We're guaranteed to already have the key in such places, since we require it in ->open().
open()fails with ENOKEY otherwise, and a file descriptor is never made available.This pertains to regular files only. (Directories can be opened with or without their key.)
Eric Biggers (4):
ext4: don't bother checking for encryption key in ->mmap()
f2fs: don't bother checking for encryption key in ->mmap()
ubifs: don't bother checking for encryption key in ->mmap()
f2fs: don't bother checking for encryption key in ->write_iter()
Quoted 4 lines
fs/ext4/file.c | 7 ------- fs/f2fs/file.c | 13 ------------- fs/ubifs/file.c | 9 --------- 3 files changed, 29 deletions(-)
The whole series looks good to me. So feel free to add my
David