@@ -261,9 +261,9 @@ DIRECT_KEY policies
261261
262262The Adiantum encryption mode (see `Encryption modes and usage `_) is
263263suitable for both contents and filenames encryption, and it accepts
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.
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.
267267
268268Therefore, to improve performance and save memory, for Adiantum a
269269"direct key" configuration is supported. When the user has enabled
@@ -300,8 +300,8 @@ IV_INO_LBLK_32 policies
300300
301301IV_INO_LBLK_32 policies work like IV_INO_LBLK_64, except that for
302302IV_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
304- logical block number mod 2^32 to produce a 32-bit IV.
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.
305305
306306This format is optimized for use with inline encryption hardware
307307compliant with the eMMC v5.2 standard, which supports only 32 IV bits
@@ -451,31 +451,62 @@ acceleration is recommended:
451451Contents encryption
452452-------------------
453453
454- For file contents, each filesystem block is encrypted independently.
455- Starting from Linux kernel 5.5, encryption of filesystems with block
456- size less than system's page size is supported.
457-
458- Each block's IV is set to the logical block number within the file as
459- a little endian number, except that:
460-
461- - With CBC mode encryption, ESSIV is also used. Specifically, each IV
462- is encrypted with AES-256 where the AES-256 key is the SHA-256 hash
463- of the file's data encryption key.
464-
465- - With `DIRECT_KEY policies `_, the file's nonce is appended to the IV.
466- Currently this is only allowed with the Adiantum encryption mode.
467-
468- - With `IV_INO_LBLK_64 policies `_, the logical block number is limited
469- to 32 bits and is placed in bits 0-31 of the IV. The inode number
470- (which is also limited to 32 bits) is placed in bits 32-63.
471-
472- - With `IV_INO_LBLK_32 policies `_, the logical block number is limited
473- to 32 bits and is placed in bits 0-31 of the IV. The inode number
474- is then hashed and added mod 2^32.
475-
476- Note that because file logical block numbers are included in the IVs,
477- filesystems must enforce that blocks are never shifted around within
478- encrypted files, e.g. via "collapse range" or "insert range".
454+ For contents encryption, each file's contents is divided into "data
455+ units". Each data unit is encrypted independently. The IV for each
456+ data unit incorporates the zero-based index of the data unit within
457+ the file. This ensures that each data unit within a file is encrypted
458+ differently, which is essential to prevent leaking information.
459+
460+ Note: the encryption depending on the offset into the file means that
461+ operations like "collapse range" and "insert range" that rearrange the
462+ extent mapping of files are not supported on encrypted files.
463+
464+ There are two cases for the sizes of the data units:
465+
466+ * Fixed-size data units. This is how all filesystems other than UBIFS
467+ work. A file's data units are all the same size; the last data unit
468+ is zero-padded if needed. By default, the data unit size is equal
469+ to the filesystem block size. On some filesystems, users can select
470+ a sub-block data unit size via the ``log2_data_unit_size `` field of
471+ the encryption policy; see `FS_IOC_SET_ENCRYPTION_POLICY `_.
472+
473+ * Variable-size data units. This is what UBIFS does. Each "UBIFS
474+ data node" is treated as a crypto data unit. Each contains variable
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.
477+
478+ In the case of compression + encryption, the compressed data is
479+ encrypted. UBIFS compression works as described above. f2fs
480+ compression works a bit differently; it compresses a number of
481+ filesystem blocks into a smaller number of filesystem blocks.
482+ Therefore a f2fs-compressed file still uses fixed-size data units, and
483+ it is encrypted in a similar way to a file containing holes.
484+
485+ As mentioned in `Key hierarchy `_, the default encryption setting uses
486+ per-file keys. In this case, the IV for each data unit is simply the
487+ index of the data unit in the file. However, users can select an
488+ encryption setting that does not use per-file keys. For these, some
489+ kind of file identifier is incorporated into the IVs as follows:
490+
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.
493+
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
497+ inode numbers fit in 32 bits.
498+
499+ - With `IV_INO_LBLK_32 policies `_, the file's inode number is hashed
500+ and added to the data unit index. The resulting value is truncated
501+ to 32 bits and placed in bits 0-31 of the IV. This setting is only
502+ allowed when data unit indices and inode numbers fit in 32 bits.
503+
504+ The byte order of the IV is always little endian.
505+
506+ If the user selects FSCRYPT_MODE_AES_128_CBC for the contents mode, an
507+ ESSIV layer is automatically included. In this case, before the IV is
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.
479510
480511Filenames encryption
481512--------------------
@@ -544,7 +575,8 @@ follows::
544575 __u8 contents_encryption_mode;
545576 __u8 filenames_encryption_mode;
546577 __u8 flags;
547- __u8 __reserved[4];
578+ __u8 log2_data_unit_size;
579+ __u8 __reserved[3];
548580 __u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
549581 };
550582
@@ -586,6 +618,29 @@ This structure must be initialized as follows:
586618 The DIRECT_KEY, IV_INO_LBLK_64, and IV_INO_LBLK_32 flags are
587619 mutually exclusive.
588620
621+ - ``log2_data_unit_size `` is the log2 of the data unit size in bytes,
622+ or 0 to select the default data unit size. The data unit size is
623+ the granularity of file contents encryption. For example, setting
624+ ``log2_data_unit_size `` to 12 causes file contents be passed to the
625+ underlying encryption algorithm (such as AES-256-XTS) in 4096-byte
626+ data units, each with its own IV.
627+
628+ Not all filesystems support setting ``log2_data_unit_size ``. ext4
629+ and f2fs support it since Linux v6.7. On filesystems that support
630+ it, the supported nonzero values are 9 through the log2 of the
631+ filesystem block size, inclusively. The default value of 0 selects
632+ the filesystem block size.
633+
634+ The main use case for ``log2_data_unit_size `` is for selecting a
635+ data unit size smaller than the filesystem block size for
636+ compatibility with inline encryption hardware that only supports
637+ smaller data unit sizes. ``/sys/block/$disk/queue/crypto/ `` may be
638+ useful for checking which data unit sizes are supported by a
639+ particular system's inline encryption hardware.
640+
641+ Leave this field zeroed unless you are certain you need it. Using
642+ an unnecessarily small data unit size reduces performance.
643+
589644- For v2 encryption policies, ``__reserved `` must be zeroed.
590645
591646- For v1 encryption policies, ``master_key_descriptor `` specifies how
@@ -1079,8 +1134,8 @@ The caller must zero all input fields, then fill in ``key_spec``:
10791134On success, 0 is returned and the kernel fills in the output fields:
10801135
10811136- ``status `` indicates whether the key is absent, present, or
1082- incompletely removed. Incompletely removed means that the master
1083- secret has been removed , but some files are still in use; i.e.,
1137+ incompletely removed. Incompletely removed means that removal has
1138+ been initiated , but some files are still in use; i.e.,
10841139 `FS_IOC_REMOVE_ENCRYPTION_KEY `_ returned 0 but set the informational
10851140 status flag FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY.
10861141
0 commit comments