aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2020-05-06 14:15:07 -0700
committerEric Biggers <ebiggers@google.com>2020-05-14 11:44:58 -0700
commit6be68d89b4d524dde1476be8f895a69cc08237ee (patch)
tree330325437da0ba1e193b23584b7673ff33b1a573
parent8711e464f7dfcd3c18cbbbfa95127bc8868e0430 (diff)
downloadhikey-linaro-6be68d89b4d524dde1476be8f895a69cc08237ee.tar.gz
ANDROID: fscrypt: set dun_bytes more precisely
Make fscrypt set dun_bytes to only what it actually needs, so that it can make use of inline crypto hardware in more cases. Bug: 144046242 Bug: 153512828 Change-Id: I36f90ea6b64ef51a9d58ffb069d2cba74965c239 Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r--fs/crypto/inline_crypt.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/crypto/inline_crypt.c b/fs/crypto/inline_crypt.c
index 976617112d52..f96e2972a003 100644
--- a/fs/crypto/inline_crypt.c
+++ b/fs/crypto/inline_crypt.c
@@ -44,13 +44,20 @@ static void fscrypt_get_devices(struct super_block *sb, int num_devs,
static unsigned int fscrypt_get_dun_bytes(const struct fscrypt_info *ci)
{
- unsigned int dun_bytes = 8;
+ struct super_block *sb = ci->ci_inode->i_sb;
+ unsigned int flags = fscrypt_policy_flags(&ci->ci_policy);
+ int ino_bits = 64, lblk_bits = 64;
- if (fscrypt_policy_flags(&ci->ci_policy) &
- FSCRYPT_POLICY_FLAG_DIRECT_KEY)
- dun_bytes += FS_KEY_DERIVATION_NONCE_SIZE;
+ if (flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY)
+ return offsetofend(union fscrypt_iv, nonce);
- return dun_bytes;
+ if (flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64)
+ return sizeof(__le64);
+
+ /* Default case: IVs are just the file logical block number */
+ if (sb->s_cop->get_ino_and_lblk_bits)
+ sb->s_cop->get_ino_and_lblk_bits(sb, &ino_bits, &lblk_bits);
+ return DIV_ROUND_UP(lblk_bits, 8);
}
/* Enable inline encryption for this file if supported. */