@@ -38,20 +38,14 @@ fail at runtime.
38
38
Use cases
39
39
=========
40
40
41
- By itself, the base fs-verity feature only provides integrity
42
- protection, i.e. detection of accidental (non-malicious) corruption.
41
+ By itself, fs-verity only provides integrity protection, i.e.
42
+ detection of accidental (non-malicious) corruption.
43
43
44
44
However, because fs-verity makes retrieving the file hash extremely
45
45
efficient, it's primarily meant to be used as a tool to support
46
46
authentication (detection of malicious modifications) or auditing
47
47
(logging file hashes before use).
48
48
49
- Trusted userspace code (e.g. operating system code running on a
50
- read-only partition that is itself authenticated by dm-verity) can
51
- authenticate the contents of an fs-verity file by using the
52
- `FS_IOC_MEASURE_VERITY `_ ioctl to retrieve its hash, then verifying a
53
- digital signature of it.
54
-
55
49
A standard file hash could be used instead of fs-verity. However,
56
50
this is inefficient if the file is large and only a small portion may
57
51
be accessed. This is often the case for Android application package
@@ -69,24 +63,31 @@ still be used on read-only filesystems. fs-verity is for files that
69
63
must live on a read-write filesystem because they are independently
70
64
updated and potentially user-installed, so dm-verity cannot be used.
71
65
72
- The base fs-verity feature is a hashing mechanism only; actually
73
- authenticating the files may be done by:
74
-
75
- * Userspace-only
76
-
77
- * Builtin signature verification + userspace policy
78
-
79
- fs-verity optionally supports a simple signature verification
80
- mechanism where users can configure the kernel to require that
81
- all fs-verity files be signed by a key loaded into a keyring;
82
- see `Built-in signature verification `_.
83
-
84
- * Integrity Measurement Architecture (IMA)
85
-
86
- IMA supports including fs-verity file digests and signatures in the
87
- IMA measurement list and verifying fs-verity based file signatures
88
- stored as security.ima xattrs, based on policy.
89
-
66
+ fs-verity does not mandate a particular scheme for authenticating its
67
+ file hashes. (Similarly, dm-verity does not mandate a particular
68
+ scheme for authenticating its block device root hashes.) Options for
69
+ authenticating fs-verity file hashes include:
70
+
71
+ - Trusted userspace code. Often, the userspace code that accesses
72
+ files can be trusted to authenticate them. Consider e.g. an
73
+ application that wants to authenticate data files before using them,
74
+ or an application loader that is part of the operating system (which
75
+ is already authenticated in a different way, such as by being loaded
76
+ from a read-only partition that uses dm-verity) and that wants to
77
+ authenticate applications before loading them. In these cases, this
78
+ trusted userspace code can authenticate a file's contents by
79
+ retrieving its fs-verity digest using `FS_IOC_MEASURE_VERITY `_, then
80
+ verifying a signature of it using any userspace cryptographic
81
+ library that supports digital signatures.
82
+
83
+ - Integrity Measurement Architecture (IMA). IMA supports fs-verity
84
+ file digests as an alternative to its traditional full file digests.
85
+ "IMA appraisal" enforces that files contain a valid, matching
86
+ signature in their "security.ima" extended attribute, as controlled
87
+ by the IMA policy. For more information, see the IMA documentation.
88
+
89
+ - Trusted userspace code in combination with `Built-in signature
90
+ verification `_. This approach should be used only with great care.
90
91
91
92
User API
92
93
========
@@ -111,8 +112,7 @@ follows::
111
112
};
112
113
113
114
This structure contains the parameters of the Merkle tree to build for
114
- the file, and optionally contains a signature. It must be initialized
115
- as follows:
115
+ the file. It must be initialized as follows:
116
116
117
117
- ``version `` must be 1.
118
118
- ``hash_algorithm `` must be the identifier for the hash algorithm to
@@ -129,12 +129,14 @@ as follows:
129
129
file or device. Currently the maximum salt size is 32 bytes.
130
130
- ``salt_ptr `` is the pointer to the salt, or NULL if no salt is
131
131
provided.
132
- - ``sig_size `` is the size of the signature in bytes, or 0 if no
133
- signature is provided. Currently the signature is (somewhat
134
- arbitrarily) limited to 16128 bytes. See `Built-in signature
135
- verification `_ for more information.
136
- - ``sig_ptr `` is the pointer to the signature, or NULL if no
137
- signature is provided.
132
+ - ``sig_size `` is the size of the builtin signature in bytes, or 0 if no
133
+ builtin signature is provided. Currently the builtin signature is
134
+ (somewhat arbitrarily) limited to 16128 bytes.
135
+ - ``sig_ptr `` is the pointer to the builtin signature, or NULL if no
136
+ builtin signature is provided. A builtin signature is only needed
137
+ if the `Built-in signature verification `_ feature is being used. It
138
+ is not needed for IMA appraisal, and it is not needed if the file
139
+ signature is being handled entirely in userspace.
138
140
- All reserved fields must be zeroed.
139
141
140
142
FS_IOC_ENABLE_VERITY causes the filesystem to build a Merkle tree for
@@ -158,7 +160,7 @@ fatal signal), no changes are made to the file.
158
160
FS_IOC_ENABLE_VERITY can fail with the following errors:
159
161
160
162
- ``EACCES ``: the process does not have write access to the file
161
- - ``EBADMSG ``: the signature is malformed
163
+ - ``EBADMSG ``: the builtin signature is malformed
162
164
- ``EBUSY ``: this ioctl is already running on the file
163
165
- ``EEXIST ``: the file already has verity enabled
164
166
- ``EFAULT ``: the caller provided inaccessible memory
@@ -168,10 +170,10 @@ FS_IOC_ENABLE_VERITY can fail with the following errors:
168
170
reserved bits are set; or the file descriptor refers to neither a
169
171
regular file nor a directory.
170
172
- ``EISDIR ``: the file descriptor refers to a directory
171
- - ``EKEYREJECTED ``: the signature doesn't match the file
172
- - ``EMSGSIZE ``: the salt or signature is too long
173
- - ``ENOKEY ``: the fs-verity keyring doesn't contain the certificate
174
- needed to verify the signature
173
+ - ``EKEYREJECTED ``: the builtin signature doesn't match the file
174
+ - ``EMSGSIZE ``: the salt or builtin signature is too long
175
+ - ``ENOKEY ``: the ". fs-verity" keyring doesn't contain the certificate
176
+ needed to verify the builtin signature
175
177
- ``ENOPKG ``: fs-verity recognizes the hash algorithm, but it's not
176
178
available in the kernel's crypto API as currently configured (e.g.
177
179
for SHA-512, missing CONFIG_CRYPTO_SHA512).
@@ -180,8 +182,8 @@ FS_IOC_ENABLE_VERITY can fail with the following errors:
180
182
support; or the filesystem superblock has not had the 'verity'
181
183
feature enabled on it; or the filesystem does not support fs-verity
182
184
on this file. (See `Filesystem support `_.)
183
- - ``EPERM ``: the file is append-only; or, a signature is required and
184
- one was not provided.
185
+ - ``EPERM ``: the file is append-only; or, a builtin signature is
186
+ required and one was not provided.
185
187
- ``EROFS ``: the filesystem is read-only
186
188
- ``ETXTBSY ``: someone has the file open for writing. This can be the
187
189
caller's file descriptor, another open file descriptor, or the file
@@ -270,9 +272,9 @@ This ioctl takes in a pointer to the following structure::
270
272
- ``FS_VERITY_METADATA_TYPE_DESCRIPTOR `` reads the fs-verity
271
273
descriptor. See `fs-verity descriptor `_.
272
274
273
- - ``FS_VERITY_METADATA_TYPE_SIGNATURE `` reads the signature which was
274
- passed to FS_IOC_ENABLE_VERITY, if any. See `Built-in signature
275
- verification `_.
275
+ - ``FS_VERITY_METADATA_TYPE_SIGNATURE `` reads the builtin signature
276
+ which was passed to FS_IOC_ENABLE_VERITY, if any. See `Built-in
277
+ signature verification `_.
276
278
277
279
The semantics are similar to those of ``pread() ``. ``offset ``
278
280
specifies the offset in bytes into the metadata item to read from, and
@@ -299,7 +301,7 @@ FS_IOC_READ_VERITY_METADATA can fail with the following errors:
299
301
overflowed
300
302
- ``ENODATA ``: the file is not a verity file, or
301
303
FS_VERITY_METADATA_TYPE_SIGNATURE was requested but the file doesn't
302
- have a built-in signature
304
+ have a builtin signature
303
305
- ``ENOTTY ``: this type of filesystem does not implement fs-verity, or
304
306
this ioctl is not yet implemented on it
305
307
- ``EOPNOTSUPP ``: the kernel was not configured with fs-verity
@@ -347,8 +349,8 @@ non-verity one, with the following exceptions:
347
349
with EIO (for read()) or SIGBUS (for mmap() reads).
348
350
349
351
- If the sysctl "fs.verity.require_signatures" is set to 1 and the
350
- file is not signed by a key in the fs-verity keyring, then opening
351
- the file will fail. See `Built-in signature verification `_.
352
+ file is not signed by a key in the ". fs-verity" keyring, then
353
+ opening the file will fail. See `Built-in signature verification `_.
352
354
353
355
Direct access to the Merkle tree is not supported. Therefore, if a
354
356
verity file is copied, or is backed up and restored, then it will lose
@@ -433,29 +435,34 @@ root hash as well as other fields such as the file size::
433
435
Built-in signature verification
434
436
===============================
435
437
436
- With CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y, fs-verity supports putting
437
- a portion of an authentication policy (see `Use cases `_) in the
438
- kernel. Specifically, it adds support for:
438
+ CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y adds supports for in-kernel
439
+ verification of fs-verity builtin signatures.
440
+
441
+ **IMPORTANT **! Please take great care before using this feature.
442
+ It is not the only way to do signatures with fs-verity, and the
443
+ alternatives (such as userspace signature verification, and IMA
444
+ appraisal) can be much better. It's also easy to fall into a trap
445
+ of thinking this feature solves more problems than it actually does.
446
+
447
+ Enabling this option adds the following:
439
448
440
- 1. At fs-verity module initialization time, a keyring ".fs-verity" is
441
- created. The root user can add trusted X.509 certificates to this
442
- keyring using the add_key() system call, then (when done)
443
- optionally use keyctl_restrict_keyring() to prevent additional
444
- certificates from being added.
449
+ 1. At boot time, the kernel creates a keyring named ".fs-verity". The
450
+ root user can add trusted X.509 certificates to this keyring using
451
+ the add_key() system call.
445
452
446
453
2. `FS_IOC_ENABLE_VERITY `_ accepts a pointer to a PKCS#7 formatted
447
454
detached signature in DER format of the file's fs-verity digest.
448
- On success, this signature is persisted alongside the Merkle tree.
449
- Then, any time the file is opened, the kernel will verify the
455
+ On success, the ioctl persists the signature alongside the Merkle
456
+ tree. Then, any time the file is opened, the kernel verifies the
450
457
file's actual digest against this signature, using the certificates
451
458
in the ".fs-verity" keyring.
452
459
453
460
3. A new sysctl "fs.verity.require_signatures" is made available.
454
461
When set to 1, the kernel requires that all verity files have a
455
462
correctly signed digest as described in (2).
456
463
457
- fs-verity file digests must be signed in the following format, which
458
- is similar to the structure used by ` FS_IOC_MEASURE_VERITY `_ ::
464
+ The data that the signature as described in (2) must be a signature of
465
+ is the fs-verity file digest in the following format ::
459
466
460
467
struct fsverity_formatted_digest {
461
468
char magic[8]; /* must be "FSVerity" */
@@ -464,13 +471,66 @@ is similar to the structure used by `FS_IOC_MEASURE_VERITY`_::
464
471
__u8 digest[];
465
472
};
466
473
467
- fs-verity's built-in signature verification support is meant as a
468
- relatively simple mechanism that can be used to provide some level of
469
- authenticity protection for verity files, as an alternative to doing
470
- the signature verification in userspace or using IMA-appraisal.
471
- However, with this mechanism, userspace programs still need to check
472
- that the verity bit is set, and there is no protection against verity
473
- files being swapped around.
474
+ That's it. It should be emphasized again that fs-verity builtin
475
+ signatures are not the only way to do signatures with fs-verity. See
476
+ `Use cases `_ for an overview of ways in which fs-verity can be used.
477
+ fs-verity builtin signatures have some major limitations that should
478
+ be carefully considered before using them:
479
+
480
+ - Builtin signature verification does *not * make the kernel enforce
481
+ that any files actually have fs-verity enabled. Thus, it is not a
482
+ complete authentication policy. Currently, if it is used, the only
483
+ way to complete the authentication policy is for trusted userspace
484
+ code to explicitly check whether files have fs-verity enabled with a
485
+ signature before they are accessed. (With
486
+ fs.verity.require_signatures=1, just checking whether fs-verity is
487
+ enabled suffices.) But, in this case the trusted userspace code
488
+ could just store the signature alongside the file and verify it
489
+ itself using a cryptographic library, instead of using this feature.
490
+
491
+ - A file's builtin signature can only be set at the same time that
492
+ fs-verity is being enabled on the file. Changing or deleting the
493
+ builtin signature later requires re-creating the file.
494
+
495
+ - Builtin signature verification uses the same set of public keys for
496
+ all fs-verity enabled files on the system. Different keys cannot be
497
+ trusted for different files; each key is all or nothing.
498
+
499
+ - The sysctl fs.verity.require_signatures applies system-wide.
500
+ Setting it to 1 only works when all users of fs-verity on the system
501
+ agree that it should be set to 1. This limitation can prevent
502
+ fs-verity from being used in cases where it would be helpful.
503
+
504
+ - Builtin signature verification can only use signature algorithms
505
+ that are supported by the kernel. For example, the kernel does not
506
+ yet support Ed25519, even though this is often the signature
507
+ algorithm that is recommended for new cryptographic designs.
508
+
509
+ - fs-verity builtin signatures are in PKCS#7 format, and the public
510
+ keys are in X.509 format. These formats are commonly used,
511
+ including by some other kernel features (which is why the fs-verity
512
+ builtin signatures use them), and are very feature rich.
513
+ Unfortunately, history has shown that code that parses and handles
514
+ these formats (which are from the 1990s and are based on ASN.1)
515
+ often has vulnerabilities as a result of their complexity. This
516
+ complexity is not inherent to the cryptography itself.
517
+
518
+ fs-verity users who do not need advanced features of X.509 and
519
+ PKCS#7 should strongly consider using simpler formats, such as plain
520
+ Ed25519 keys and signatures, and verifying signatures in userspace.
521
+
522
+ fs-verity users who choose to use X.509 and PKCS#7 anyway should
523
+ still consider that verifying those signatures in userspace is more
524
+ flexible (for other reasons mentioned earlier in this document) and
525
+ eliminates the need to enable CONFIG_FS_VERITY_BUILTIN_SIGNATURES
526
+ and its associated increase in kernel attack surface. In some cases
527
+ it can even be necessary, since advanced X.509 and PKCS#7 features
528
+ do not always work as intended with the kernel. For example, the
529
+ kernel does not check X.509 certificate validity times.
530
+
531
+ Note: IMA appraisal, which supports fs-verity, does not use PKCS#7
532
+ for its signatures, so it partially avoids the issues discussed
533
+ here. IMA appraisal does use X.509.
474
534
475
535
Filesystem support
476
536
==================
0 commit comments