Skip to content

Commit 55e32c5

Browse files
committed
fscrypt: don't load ->i_crypt_info before it's known to be valid
In fscrypt_set_bio_crypt_ctx(), ->i_crypt_info isn't known to be non-NULL until we check fscrypt_inode_uses_inline_crypto(). So, load ->i_crypt_info after the check rather than before. This makes no difference currently, but it prevents people from introducing bugs where the pointer is dereferenced when it may be NULL. Suggested-by: Dave Chinner <[email protected]> Cc: Satya Tangirala <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 880253e commit 55e32c5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/crypto/inline_crypt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,12 @@ static void fscrypt_generate_dun(const struct fscrypt_info *ci, u64 lblk_num,
244244
void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
245245
u64 first_lblk, gfp_t gfp_mask)
246246
{
247-
const struct fscrypt_info *ci = inode->i_crypt_info;
247+
const struct fscrypt_info *ci;
248248
u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE];
249249

250250
if (!fscrypt_inode_uses_inline_crypto(inode))
251251
return;
252+
ci = inode->i_crypt_info;
252253

253254
fscrypt_generate_dun(ci, first_lblk, dun);
254255
bio_crypt_set_ctx(bio, &ci->ci_enc_key.blk_key->base, dun, gfp_mask);

0 commit comments

Comments
 (0)