1 ext4 crypto: handle unexpected lack of encryption keys
3 Fix up attempts by users to try to write to a file when they don't
4 have access to the encryption key.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 fs/ext4/crypto.c | 3 ++-
9 fs/ext4/crypto_policy.c | 3 ++-
10 fs/ext4/file.c | 17 ++++++++++-------
11 3 files changed, 14 insertions(+), 9 deletions(-)
13 diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
14 index ac2419c..6634478 100644
15 --- a/fs/ext4/crypto.c
16 +++ b/fs/ext4/crypto.c
17 @@ -104,7 +104,8 @@ struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode)
19 struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
23 + return ERR_PTR(-ENOKEY);
26 * We first try getting the ctx from a free list because in
27 diff --git a/fs/ext4/crypto_policy.c b/fs/ext4/crypto_policy.c
28 index a1d434d..02c4e5d 100644
29 --- a/fs/ext4/crypto_policy.c
30 +++ b/fs/ext4/crypto_policy.c
31 @@ -183,7 +183,8 @@ int ext4_inherit_context(struct inode *parent, struct inode *child)
34 ci = EXT4_I(parent)->i_crypt_info;
39 ctx.format = EXT4_ENCRYPTION_CONTEXT_FORMAT_V1;
40 if (DUMMY_ENCRYPTION_ENABLED(EXT4_SB(parent->i_sb))) {
41 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
42 index 875ca6b..ac517f1 100644
45 @@ -226,6 +226,8 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
46 int err = ext4_get_encryption_info(inode);
49 + if (ext4_encryption_info(inode) == NULL)
53 if (IS_DAX(file_inode(file))) {
54 @@ -278,6 +280,13 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
55 ext4_journal_stop(handle);
58 + if (ext4_encrypted_inode(inode)) {
59 + ret = ext4_get_encryption_info(inode);
62 + if (ext4_encryption_info(inode) == NULL)
66 * Set up the jbd2_inode if we are opening the inode for
67 * writing and the journal is present
68 @@ -287,13 +296,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
72 - ret = dquot_file_open(inode, filp);
73 - if (!ret && ext4_encrypted_inode(inode)) {
74 - ret = ext4_get_encryption_info(inode);
79 + return dquot_file_open(inode, filp);