Lines Matching +full:keys +full:- +full:per +full:- +full:group
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
27 with different keys and to have unencrypted files on the same
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, and
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 such as a table-based implementation of AES, it may be possible for an
98 Therefore, any encryption-specific access control checks would merely
107 security vulnerability, can compromise all encryption keys that are
110 However, fscrypt allows encryption keys to be removed from the kernel,
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.
128 - The kernel cannot magically wipe copies of the master key(s) that
135 containing keys to prevent it from being swapped out.
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 -----------
178 keys can be up to 64 bytes long, and must be at least as long as the
180 encryption modes being used. For example, if any AES-256 mode is
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 -----------------------
209 (Key Derivation Function) to derive the actual keys.
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
230 context bytes are used for other types of derived keys.
232 HKDF-SHA512 is preferred to the original AES-128-ECB based KDF because
235 used by other software, whereas the AES-128-ECB based KDF is ad-hoc.
237 Per-file encryption keys
238 ------------------------
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
250 Key derivation was chosen over key wrapping because wrapped keys would
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 logical block number
265 and a 16-byte per-file nonce. Also, the overhead of each Adiantum key
266 is 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
279 - For v2 encryption policies, the encryption is done with a per-mode
284 -----------------------
287 the encryption keys are derived from the master key, encryption mode
295 compliant with the UFS standard, which supports only 64 IV bits per
299 -----------------------
302 IV_INO_LBLK_32, the inode number is hashed with SipHash-2-4 (where the
304 logical block number mod 2^32 to produce a 32-bit IV.
308 per I/O request and may have only a small number of keyslots. This
313 ---------------
315 For master keys used for v2 encryption policies, a unique 16-byte "key
319 Dirhash keys
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 - AES-256-XTS for contents and AES-256-CTS-CBC for filenames
338 - AES-128-CBC for contents and AES-128-CTS-CBC for filenames
339 - Adiantum for both contents and filenames
341 If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair.
343 AES-128-CBC was added only for low-powered embedded devices with
345 use AES-128-CBC, CONFIG_CRYPTO_ESSIV and CONFIG_CRYPTO_SHA256 (or
346 another SHA-256 implementation) must be enabled so that ESSIV can be
349 Adiantum is a (primarily) stream cipher-based mode that is fast even
351 wide-block mode, unlike XTS. It can also eliminate the need to derive
352 per-file encryption keys. However, it depends on the security of two
353 primitives, XChaCha12 and AES-256, rather than just one. See the
354 paper "Adiantum: length-preserving encryption for entry-level
366 -------------------
375 - With CBC mode encryption, ESSIV is also used. Specifically, each IV
376 is encrypted with AES-256 where the AES-256 key is the SHA-256 hash
379 - With `DIRECT_KEY policies`_, the file's nonce is appended to the IV.
382 - With `IV_INO_LBLK_64 policies`_, the logical block number is limited
383 to 32 bits and is placed in bits 0-31 of the IV. The inode number
384 (which is also limited to 32 bits) is placed in bits 32-63.
386 - With `IV_INO_LBLK_32 policies`_, the logical block number is limited
387 to 32 bits and is placed in bits 0-31 of the IV. The inode number
395 --------------------
407 With CTS-CBC, the IV reuse means that when the plaintext filenames
411 weakness, as it is a wide-block encryption mode.
415 filenames shorter than 16 bytes are NUL-padded to 16 bytes before
417 via their ciphertexts, all filenames are NUL-padded to the next 4, 8,
418 16, or 32-byte boundary (configurable). 32 is recommended since this
432 ----------------------------
467 - ``version`` must be FSCRYPT_POLICY_V1 (0) if
473 - ``contents_encryption_mode`` and ``filenames_encryption_mode`` must
479 - ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
481 - FSCRYPT_POLICY_FLAGS_PAD_*: The amount of NUL padding to use when
484 - FSCRYPT_POLICY_FLAG_DIRECT_KEY: See `DIRECT_KEY policies`_.
485 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64: See `IV_INO_LBLK_64
487 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32: See `IV_INO_LBLK_32
496 - For v2 encryption policies, ``__reserved`` must be zeroed.
498 - For v1 encryption policies, ``master_key_descriptor`` specifies how
499 to find the master key in a keyring; see `Adding keys`_. It is up
502 ``SHA-512(SHA-512(master_key))``, but this particular scheme is not
519 corresponding master key as described in `Adding keys`_, all regular
541 filesystem with one key should consider using dm-crypt instead.
545 - ``EACCES``: the file is not owned by the process's uid, nor does the
548 - ``EEXIST``: the file is already encrypted with an encryption policy
550 - ``EINVAL``: an invalid encryption policy was specified (invalid
554 - ``ENOKEY``: a v2 encryption policy was specified, but the key with
558 - ``ENOTDIR``: the file is unencrypted and is a regular file, not a
560 - ``ENOTEMPTY``: the file is unencrypted and is a nonempty directory
561 - ``ENOTTY``: this type of filesystem does not implement encryption
562 - ``EOPNOTSUPP``: the kernel was not configured with encryption
567 feature flag enabled using ``tune2fs -O encrypt`` or ``mkfs.ext4 -O
569 - ``EPERM``: this directory may not be encrypted, e.g. because it is
571 - ``EROFS``: the filesystem is readonly
574 ----------------------------
578 - `FS_IOC_GET_ENCRYPTION_POLICY_EX`_
579 - `FS_IOC_GET_ENCRYPTION_POLICY`_
615 - ``EINVAL``: the file is encrypted, but it uses an unrecognized
617 - ``ENODATA``: the file is not encrypted
618 - ``ENOTTY``: this type of filesystem does not implement encryption,
621 - ``EOPNOTSUPP``: the kernel was not configured with encryption
624 - ``EOVERFLOW``: the file is encrypted and uses a recognized
648 Getting the per-filesystem salt
649 -------------------------------
653 generated 16-byte value stored in the filesystem superblock. This
655 from a passphrase or other low-entropy user credential.
661 ---------------------------------
664 On encrypted files and directories it gets the inode's 16-byte nonce.
671 Adding keys
672 -----------
714 - If the key is being added for use by v1 encryption policies, then
727 not need any privileges. However, the number of keys that can be
729 ``Documentation/security/keys/core.rst``).
731 - ``raw_size`` must be the size of the ``raw`` key provided, in bytes.
735 - ``key_id`` is 0 if the raw key is given directly in the ``raw``
737 type "fscrypt-provisioning" whose payload is
740 Since ``raw`` is variable-length, the total size of this key's
747 allow re-adding keys after a filesystem is unmounted and re-mounted,
748 without having to store the raw keys in userspace memory.
750 - ``raw`` is a variable-length field which must contain the actual
754 For v2 policy keys, the kernel keeps track of which user (identified
756 removed by that user --- or by "root", if they use
772 - ``EACCES``: FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR was specified, but the
776 - ``EDQUOT``: the key quota for this user would be exceeded by adding
778 - ``EINVAL``: invalid key size or key specifier type, or reserved bits
780 - ``EKEYREJECTED``: the raw key was specified by Linux key ID, but the
782 - ``ENOKEY``: the raw key was specified by Linux key ID, but no key
784 - ``ENOTTY``: this type of filesystem does not implement encryption
785 - ``EOPNOTSUPP``: the kernel was not configured with encryption
793 provided by adding it to a process-subscribed keyring, e.g. to a
799 combination with FS_IOC_REMOVE_ENCRYPTION_KEY (see `Removing keys`_),
809 Nevertheless, to add a key to one of the process-subscribed keyrings,
811 ``Documentation/security/keys/core.rst``). The key type must be
812 "logon"; keys of this type are kept in kernel memory and cannot be
814 followed by the 16-character lower case hex representation of the
828 bytes ``raw[0..size-1]`` (inclusive) are the actual key.
831 with a filesystem-specific prefix such as "ext4:". However, the
832 filesystem-specific prefixes are deprecated and should not be used in
835 Removing keys
836 -------------
841 - `FS_IOC_REMOVE_ENCRYPTION_KEY`_
842 - `FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS`_
844 These two ioctls differ only in cases where v2 policy keys are added
845 or removed by non-root users.
847 These ioctls don't work on keys that were added via the legacy
848 process-subscribed keyrings mechanism.
874 - The key to remove is specified by ``key_spec``:
876 - To remove a key used by v1 encryption policies, set
882 - To remove a key used by v2 encryption policies, set
886 For v2 policy keys, this ioctl is usable by non-root users. However,
901 lock files that are still in-use, so this ioctl is expected to be used
913 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY``: set if some file(s)
914 are still in-use. Not guaranteed to be set in the case where only
916 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS``: set if only the
921 - ``EACCES``: The FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR key specifier type
924 - ``EINVAL``: invalid key specifier type, or reserved bits were set
925 - ``ENOKEY``: the key object was not found at all, i.e. it was never
929 - ``ENOTTY``: this type of filesystem does not implement encryption
930 - ``EOPNOTSUPP``: the kernel was not configured with encryption
938 `FS_IOC_REMOVE_ENCRYPTION_KEY`_, except that for v2 policy keys, the
942 only meaningful if non-root users are adding and removing keys.
949 ------------------
978 - To get the status of a key for v1 encryption policies, set
982 - To get the status of a key for v2 encryption policies, set
988 - ``status`` indicates whether the key is absent, present, or
994 - ``status_flags`` can contain the following flags:
996 - ``FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF`` indicates that the key
997 has added by the current user. This is only set for keys
1000 - ``user_count`` specifies the number of users who have added the key.
1001 This is only set for keys identified by ``identifier`` rather than
1006 - ``EINVAL``: invalid key specifier type, or reserved bits were set
1007 - ``ENOTTY``: this type of filesystem does not implement encryption
1008 - ``EOPNOTSUPP``: the kernel was not configured with encryption
1017 FS_IOC_GET_ENCRYPTION_KEY_STATUS can only get the status of keys in
1018 the filesystem-level keyring, i.e. the keyring managed by
1022 process-subscribed keyrings.
1028 ------------
1031 symlinks behave very similarly to their unencrypted counterparts ---
1035 - Unencrypted files, or files encrypted with a different encryption
1050 - Direct I/O is not supported on encrypted files. Attempts to use
1053 - The fallocate operations FALLOC_FL_COLLAPSE_RANGE and
1057 - Online defragmentation of encrypted files is not supported. The
1061 - The ext4 filesystem does not support data journaling with encrypted
1064 - DAX (Direct Access) is not supported on encrypted files.
1066 - The st_size of an encrypted symlink will not necessarily give the
1069 than the plaintext due to NUL-padding and an extra 2-byte overhead.
1071 - The maximum length of an encrypted symlink is 2 bytes shorter than
1081 ---------------
1087 - File metadata may be read, e.g. using stat().
1089 - Directories may be listed, in which case the filenames will be
1100 - Files may be deleted. That is, nondirectory files may be deleted
1102 rmdir() as usual. Therefore, ``rm`` and ``rm -r`` will work as
1105 - Symlink targets may be read and followed, but they will be presented
1129 (recursively) will inherit that encryption policy. Special files ---
1130 that is, named pipes, device nodes, and UNIX domain sockets --- will
1137 during ->lookup() to provide limited protection against offline
1141 this by validating all top-level encryption policies prior to access.
1147 ------------------
1149 An encryption policy is represented on-disk by
1153 exposed by the xattr-related system calls such as getxattr() and
1186 different files to be encrypted differently; see `Per-file encryption
1187 keys`_ and `DIRECT_KEY policies`_.
1190 -----------------
1192 For the read path (->readpage()) of regular files, filesystems can
1193 read the ciphertext into the page cache and decrypt it in-place. The
1197 For the write path (->writepage()) of regular files, filesystems
1198 cannot encrypt data in-place in the page cache, since the cached
1209 uses blk-crypto to perform the en/decryption instead of making use of
1218 -----------------------------
1222 filename hashes. When a ->lookup() is requested, the filesystem
1232 i.e. the bytes actually stored on-disk in the directory entries. When
1233 asked to do a ->lookup() with the key, the filesystem just encrypts
1234 the user-supplied name to get the ciphertext.
1238 filenames. Therefore, readdir() must base64-encode the ciphertext for
1239 presentation. For most filenames, this works fine; on ->lookup(), the
1240 filesystem just base64-decodes the user-supplied name to get back to
1247 filesystem-specific hash(es) needed for directory lookups. This
1249 the filename given in ->lookup() back to a particular directory entry
1256 ``rm -r`` work as expected on encrypted directories.
1263 group on the relevant filesystem(s). One can also run the tests
1266 f2fs encryption using `kvm-xfstests
1267 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_::
1269 kvm-xfstests -c ext4,f2fs -g encrypt
1270 kvm-xfstests -c ext4,f2fs -g encrypt -m inlinecrypt
1273 a separate command, and it takes some time for kvm-xfstests to set up
1276 kvm-xfstests -c ubifs -g encrypt
1278 No tests should fail. However, tests that use non-default encryption
1284 Besides running the "encrypt" group tests, for ext4 and f2fs it's also
1289 kvm-xfstests, use the "encrypt" filesystem configuration::
1291 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1292 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt
1294 Because this runs many more tests than "-g encrypt" does, it takes
1295 much longer to run; so also consider using `gce-xfstests
1296 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/gce-xfstests.md>`_
1297 instead of kvm-xfstests::
1299 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1300 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt