Lines Matching +full:master +full:- +full:level
2 Filesystem-level encryption (fscrypt)
11 Note: "fscrypt" in this document refers to the kernel-level portion,
14 covers the kernel-level portion. For command-line examples of how to
20 <https://source.android.com/security/encryption/file-based>`_, over
25 Unlike dm-crypt, fscrypt operates at the filesystem level rather than
26 at the block device level. This allows it to encrypt different files
28 filesystem. This is useful for multi-user systems where each user's
29 data-at-rest needs to be cryptographically isolated from the others.
34 directly into supported filesystems --- currently ext4, F2FS, UBIFS,
44 fscrypt does not support encrypting files in-place. Instead, it
54 ---------------
58 event of a single point-in-time permanent offline compromise of the
60 non-filename metadata, e.g. file sizes, file permissions, file
70 --------------
75 Side-channel attacks
78 fscrypt is only resistant to side-channel attacks, such as timing or
81 vulnerable algorithm is used, such as a table-based implementation of
98 Therefore, any encryption-specific access control checks would merely
114 FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS ioctl) can wipe a master
117 thereby wiping their per-file keys and making them once again appear
122 - Per-file keys for in-use files will *not* be removed or wiped.
124 encrypted files and directories before removing a master key, as
128 - The kernel cannot magically wipe copies of the master key(s) that
130 copies of the master key(s) it makes as well; normally this should
137 - In general, decrypted contents and filenames in the kernel VFS
144 - Secret keys might still exist in CPU registers, in crypto
154 - There is no verification that the provided master key is correct.
156 with another user's encrypted files to which they have read-only
160 meaning of "read-only access".
162 - A compromise of a per-file key also compromises the master key from
165 - Non-root users cannot securely remove encryption keys.
174 Master Keys
175 -----------
177 Each encrypted directory tree is protected by a *master key*. Master
180 encryption modes being used. For example, if any AES-256 mode is
181 used, the master key must be at least 256 bits, i.e. 32 bytes. A
183 policy and AES-256-XTS is used; such keys must be 64 bytes.
186 appropriate master key. There can be any number of master keys, each
190 Master keys must be real cryptographic keys, i.e. indistinguishable
192 **must not** directly use a password as a master key, zero-pad a
197 Instead, users should generate master keys either using a
200 therefore, if userspace derives the key from a low-entropy secret such
205 -----------------------
207 With one exception, fscrypt never uses the master key(s) for
211 The KDF used for a particular master key differs depending on whether
214 encryption policies. (No real-world attack is currently known on this
218 For v1 encryption policies, the KDF only supports deriving per-file
219 encryption keys. It works by encrypting the master key with
220 AES-128-ECB, using the file's 16-byte nonce as the AES key. The
224 For v2 encryption policies, the KDF is HKDF-SHA512. The master key is
226 "application-specific information string" is used for each distinct
227 key to be derived. For example, when a per-file encryption key is
228 derived, the application-specific information string is the file's
232 HKDF-SHA512 is preferred to the original AES-128-ECB based KDF because
234 entropy from the master key. HKDF is also standardized and widely
235 used by other software, whereas the AES-128-ECB based KDF is ad-hoc.
237 Per-file encryption keys
238 ------------------------
240 Since each master key can protect many files, it is necessary to
243 cases, fscrypt does this by deriving per-file keys. When a new
245 fscrypt randomly generates a 16-byte nonce and stores it in the
247 derivation function`_) to derive the file's key from the master key
251 require larger xattrs which would be less likely to fit in-line in the
255 alternative master keys or to support rotating master keys. Instead,
256 the master keys may be wrapped in userspace, e.g. as is done by the
260 -------------------
264 long IVs --- long enough to hold both an 8-byte data unit index and a
265 16-byte per-file nonce. Also, the overhead of each Adiantum key is
266 greater than that of an AES-256-XTS key.
271 per-file encryption keys are not used. Instead, whenever any data
272 (contents or filenames) is encrypted, the file's 16-byte nonce is
275 - For v1 encryption policies, the encryption is done directly with the
276 master key. Because of this, users **must not** use the same master
279 - For v2 encryption policies, the encryption is done with a per-mode
280 key derived using the KDF. Users may use the same master key for
284 -----------------------
287 the encryption keys are derived from the master key, encryption mode
289 protected by the same master key sharing a single contents encryption
299 -----------------------
302 IV_INO_LBLK_32, the inode number is hashed with SipHash-2-4 (where the
303 SipHash key is derived from the master key) and added to the file data
304 unit index mod 2^32 to produce a 32-bit IV.
309 format results in some level of IV reuse, so it should only be used
313 ---------------
315 For master keys used for v2 encryption policies, a unique 16-byte "key
320 ------------
322 For directories that are indexed using a secret-keyed dirhash over the
323 plaintext filenames, the KDF is also used to derive a 128-bit
324 SipHash-2-4 key per directory in order to hash filenames. This works
325 just like deriving a per-file encryption key, except that a different
326 KDF context is used. Currently, only casefolded ("case-insensitive")
337 ---------------
341 - AES-256-XTS for contents and AES-256-CTS-CBC for filenames
342 - AES-256-XTS for contents and AES-256-HCTR2 for filenames
343 - Adiantum for both contents and filenames
344 - AES-128-CBC-ESSIV for contents and AES-128-CTS-CBC for filenames
345 - SM4-XTS for contents and SM4-CTS-CBC for filenames
351 `CBC-ESSIV mode
352 <https://en.wikipedia.org/wiki/Disk_encryption_theory#Encrypted_salt-sector_initialization_vector_(…
353 or a wide-block cipher. Filenames encryption uses a
354 block cipher in `CTS-CBC mode
355 <https://en.wikipedia.org/wiki/Ciphertext_stealing>`_ or a wide-block
358 The (AES-256-XTS, AES-256-CTS-CBC) pair is the recommended default.
362 The (AES-256-XTS, AES-256-HCTR2) pair is also a good choice that
363 upgrades the filenames encryption to use a wide-block cipher. (A
364 *wide-block cipher*, also called a tweakable super-pseudorandom
366 entire result.) As described in `Filenames encryption`_, a wide-block
367 cipher is the ideal mode for the problem domain, though CTS-CBC is the
372 of hardware acceleration for AES. Adiantum is a wide-block cipher
373 that uses XChaCha12 and AES-256 as its underlying components. Most of
378 The (AES-128-CBC-ESSIV, AES-128-CTS-CBC) pair exists only to support
379 systems whose only form of AES acceleration is an off-CPU crypto
384 - (SM4-XTS, SM4-CTS-CBC)
392 ---------------------
395 only the basic support from the crypto API needed to use AES-256-XTS
396 and AES-256-CTS-CBC encryption. For optimal performance, it is
397 strongly recommended to also enable any available platform-specific
399 wish to use. Support for any "non-default" encryption modes typically
410 - AES-256-XTS and AES-256-CTS-CBC
411 - Recommended:
412 - arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
413 - x86: CONFIG_CRYPTO_AES_NI_INTEL
415 - AES-256-HCTR2
416 - Mandatory:
417 - CONFIG_CRYPTO_HCTR2
418 - Recommended:
419 - arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
420 - arm64: CONFIG_CRYPTO_POLYVAL_ARM64_CE
421 - x86: CONFIG_CRYPTO_AES_NI_INTEL
422 - x86: CONFIG_CRYPTO_POLYVAL_CLMUL_NI
424 - Adiantum
425 - Mandatory:
426 - CONFIG_CRYPTO_ADIANTUM
427 - Recommended:
428 - arm32: CONFIG_CRYPTO_CHACHA20_NEON
429 - arm32: CONFIG_CRYPTO_NHPOLY1305_NEON
430 - arm64: CONFIG_CRYPTO_CHACHA20_NEON
431 - arm64: CONFIG_CRYPTO_NHPOLY1305_NEON
432 - x86: CONFIG_CRYPTO_CHACHA20_X86_64
433 - x86: CONFIG_CRYPTO_NHPOLY1305_SSE2
434 - x86: CONFIG_CRYPTO_NHPOLY1305_AVX2
436 - AES-128-CBC-ESSIV and AES-128-CTS-CBC:
437 - Mandatory:
438 - CONFIG_CRYPTO_ESSIV
439 - CONFIG_CRYPTO_SHA256 or another SHA-256 implementation
440 - Recommended:
441 - AES-CBC acceleration
443 fscrypt also uses HMAC-SHA512 for key derivation, so enabling SHA-512
446 - SHA-512
447 - Recommended:
448 - arm64: CONFIG_CRYPTO_SHA512_ARM64_CE
449 - x86: CONFIG_CRYPTO_SHA512_SSSE3
452 -------------------
456 data unit incorporates the zero-based index of the data unit within
466 * Fixed-size data units. This is how all filesystems other than UBIFS
468 is zero-padded if needed. By default, the data unit size is equal
470 a sub-block data unit size via the ``log2_data_unit_size`` field of
473 * Variable-size data units. This is what UBIFS does. Each "UBIFS
475 length, possibly compressed data, zero-padded to the next 16-byte
476 boundary. Users cannot select a sub-block data unit size on UBIFS.
482 Therefore a f2fs-compressed file still uses fixed-size data units, and
486 per-file keys. In this case, the IV for each data unit is simply the
488 encryption setting that does not use per-file keys. For these, some
491 - With `DIRECT_KEY policies`_, the data unit index is placed in bits
492 0-63 of the IV, and the file's nonce is placed in bits 64-191.
494 - With `IV_INO_LBLK_64 policies`_, the data unit index is placed in
495 bits 0-31 of the IV, and the file's inode number is placed in bits
496 32-63. This setting is only allowed when data unit indices and
499 - With `IV_INO_LBLK_32 policies`_, the file's inode number is hashed
501 to 32 bits and placed in bits 0-31 of the IV. This setting is only
508 passed to AES-128-CBC, it is encrypted with AES-256 where the AES-256
509 key is the SHA-256 hash of the file's contents encryption key.
512 --------------------
524 With CTS-CBC, the IV reuse means that when the plaintext filenames share a
528 wide-block encryption modes.
532 filenames shorter than 16 bytes are NUL-padded to 16 bytes before
534 via their ciphertexts, all filenames are NUL-padded to the next 4, 8,
535 16, or 32-byte boundary (configurable). 32 is recommended since this
549 ----------------------------
585 - ``version`` must be FSCRYPT_POLICY_V1 (0) if
591 - ``contents_encryption_mode`` and ``filenames_encryption_mode`` must
604 - ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
606 - FSCRYPT_POLICY_FLAGS_PAD_*: The amount of NUL padding to use when
609 - FSCRYPT_POLICY_FLAG_DIRECT_KEY: See `DIRECT_KEY policies`_.
610 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64: See `IV_INO_LBLK_64
612 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32: See `IV_INO_LBLK_32
621 - ``log2_data_unit_size`` is the log2 of the data unit size in bytes,
625 underlying encryption algorithm (such as AES-256-XTS) in 4096-byte
644 - For v2 encryption policies, ``__reserved`` must be zeroed.
646 - For v1 encryption policies, ``master_key_descriptor`` specifies how
647 to find the master key in a keyring; see `Adding keys`_. It is up
649 master key. The e4crypt and fscrypt tools use the first 8 bytes of
650 ``SHA-512(SHA-512(master_key))``, but this particular scheme is not
651 required. Also, the master key need not be in the keyring yet when
667 corresponding master key as described in `Adding keys`_, all regular
689 filesystem with one key should consider using dm-crypt instead.
693 - ``EACCES``: the file is not owned by the process's uid, nor does the
696 - ``EEXIST``: the file is already encrypted with an encryption policy
698 - ``EINVAL``: an invalid encryption policy was specified (invalid
702 - ``ENOKEY``: a v2 encryption policy was specified, but the key with
706 - ``ENOTDIR``: the file is unencrypted and is a regular file, not a
708 - ``ENOTEMPTY``: the file is unencrypted and is a nonempty directory
709 - ``ENOTTY``: this type of filesystem does not implement encryption
710 - ``EOPNOTSUPP``: the kernel was not configured with encryption
715 feature flag enabled using ``tune2fs -O encrypt`` or ``mkfs.ext4 -O
717 - ``EPERM``: this directory may not be encrypted, e.g. because it is
719 - ``EROFS``: the filesystem is readonly
722 ----------------------------
726 - `FS_IOC_GET_ENCRYPTION_POLICY_EX`_
727 - `FS_IOC_GET_ENCRYPTION_POLICY`_
763 - ``EINVAL``: the file is encrypted, but it uses an unrecognized
765 - ``ENODATA``: the file is not encrypted
766 - ``ENOTTY``: this type of filesystem does not implement encryption,
769 - ``EOPNOTSUPP``: the kernel was not configured with encryption
772 - ``EOVERFLOW``: the file is encrypted and uses a recognized
796 Getting the per-filesystem salt
797 -------------------------------
801 generated 16-byte value stored in the filesystem superblock. This
803 from a passphrase or other low-entropy user credential.
809 ---------------------------------
812 On encrypted files and directories it gets the inode's 16-byte nonce.
820 -----------
825 The FS_IOC_ADD_ENCRYPTION_KEY ioctl adds a master encryption key to
862 - If the key is being added for use by v1 encryption policies, then
879 - ``raw_size`` must be the size of the ``raw`` key provided, in bytes.
883 - ``key_id`` is 0 if the raw key is given directly in the ``raw``
885 type "fscrypt-provisioning" whose payload is
888 Since ``raw`` is variable-length, the total size of this key's
895 allow re-adding keys after a filesystem is unmounted and re-mounted,
898 - ``raw`` is a variable-length field which must contain the actual
904 removed by that user --- or by "root", if they use
920 - ``EACCES``: FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR was specified, but the
924 - ``EDQUOT``: the key quota for this user would be exceeded by adding
926 - ``EINVAL``: invalid key size or key specifier type, or reserved bits
928 - ``EKEYREJECTED``: the raw key was specified by Linux key ID, but the
930 - ``ENOKEY``: the raw key was specified by Linux key ID, but no key
932 - ``ENOTTY``: this type of filesystem does not implement encryption
933 - ``EOPNOTSUPP``: the kernel was not configured with encryption
940 For v1 encryption policies, a master encryption key can also be
941 provided by adding it to a process-subscribed keyring, e.g. to a
957 Nevertheless, to add a key to one of the process-subscribed keyrings,
962 followed by the 16-character lower case hex representation of the
976 bytes ``raw[0..size-1]`` (inclusive) are the actual key.
979 with a filesystem-specific prefix such as "ext4:". However, the
980 filesystem-specific prefixes are deprecated and should not be used in
984 -------------
989 - `FS_IOC_REMOVE_ENCRYPTION_KEY`_
990 - `FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS`_
993 or removed by non-root users.
996 process-subscribed keyrings mechanism.
1005 The FS_IOC_REMOVE_ENCRYPTION_KEY ioctl removes a claim to a master
1022 - The key to remove is specified by ``key_spec``:
1024 - To remove a key used by v1 encryption policies, set
1030 - To remove a key used by v2 encryption policies, set
1034 For v2 policy keys, this ioctl is usable by non-root users. However,
1049 lock files that are still in-use, so this ioctl is expected to be used
1061 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY``: set if some file(s)
1062 are still in-use. Not guaranteed to be set in the case where only
1064 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS``: set if only the
1069 - ``EACCES``: The FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR key specifier type
1072 - ``EINVAL``: invalid key specifier type, or reserved bits were set
1073 - ``ENOKEY``: the key object was not found at all, i.e. it was never
1077 - ``ENOTTY``: this type of filesystem does not implement encryption
1078 - ``EOPNOTSUPP``: the kernel was not configured with encryption
1090 only meaningful if non-root users are adding and removing keys.
1097 ------------------
1103 master encryption key. It can be executed on any file or directory on
1126 - To get the status of a key for v1 encryption policies, set
1130 - To get the status of a key for v2 encryption policies, set
1136 - ``status`` indicates whether the key is absent, present, or
1142 - ``status_flags`` can contain the following flags:
1144 - ``FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF`` indicates that the key
1148 - ``user_count`` specifies the number of users who have added the key.
1154 - ``EINVAL``: invalid key specifier type, or reserved bits were set
1155 - ``ENOTTY``: this type of filesystem does not implement encryption
1156 - ``EOPNOTSUPP``: the kernel was not configured with encryption
1166 the filesystem-level keyring, i.e. the keyring managed by
1170 process-subscribed keyrings.
1176 ------------
1179 symlinks behave very similarly to their unencrypted counterparts ---
1183 - Unencrypted files, or files encrypted with a different encryption
1198 - Direct I/O is supported on encrypted files only under some
1201 - The fallocate operations FALLOC_FL_COLLAPSE_RANGE and
1205 - Online defragmentation of encrypted files is not supported. The
1209 - The ext4 filesystem does not support data journaling with encrypted
1212 - DAX (Direct Access) is not supported on encrypted files.
1214 - The maximum length of an encrypted symlink is 2 bytes shorter than
1224 ---------------
1230 - File metadata may be read, e.g. using stat().
1232 - Directories may be listed, in which case the filenames will be
1243 - Files may be deleted. That is, nondirectory files may be deleted
1245 rmdir() as usual. Therefore, ``rm`` and ``rm -r`` will work as
1248 - Symlink targets may be read and followed, but they will be presented
1272 (recursively) will inherit that encryption policy. Special files ---
1273 that is, named pipes, device nodes, and UNIX domain sockets --- will
1280 during ->lookup() to provide limited protection against offline
1284 this by validating all top-level encryption policies prior to access.
1301 through a set of extensions to the block layer called *blk-crypto*.
1302 blk-crypto allows filesystems to attach encryption contexts to bios
1304 in-line. For more information about blk-crypto, see
1305 :ref:`Documentation/block/inline-encryption.rst <inline_encryption>`.
1308 blk-crypto instead of the kernel crypto API to encrypt/decrypt file
1318 and where blk-crypto-fallback is unusable. (For blk-crypto-fallback
1327 the on-disk format, so users may freely switch back and forth between
1338 the filesystem must be mounted with ``-o inlinecrypt`` and inline
1355 ------------------
1357 An encryption policy is represented on-disk by
1361 exposed by the xattr-related system calls such as getxattr() and
1395 different files to be encrypted differently; see `Per-file encryption
1399 -----------------
1408 For the read path (->read_folio()) of regular files, filesystems can
1409 read the ciphertext into the page cache and decrypt it in-place. The
1413 For the write path (->writepage()) of regular files, filesystems
1414 cannot encrypt data in-place in the page cache, since the cached
1422 -----------------------------
1426 filename hashes. When a ->lookup() is requested, the filesystem
1436 i.e. the bytes actually stored on-disk in the directory entries. When
1437 asked to do a ->lookup() with the key, the filesystem just encrypts
1438 the user-supplied name to get the ciphertext.
1442 filenames. Therefore, readdir() must base64url-encode the ciphertext
1443 for presentation. For most filenames, this works fine; on ->lookup(),
1444 the filesystem just base64url-decodes the user-supplied name to get
1451 filesystem-specific hash(es) needed for directory lookups. This
1453 the filename given in ->lookup() back to a particular directory entry
1460 ``rm -r`` work as expected on encrypted directories.
1470 f2fs encryption using `kvm-xfstests
1471 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_::
1473 kvm-xfstests -c ext4,f2fs -g encrypt
1474 kvm-xfstests -c ext4,f2fs -g encrypt -m inlinecrypt
1477 a separate command, and it takes some time for kvm-xfstests to set up
1480 kvm-xfstests -c ubifs -g encrypt
1482 No tests should fail. However, tests that use non-default encryption
1493 kvm-xfstests, use the "encrypt" filesystem configuration::
1495 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1496 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt
1498 Because this runs many more tests than "-g encrypt" does, it takes
1499 much longer to run; so also consider using `gce-xfstests
1500 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/gce-xfstests.md>`_
1501 instead of kvm-xfstests::
1503 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1504 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt