Skip to content

Commit 7c373e4

Browse files
jxwufanpcmoore
authored andcommitted
fsverity: expose verified fsverity built-in signatures to LSMs
This patch enhances fsverity's capabilities to support both integrity and authenticity protection by introducing the exposure of built-in signatures through a new LSM hook. This functionality allows LSMs, e.g. IPE, to enforce policies based on the authenticity and integrity of files, specifically focusing on built-in fsverity signatures. It enables a policy enforcement layer within LSMs for fsverity, offering granular control over the usage of authenticity claims. For instance, a policy could be established to only permit the execution of all files with verified built-in fsverity signatures. The introduction of a security_inode_setintegrity() hook call within fsverity's workflow ensures that the verified built-in signature of a file is exposed to LSMs. This enables LSMs to recognize and label fsverity files that contain a verified built-in fsverity signature. This hook is invoked subsequent to the fsverity_verify_signature() process, guaranteeing the signature's verification against fsverity's keyring. This mechanism is crucial for maintaining system security, as it operates in kernel space, effectively thwarting attempts by malicious binaries to bypass user space stack interactions. The second to last commit in this patch set will add a link to the IPE documentation in fsverity.rst. Signed-off-by: Deven Bowers <[email protected]> Signed-off-by: Fan Wu <[email protected]> Acked-by: Eric Biggers <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent fb55e17 commit 7c373e4

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Documentation/filesystems/fsverity.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ authenticating fs-verity file hashes include:
8686
signature in their "security.ima" extended attribute, as controlled
8787
by the IMA policy. For more information, see the IMA documentation.
8888

89+
- Integrity Policy Enforcement (IPE). IPE supports enforcing access
90+
control decisions based on immutable security properties of files,
91+
including those protected by fs-verity's built-in signatures.
92+
"IPE policy" specifically allows for the authorization of fs-verity
93+
files using properties ``fsverity_digest`` for identifying
94+
files by their verity digest, and ``fsverity_signature`` to authorize
95+
files with a verified fs-verity's built-in signature.
96+
8997
- Trusted userspace code in combination with `Built-in signature
9098
verification`_. This approach should be used only with great care.
9199

@@ -457,7 +465,11 @@ Enabling this option adds the following:
457465
On success, the ioctl persists the signature alongside the Merkle
458466
tree. Then, any time the file is opened, the kernel verifies the
459467
file's actual digest against this signature, using the certificates
460-
in the ".fs-verity" keyring.
468+
in the ".fs-verity" keyring. This verification happens as long as the
469+
file's signature exists, regardless of the state of the sysctl variable
470+
"fs.verity.require_signatures" described in the next item. The IPE LSM
471+
relies on this behavior to recognize and label fsverity files
472+
that contain a verified built-in fsverity signature.
461473

462474
3. A new sysctl "fs.verity.require_signatures" is made available.
463475
When set to 1, the kernel requires that all verity files have a
@@ -481,7 +493,7 @@ be carefully considered before using them:
481493

482494
- Builtin signature verification does *not* make the kernel enforce
483495
that any files actually have fs-verity enabled. Thus, it is not a
484-
complete authentication policy. Currently, if it is used, the only
496+
complete authentication policy. Currently, if it is used, one
485497
way to complete the authentication policy is for trusted userspace
486498
code to explicitly check whether files have fs-verity enabled with a
487499
signature before they are accessed. (With
@@ -490,6 +502,13 @@ be carefully considered before using them:
490502
could just store the signature alongside the file and verify it
491503
itself using a cryptographic library, instead of using this feature.
492504

505+
- Another approach is to utilize fs-verity builtin signature
506+
verification in conjunction with the IPE LSM, which supports defining
507+
a kernel-enforced, system-wide authentication policy that allows only
508+
files with a verified fs-verity builtin signature to perform certain
509+
operations, such as execution. Note that IPE doesn't require
510+
fs.verity.require_signatures=1.
511+
493512
- A file's builtin signature can only be set at the same time that
494513
fs-verity is being enabled on the file. Changing or deleting the
495514
builtin signature later requires re-creating the file.

fs/verity/signature.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <linux/cred.h>
1919
#include <linux/key.h>
20+
#include <linux/security.h>
2021
#include <linux/slab.h>
2122
#include <linux/verification.h>
2223

@@ -41,7 +42,11 @@ static struct key *fsverity_keyring;
4142
* @sig_size: size of signature in bytes, or 0 if no signature
4243
*
4344
* If the file includes a signature of its fs-verity file digest, verify it
44-
* against the certificates in the fs-verity keyring.
45+
* against the certificates in the fs-verity keyring. Note that signatures
46+
* are verified regardless of the state of the 'fsverity_require_signatures'
47+
* variable and the LSM subsystem relies on this behavior to help enforce
48+
* file integrity policies. Please discuss changes with the LSM list
49+
* (thank you!).
4550
*
4651
* Return: 0 on success (signature valid or not required); -errno on failure
4752
*/
@@ -106,6 +111,17 @@ int fsverity_verify_signature(const struct fsverity_info *vi,
106111
return err;
107112
}
108113

114+
err = security_inode_setintegrity(inode,
115+
LSM_INT_FSVERITY_BUILTINSIG_VALID,
116+
signature,
117+
sig_size);
118+
119+
if (err) {
120+
fsverity_err(inode, "Error %d exposing file signature to LSMs",
121+
err);
122+
return err;
123+
}
124+
109125
return 0;
110126
}
111127

include/linux/security.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct dm_verity_digest {
9292
enum lsm_integrity_type {
9393
LSM_INT_DMVERITY_SIG_VALID,
9494
LSM_INT_DMVERITY_ROOTHASH,
95+
LSM_INT_FSVERITY_BUILTINSIG_VALID,
9596
};
9697

9798
/*

0 commit comments

Comments
 (0)