Pull fscrypt updates from Eric Biggers: "Some cleanups for fs/crypto/: - Allow 256-bit master keys with AES-256-XTS - Improve documentation and comments - Remove unneeded field fscrypt_operations::max_namelen" * tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt: fscrypt: improve a few comments fscrypt: allow 256-bit master keys with AES-256-XTS fscrypt: improve documentation for inline encryption fscrypt: clean up comments in bio.c fscrypt: remove fscrypt_operations::max_namelen
Unified · Split
| @@ -1,5 +1,7 @@ | |||
| 1 | .. SPDX-License-Identifier: GPL-2.0 | 1 | .. SPDX-License-Identifier: GPL-2.0 |
| 2 | 2 | ||
| 3 | .. _inline_encryption: | ||
| 4 | |||
| 3 | ================= | 5 | ================= |
| 4 | Inline Encryption | 6 | Inline Encryption |
| 5 | ================= | 7 | ================= |
| @@ -77,11 +77,11 @@ Side-channel attacks · 76 unmodified lines | |||
| 77 | 77 | ||
| 78 | fscrypt is only resistant to side-channel attacks, such as timing or | 78 | fscrypt is only resistant to side-channel attacks, such as timing or |
| 79 | electromagnetic attacks, to the extent that the underlying Linux | 79 | electromagnetic attacks, to the extent that the underlying Linux |
| 80 | Cryptographic API algorithms are. If a vulnerable algorithm is used, | 80 | Cryptographic API algorithms or inline encryption hardware are. If a |
| 81 | such as a table-based implementation of AES, it may be possible for an | 81 | vulnerable algorithm is used, such as a table-based implementation of |
| 82 | attacker to mount a side channel attack against the online system. | 82 | AES, it may be possible for an attacker to mount a side channel attack |
| 83 | Side channel attacks may also be mounted against applications | 83 | against the online system. Side channel attacks may also be mounted |
| 84 | consuming decrypted data. | 84 | against applications consuming decrypted data. |
| 85 | 85 | ||
| 86 | Unauthorized file access | 86 | Unauthorized file access |
| 87 | ~~~~~~~~~~~~~~~~~~~~~~~~ | 87 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| @@ -176,11 +176,11 @@ Master Keys · 88 unmodified lines | |||
| 176 | 176 | ||
| 177 | Each encrypted directory tree is protected by a *master key*. Master | 177 | Each encrypted directory tree is protected by a *master key*. Master |
| 178 | keys can be up to 64 bytes long, and must be at least as long as the | 178 | keys can be up to 64 bytes long, and must be at least as long as the |
| 179 | greater of the key length needed by the contents and filenames | 179 | greater of the security strength of the contents and filenames |
| 180 | encryption modes being used. For example, if AES-256-XTS is used for | 180 | encryption modes being used. For example, if any AES-256 mode is |
| 181 | contents encryption, the master key must be 64 bytes (512 bits). Note | 181 | used, the master key must be at least 256 bits, i.e. 32 bytes. A |
| 182 | that the XTS mode is defined to require a key twice as long as that | 182 | stricter requirement applies if the key is used by a v1 encryption |
| 183 | required by the underlying block cipher. | 183 | policy and AES-256-XTS is used; such keys must be 64 bytes. |
| 184 | 184 | ||
| 185 | To "unlock" an encrypted directory tree, userspace must provide the | 185 | To "unlock" an encrypted directory tree, userspace must provide the |
| 186 | appropriate master key. There can be any number of master keys, each | 186 | appropriate master key. There can be any number of master keys, each |
| @@ -1135,6 +1135,50 @@ where applications may later write sensitive data. It is recommended · 948 unmodified lines | |||
| 1135 | that systems implementing a form of "verified boot" take advantage of | 1135 | that systems implementing a form of "verified boot" take advantage of |
| 1136 | this by validating all top-level encryption policies prior to access. | 1136 | this by validating all top-level encryption policies prior to access. |
| 1137 | 1137 | ||
| 1138 | Inline encryption support | ||
| 1139 | ========================= | ||
| 1140 | |||
| 1141 | By default, fscrypt uses the kernel crypto API for all cryptographic | ||
| 1142 | operations (other than HKDF, which fscrypt partially implements | ||
| 1143 | itself). The kernel crypto API supports hardware crypto accelerators, | ||
| 1144 | but only ones that work in the traditional way where all inputs and | ||
| 1145 | outputs (e.g. plaintexts and ciphertexts) are in memory. fscrypt can | ||
| 1146 | take advantage of such hardware, but the traditional acceleration | ||
| 1147 | model isn't particularly efficient and fscrypt hasn't been optimized | ||
| 1148 | for it. | ||
| 1149 | |||
| 1150 | Instead, many newer systems (especially mobile SoCs) have *inline | ||
| 1151 | encryption hardware* that can encrypt/decrypt data while it is on its | ||
| 1152 | way to/from the storage device. Linux supports inline encryption | ||
| 1153 | through a set of extensions to the block layer called *blk-crypto*. | ||
| 1154 | blk-crypto allows filesystems to attach encryption contexts to bios | ||
| 1155 | (I/O requests) to specify how the data will be encrypted or decrypted | ||
| 1156 | in-line. For more information about blk-crypto, see | ||
| 1157 | :ref:`Documentation/block/inline-encryption.rst <inline_encryption>`. | ||
| 1158 | |||
| 1159 | On supported filesystems (currently ext4 and f2fs), fscrypt can use | ||
| 1160 | blk-crypto instead of the kernel crypto API to encrypt/decrypt file | ||
| 1161 | contents. To enable this, set CONFIG_FS_ENCRYPTION_INLINE_CRYPT=y in | ||
| 1162 | the kernel configuration, and specify the "inlinecrypt" mount option | ||
| 1163 | when mounting the filesystem. | ||
| 1164 | |||
| 1165 | Note that the "inlinecrypt" mount option just specifies to use inline | ||
| 1166 | encryption when possible; it doesn't force its use. fscrypt will | ||
| 1167 | still fall back to using the kernel crypto API on files where the | ||
| 1168 | inline encryption hardware doesn't have the needed crypto capabilities | ||
| 1169 | (e.g. support for the needed encryption algorithm and data unit size) | ||
| 1170 | and where blk-crypto-fallback is unusable. (For blk-crypto-fallback | ||
| 1171 | to be usable, it must be enabled in the kernel configuration with | ||
| 1172 | CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK=y.) | ||
| 1173 | |||
| 1174 | Currently fscrypt always uses the filesystem block size (which is | ||
| 1175 | usually 4096 bytes) as the data unit size. Therefore, it can only use | ||
| 1176 | inline encryption hardware that supports that data unit size. | ||
| 1177 | |||
| 1178 | Inline encryption doesn't affect the ciphertext or other aspects of | ||
| 1179 | the on-disk format, so users may freely switch back and forth between | ||
| 1180 | using "inlinecrypt" and not using "inlinecrypt". | ||
| 1181 | |||
| 1138 | Implementation details | 1182 | Implementation details |
| 1139 | ====================== | 1183 | ====================== |
| 1140 | 1184 | ||
| @@ -1184,6 +1228,13 @@ keys`_ and `DIRECT_KEY policies`_. · 43 unmodified lines | |||
| 1184 | Data path changes | 1228 | Data path changes |
| 1185 | ----------------- | 1229 | ----------------- |
| 1186 | 1230 | ||
| 1231 | When inline encryption is used, filesystems just need to associate | ||
| 1232 | encryption contexts with bios to specify how the block layer or the | ||
| 1233 | inline encryption hardware will encrypt/decrypt the file contents. | ||
| 1234 | |||
| 1235 | When inline encryption isn't used, filesystems must encrypt/decrypt | ||
| 1236 | the file contents themselves, as described below: | ||
| 1237 | |||
| 1187 | For the read path (->readpage()) of regular files, filesystems can | 1238 | For the read path (->readpage()) of regular files, filesystems can |
| 1188 | read the ciphertext into the page cache and decrypt it in-place. The | 1239 | read the ciphertext into the page cache and decrypt it in-place. The |
| 1189 | page lock must be held until decryption has finished, to prevent the | 1240 | page lock must be held until decryption has finished, to prevent the |
| @@ -1197,18 +1248,6 @@ buffer. Some filesystems, such as UBIFS, already use temporary · 7 unmodified lines | |||
| 1197 | buffers regardless of encryption. Other filesystems, such as ext4 and | 1248 | buffers regardless of encryption. Other filesystems, such as ext4 and |
| 1198 | F2FS, have to allocate bounce pages specially for encryption. | 1249 | F2FS, have to allocate bounce pages specially for encryption. |
| 1199 | 1250 | ||
| 1200 | Fscrypt is also able to use inline encryption hardware instead of the | ||
| 1201 | kernel crypto API for en/decryption of file contents. When possible, | ||
| 1202 | and if directed to do so (by specifying the 'inlinecrypt' mount option | ||
| 1203 | for an ext4/F2FS filesystem), it adds encryption contexts to bios and | ||
| 1204 | uses blk-crypto to perform the en/decryption instead of making use of | ||
| 1205 | the above read/write path changes. Of course, even if directed to | ||
| 1206 | make use of inline encryption, fscrypt will only be able to do so if | ||
| 1207 | either hardware inline encryption support is available for the | ||
| 1208 | selected encryption algorithm or CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK | ||
| 1209 | is selected. If neither is the case, fscrypt will fall back to using | ||
| 1210 | the above mentioned read/write path changes for en/decryption. | ||
| 1211 | |||
| 1212 | Filename hashing and encoding | 1251 | Filename hashing and encoding |
| 1213 | ----------------------------- | 1252 | ----------------------------- |
| 1214 | 1253 | ||
| @@ -1,23 +1,10 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* | 2 | /* |
| 3 | * This contains encryption functions for per-file encryption. | 3 | * Utility functions for file contents encryption/decryption on |
| 4 | * block device-based filesystems. | ||
| 4 | * | 5 | * |
| 5 | * Copyright (C) 2015, Google, Inc. | 6 | * Copyright (C) 2015, Google, Inc. |
| 6 | * Copyright (C) 2015, Motorola Mobility | 7 | * Copyright (C) 2015, Motorola Mobility |
| 7 | * | ||
| 8 | * Written by Michael Halcrow, 2014. | ||
| 9 | * | ||
| 10 | * Filename encryption additions | ||
| 11 | * Uday Savagaonkar, 2014 | ||
| 12 | * Encryption policy handling additions | ||
| 13 | * Ildar Muslukhov, 2014 | ||
| 14 | * Add fscrypt_pullback_bio_page() | ||
| 15 | * Jaegeuk Kim, 2015. | ||
| 16 | * | ||
| 17 | * This has not yet undergone a rigorous security audit. | ||
| 18 | * | ||
| 19 | * The usage of AES-XTS should conform to recommendations in NIST | ||
| 20 | * Special Publication 800-38E and IEEE P1619/D16. | ||
| 21 | */ | 8 | */ |
| 22 | 9 | ||
| 23 | #include <linux/pagemap.h> | 10 | #include <linux/pagemap.h> |
| @@ -26,6 +13,21 @@ · 2 unmodified lines | |||
| 26 | #include <linux/namei.h> | 13 | #include <linux/namei.h> |
| 27 | #include "fscrypt_private.h" | 14 | #include "fscrypt_private.h" |
| 28 | 15 | ||
| 16 | /** | ||
| 17 | * fscrypt_decrypt_bio() - decrypt the contents of a bio | ||
| 18 | * @bio: the bio to decrypt | ||
| 19 | * | ||
| 20 | * Decrypt the contents of a "read" bio following successful completion of the | ||
| 21 | * underlying disk read. The bio must be reading a whole number of blocks of an | ||
| 22 | * encrypted file directly into the page cache. If the bio is reading the | ||
| 23 | * ciphertext into bounce pages instead of the page cache (for example, because | ||
| 24 | * the file is also compressed, so decompression is required after decryption), | ||
| 25 | * then this function isn't applicable. This function may sleep, so it must be | ||
| 26 | * called from a workqueue rather than from the bio's bi_end_io callback. | ||
| 27 | * | ||
| 28 | * This function sets PG_error on any pages that contain any blocks that failed | ||
| 29 | * to be decrypted. The filesystem must not mark such pages uptodate. | ||
| 30 | */ | ||
| 29 | void fscrypt_decrypt_bio(struct bio *bio) | 31 | void fscrypt_decrypt_bio(struct bio *bio) |
| 30 | { | 32 | { |
| 31 | struct bio_vec *bv; | 33 | struct bio_vec *bv; |
| @@ -429,8 +429,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname, · 428 unmodified lines | |||
| 429 | 429 | ||
| 430 | if (fscrypt_has_encryption_key(dir)) { | 430 | if (fscrypt_has_encryption_key(dir)) { |
| 431 | if (!fscrypt_fname_encrypted_size(&dir->i_crypt_info->ci_policy, | 431 | if (!fscrypt_fname_encrypted_size(&dir->i_crypt_info->ci_policy, |
| 432 | iname->len, | 432 | iname->len, NAME_MAX, |
| 433 | dir->i_sb->s_cop->max_namelen, | ||
| 434 | &fname->crypto_buf.len)) | 433 | &fname->crypto_buf.len)) |
| 435 | return -ENAMETOOLONG; | 434 | return -ENAMETOOLONG; |
| 436 | fname->crypto_buf.name = kmalloc(fname->crypto_buf.len, | 435 | fname->crypto_buf.name = kmalloc(fname->crypto_buf.len, |
| @@ -20,6 +20,11 @@ · 19 unmodified lines | |||
| 20 | 20 | ||
| 21 | #define FSCRYPT_FILE_NONCE_SIZE 16 | 21 | #define FSCRYPT_FILE_NONCE_SIZE 16 |
| 22 | 22 | ||
| 23 | /* | ||
| 24 | * Minimum size of an fscrypt master key. Note: a longer key will be required | ||
| 25 | * if ciphers with a 256-bit security strength are used. This is just the | ||
| 26 | * absolute minimum, which applies when only 128-bit encryption is used. | ||
| 27 | */ | ||
| 23 | #define FSCRYPT_MIN_KEY_SIZE 16 | 28 | #define FSCRYPT_MIN_KEY_SIZE 16 |
| 24 | 29 | ||
| 25 | #define FSCRYPT_CONTEXT_V1 1 | 30 | #define FSCRYPT_CONTEXT_V1 1 |
| @@ -413,7 +418,11 @@ struct fscrypt_master_key_secret { · 387 unmodified lines | |||
| 413 | */ | 418 | */ |
| 414 | struct fscrypt_hkdf hkdf; | 419 | struct fscrypt_hkdf hkdf; |
| 415 | 420 | ||
| 416 | /* Size of the raw key in bytes. Set even if ->raw isn't set. */ | 421 | /* |
| 422 | * Size of the raw key in bytes. This remains set even if ->raw was | ||
| 423 | * zeroized due to no longer being needed. I.e. we still remember the | ||
| 424 | * size of the key even if we don't need to remember the key itself. | ||
| 425 | */ | ||
| 417 | u32 size; | 426 | u32 size; |
| 418 | 427 | ||
| 419 | /* For v1 policy keys: the raw key. Wiped for v2 policy keys. */ | 428 | /* For v1 policy keys: the raw key. Wiped for v2 policy keys. */ |
| @@ -549,8 +558,9 @@ int __init fscrypt_init_keyring(void); · 129 unmodified lines | |||
| 549 | struct fscrypt_mode { | 558 | struct fscrypt_mode { |
| 550 | const char *friendly_name; | 559 | const char *friendly_name; |
| 551 | const char *cipher_str; | 560 | const char *cipher_str; |
| 552 | int keysize; | 561 | int keysize; /* key size in bytes */ |
| 553 | int ivsize; | 562 | int security_strength; /* security strength in bytes */ |
| 563 | int ivsize; /* IV size in bytes */ | ||
| 554 | int logged_impl_name; | 564 | int logged_impl_name; |
| 555 | enum blk_crypto_mode_num blk_crypto_mode; | 565 | enum blk_crypto_mode_num blk_crypto_mode; |
| 556 | }; | 566 | }; |
| @@ -16,9 +16,14 @@ · 15 unmodified lines | |||
| 16 | 16 | ||
| 17 | /* | 17 | /* |
| 18 | * HKDF supports any unkeyed cryptographic hash algorithm, but fscrypt uses | 18 | * HKDF supports any unkeyed cryptographic hash algorithm, but fscrypt uses |
| 19 | * SHA-512 because it is reasonably secure and efficient; and since it produces | 19 | * SHA-512 because it is well-established, secure, and reasonably efficient. |
| 20 | * a 64-byte digest, deriving an AES-256-XTS key preserves all 64 bytes of | 20 | * |
| 21 | * entropy from the master key and requires only one iteration of HKDF-Expand. | 21 | * HKDF-SHA256 was also considered, as its 256-bit security strength would be |
| 22 | * sufficient here. A 512-bit security strength is "nice to have", though. | ||
| 23 | * Also, on 64-bit CPUs, SHA-512 is usually just as fast as SHA-256. In the | ||
| 24 | * common case of deriving an AES-256-XTS key (512 bits), that can result in | ||
| 25 | * HKDF-SHA512 being much faster than HKDF-SHA256, as the longer digest size of | ||
| 26 | * SHA-512 causes HKDF-Expand to only need to do one iteration rather than two. | ||
| 22 | */ | 27 | */ |
| 23 | #define HKDF_HMAC_ALG "hmac(sha512)" | 28 | #define HKDF_HMAC_ALG "hmac(sha512)" |
| 24 | #define HKDF_HASHLEN SHA512_DIGEST_SIZE | 29 | #define HKDF_HASHLEN SHA512_DIGEST_SIZE |
| @@ -19,6 +19,7 @@ struct fscrypt_mode fscrypt_modes[] = { · 18 unmodified lines | |||
| 19 | .friendly_name = "AES-256-XTS", | 19 | .friendly_name = "AES-256-XTS", |
| 20 | .cipher_str = "xts(aes)", | 20 | .cipher_str = "xts(aes)", |
| 21 | .keysize = 64, | 21 | .keysize = 64, |
| 22 | .security_strength = 32, | ||
| 22 | .ivsize = 16, | 23 | .ivsize = 16, |
| 23 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_256_XTS, | 24 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_256_XTS, |
| 24 | }, | 25 | }, |
| @@ -26,12 +27,14 @@ struct fscrypt_mode fscrypt_modes[] = { · 1 unmodified line | |||
| 26 | .friendly_name = "AES-256-CTS-CBC", | 27 | .friendly_name = "AES-256-CTS-CBC", |
| 27 | .cipher_str = "cts(cbc(aes))", | 28 | .cipher_str = "cts(cbc(aes))", |
| 28 | .keysize = 32, | 29 | .keysize = 32, |
| 30 | .security_strength = 32, | ||
| 29 | .ivsize = 16, | 31 | .ivsize = 16, |
| 30 | }, | 32 | }, |
| 31 | [FSCRYPT_MODE_AES_128_CBC] = { | 33 | [FSCRYPT_MODE_AES_128_CBC] = { |
| 32 | .friendly_name = "AES-128-CBC-ESSIV", | 34 | .friendly_name = "AES-128-CBC-ESSIV", |
| 33 | .cipher_str = "essiv(cbc(aes),sha256)", | 35 | .cipher_str = "essiv(cbc(aes),sha256)", |
| 34 | .keysize = 16, | 36 | .keysize = 16, |
| 37 | .security_strength = 16, | ||
| 35 | .ivsize = 16, | 38 | .ivsize = 16, |
| 36 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV, | 39 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV, |
| 37 | }, | 40 | }, |
| @@ -39,12 +42,14 @@ struct fscrypt_mode fscrypt_modes[] = { · 1 unmodified line | |||
| 39 | .friendly_name = "AES-128-CTS-CBC", | 42 | .friendly_name = "AES-128-CTS-CBC", |
| 40 | .cipher_str = "cts(cbc(aes))", | 43 | .cipher_str = "cts(cbc(aes))", |
| 41 | .keysize = 16, | 44 | .keysize = 16, |
| 45 | .security_strength = 16, | ||
| 42 | .ivsize = 16, | 46 | .ivsize = 16, |
| 43 | }, | 47 | }, |
| 44 | [FSCRYPT_MODE_ADIANTUM] = { | 48 | [FSCRYPT_MODE_ADIANTUM] = { |
| 45 | .friendly_name = "Adiantum", | 49 | .friendly_name = "Adiantum", |
| 46 | .cipher_str = "adiantum(xchacha12,aes)", | 50 | .cipher_str = "adiantum(xchacha12,aes)", |
| 47 | .keysize = 32, | 51 | .keysize = 32, |
| 52 | .security_strength = 32, | ||
| 48 | .ivsize = 32, | 53 | .ivsize = 32, |
| 49 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_ADIANTUM, | 54 | .blk_crypto_mode = BLK_ENCRYPTION_MODE_ADIANTUM, |
| 50 | }, | 55 | }, |
| @@ -117,8 +122,9 @@ err_free_tfm: · 66 unmodified lines | |||
| 117 | 122 | ||
| 118 | /* | 123 | /* |
| 119 | * Prepare the crypto transform object or blk-crypto key in @prep_key, given the | 124 | * Prepare the crypto transform object or blk-crypto key in @prep_key, given the |
| 120 | * raw key, encryption mode, and flag indicating which encryption implementation | 125 | * raw key, encryption mode (@ci->ci_mode), flag indicating which encryption |
| 121 | * (fs-layer or blk-crypto) will be used. | 126 | * implementation (fs-layer or blk-crypto) will be used (@ci->ci_inlinecrypt), |
| 127 | * and IV generation method (@ci->ci_policy.flags). | ||
| 122 | */ | 128 | */ |
| 123 | int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key, | 129 | int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key, |
| 124 | const u8 *raw_key, const struct fscrypt_info *ci) | 130 | const u8 *raw_key, const struct fscrypt_info *ci) |
| @@ -357,6 +363,45 @@ static int fscrypt_setup_v2_file_key(struct fscrypt_info *ci, · 232 unmodified lines | |||
| 357 | return 0; | 363 | return 0; |
| 358 | } | 364 | } |
| 359 | 365 | ||
| 366 | /* | ||
| 367 | * Check whether the size of the given master key (@mk) is appropriate for the | ||
| 368 | * encryption settings which a particular file will use (@ci). | ||
| 369 | * | ||
| 370 | * If the file uses a v1 encryption policy, then the master key must be at least | ||
| 371 | * as long as the derived key, as this is a requirement of the v1 KDF. | ||
| 372 | * | ||
| 373 | * Otherwise, the KDF can accept any size key, so we enforce a slightly looser | ||
| 374 | * requirement: we require that the size of the master key be at least the | ||
| 375 | * maximum security strength of any algorithm whose key will be derived from it | ||
| 376 | * (but in practice we only need to consider @ci->ci_mode, since any other | ||
| 377 | * possible subkeys such as DIRHASH and INODE_HASH will never increase the | ||
| 378 | * required key size over @ci->ci_mode). This allows AES-256-XTS keys to be | ||
| 379 | * derived from a 256-bit master key, which is cryptographically sufficient, | ||
| 380 | * rather than requiring a 512-bit master key which is unnecessarily long. (We | ||
| 381 | * still allow 512-bit master keys if the user chooses to use them, though.) | ||
| 382 | */ | ||
| 383 | static bool fscrypt_valid_master_key_size(const struct fscrypt_master_key *mk, | ||
| 384 | const struct fscrypt_info *ci) | ||
| 385 | { | ||
| 386 | unsigned int min_keysize; | ||
| 387 | |||
| 388 | if (ci->ci_policy.version == FSCRYPT_POLICY_V1) | ||
| 389 | min_keysize = ci->ci_mode->keysize; | ||
| 390 | else | ||
| 391 | min_keysize = ci->ci_mode->security_strength; | ||
| 392 | |||
| 393 | if (mk->mk_secret.size < min_keysize) { | ||
| 394 | fscrypt_warn(NULL, | ||
| 395 | "key with %s %*phN is too short (got %u bytes, need %u+ bytes)", | ||
| 396 | master_key_spec_type(&mk->mk_spec), | ||
| 397 | master_key_spec_len(&mk->mk_spec), | ||
| 398 | (u8 *)&mk->mk_spec.u, | ||
| 399 | mk->mk_secret.size, min_keysize); | ||
| 400 | return false; | ||
| 401 | } | ||
| 402 | return true; | ||
| 403 | } | ||
| 404 | |||
| 360 | /* | 405 | /* |
| 361 | * Find the master key, then set up the inode's actual encryption key. | 406 | * Find the master key, then set up the inode's actual encryption key. |
| 362 | * | 407 | * |
| @@ -422,18 +467,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, · 59 unmodified lines | |||
| 422 | goto out_release_key; | 467 | goto out_release_key; |
| 423 | } | 468 | } |
| 424 | 469 | ||
| 425 | /* | 470 | if (!fscrypt_valid_master_key_size(mk, ci)) { |
| 426 | * Require that the master key be at least as long as the derived key. | ||
| 427 | * Otherwise, the derived key cannot possibly contain as much entropy as | ||
| 428 | * that required by the encryption mode it will be used for. For v1 | ||
| 429 | * policies it's also required for the KDF to work at all. | ||
| 430 | */ | ||
| 431 | if (mk->mk_secret.size < ci->ci_mode->keysize) { | ||
| 432 | fscrypt_warn(NULL, | ||
| 433 | "key with %s %*phN is too short (got %u bytes, need %u+ bytes)", | ||
| 434 | master_key_spec_type(&mk_spec), | ||
| 435 | master_key_spec_len(&mk_spec), (u8 *)&mk_spec.u, | ||
| 436 | mk->mk_secret.size, ci->ci_mode->keysize); | ||
| 437 | err = -ENOKEY; | 471 | err = -ENOKEY; |
| 438 | goto out_release_key; | 472 | goto out_release_key; |
| 439 | } | 473 | } |
| @@ -1572,7 +1572,6 @@ static const struct fscrypt_operations ext4_cryptops = { · 1571 unmodified lines | |||
| 1572 | .set_context = ext4_set_context, | 1572 | .set_context = ext4_set_context, |
| 1573 | .get_dummy_policy = ext4_get_dummy_policy, | 1573 | .get_dummy_policy = ext4_get_dummy_policy, |
| 1574 | .empty_dir = ext4_empty_dir, | 1574 | .empty_dir = ext4_empty_dir, |
| 1575 | .max_namelen = EXT4_NAME_LEN, | ||
| 1576 | .has_stable_inodes = ext4_has_stable_inodes, | 1575 | .has_stable_inodes = ext4_has_stable_inodes, |
| 1577 | .get_ino_and_lblk_bits = ext4_get_ino_and_lblk_bits, | 1576 | .get_ino_and_lblk_bits = ext4_get_ino_and_lblk_bits, |
| 1578 | }; | 1577 | }; |
| @@ -2976,7 +2976,6 @@ static const struct fscrypt_operations f2fs_cryptops = { · 2975 unmodified lines | |||
| 2976 | .set_context = f2fs_set_context, | 2976 | .set_context = f2fs_set_context, |
| 2977 | .get_dummy_policy = f2fs_get_dummy_policy, | 2977 | .get_dummy_policy = f2fs_get_dummy_policy, |
| 2978 | .empty_dir = f2fs_empty_dir, | 2978 | .empty_dir = f2fs_empty_dir, |
| 2979 | .max_namelen = F2FS_NAME_LEN, | ||
| 2980 | .has_stable_inodes = f2fs_has_stable_inodes, | 2979 | .has_stable_inodes = f2fs_has_stable_inodes, |
| 2981 | .get_ino_and_lblk_bits = f2fs_get_ino_and_lblk_bits, | 2980 | .get_ino_and_lblk_bits = f2fs_get_ino_and_lblk_bits, |
| 2982 | .get_num_devices = f2fs_get_num_devices, | 2981 | .get_num_devices = f2fs_get_num_devices, |
| @@ -82,5 +82,4 @@ const struct fscrypt_operations ubifs_crypt_operations = { · 81 unmodified lines | |||
| 82 | .get_context = ubifs_crypt_get_context, | 82 | .get_context = ubifs_crypt_get_context, |
| 83 | .set_context = ubifs_crypt_set_context, | 83 | .set_context = ubifs_crypt_set_context, |
| 84 | .empty_dir = ubifs_crypt_empty_dir, | 84 | .empty_dir = ubifs_crypt_empty_dir, |
| 85 | .max_namelen = UBIFS_MAX_NLEN, | ||
| 86 | }; | 85 | }; |
| @@ -118,9 +118,6 @@ struct fscrypt_operations { · 117 unmodified lines | |||
| 118 | */ | 118 | */ |
| 119 | bool (*empty_dir)(struct inode *inode); | 119 | bool (*empty_dir)(struct inode *inode); |
| 120 | 120 | ||
| 121 | /* The filesystem's maximum ciphertext filename length, in bytes */ | ||
| 122 | unsigned int max_namelen; | ||
| 123 | |||
| 124 | /* | 121 | /* |
| 125 | * Check whether the filesystem's inode numbers and UUID are stable, | 122 | * Check whether the filesystem's inode numbers and UUID are stable, |
| 126 | * meaning that they will never be changed even by offline operations | 123 | * meaning that they will never be changed even by offline operations |