Skip to content

Commit 5befc19

Browse files
lxbszebiggers
authored andcommitted
fscrypt: explicitly require that inode->i_blkbits be set
Document that fscrypt_prepare_new_inode() requires inode->i_blkbits to be set, and make it WARN if it's not. This would have made the CephFS bug https://tracker.ceph.com/issues/64035 a bit easier to debug. Signed-off-by: Xiubo Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 41bccc9 commit 5befc19

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/crypto/keysetup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported)
687687
/**
688688
* fscrypt_prepare_new_inode() - prepare to create a new inode in a directory
689689
* @dir: a possibly-encrypted directory
690-
* @inode: the new inode. ->i_mode must be set already.
690+
* @inode: the new inode. ->i_mode and ->i_blkbits must be set already.
691691
* ->i_ino doesn't need to be set yet.
692692
* @encrypt_ret: (output) set to %true if the new inode will be encrypted
693693
*
@@ -717,6 +717,9 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
717717
if (IS_ERR(policy))
718718
return PTR_ERR(policy);
719719

720+
if (WARN_ON_ONCE(inode->i_blkbits == 0))
721+
return -EINVAL;
722+
720723
if (WARN_ON_ONCE(inode->i_mode == 0))
721724
return -EINVAL;
722725

0 commit comments

Comments
 (0)