summaryrefslogtreecommitdiff
path: root/fs/crypto/policy.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-09-25 08:54:49 +0300
committerEric Biggers <ebiggers@google.com>2023-09-26 08:34:30 +0300
commitf0904e8bc3c513e9fd50bdca5365f998578177a0 (patch)
treea4283956108b4d0883cb5f8419b2fad1415b265c /fs/crypto/policy.c
parent40e13e18168fd0f1a6ad10166f5042a21c47ab99 (diff)
downloadlinux-f0904e8bc3c513e9fd50bdca5365f998578177a0.tar.xz
fscrypt: compute max_lblk_bits from s_maxbytes and block size
For a given filesystem, the number of bits used by the maximum file logical block number is computable from the maximum file size and the block size. These values are always present in struct super_block. Therefore, compute it this way instead of using the value from fscrypt_operations::get_ino_and_lblk_bits. Since filesystems always have to set the super_block fields anyway, this avoids having to provide this information redundantly via fscrypt_operations. This change is in preparation for adding support for sub-block data units. For that, the value that is needed will become "the maximum file data unit index". A hardcoded value won't suffice for that; it will need to be computed anyway. Link: https://lore.kernel.org/r/20230925055451.59499-4-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs/crypto/policy.c')
-rw-r--r--fs/crypto/policy.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
index f4456ecb3f87..7b34949e49de 100644
--- a/fs/crypto/policy.c
+++ b/fs/crypto/policy.c
@@ -119,8 +119,7 @@ static bool supported_direct_key_modes(const struct inode *inode,
static bool supported_iv_ino_lblk_policy(const struct fscrypt_policy_v2 *policy,
const struct inode *inode,
- const char *type,
- int max_ino_bits, int max_lblk_bits)
+ const char *type, int max_ino_bits)
{
struct super_block *sb = inode->i_sb;
int ino_bits = 64, lblk_bits = 64;
@@ -158,9 +157,14 @@ static bool supported_iv_ino_lblk_policy(const struct fscrypt_policy_v2 *policy,
type, sb->s_id);
return false;
}
- if (lblk_bits > max_lblk_bits) {
+
+ /*
+ * IV_INO_LBLK_64 and IV_INO_LBLK_32 both require that file logical
+ * block numbers fit in 32 bits.
+ */
+ if (fscrypt_max_file_lblk_bits(sb) > 32) {
fscrypt_warn(inode,
- "Can't use %s policy on filesystem '%s' because its block numbers are too long",
+ "Can't use %s policy on filesystem '%s' because its maximum file size is too large",
type, sb->s_id);
return false;
}
@@ -239,8 +243,7 @@ static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy,
return false;
if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) &&
- !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_64",
- 32, 32))
+ !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_64", 32))
return false;
/*
@@ -250,8 +253,7 @@ static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy,
* implementation limit is 32 bits.
*/
if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) &&
- !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_32",
- 32, 32))
+ !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_32", 32))
return false;
if (memchr_inv(policy->__reserved, 0, sizeof(policy->__reserved))) {