Skip to content

Commit cd0265f

Browse files
ebiggerstytso
authored andcommitted
fscrypt: drop inode argument from fscrypt_get_ctx()
The only reason the inode is being passed to fscrypt_get_ctx() is to verify that the encryption key is available. However, all callers already ensure this because if we get as far as trying to do I/O to an encrypted file without the key, there's already a bug. Therefore, remove this unnecessary argument. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent dc4060a commit cd0265f

4 files changed

Lines changed: 9 additions & 16 deletions

File tree

‎fs/crypto/bio.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
104104

105105
BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE);
106106

107-
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
107+
ctx = fscrypt_get_ctx(GFP_NOFS);
108108
if (IS_ERR(ctx))
109109
return PTR_ERR(ctx);
110110

‎fs/crypto/crypto.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,17 @@ EXPORT_SYMBOL(fscrypt_release_ctx);
8787

8888
/**
8989
* fscrypt_get_ctx() - Gets an encryption context
90-
* @inode: The inode for which we are doing the crypto
9190
* @gfp_flags: The gfp flag for memory allocation
9291
*
9392
* Allocates and initializes an encryption context.
9493
*
95-
* Return: An allocated and initialized encryption context on success; error
96-
* value or NULL otherwise.
94+
* Return: A new encryption context on success; an ERR_PTR() otherwise.
9795
*/
98-
struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, gfp_t gfp_flags)
96+
struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
9997
{
100-
struct fscrypt_ctx *ctx = NULL;
101-
struct fscrypt_info *ci = inode->i_crypt_info;
98+
struct fscrypt_ctx *ctx;
10299
unsigned long flags;
103100

104-
if (ci == NULL)
105-
return ERR_PTR(-ENOKEY);
106-
107101
/*
108102
* We first try getting the ctx from a free list because in
109103
* the common case the ctx will have an allocated and
@@ -258,9 +252,9 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
258252

259253
BUG_ON(!PageLocked(page));
260254

261-
ctx = fscrypt_get_ctx(inode, gfp_flags);
255+
ctx = fscrypt_get_ctx(gfp_flags);
262256
if (IS_ERR(ctx))
263-
return (struct page *)ctx;
257+
return ERR_CAST(ctx);
264258

265259
/* The encryption operation will require a bounce page. */
266260
ciphertext_page = fscrypt_alloc_bounce_page(ctx, gfp_flags);

‎fs/ext4/readpage.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
244244
struct fscrypt_ctx *ctx = NULL;
245245

246246
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) {
247-
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
247+
ctx = fscrypt_get_ctx(GFP_NOFS);
248248
if (IS_ERR(ctx))
249249
goto set_error_page;
250250
}

‎include/linux/fscrypt.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
9090

9191
/* crypto.c */
9292
extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
93-
extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
93+
extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
9494
extern void fscrypt_release_ctx(struct fscrypt_ctx *);
9595
extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
9696
unsigned int, unsigned int,
@@ -247,8 +247,7 @@ static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
247247
{
248248
}
249249

250-
static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
251-
gfp_t gfp_flags)
250+
static inline struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
252251
{
253252
return ERR_PTR(-EOPNOTSUPP);
254253
}

0 commit comments

Comments
 (0)