Lines Matching +full:hardware +full:- +full:wise

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
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
80 Cryptographic API algorithms or inline encryption hardware are. If a
81 vulnerable algorithm is used, such as a table-based implementation of
98 Therefore, any encryption-specific access control checks would merely
102 Read-only kernel memory compromise
105 Unless `hardware-wrapped keys`_ are used, an attacker who gains the
108 compromise all fscrypt keys that are currently in-use. This also
112 However, if hardware-wrapped keys are used, then the fscrypt master
124 thereby wiping their per-file keys and making them once again appear
129 - Per-file keys for in-use files will *not* be removed or wiped.
135 - The kernel cannot magically wipe copies of the master key(s) that
144 - In general, decrypted contents and filenames in the kernel VFS
150 - Secret keys might still exist in CPU registers or in other places
158 any in-use fscrypt keys. Thus, usually fscrypt provides no meaningful
164 However, if `hardware-wrapped keys`_ are used, such attackers will be
167 useful if the attacker is significantly time-limited and/or
168 bandwidth-limited, so they can only exfiltrate some data and need to
177 - There is no verification that the provided master key is correct.
179 with another user's encrypted files to which they have read-only
183 meaning of "read-only access".
185 - A compromise of a per-file key also compromises the master key from
188 - Non-root users cannot securely remove encryption keys.
198 hardware-wrapped keys. The use of hardware-wrapped keys modifies the
199 key hierarchy slightly. For details, see `Hardware-wrapped keys`_.
202 -----------
207 encryption modes being used. For example, if any AES-256 mode is
210 policy and AES-256-XTS is used; such keys must be 64 bytes.
219 **must not** directly use a password as a master key, zero-pad a
227 therefore, if userspace derives the key from a low-entropy secret such
232 -----------------------
241 encryption policies. (No real-world attack is currently known on this
245 For v1 encryption policies, the KDF only supports deriving per-file
247 AES-128-ECB, using the file's 16-byte nonce as the AES key. The
251 For v2 encryption policies, the KDF is HKDF-SHA512. The master key is
253 "application-specific information string" is used for each distinct
254 key to be derived. For example, when a per-file encryption key is
255 derived, the application-specific information string is the file's
259 HKDF-SHA512 is preferred to the original AES-128-ECB based KDF because
262 used by other software, whereas the AES-128-ECB based KDF is ad-hoc.
264 Per-file encryption keys
265 ------------------------
270 cases, fscrypt does this by deriving per-file keys. When a new
272 fscrypt randomly generates a 16-byte nonce and stores it in the
278 require larger xattrs which would be less likely to fit in-line in the
287 -------------------
291 long IVs --- long enough to hold both an 8-byte data unit index and a
292 16-byte per-file nonce. Also, the overhead of each Adiantum key is
293 greater than that of an AES-256-XTS key.
298 per-file encryption keys are not used. Instead, whenever any data
299 (contents or filenames) is encrypted, the file's 16-byte nonce is
302 - For v1 encryption policies, the encryption is done directly with the
306 - For v2 encryption policies, the encryption is done with a per-mode
311 -----------------------
321 This format is optimized for use with inline encryption hardware
326 -----------------------
329 IV_INO_LBLK_32, the inode number is hashed with SipHash-2-4 (where the
331 unit index mod 2^32 to produce a 32-bit IV.
333 This format is optimized for use with inline encryption hardware
337 when necessary due to hardware limitations.
340 ---------------
342 For master keys used for v2 encryption policies, a unique 16-byte "key
347 ------------
349 For directories that are indexed using a secret-keyed dirhash over the
350 plaintext filenames, the KDF is also used to derive a 128-bit
351 SipHash-2-4 key per directory in order to hash filenames. This works
352 just like deriving a per-file encryption key, except that a different
353 KDF context is used. Currently, only casefolded ("case-insensitive")
364 ---------------
368 - AES-256-XTS for contents and AES-256-CBC-CTS for filenames
369 - AES-256-XTS for contents and AES-256-HCTR2 for filenames
370 - Adiantum for both contents and filenames
371 - AES-128-CBC-ESSIV for contents and AES-128-CBC-CTS for filenames
372 - SM4-XTS for contents and SM4-CBC-CTS for filenames
374 Note: in the API, "CBC" means CBC-ESSIV, and "CTS" means CBC-CTS.
375 So, for example, FSCRYPT_MODE_AES_256_CTS means AES-256-CBC-CTS.
381 `CBC-ESSIV mode
382 <https://en.wikipedia.org/wiki/Disk_encryption_theory#Encrypted_salt-sector_initialization_vector_(…
383 or a wide-block cipher. Filenames encryption uses a
384 block cipher in `CBC-CTS mode
385 <https://en.wikipedia.org/wiki/Ciphertext_stealing>`_ or a wide-block
388 The (AES-256-XTS, AES-256-CBC-CTS) pair is the recommended default.
392 The (AES-256-XTS, AES-256-HCTR2) pair is also a good choice that
393 upgrades the filenames encryption to use a wide-block cipher. (A
394 *wide-block cipher*, also called a tweakable super-pseudorandom
396 entire result.) As described in `Filenames encryption`_, a wide-block
397 cipher is the ideal mode for the problem domain, though CBC-CTS is the
402 of hardware acceleration for AES. Adiantum is a wide-block cipher
403 that uses XChaCha12 and AES-256 as its underlying components. Most of
408 The (AES-128-CBC-ESSIV, AES-128-CBC-CTS) pair was added to try to
410 in the CPU but do have a non-inline crypto engine such as CAAM or CESA
411 that supports AES-CBC (and not AES-XTS). This is deprecated. It has
417 - (SM4-XTS, SM4-CBC-CTS)
425 ---------------------
428 only the basic support from the crypto API needed to use AES-256-XTS
429 and AES-256-CBC-CTS encryption. For optimal performance, it is
430 strongly recommended to also enable any available platform-specific
432 wish to use. Support for any "non-default" encryption modes typically
438 also be configured to use inline encryption hardware instead of the
443 - AES-256-XTS and AES-256-CBC-CTS
444 - Recommended:
445 - arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
446 - x86: CONFIG_CRYPTO_AES_NI_INTEL
448 - AES-256-HCTR2
449 - Mandatory:
450 - CONFIG_CRYPTO_HCTR2
451 - Recommended:
452 - arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
453 - x86: CONFIG_CRYPTO_AES_NI_INTEL
455 - Adiantum
456 - Mandatory:
457 - CONFIG_CRYPTO_ADIANTUM
458 - Recommended:
459 - arm32: CONFIG_CRYPTO_NHPOLY1305_NEON
460 - arm64: CONFIG_CRYPTO_NHPOLY1305_NEON
461 - x86: CONFIG_CRYPTO_NHPOLY1305_SSE2
462 - x86: CONFIG_CRYPTO_NHPOLY1305_AVX2
464 - AES-128-CBC-ESSIV and AES-128-CBC-CTS:
465 - Mandatory:
466 - CONFIG_CRYPTO_ESSIV
467 - CONFIG_CRYPTO_SHA256 or another SHA-256 implementation
468 - Recommended:
469 - AES-CBC acceleration
472 -------------------
476 data unit incorporates the zero-based index of the data unit within
486 * Fixed-size data units. This is how all filesystems other than UBIFS
488 is zero-padded if needed. By default, the data unit size is equal
490 a sub-block data unit size via the ``log2_data_unit_size`` field of
493 * Variable-size data units. This is what UBIFS does. Each "UBIFS
495 length, possibly compressed data, zero-padded to the next 16-byte
496 boundary. Users cannot select a sub-block data unit size on UBIFS.
502 Therefore a f2fs-compressed file still uses fixed-size data units, and
506 per-file keys. In this case, the IV for each data unit is simply the
508 encryption setting that does not use per-file keys. For these, some
511 - With `DIRECT_KEY policies`_, the data unit index is placed in bits
512 0-63 of the IV, and the file's nonce is placed in bits 64-191.
514 - With `IV_INO_LBLK_64 policies`_, the data unit index is placed in
515 bits 0-31 of the IV, and the file's inode number is placed in bits
516 32-63. This setting is only allowed when data unit indices and
519 - With `IV_INO_LBLK_32 policies`_, the file's inode number is hashed
521 to 32 bits and placed in bits 0-31 of the IV. This setting is only
528 passed to AES-128-CBC, it is encrypted with AES-256 where the AES-256
529 key is the SHA-256 hash of the file's contents encryption key.
532 --------------------
544 With CBC-CTS, the IV reuse means that when the plaintext filenames share a
548 wide-block encryption modes.
552 filenames shorter than 16 bytes are NUL-padded to 16 bytes before
554 via their ciphertexts, all filenames are NUL-padded to the next 4, 8,
555 16, or 32-byte boundary (configurable). 32 is recommended since this
569 ----------------------------
605 - ``version`` must be FSCRYPT_POLICY_V1 (0) if
611 - ``contents_encryption_mode`` and ``filenames_encryption_mode`` must
624 - ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
626 - FSCRYPT_POLICY_FLAGS_PAD_*: The amount of NUL padding to use when
629 - FSCRYPT_POLICY_FLAG_DIRECT_KEY: See `DIRECT_KEY policies`_.
630 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64: See `IV_INO_LBLK_64
632 - FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32: See `IV_INO_LBLK_32
641 - ``log2_data_unit_size`` is the log2 of the data unit size in bytes,
645 underlying encryption algorithm (such as AES-256-XTS) in 4096-byte
656 compatibility with inline encryption hardware that only supports
659 particular system's inline encryption hardware.
664 - For v2 encryption policies, ``__reserved`` must be zeroed.
666 - For v1 encryption policies, ``master_key_descriptor`` specifies how
670 ``SHA-512(SHA-512(master_key))``, but this particular scheme is not
709 filesystem with one key should consider using dm-crypt instead.
713 - ``EACCES``: the file is not owned by the process's uid, nor does the
716 - ``EEXIST``: the file is already encrypted with an encryption policy
718 - ``EINVAL``: an invalid encryption policy was specified (invalid
722 - ``ENOKEY``: a v2 encryption policy was specified, but the key with
726 - ``ENOTDIR``: the file is unencrypted and is a regular file, not a
728 - ``ENOTEMPTY``: the file is unencrypted and is a nonempty directory
729 - ``ENOTTY``: this type of filesystem does not implement encryption
730 - ``EOPNOTSUPP``: the kernel was not configured with encryption
735 feature flag enabled using ``tune2fs -O encrypt`` or ``mkfs.ext4 -O
737 - ``EPERM``: this directory may not be encrypted, e.g. because it is
739 - ``EROFS``: the filesystem is readonly
742 ----------------------------
746 - `FS_IOC_GET_ENCRYPTION_POLICY_EX`_
747 - `FS_IOC_GET_ENCRYPTION_POLICY`_
783 - ``EINVAL``: the file is encrypted, but it uses an unrecognized
785 - ``ENODATA``: the file is not encrypted
786 - ``ENOTTY``: this type of filesystem does not implement encryption,
789 - ``EOPNOTSUPP``: the kernel was not configured with encryption
792 - ``EOVERFLOW``: the file is encrypted and uses a recognized
816 Getting the per-filesystem salt
817 -------------------------------
821 generated 16-byte value stored in the filesystem superblock. This
823 from a passphrase or other low-entropy user credential.
829 ---------------------------------
832 On encrypted files and directories it gets the inode's 16-byte nonce.
840 -----------
884 - If the key is being added for use by v1 encryption policies, then
901 - ``raw_size`` must be the size of the ``raw`` key provided, in bytes.
905 - ``key_id`` is 0 if the key is given directly in the ``raw`` field.
907 "fscrypt-provisioning" whose payload is struct
911 variable-length, the total size of this key's payload must be
917 allow re-adding keys after a filesystem is unmounted and re-mounted,
920 - ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
922 - FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED: This denotes that the key is a
923 hardware-wrapped key. See `Hardware-wrapped keys`_. This flag
926 - ``raw`` is a variable-length field which must contain the actual
934 removed by that user --- or by "root", if they use
950 - ``EACCES``: FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR was specified, but the
954 - ``EBADMSG``: invalid hardware-wrapped key
955 - ``EDQUOT``: the key quota for this user would be exceeded by adding
957 - ``EINVAL``: invalid key size or key specifier type, or reserved bits
959 - ``EKEYREJECTED``: the key was specified by Linux key ID, but the key
961 - ``ENOKEY``: the key was specified by Linux key ID, but no key exists
963 - ``ENOTTY``: this type of filesystem does not implement encryption
964 - ``EOPNOTSUPP``: the kernel was not configured with encryption
966 had encryption enabled on it; or a hardware wrapped key was specified
967 but the filesystem does not support inline encryption or the hardware
968 does not support hardware-wrapped keys
974 provided by adding it to a process-subscribed keyring, e.g. to a
990 Nevertheless, to add a key to one of the process-subscribed keyrings,
995 followed by the 16-character lower case hex representation of the
1009 bytes ``raw[0..size-1]`` (inclusive) are the actual key.
1012 with a filesystem-specific prefix such as "ext4:". However, the
1013 filesystem-specific prefixes are deprecated and should not be used in
1017 -------------
1022 - `FS_IOC_REMOVE_ENCRYPTION_KEY`_
1023 - `FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS`_
1026 or removed by non-root users.
1029 process-subscribed keyrings mechanism.
1054 - The key to remove is specified by ``key_spec``:
1056 - To remove a key used by v1 encryption policies, set
1062 - To remove a key used by v2 encryption policies, set
1066 For v2 policy keys, this ioctl is usable by non-root users. However,
1081 lock files that are still in-use, so this ioctl is expected to be used
1093 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY``: set if some file(s)
1094 are still in-use. Not guaranteed to be set in the case where only
1096 - ``FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS``: set if only the
1101 - ``EACCES``: The FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR key specifier type
1104 - ``EINVAL``: invalid key specifier type, or reserved bits were set
1105 - ``ENOKEY``: the key object was not found at all, i.e. it was never
1109 - ``ENOTTY``: this type of filesystem does not implement encryption
1110 - ``EOPNOTSUPP``: the kernel was not configured with encryption
1122 only meaningful if non-root users are adding and removing keys.
1129 ------------------
1158 - To get the status of a key for v1 encryption policies, set
1162 - To get the status of a key for v2 encryption policies, set
1168 - ``status`` indicates whether the key is absent, present, or
1174 - ``status_flags`` can contain the following flags:
1176 - ``FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF`` indicates that the key
1180 - ``user_count`` specifies the number of users who have added the key.
1186 - ``EINVAL``: invalid key specifier type, or reserved bits were set
1187 - ``ENOTTY``: this type of filesystem does not implement encryption
1188 - ``EOPNOTSUPP``: the kernel was not configured with encryption
1198 the filesystem-level keyring, i.e. the keyring managed by
1202 process-subscribed keyrings.
1208 ------------
1211 symlinks behave very similarly to their unencrypted counterparts ---
1215 - Unencrypted files, or files encrypted with a different encryption
1230 - Direct I/O is supported on encrypted files only under some
1233 - The fallocate operations FALLOC_FL_COLLAPSE_RANGE and
1237 - Online defragmentation of encrypted files is not supported. The
1241 - The ext4 filesystem does not support data journaling with encrypted
1244 - DAX (Direct Access) is not supported on encrypted files.
1246 - The maximum length of an encrypted symlink is 2 bytes shorter than
1256 ---------------
1262 - File metadata may be read, e.g. using stat().
1264 - Directories may be listed, in which case the filenames will be
1275 - Files may be deleted. That is, nondirectory files may be deleted
1277 rmdir() as usual. Therefore, ``rm`` and ``rm -r`` will work as
1280 - Symlink targets may be read and followed, but they will be presented
1304 (recursively) will inherit that encryption policy. Special files ---
1305 that is, named pipes, device nodes, and UNIX domain sockets --- will
1312 during ->lookup() to provide limited protection against offline
1316 this by validating all top-level encryption policies prior to access.
1322 hardware* that can encrypt/decrypt data while it is on its way to/from
1324 extensions to the block layer called *blk-crypto*. blk-crypto allows
1326 specify how the data will be encrypted or decrypted in-line. For more
1327 information about blk-crypto, see
1328 :ref:`Documentation/block/inline-encryption.rst <inline_encryption>`.
1331 blk-crypto instead of the kernel crypto API to encrypt/decrypt file
1339 inline encryption hardware doesn't have the needed crypto capabilities
1341 and where blk-crypto-fallback is unusable. (For blk-crypto-fallback
1344 protected by a raw key rather than a hardware-wrapped key.)
1348 inline encryption hardware that supports that data unit size.
1351 the on-disk format, so users may freely switch back and forth between
1353 files that are protected by a hardware-wrapped key can only be
1354 encrypted/decrypted by the inline encryption hardware and therefore
1356 more information about hardware-wrapped keys, see below.
1358 Hardware-wrapped keys
1359 ---------------------
1361 fscrypt supports using *hardware-wrapped keys* when the inline
1362 encryption hardware supports it. Such keys are only present in kernel
1364 (decrypted) by the inline encryption hardware and are temporally bound
1369 encryption hardware, e.g. filenames encryption.
1371 Note that hardware-wrapped keys aren't specific to fscrypt; they are a
1372 block layer feature (part of *blk-crypto*). For more details about
1373 hardware-wrapped keys, see the block layer documentation at
1374 :ref:`Documentation/block/inline-encryption.rst
1376 the details of how fscrypt can use hardware-wrapped keys.
1378 fscrypt supports hardware-wrapped keys by allowing the fscrypt master
1379 keys to be hardware-wrapped keys as an alternative to raw keys. To
1380 add a hardware-wrapped key with `FS_IOC_ADD_ENCRYPTION_KEY`_,
1384 applicable. The key must be in ephemerally-wrapped form, not
1385 long-term wrapped form.
1387 Some limitations apply. First, files protected by a hardware-wrapped
1388 key are tied to the system's inline encryption hardware. Therefore
1391 currently the hardware-wrapped key support is only compatible with
1395 this limitation by passing per-file nonces down the storage stack to
1396 allow the hardware to derive per-file keys.
1398 Implementation-wise, to encrypt/decrypt the contents of files that are
1399 protected by a hardware-wrapped key, fscrypt uses blk-crypto,
1400 attaching the hardware-wrapped key to the bio crypt contexts. As is
1403 hardware-wrapped key, the hardware doesn't program the given key
1404 directly into a keyslot but rather unwraps it (using the hardware's
1414 key from a hardware-wrapped key, fscrypt asks the inline encryption
1415 hardware to derive a cryptographically isolated "software secret" from
1416 the hardware-wrapped key. fscrypt uses this "software secret" to key
1419 Note that this implies that the hardware-wrapped key feature only
1431 the filesystem must be mounted with ``-o inlinecrypt`` and inline
1432 encryption hardware must be present. However, a software fallback
1448 ------------------
1450 An encryption policy is represented on-disk by
1454 exposed by the xattr-related system calls such as getxattr() and
1488 different files to be encrypted differently; see `Per-file encryption
1492 -----------------
1496 inline encryption hardware will encrypt/decrypt the file contents.
1501 For the read path (->read_folio()) of regular files, filesystems can
1502 read the ciphertext into the page cache and decrypt it in-place. The
1506 For the write path (->writepages()) of regular files, filesystems
1507 cannot encrypt data in-place in the page cache, since the cached
1515 -----------------------------
1519 filename hashes. When a ->lookup() is requested, the filesystem
1529 i.e. the bytes actually stored on-disk in the directory entries. When
1530 asked to do a ->lookup() with the key, the filesystem just encrypts
1531 the user-supplied name to get the ciphertext.
1535 filenames. Therefore, readdir() must base64url-encode the ciphertext
1536 for presentation. For most filenames, this works fine; on ->lookup(),
1537 the filesystem just base64url-decodes the user-supplied name to get
1544 filesystem-specific hash(es) needed for directory lookups. This
1546 the filename given in ->lookup() back to a particular directory entry
1553 ``rm -r`` work as expected on encrypted directories.
1563 f2fs encryption using `kvm-xfstests
1564 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_::
1566 kvm-xfstests -c ext4,f2fs -g encrypt
1567 kvm-xfstests -c ext4,f2fs -g encrypt -m inlinecrypt
1570 a separate command, and it takes some time for kvm-xfstests to set up
1573 kvm-xfstests -c ubifs -g encrypt
1575 No tests should fail. However, tests that use non-default encryption
1586 kvm-xfstests, use the "encrypt" filesystem configuration::
1588 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1589 kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt
1591 Because this runs many more tests than "-g encrypt" does, it takes
1592 much longer to run; so also consider using `gce-xfstests
1593 <https://github.com/tytso/xfstests-bld/blob/master/Documentation/gce-xfstests.md>`_
1594 instead of kvm-xfstests::
1596 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto
1597 gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt