Integrity Policy Enforcement LSM (IPE)
Subsystems (10)
RFC PATCH v11 1/19 security: add ipe lsm
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Integrity Policy Enforcement (IPE) is an LSM that provides an complimentary approach to Mandatory Access Control than existing LSMs today.
Existing LSMs have centered around the concept of access to a resource should be controlled by the current user's credentials. IPE's approach, is that access to a resource should be controlled by the system's trust of a current resource.
The basis of this approach is defining a global policy to specify which resource can be trusted.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move ipe_load_properties to patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables with ipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ Use GFP_KERNEL for audit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Use rcu_access_pointer for rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12
v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.
v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.
v6:
+ No changes
v7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Introduce the concept of an ipe_context, a scoped way to introduce execution policies, used initially for allowing for kunit tests in isolation.
v8:
+ Follow lsmname_hook_name convention for lsm hooks.
+ Move LSM blob accessors to ipe.c and mark LSM blobs as static.
v9:
+ Remove ipe_context for simplification
v10:
+ Add github url
v11:
+ Correct github url
+ Move ipe before bpf
--- MAINTAINERS | 7 +++++++ security/Kconfig | 11 ++++++----- security/Makefile | 1 + security/ipe/Kconfig | 17 +++++++++++++++++ security/ipe/Makefile | 9 +++++++++ security/ipe/ipe.c | 35 +++++++++++++++++++++++++++++++++++ security/ipe/ipe.h | 16 ++++++++++++++++ 7 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 security/ipe/Kconfig create mode 100644 security/ipe/Makefile create mode 100644 security/ipe/ipe.c create mode 100644 security/ipe/ipe.h
MAINTAINERS +7 -0
@@ -10389,6 +10389,13 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git F: security/integrity/ F: security/integrity/ima/ +INTEGRITY POLICY ENFORCEMENT (IPE) +M: Fan Wu <[email protected]> +L: [email protected] +S: Supported +T: git https://github.com/microsoft/ipe.git +F: security/ipe/ + INTEL 810/815 FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]> L: [email protected]
security/Kconfig +6 -5
@@ -194,6 +194,7 @@ source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" source "security/landlock/Kconfig" +source "security/ipe/Kconfig" source "security/integrity/Kconfig"
@@ -233,11 +234,11 @@ endchoice config LSM string "Ordered list of enabled LSMs" - default "landlock,lockdown,yama,loadpin,safesetid,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "landlock,lockdown,yama,loadpin,safesetid,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "landlock,lockdown,yama,loadpin,safesetid,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "landlock,lockdown,yama,loadpin,safesetid,bpf" if DEFAULT_SECURITY_DAC - default "landlock,lockdown,yama,loadpin,safesetid,selinux,smack,tomoyo,apparmor,bpf" + default "landlock,lockdown,yama,loadpin,safesetid,smack,selinux,tomoyo,apparmor,ipe,bpf" if DEFAULT_SECURITY_SMACK + default "landlock,lockdown,yama,loadpin,safesetid,apparmor,selinux,smack,tomoyo,ipe,bpf" if DEFAULT_SECURITY_APPARMOR + default "landlock,lockdown,yama,loadpin,safesetid,tomoyo,ipe,bpf" if DEFAULT_SECURITY_TOMOYO + default "landlock,lockdown,yama,loadpin,safesetid,ipe,bpf" if DEFAULT_SECURITY_DAC + default "landlock,lockdown,yama,loadpin,safesetid,selinux,smack,tomoyo,apparmor,ipe,bpf" help A comma-separated list of LSMs, in initialization order. Any LSMs left off this list, except for those with order
security/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ obj-$(CONFIG_CGROUPS) += device_cgroup.o obj-$(CONFIG_BPF_LSM) += bpf/ obj-$(CONFIG_SECURITY_LANDLOCK) += landlock/ +obj-$(CONFIG_SECURITY_IPE) += ipe/ # Object integrity file lists obj-$(CONFIG_INTEGRITY) += integrity/
security/ipe/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Integrity Policy Enforcement (IPE) configuration +# + +menuconfig SECURITY_IPE + bool "Integrity Policy Enforcement (IPE)" + depends on SECURITY && SECURITYFS + select PKCS7_MESSAGE_PARSER + select SYSTEM_DATA_VERIFICATION + help + This option enables the Integrity Policy Enforcement LSM + allowing users to define a policy to enforce a trust-based access + control. A key feature of IPE is a customizable policy to allow + admins to reconfigure trust requirements on the fly. + + If unsure, answer N.
security/ipe/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) Microsoft Corporation. All rights reserved. +# +# Makefile for building the IPE module as part of the kernel tree. +# + +obj-$(CONFIG_SECURITY_IPE) += \ + ipe.o \
security/ipe/ipe.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe.h" + +static struct lsm_blob_sizes ipe_blobs__ro_after_init = { +}; + +static struct security_hook_list ipe_hooks[]__ro_after_init = { +}; + +/** +* ipe_init - Entry point of IPE. +* +* This is called at LSM init, which happens occurs early during kernel +* start up. During this phase, IPE registers its hooks and loads the +* builtin boot policy. +* Return: +* * 0 - OK +* * -ENOMEM - Out of memory +*/ +static int __init ipe_init (void ) +{ +security_add_hooks (ipe_hooks,ARRAY_SIZE (ipe_hooks),"ipe" ); + +return 0 ; +} + +DEFINE_LSM (ipe) = { + .name ="ipe" , + .init = ipe_init, + .blobs = &ipe_blobs, +};
security/ipe/ipe.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef _IPE_H +#define _IPE_H + +#ifdef pr_fmt +#undef pr_fmt +#endif +#define pr_fmt (fmt) "IPE: " fmt + +#include <linux/lsm_hooks.h> + +#endif /* _IPE_H */
Signature · 1 line
2.25.1
RFC PATCH v11 3/19 ipe: add evaluation loop
In reply to Fan WuFrom: Deven Bowers <[email protected]>
IPE must have a centralized function to evaluate incoming callers against IPE's policy. This iteration of the policy for against the rules for that specific caller is known as the evaluation loop.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move ipe_load_properties to patch 04.
+ Remove useless 0-initializations Prefix extern variables with ipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ Use GFP_KERNEL for audit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Use rcu_access_pointer for rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+Move policy load and activation audit event to 03/12
v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.
v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record,
+ reconstruct the exact rule.
v6:
+ No changes
v7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Propagating changes to support the new ipe_context structure in the evaluation loop.
v8:
+ Remove ipe_hook enumeration; hooks can be correlated via syscall record.
v9:
+ Remove ipe_context related code and simplify the evaluation loop.
v10:
+ Split eval part and boot_verified part
v11:
+ Fix code style issues
--- security/ipe/Makefile | 1 + security/ipe/eval.c | 96 +++++++++++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 24 +++++++++++ 3 files changed, 121 insertions(+) create mode 100644 security/ipe/eval.c create mode 100644 security/ipe/eval.h
security/ipe/Makefile +1 -0
@@ -6,6 +6,7 @@ # obj-$(CONFIG_SECURITY_IPE) += \ + eval.o \ ipe.o \ policy.o \ policy_parser.o \
security/ipe/eval.c new file +96 -0
96 lines not on this page · raw message
security/ipe/eval.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef _IPE_EVAL_H +#define _IPE_EVAL_H + +#include <linux/file.h> +#include <linux/types.h> + +#include "policy.h" + +extern struct ipe_policy __rcu *ipe_active_policy; + +struct ipe_eval_ctx { +enum ipe_op_type op; + +const struct file *file; +}; + +int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx); + +#endif /* _IPE_EVAL_H */
Signature · 1 line
2.25.1
RFC PATCH v11 4/19 ipe: add LSM hooks on execution and kernel read
In reply to Fan WuFrom: Deven Bowers <[email protected]>
IPE's initial goal is to control both execution and the loading of kernel modules based on the system's definition of trust. It accomplishes this by plugging into the security hooks for bprm_check_security, file_mprotect, mmap_file, kernel_load_data, and kernel_read_data.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move ipe_load_properties to patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables with ipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ Use GFP_KERNEL for audit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Use rcu_access_pointer for rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12
v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.
v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.
v6:
+ No changes
v7:
+ Further split lsm creation, the audit system, the evaluation loop and access control hooks into separate commits.
v8:
+ Rename hook functions to follow the lsmname_hook_name convention
+ Remove ipe_hook enumeration, can be derived from correlation with syscall audit record.
v9:
+ Minor changes for adapting to the new parser
v10:
+ Remove @reqprot part
v11:
+ Fix code style issues
--- security/ipe/Makefile | 1 + security/ipe/eval.c | 14 ++++ security/ipe/eval.h | 3 + security/ipe/hooks.c | 183 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 25 ++++++ security/ipe/ipe.c | 6 ++ 6 files changed, 232 insertions(+) create mode 100644 security/ipe/hooks.c create mode 100644 security/ipe/hooks.h
security/ipe/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_SECURITY_IPE) += \ eval.o \ + hooks.o \ ipe.o \ policy.o \ policy_parser.o \
security/ipe/eval.c +14 -0
@@ -16,6 +16,20 @@struct ipe_policy __rcu *ipe_active_policy; +/** +* build_eval_ctx - Build an evaluation context. +* @ctx: Supplies a pointer to the context to be populdated. +* @file: Supplies a pointer to the file to associated with the evaluation. +* @op: Supplies the IPE policy operation associated with the evaluation. +*/ +void build_eval_ctx (struct ipe_eval_ctx *ctx, +const struct file *file, +enum ipe_op_type op) +{ + ctx->file = file; + ctx->op = op; +} +/** * evaluate_property - Analyze @ctx against a property. * @ctx: Supplies a pointer to the context to be evaluated.
security/ipe/eval.h +3 -0
@@ -11,6 +11,8 @@#include "policy.h" +#define IPE_EVAL_CTX_INIT ((struct ipe_eval_ctx){ 0 }) +extern struct ipe_policy __rcu *ipe_active_policy;struct ipe_eval_ctx {
@@ -19,6 +21,7 @@ struct ipe_eval_ctx { const struct file *file; }; +void build_eval_ctx (struct ipe_eval_ctx *ctx,const struct file *file,enum ipe_op_type op);int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx);#endif /* _IPE_EVAL_H */
security/ipe/hooks.c new file +183 -0
183 lines not on this page · raw message
security/ipe/hooks.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef _IPE_HOOKS_H +#define _IPE_HOOKS_H + +#include <linux/fs.h> +#include <linux/binfmts.h> +#include <linux/security.h> + +int ipe_bprm_check_security (struct linux_binprm *bprm); + +int ipe_mmap_file (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_file_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_kernel_read_file (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_kernel_load_data (enum kernel_load_data_id id,bool contents); + +#endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +6 -0
@@ -4,11 +4,17 @@*/ #include "ipe.h" +#include "hooks.h" static struct lsm_blob_sizes ipe_blobs__ro_after_init = { };static struct security_hook_list ipe_hooks[]__ro_after_init = { +LSM_HOOK_INIT (bprm_check_security, ipe_bprm_check_security), +LSM_HOOK_INIT (mmap_file, ipe_mmap_file), +LSM_HOOK_INIT (file_mprotect, ipe_file_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_kernel_read_file), +LSM_HOOK_INIT (kernel_load_data, ipe_kernel_load_data), };/**
Signature · 1 line
2.25.1
v11 cover Integrity Policy Enforcement LSM (IPE)
Overview:
---------
IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing mandatory access control mechanisms base their decisions on labels and paths, IPE instead determines whether or not an operation should be allowed based on immutable security properties of the system component the operation is being performed on.
IPE itself does not mandate how the security property should be evaluated, but relies on an extensible set of external property providers to evaluate the component. IPE makes its decision based on reference values for the selected properties, specified in the IPE policy.
The reference values represent the value that the policy writer and the local system administrator (based on the policy signature) trust for the system to accomplish the desired tasks.
One such provider is for example dm-verity, which is able to represent the integrity property of a partition (its immutable state) with a digest.
IPE is compiled under CONFIG_SECURITY_IPE.
Use Cases
---------
IPE works best in fixed-function devices: Devices in which their purpose is clearly defined and not supposed to be changed (e.g. network firewall device in a data center, an IoT device, etcetera), where all software and configuration is built and provisioned by the system owner.
IPE is a long-way off for use in general-purpose computing: the Linux community as a whole tends to follow a decentralized trust model, known as the web of trust, which IPE has no support for as of yet. There are exceptions, such as the case where a Linux distribution vendor trusts only their own keys, where IPE can successfully be used to enforce the trust requirement.
Additionally, while most packages are signed today, the files inside the packages (for instance, the executables), tend to be unsigned. This makes it difficult to utilize IPE in systems where a package manager is expected to be functional, without major changes to the package manager and ecosystem behind it.
DIGLIM[1] is a system that when combined with IPE, could be used to enable general purpose computing scenarios.
Policy:
-------
IPE policy is a plain-text policy composed of multiple statements over several lines. There is one required line, at the top of the policy, indicating the policy name, and the policy version, for instance:
policy_name=Ex_Policy policy_version=0.0.0
The policy version indicates the current version of the policy. This is used to prevent roll-back of policy to potentially insecure previous versions of the policy.
The next portion of IPE policy, are rules. Rules are formed by key=value pairs, known as properties. IPE rules require two keys: "action", which determines what IPE does when it encounters a match against the policy and "op", which determines when that rule should be evaluated.
Thus, a minimal rule is:
op=EXECUTE action=ALLOW
This example rule will allow any execution. A rule is required to have the "op" property as the first token of a rule, and the "action" as the last token of the rule.
Additional properties are used to restrict attributes about the files being evaluated. These properties are intended to be deterministic attributes that are resident in the kernel.
For example:
op=EXECUTE dmverity_signature=FALSE action=DENY
This rule with property dmverity_signature will deny any file not from a signed dmverity volume to be executed.
All available properties for IPE described in the documentation patch of this series.
Rules are evaluated top-to-bottom. As a result, any revocation rules, or denies should be placed early in the file to ensure that these rules are evaluated before a rule with "action=ALLOW" is hit.
Any unknown syntax in IPE policy will result in a fatal error to parse the policy.
Additionally, a DEFAULT operation must be set for all understood operations within IPE. For policies to remain completely forwards compatible, it is recommended that users add a "DEFAULT action=ALLOW" and override the defaults on a per-operation basis.
For more information about the policy syntax, see the kernel documentation page.
Early Usermode Protection:
--------------------------
IPE can be provided with a policy at startup to load and enforce. This is intended to be a minimal policy to get the system to a state where userspace is setup and ready to receive commands, at which point a policy can be deployed via securityfs. This "boot policy" can be specified via the config, SECURITY_IPE_BOOT_POLICY, which accepts a path to a plain-text version of the IPE policy to apply. This policy will be compiled into the kernel. If not specified, IPE will be disabled until a policy is deployed and activated through the method above.
Policy Examples:
----------------
Allow all:
policy_name=Allow_All policy_version=0.0.0
DEFAULT action=ALLOW
Allow only initial superblock:
policy_name=Allow_All_Initial_SB policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW
Allow any signed dm-verity volume and the initial superblock:
policy_name=AllowSignedAndInitial policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_signature=TRUE action=ALLOW
Prohibit execution from a specific dm-verity volume, while allowing all signed volumes and the initial superblock:
policy_name=ProhibitSingleVolume policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE dmverity_roothash=sha256:401fcec5944823ae12f62726e8184407a5fa9599783f030dec146938 action=DENY op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_signature=TRUE action=ALLOW
Allow only a specific dm-verity volume:
policy_name=AllowSpecific policy_version=0.0.0
DEFAULT action=DENY
op=EXECUTE dmverity_roothash=sha256:401fcec5944823ae12f62726e8184407a5fa9599783f030dec146938 action=ALLOW
Allow any signed fs-verity file
policy_name=AllowSignedFSVerity policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE fsverity_signature=TRUE action=ALLOW
Deny a specific fs-verity file:
policy_name=ProhibitSpecificFSVF policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE fsverity_digest=sha256:fd88f2b8824e197f850bf4c5109bea5cf0ee38104f710843bb72da796ba5af9e action=DENY op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_signature=TRUE action=ALLOW
Deploying Policies:
-------------------
First sign a plain text policy, with a certificate that is present in the SYSTEM_TRUSTED_KEYRING of your test machine. Through openssl, the signing can be done via:
openssl smime -sign -in "$MY_POLICY" -signer "$MY_CERTIFICATE" \
-inkey "$MY_PRIVATE_KEY" -outform der -noattr -nodetach \
-out "$MY_POLICY.p7s"Then, simply cat the file into the IPE's "new_policy" securityfs node:
cat "$MY_POLICY.p7s" > /sys/kernel/security/ipe/new_policy
The policy should now be present under the policies/ subdirectory, under its "policy_name" attribute.
The policy is now present in the kernel and can be marked as active, via the securityfs node:
echo 1 > "/sys/kernel/security/ipe/$MY_POLICY_NAME/active"
This will now mark the policy as active and the system will be enforcing $MY_POLICY_NAME.
There is one requirement when marking a policy as active, the policy_version attribute must either increase, or remain the same as the currently running policy.
Policies can be updated via:
cat "$MY_UPDATED_POLICY.p7s" > \
"/sys/kernel/security/ipe/policies/$MY_POLICY_NAME/update"Additionally, policies can be deleted via the "delete" securityfs node. Simply write "1" to the corresponding node in the policy folder:
echo 1 > "/sys/kernel/security/ipe/policies/$MY_POLICY_NAME/delete"
There is only one requirement to delete policies, the policy being deleted must not be the active policy.
NOTE: Any securityfs write to IPE's nodes will require CAP_MAC_ADMIN.
Integrations:
-------------
This patch series adds support for fsverity via digest and signature (fsverity_signature and fsverity_digest), dm-verity by digest and signature (dmverity_signature and dmverity_roothash), and trust for the initramfs (boot_verified).
Please see the documentation patch for more information about the integrations available.
Testing:
--------
KUnit Tests are available. Recommended kunitconfig:
CONFIG_KUNIT=y
CONFIG_SECURITY=y
CONFIG_SECURITYFS=y
CONFIG_PKCS7_MESSAGE_PARSER=y
CONFIG_SYSTEM_DATA_VERIFICATION=y
CONFIG_FS_VERITY=y
CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y
CONFIG_BLOCK=y
CONFIG_MD=y
CONFIG_BLK_DEV_DM=y
CONFIG_DM_VERITY=y
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y
CONFIG_NET=y
CONFIG_AUDIT=y
CONFIG_AUDITSYSCALL=y
CONFIG_SECURITY_IPE=y
CONFIG_IPE_PROP_DM_VERITY=y
CONFIG_IPE_PROP_FS_VERITY=y
CONFIG_SECURITY_IPE_KUNIT_TEST=y
Simply run:
make ARCH=um mrproper
./tools/testing/kunit/kunit.py run --kunitconfig <path/to/config>
And the tests will execute and report the result. For more indepth testing, it will require you to create and mount a dm-verity volume or fs-verity enabled file.
Documentation:
--------------
There is both documentation available on github at
https://microsoft.github.io/ipe, and Documentation in this patch series, to be added in-tree.
Known Gaps:
-----------
IPE has two known gaps:
1. IPE cannot verify the integrity of anonymous executable memory, such as the trampolines created by gcc closures and libffi (<3.4.2), or JIT'd code. Unfortunately, as this is dynamically generated code, there is no way for IPE to ensure the integrity of this code to form a trust basis. In all cases, the return result for these operations will be whatever the admin configures the DEFAULT action for "EXECUTE".
2. IPE cannot verify the integrity of interpreted languages' programs when these scripts invoked via ``<interpreter> <file>``. This is because the way interpreters execute these files, the scripts themselves are not evaluated as executable code through one of IPE's hooks. Interpreters can be enlightened to the usage of IPE by trying to mmap a file into executable memory (+X), after opening the file and responding to the error code appropriately. This also applies to included files, or high value files, such as configuration files of critical system components.
Appendix:
---------
A. IPE Github Repository: https://github.com/microsoft/ipe
B. IPE Users' Guide: Documentation/admin-guide/LSM/ipe.rst
References:
-----------
1: https://lore.kernel.org/bpf/[email protected]/
FAQ:
----
Q: What is the difference between IMA and IPE?
A: See the documentation patch for more on this topic.
Previous Postings
-----------------
v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/1634151995-16266-1-git-send-email-deven.desai@linux.microsoft.com/
v8: https://lore.kernel.org/all/1654714889-26728-1-git-send-email-deven.desai@linux.microsoft.com/
v9: https://lore.kernel.org/lkml/[email protected]/
v10: https://lore.kernel.org/lkml/[email protected]/
Changelog:
----------
v2:
Split the second patch of the previous series into two. Minor corrections in the cover-letter and documentation comments regarding CAP_MAC_ADMIN checks in IPE.
v3:
Address various comments by Jann Horn. Highlights:
Switch various audit allocators to GFP_KERNEL. Utilize rcu_access_pointer() in various locations. Strip out the caching system for properties
Strip comments from headers
Move functions around in patches
Remove kernel command line parameters
Reconcile the race condition on the delete node for policy by
expanding the policy critical section.
Address a few comments by Jonathan Corbet around the documentation
pages for IPE.
Fix an issue with the initialization of IPE policy with a "-0"
version, caused by not initializing the hlist entries before freeing.
v4:
Address a concern around IPE's behavior with unknown syntax.
Specifically, make any unknown syntax a fatal error instead of a warning, as suggested by Mickaël Salaün.
Introduce a new securityfs node, $securityfs/ipe/property_config,
which provides a listing of what properties are enabled by the kernel and their versions. This allows usermode to predict what policies should be allowed.
Strip some comments from c files that I missed.
Clarify some documentation comments around 'boot_verified'.
While this currently does not functionally change the property itself, the distinction is important when IPE can enforce verified reads. Additionally, 'KERNEL_READ' was omitted from the documentation. This has been corrected.
Change SecurityFS and SHA1 to a reverse dependency.
Update the cover-letter with the updated behavior of unknown syntax. Remove all sysctls, making an equivalent function in securityfs. Rework the active/delete mechanism to be a node under the policy in
$securityfs/ipe/policies.
The kernel command line parameters ipe.enforce and ipe.success_audit
have returned as this functionality is no longer exposed through sysfs.
v5:
Correct some grammatical errors reported by Randy Dunlap. Fix some warnings reported by kernel test bot.
Change convention around security_bdev_setsecurity. -ENOSYS
is now expected if an LSM does not implement a particular @name, as suggested by Casey Schaufler.
Minor string corrections related to the move from sysfs to securityfs Correct a spelling of an #ifdef for the permissive argument. Add the kernel parameters re-added to the documentation. Fix a minor bug where the mode being audited on permissive switch
was the original mode, not the mode being swapped to.
Cleanup doc comments, fix some whitespace alignment issues.
v6:
Change if statement condition in security_bdev_setsecurity to be
more concise, as suggested by Casey Schaufler and Al Viro
Drop the 6th patch in the series, "dm-verity move signature check..."
due to numerous issues, and it ultimately providing no real value.
Fix the patch tree - the previous iteration appears to have been in a
torn state (patches 8+9 were merged). This has since been corrected.
v7:
* Reword cover letter to more accurate convey IPE's purpose and latest updates.
* Refactor series to:
1. Support a context structure, enabling:
1. Easier Testing via KUNIT
2. A better architecture for future designs
2. Make parser code cleaner
* Move patch 01/12 to [14/16] of the series
* Split up patch 02/12 into four parts:
1. context creation [01/16]
2. audit [07/16]
3. evaluation loop [03/16]
4. access control hooks [05/16]
5. permissive mode [08/16]
* Split up patch 03/12 into two parts:
1. parser [02/16]
2. userspace interface [04/16]
* Reword and refactor patch 04/12 to [09/16]
* Squash patch 05/12, 07/12, 09/12 to [10/16]
* Squash patch 08/12, 10/12 to [11/16]
* Change audit records to MAC region (14XX) from Integrity region (18XX)
* Add FSVerity Support
* Interface changes:
1. "raw" was renamed to "pkcs7" and made read only
2. "raw"'s write functionality (update a policy) moved to "update"
3. introduced "version", "policy_name" nodes.
4. "content" renamed to "policy"
5. The boot policy can now be updated like any other policy.
* Add additional developer-level documentation
* Update admin-guide docs to reflect changes.
* Kunit tests
* Dropped CONFIG_SECURITY_IPE_PERMISSIVE_SWITCH - functionality can easily come later with a small patch.
* Use partition0 for block_device for dm-verity patch
v8:
* Add changelog information to individual commits
* A large number of changes to the audit patch.
* split fs/ & security/ changes to two separate patches.
* split block/, security/ & drivers/md/ changes to separate patches.
* Add some historical context to what lead to the creation of IPE in the documentation patch.
* Cover-letter changes suggested by Roberto Sassu.
v9:
* Rewrite IPE parser to use kernel match_table parser.
* Adapt existing IPE properties to the new parser.
* Remove ipe_context, quote policy syntax, kernel_read for simplicity.
* Add new function in the security file system to delete IPE policy.
* Make IPE audit builtin and change several audit formats.
* Make boot_verified property builtin
v10:
* Address various code style/format issues
* Correct the rcu locking for active policy
* Fix memleak bugs in the parser, optimize the parser per upstream feedback
* Adding new audit events for IPE and update audit formats
* Make the dmverity property auto selected
* Adding more context in the commit messages
v11:
* Address various code style/format issues
* Add finalize hook to device mapper
* move the security hook for dm-verity to the new device mapper finalize hook
Deven Bowers (14):
security: add ipe lsm
ipe: add policy parser
ipe: add evaluation loop
ipe: add LSM hooks on execution and kernel read
ipe: introduce 'boot_verified' as a trust provider
ipe: add userspace interface
uapi|audit|ipe: add ipe auditing support
ipe: add permissive toggle
block|security: add LSM blob to block_device
dm verity: consume root hash digest and signature data via LSM hook
ipe: add support for dm-verity as a trust provider
scripts: add boot policy generation program
ipe: kunit test for parser
documentation: add ipe documentation
Fan Wu (5):
security: add new securityfs delete function dm verity: set DM_TARGET_SINGLETON feature flag
dm: add finalize hook to target_type
fsverity: consume builtin signature via LSM hook
ipe: enable support for fs-verity as a trust provider
Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 752 ++++++++++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 420 ++++++++++ MAINTAINERS | 10 + block/bdev.c | 7 + drivers/md/dm-verity-target.c | 73 +- drivers/md/dm-verity.h | 6 + drivers/md/dm.c | 12 + fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +- include/linux/blk_types.h | 3 + include/linux/device-mapper.h | 7 + include/linux/dm-verity.h | 19 + include/linux/fsverity.h | 2 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 23 + include/uapi/linux/audit.h | 3 + scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 6 + scripts/ipe/polgen/polgen.c | 145 ++++ security/Kconfig | 11 +- security/Makefile | 1 + security/inode.c | 25 + security/ipe/.gitignore | 1 + security/ipe/Kconfig | 75 ++ security/ipe/Makefile | 31 + security/ipe/audit.c | 267 +++++++ security/ipe/audit.h | 19 + security/ipe/digest.c | 142 ++++ security/ipe/digest.h | 26 + security/ipe/eval.c | 419 ++++++++++ security/ipe/eval.h | 61 ++ security/ipe/fs.c | 247 ++++++ security/ipe/fs.h | 16 + security/ipe/hooks.c | 276 +++++++ security/ipe/hooks.h | 42 + security/ipe/ipe.c | 85 ++ security/ipe/ipe.h | 25 + security/ipe/policy.c | 218 +++++ security/ipe/policy.h | 100 +++ security/ipe/policy_fs.c | 481 +++++++++++ security/ipe/policy_parser.c | 550 +++++++++++++ security/ipe/policy_parser.h | 11 + security/ipe/policy_tests.c | 294 +++++++ security/security.c | 99 +++ 50 files changed, 5054 insertions(+), 8 deletions(-) create mode 100644 Documentation/admin-guide/LSM/ipe.rst create mode 100644 Documentation/security/ipe.rst create mode 100644 include/linux/dm-verity.h create mode 100644 scripts/ipe/Makefile create mode 100644 scripts/ipe/polgen/.gitignore create mode 100644 scripts/ipe/polgen/Makefile create mode 100644 scripts/ipe/polgen/polgen.c create mode 100644 security/ipe/.gitignore create mode 100644 security/ipe/Kconfig create mode 100644 security/ipe/Makefile create mode 100644 security/ipe/audit.c create mode 100644 security/ipe/audit.h create mode 100644 security/ipe/digest.c create mode 100644 security/ipe/digest.h create mode 100644 security/ipe/eval.c create mode 100644 security/ipe/eval.h create mode 100644 security/ipe/fs.c create mode 100644 security/ipe/fs.h create mode 100644 security/ipe/hooks.c create mode 100644 security/ipe/hooks.h create mode 100644 security/ipe/ipe.c create mode 100644 security/ipe/ipe.h create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h create mode 100644 security/ipe/policy_fs.c create mode 100644 security/ipe/policy_parser.c create mode 100644 security/ipe/policy_parser.h create mode 100644 security/ipe/policy_tests.c
--
2.25.1
RFC PATCH v11 11/19 dm verity: set DM_TARGET_SINGLETON feature flag
The device-mapper has a flag to mark targets as singleton, which is a required flag for immutable targets. Without this flag, multiple dm-verity targets can be added to a mapped device, which has no practical use cases and will let dm_table_get_immutable_target return NULL. This patch adds the missing flag, restricting only one dm-verity target per mapped device.
---
v1-v10:
+ Not present
--- drivers/md/dm-verity-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-target.c +1 -1
@@ -1503,7 +1503,7 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned istatic struct target_type verity_target = { .name ="verity" , - .features =DM_TARGET_IMMUTABLE , + .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE , .version = {1 ,9 ,0 }, .module =THIS_MODULE , .ctr = verity_ctr,
Signature · 1 line
2.25.1
RFC PATCH v11 9/19 ipe: add permissive toggle
In reply to Fan WuFrom: Deven Bowers <[email protected]>
IPE, like SELinux, supports a permissive mode. This mode allows policy authors to test and evaluate IPE policy without it effecting their programs. When the mode is changed, a 1404 AUDIT_MAC_STATUS be reported.
This patch adds the following audit records:
audit: MAC_STATUS enforcing=0 old_enforcing=1 auid=4294967295
ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1
audit: MAC_STATUS enforcing=1 old_enforcing=0 auid=4294967295
ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1The audit record only emit when the value from the user input is different from the current enforce value.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move ipe_load_properties to patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables with ipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ Use GFP_KERNEL for audit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Use rcu_access_pointer for rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12
v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.
v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.
v6:
+ No changes
v7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Propagating changes to support the new ipe_context structure in the evaluation loop.
+ Split out permissive functionality into a separate patch for easier review.
+ Remove permissive switch compile-time configuration option - this is trivial to add later.
v8:
+ Remove "IPE" prefix from permissive audit record
+ align fields to the linux-audit field dictionary. This causes the following fields to change:
enforce -> permissive
+ Remove duplicated information correlated with syscall record, that will always be present in the audit event.
+ Change audit types:
+ AUDIT_TRUST_STATUS -> AUDIT_MAC_STATUS
+ There is no significant difference in meaning between these types.
v9:
+ Clean up ipe_context related code
v10:
+ Change audit format to comform with the existing format selinux is using
+ Remove the audit record emission during init to align with selinux, which does not perform this action.
v11:
+ Remove redundant code
--- security/ipe/audit.c | 22 ++++++++++++++ security/ipe/audit.h | 1 + security/ipe/eval.c | 14 +++++++-- security/ipe/eval.h | 1 + security/ipe/fs.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-)
security/ipe/audit.c +22 -0
@@ -193,3 +193,25 @@ void ipe_audit_policy_load(const struct ipe_policy *const p)audit_log_end (ab); } + +/** +* ipe_audit_enforce - Audit a change in IPE's enforcement state. +* @new_enforce: The new value enforce to be set. +* @old_enforce: The old value currently in enforce. +*/ +void ipe_audit_enforce (bool new_enforce,bool old_enforce) +{ +struct audit_buffer *ab; + + ab =audit_log_start (audit_context (),GFP_KERNEL ,AUDIT_MAC_STATUS ); +if (!ab) +return ; + +audit_log_format (ab,"enforcing=%d old_enforcing=%d auid=%u ses=%u" +" enabled=1 old-enabled=1 lsm=ipe res=1" , + new_enforce, old_enforce, +from_kuid (&init_user_ns,audit_get_loginuid (current)), +audit_get_sessionid (current)); + +audit_log_end (ab); +}
security/ipe/audit.h +1 -0
@@ -14,5 +14,6 @@ void ipe_audit_match(const struct ipe_eval_ctx *const ctx,void ipe_audit_policy_load (const struct ipe_policy *const p);void ipe_audit_policy_activation (const struct ipe_policy *const op,const struct ipe_policy *const np); +void ipe_audit_enforce (bool new_enforce,bool old_enforce);#endif /* _IPE_AUDIT_H */
security/ipe/eval.c +12 -2
@@ -19,6 +19,7 @@struct ipe_policy __rcu *ipe_active_policy;bool success_audit; +bool enforce = true;static const struct super_block *pinned_sb;static DEFINE_SPINLOCK (pin_lock);
@@ -114,12 +115,14 @@ static bool evaluate_property(const struct ipe_eval_ctx *const ctx,int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx) {bool match = false; +bool enforcing = true;enum ipe_action_type action;enum ipe_match match_type;struct ipe_policy *pol =NULL ;const struct ipe_rule *rule =NULL ;const struct ipe_op_table *rules =NULL ;struct ipe_prop *prop =NULL ; +int rc =0 ;rcu_read_lock ();
@@ -129,6 +132,8 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)return 0 ; } + enforcing =READ_ONCE (enforce); +if (ctx->op ==IPE_OP_INVALID ) {rcu_read_unlock (); action = pol->parsed->global_default_action;
@@ -167,9 +172,12 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)ipe_audit_match (ctx, match_type, action, rule);if (action ==IPE_ACTION_DENY ) -return -EACCES ; + rc = -EACCES ; + +if (!enforcing) + rc =0 ; -return 0 ; +return rc; }/**
@@ -198,3 +206,5 @@ void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)module_param (success_audit, bool,0400 );MODULE_PARM_DESC (success_audit,"Start IPE with success auditing enabled" ); +module_param (enforce, bool,0400 ); +MODULE_PARM_DESC (enforce,"Start IPE in enforce or permissive mode" );
security/ipe/eval.h +1 -0
@@ -15,6 +15,7 @@extern struct ipe_policy __rcu *ipe_active_policy;extern bool success_audit; +extern bool enforce;struct ipe_eval_ctx {enum ipe_op_type op;
security/ipe/fs.c +68 -0
98 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH v11 15/19 fsverity: consume builtin signature via LSM hook
In reply to Fan Wufsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
---
v1-v6:
+ Not present
v7:
Introduced
v8:
+ Split fs/verity/ changes and security/ changes into separate patches
+ Change signature of fsverity_create_info to accept non-const inode
+ Change signature of fsverity_verify_signature to accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns -EOPNOTSUPP, causing errors.
v9:
+ No changes
v10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends on CONFIG_FS_VERITY_BUILTIN_SIGNATURES
v11:
+ No changes
--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)
fs/verity/fsverity_private.h +1 -1
@@ -108,7 +108,7 @@ int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,unsigned int log_blocksize, const u8 *salt, size_t salt_size); -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc);void fsverity_set_info (struct inode *inode,struct fsverity_info *vi);
fs/verity/open.c +25 -1
@@ -8,6 +8,7 @@#include "fsverity_private.h" #include <linux/mm.h> +#include <linux/security.h> #include <linux/slab.h> static struct kmem_cache *fsverity_info_cachep;
@@ -172,12 +173,28 @@ static int compute_file_digest(const struct fsverity_hash_alg *hash_alg,return err; } +#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES +static int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return security_inode_setsecurity (inode,FS_VERITY_INODE_SEC_NAME , + desc->signature, +le32_to_cpu (desc->sig_size),0 ); +} +#else +static inline int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_FS_VERITY*/ +/* * Create a new fsverity_info from the given fsverity_descriptor (with optional * appended builtin signature), and check the signature if present. The * fsverity_descriptor must have already undergone basic validation. */ -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc) {struct fsverity_info *vi;
@@ -242,6 +259,13 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,spin_lock_init (&vi->hash_page_init_lock); } + err =fsverity_inode_setsecurity (inode, desc); +if (err == -EOPNOTSUPP ) + err =0 ; + +if (err) + goto fail; +return vi; fail:
include/linux/fsverity.h +2 -0
@@ -319,4 +319,6 @@ static inline int fsverity_prepare_setattr(struct dentry *dentry, return 0; } +#define FS_VERITY_INODE_SEC_NAME "fsverity.builtin-sig" +#endif /* _LINUX_FSVERITY_H */
Signature · 1 line
2.25.1
RFC PATCH v11 14/19 ipe: add support for dm-verity as a trust provider
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Allows author of IPE policy to indicate trust for a singular dm-verity volume, identified by roothash, through "dmverity_roothash" and all signed dm-verity volumes, through "dmverity_signature".
---
v2:
+ No Changes
v3:
+ No changes
v4:
+ No changes
v5:
+ No changes
v6:
+ Fix an improper cleanup that can result in
a leak
v7:
+ Squash patch 08/12, 10/12 to [11/16]
v8:
+ Undo squash of 08/12, 10/12 - separating drivers/md/ from security/ & block/
+ Use common-audit function for dmverity_signature.
+ Change implementation for storing the dm-verity digest to use the newly introduced dm_verity_digest structure introduced in patch 14/20.
v9:
+ Adapt to the new parser
v10:
+ Select the Kconfig when all dependencies are enabled
v11:
+ No changes
--- security/ipe/Kconfig | 18 +++++ security/ipe/Makefile | 1 + security/ipe/audit.c | 31 +++++++- security/ipe/digest.c | 142 +++++++++++++++++++++++++++++++++++ security/ipe/digest.h | 26 +++++++ security/ipe/eval.c | 101 ++++++++++++++++++++++++- security/ipe/eval.h | 13 ++++ security/ipe/hooks.c | 51 +++++++++++++ security/ipe/hooks.h | 8 ++ security/ipe/ipe.c | 15 ++++ security/ipe/ipe.h | 4 + security/ipe/policy.h | 3 + security/ipe/policy_parser.c | 24 +++++- 13 files changed, 433 insertions(+), 4 deletions(-) create mode 100644 security/ipe/digest.c create mode 100644 security/ipe/digest.h
security/ipe/Kconfig +18 -0
@@ -8,6 +8,7 @@ menuconfig SECURITY_IPE depends on SECURITY && SECURITYFS && AUDIT && AUDITSYSCALL select PKCS7_MESSAGE_PARSER select SYSTEM_DATA_VERIFICATION + select IPE_PROP_DM_VERITY if DM_VERITY && DM_VERITY_VERIFY_ROOTHASH_SIG help This option enables the Integrity Policy Enforcement LSM allowing users to define a policy to enforce a trust-based access
@@ -15,3 +16,20 @@ menuconfig SECURITY_IPE admins to reconfigure trust requirements on the fly. If unsure, answer N. + +if SECURITY_IPE +menu "IPE Trust Providers" + +config IPE_PROP_DM_VERITY + bool "Enable support for dm-verity volumes" + depends on DM_VERITY && DM_VERITY_VERIFY_ROOTHASH_SIG + help + This option enables the properties 'dmverity_signature' and + 'dmverity_roothash' in IPE policy. These properties evaluates + to TRUE when a file is evaluated against a dm-verity volume + that was mounted with a signed root-hash or the volume's + root hash matches the supplied value in the policy. + +endmenu + +endif
security/ipe/Makefile +1 -0
@@ -6,6 +6,7 @@ # obj-$(CONFIG_SECURITY_IPE) += \ + digest.o \ eval.o \ hooks.o \ fs.o \
security/ipe/audit.c +29 -2
@@ -13,6 +13,7 @@#include "hooks.h" #include "policy.h" #include "audit.h" +#include "digest.h" #define ACTSTR (x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY")
@@ -40,8 +41,29 @@ static const char *const audit_op_names[__IPE_OP_MAX] = {static const char *const audit_prop_names[__IPE_PROP_MAX] = {"boot_verified=FALSE" ,"boot_verified=TRUE" , +#ifdef CONFIG_IPE_PROP_DM_VERITY +"dmverity_roothash=" , +"dmverity_signature=FALSE" , +"dmverity_signature=TRUE" , +#endif /* CONFIG_IPE_PROP_DM_VERITY */ }; +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* audit_dmv_roothash - audit a roothash of a dmverity volume. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @r: Supplies a pointer to the digest structure. +*/ +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +ipe_digest_audit (ab, rh); +} +#else +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +/** * audit_rule - audit an IPE policy rule approximation. * @ab: Supplies a pointer to the audit_buffer to append to.
@@ -53,8 +75,13 @@ static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r)audit_log_format (ab,"rule=\"op=%s " , audit_op_names[r->op]); -list_for_each_entry (ptr, &r->props, next) -audit_log_format (ab,"%s " , audit_prop_names[ptr->type]); +list_for_each_entry (ptr, &r->props, next) { +audit_log_format (ab,"%s" , audit_prop_names[ptr->type]); +if (ptr->type ==IPE_PROP_DMV_ROOTHASH ) +audit_dmv_roothash (ab, ptr->value); + +audit_log_format (ab," " ); + }audit_log_format (ab,"action=%s\"" ,ACTSTR (r->action)); }
security/ipe/digest.c new file +142 -0
142 lines not on this page · raw message
security/ipe/digest.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef _IPE_DIGEST_H +#define _IPE_DIGEST_H + +#include "policy.h" +#include <linux/types.h> +#include <linux/audit.h> + +struct digest_info { +const char *alg; +const char *raw_digest; +const u8 *digest; +size_t digest_len; +}; + +int ipe_digest_parse (const char *valstr,void **value); +void ipe_digest_free (void **value); +void ipe_digest_audit (struct audit_buffer *ab,const void *val); +bool ipe_digest_eval (const void *expect,const u8 *digest,size_t digest_len, +const char *alg); + +#endif /* _IPE_DIGEST_H */
security/ipe/eval.c +100 -1
137 lines not on this page · raw message
security/ipe/eval.h +13 -0
@@ -17,11 +17,24 @@ extern struct ipe_policy __rcu *ipe_active_policy;extern bool success_audit;extern bool enforce; +#ifdef CONFIG_IPE_PROP_DM_VERITY +struct ipe_bdev { +bool dm_verity_signed; + +const u8 *digest; +size_t digest_len; +const char *digest_algo; +}; +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +struct ipe_eval_ctx {enum ipe_op_type op;const struct file *file;bool from_init_sb; +#ifdef CONFIG_IPE_PROP_DM_VERITY +const struct ipe_bdev *ipe_bdev; +#endif /* CONFIG_IPE_PROP_DM_VERITY */ };enum ipe_match {
security/ipe/hooks.c +51 -0
60 lines not on this page · raw message
security/ipe/hooks.h +8 -0
@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/binfmts.h> #include <linux/security.h> +#include <linux/blk_types.h> int ipe_bprm_check_security (struct linux_binprm *bprm);
@@ -24,4 +25,11 @@ int ipe_kernel_load_data(enum kernel_load_data_id id, bool contents);void ipe_sb_free_security (struct super_block *mnt_sb); +#ifdef CONFIG_IPE_PROP_DM_VERITY +void ipe_bdev_free_security (struct block_device *bdev); + +int ipe_bdev_setsecurity (struct block_device *bdev,const char *key, +const void *value,size_t len); +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +15 -0
@@ -5,12 +5,23 @@#include "ipe.h" #include "hooks.h" +#include "eval.h" bool ipe_enabled;static struct lsm_blob_sizes ipe_blobs__ro_after_init = { +#ifdef CONFIG_IPE_PROP_DM_VERITY + .lbs_bdev =sizeof (struct ipe_bdev ), +#endif /* CONFIG_IPE_PROP_DM_VERITY */ }; +#ifdef CONFIG_IPE_PROP_DM_VERITY +struct ipe_bdev *ipe_bdev (struct block_device *b) +{ +return b->security + ipe_blobs.lbs_bdev; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static struct security_hook_list ipe_hooks[]__ro_after_init = {LSM_HOOK_INIT (bprm_check_security, ipe_bprm_check_security),LSM_HOOK_INIT (mmap_file, ipe_mmap_file),
@@ -18,6 +29,10 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {LSM_HOOK_INIT (kernel_read_file, ipe_kernel_read_file),LSM_HOOK_INIT (kernel_load_data, ipe_kernel_load_data),LSM_HOOK_INIT (sb_free_security, ipe_sb_free_security), +#ifdef CONFIG_IPE_PROP_DM_VERITY +LSM_HOOK_INIT (bdev_free_security, ipe_bdev_free_security), + LSM_HOOK_INIT(bdev_setsecurity, ipe_bdev_setsecurity), +#endif };/**
security/ipe/ipe.h +4 -0
@@ -15,4 +15,8 @@extern bool ipe_enabled; +#ifdef CONFIG_IPE_PROP_DM_VERITY +struct ipe_bdev *ipe_bdev (struct block_device *b); +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#endif /* _IPE_H */
security/ipe/policy.h +3 -0
@@ -33,6 +33,9 @@ enum ipe_action_type {enum ipe_prop_type {IPE_PROP_BOOT_VERIFIED_FALSE ,IPE_PROP_BOOT_VERIFIED_TRUE , +IPE_PROP_DMV_ROOTHASH , +IPE_PROP_DMV_SIG_FALSE , +IPE_PROP_DMV_SIG_TRUE , __IPE_PROP_MAX };
security/ipe/policy_parser.c +23 -1
@@ -10,6 +10,7 @@#include "policy.h" #include "policy_parser.h" +#include "digest.h" #define START_COMMENT '#'#define IPE_POLICY_DELIM " \t"
@@ -216,6 +217,7 @@ static void free_rule(struct ipe_rule *r)list_for_each_entry_safe (p, t, &r->props, next) {list_del (&p->next); +ipe_digest_free (&p->value);kfree (p); }
@@ -268,6 +270,11 @@ static enum ipe_action_type parse_action(char *t)static const match_table_t property_tokens = { {IPE_PROP_BOOT_VERIFIED_FALSE ,"boot_verified=FALSE" }, {IPE_PROP_BOOT_VERIFIED_TRUE ,"boot_verified=TRUE" }, +#ifdef CONFIG_IPE_PROP_DM_VERITY + {IPE_PROP_DMV_ROOTHASH ,"dmverity_roothash=%s" }, + {IPE_PROP_DMV_SIG_FALSE ,"dmverity_signature=FALSE" }, + {IPE_PROP_DMV_SIG_TRUE ,"dmverity_signature=TRUE" }, +#endif /* CONFIG_IPE_PROP_DM_VERITY */ {IPE_PROP_INVALID ,NULL } };
@@ -287,6 +294,7 @@ static int parse_property(char *t, struct ipe_rule *r)struct ipe_prop *p =NULL ;int rc =0 ;int token; +char *dup =NULL ; p =kzalloc (sizeof (*p),GFP_KERNEL );if (!p)
@@ -295,8 +303,20 @@ static int parse_property(char *t, struct ipe_rule *r) token =match_token (t, property_tokens, args);switch (token) { +case IPE_PROP_DMV_ROOTHASH : + dup =match_strdup (&args[0 ]); +if (!dup) { + rc = -ENOMEM ; + goto err; + } + rc =ipe_digest_parse (dup, &p->value); +if (rc) + goto err; + fallthrough;case IPE_PROP_BOOT_VERIFIED_FALSE :case IPE_PROP_BOOT_VERIFIED_TRUE : +case IPE_PROP_DMV_SIG_FALSE : +case IPE_PROP_DMV_SIG_TRUE : p->type = token;break ;default :
@@ -307,10 +327,12 @@ static int parse_property(char *t, struct ipe_rule *r) goto err;list_add_tail (&p->next, &r->props); +out: +kfree (dup);return rc; err:kfree (p); -return rc; + goto out; }/**
Signature · 1 line
2.25.1
RFC PATCH v11 17/19 scripts: add boot policy generation program
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Enables an IPE policy to be enforced from kernel start, enabling access control based on trust from kernel startup. This is accomplished by transforming an IPE policy indicated by CONFIG_IPE_BOOT_POLICY into a c-string literal that is parsed at kernel startup as an unsigned policy.
---
v2:
+ No Changes
v3:
+ No Changes
v4:
+ No Changes
v5:
+ No Changes
v6:
+ No Changes
v7:
+ Move from 01/11 to 14/16
+ Don't return errno directly.
+ Make output of script more user-friendly
+ Add escaping for tab and '?'
+ Mark argv pointer const
+ Invert return code check in the boot policy parsing code path.
v8:
+ No significant changes.
v9:
+ No changes
v10:
+ Update the init part code for rcu changes in the eval loop patch
v11:
+ Fix code style issues
--- MAINTAINERS | 1 + scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 6 ++ scripts/ipe/polgen/polgen.c | 145 ++++++++++++++++++++++++++++++++++ security/ipe/.gitignore | 1 + security/ipe/Kconfig | 10 +++ security/ipe/Makefile | 11 +++ security/ipe/fs.c | 8 ++ security/ipe/ipe.c | 12 +++ 11 files changed, 198 insertions(+) create mode 100644 scripts/ipe/Makefile create mode 100644 scripts/ipe/polgen/.gitignore create mode 100644 scripts/ipe/polgen/Makefile create mode 100644 scripts/ipe/polgen/polgen.c create mode 100644 security/ipe/.gitignore
MAINTAINERS +1 -0
@@ -10394,6 +10394,7 @@ M: Fan Wu <[email protected]> L: [email protected] S: Supported T: git https://github.com/microsoft/ipe.git +F: scripts/ipe/ F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVER
scripts/Makefile +1 -0
@@ -50,6 +50,7 @@ targets += module.lds subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins subdir-$(CONFIG_MODVERSIONS) += genksyms subdir-$(CONFIG_SECURITY_SELINUX) += selinux +subdir-$(CONFIG_SECURITY_IPE) += ipe # Let clean descend into subdirs subdir- += basic dtc gdb kconfig mod
scripts/ipe/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +subdir-y := polgen
scripts/ipe/polgen/.gitignore new file +1 -0
@@ -0,0 +1 @@ +polgen
scripts/ipe/polgen/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +hostprogs-always-y := polgen +HOST_EXTRACFLAGS += \ + -I$(srctree)/include \ + -I$(srctree)/include/uapi \ +
scripts/ipe/polgen/polgen.c new file +145 -0
145 lines not on this page · raw message
security/ipe/.gitignore new file +1 -0
@@ -0,0 +1 @@ +boot-policy.c
security/ipe/Kconfig +10 -0
@@ -18,6 +18,16 @@ menuconfig SECURITY_IPE If unsure, answer N. if SECURITY_IPE +config IPE_BOOT_POLICY + string "Integrity policy to apply on system startup" + help + This option specifies a filepath to a IPE policy that is compiled + into the kernel. This policy will be enforced until a policy update + is deployed via the $securityfs/ipe/policies/$policy_name/active + interface. + + If unsure, leave blank. + menu "IPE Trust Providers" config IPE_PROP_DM_VERITY
security/ipe/Makefile +11 -0
@@ -5,7 +5,16 @@ # Makefile for building the IPE module as part of the kernel tree. # +quiet_cmd_polgen = IPE_POL $(2) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/boot-policy.c $(2) + +targets += boot-policy.c + +$(obj)/boot-policy.c: scripts/ipe/polgen/polgen $(CONFIG_IPE_BOOT_POLICY) FORCE + $(call if_changed,polgen,$(CONFIG_IPE_BOOT_POLICY)) + obj-$(CONFIG_SECURITY_IPE) += \ + boot-policy.o \ digest.o \ eval.o \ hooks.o \
@@ -15,3 +24,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ policy_fs.o \ policy_parser.o \ audit.o \ + +clean-files := boot-policy.c \
security/ipe/fs.c +8 -0
@@ -190,6 +190,7 @@ static const struct file_operations enforce_fops = {static int __init ipe_init_securityfs (void ) {int rc =0 ; +struct ipe_policy *ap;if (!ipe_enabled)return -EOPNOTSUPP ;
@@ -220,6 +221,13 @@ static int __init ipe_init_securityfs(void) goto err; } + ap =rcu_access_pointer (ipe_active_policy); +if (ap) { + rc =ipe_new_policyfs_node (ap); +if (rc) + goto err; + } + np =securityfs_create_file ("new_policy" ,0200 , root,NULL , &np_fops);if (IS_ERR (np)) { rc =PTR_ERR (np);
security/ipe/ipe.c +12 -0
@@ -7,6 +7,7 @@#include "hooks.h" #include "eval.h" +extern const char *const ipe_boot_policy;bool ipe_enabled;static struct lsm_blob_sizes ipe_blobs__ro_after_init = {
@@ -60,9 +61,20 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {*/ static int __init ipe_init (void ) { +struct ipe_policy *p =NULL ; +security_add_hooks (ipe_hooks,ARRAY_SIZE (ipe_hooks),"ipe" ); ipe_enabled = true; +if (ipe_boot_policy) { + p =ipe_new_policy (ipe_boot_policy,strlen (ipe_boot_policy), +NULL ,0 ); +if (IS_ERR (p)) +return PTR_ERR (p); + +rcu_assign_pointer (ipe_active_policy, p); + } +return 0 ; }
Signature · 1 line
2.25.1
RFC PATCH v11 19/19 documentation: add ipe documentation
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Add IPE's admin and developer documentation to the kernel tree.
---
v2:
+ No Changes
v3:
+ Add Acked-by
+ Fixup code block syntax
+ Fix a minor grammatical issue.
v4:
+ Update documentation with the results of other code changes.
v5:
+ No changes
v6:
+ No changes
v7:
+ Add additional developer-level documentation
+ Update admin-guide docs to reflect changes.
+ Drop Acked-by due to significant changes
+ Added section about audit events in admin-guide
v8:
+ Correct terminology from "audit event" to "audit record"
+ Add associated documentation with the correct "audit event" terminology.
+ Add some context to the historical motivation for IPE and design philosophy.
+ Add some content about the securityfs layout in the policies directory.
+ Various spelling and grammatical corrections.
v9:
+ Correct spelling of "pitfalls"
+ Update the docs w.r.t the new parser and new audit formats
v10:
+ Refine user docs per upstream suggetions
+ Update audit events part
v11:
+ No changes
--- Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 752 ++++++++++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 420 ++++++++++ MAINTAINERS | 2 + 6 files changed, 1188 insertions(+) create mode 100644 Documentation/admin-guide/LSM/ipe.rst create mode 100644 Documentation/security/ipe.rst
Documentation/admin-guide/LSM/index.rst +1 -0
@@ -47,3 +47,4 @@ subdirectories. tomoyo Yama SafeSetID + ipe
Documentation/admin-guide/LSM/ipe.rst new file +752 -0
752 lines not on this page · raw message
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -2262,6 +2262,18 @@ ipcmni_extend [KNL] Extend the maximum number of unique System V IPC identifiers from 32,768 to 16,777,216. + ipe.enforce= [IPE] + Format: <bool> + Determine whether IPE starts in permissive (0) or + enforce (1) mode. The default is enforce. + + ipe.success_audit= + [IPE] + Format: <bool> + Start IPE with success auditing enabled, emitting + an audit event when a binary is allowed. The default + is 0. + irqaffinity= [SMP] Set the default irq affinity mask The argument is a cpu list, as described above.
Documentation/security/index.rst +1 -0
@@ -18,3 +18,4 @@ Security Documentation digsig landlock secrets/index + ipe
Documentation/security/ipe.rst new file +420 -0
420 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -10394,6 +10394,8 @@ M: Fan Wu <[email protected]> L: [email protected] S: Supported T: git https://github.com/microsoft/ipe.git +F: Documentation/admin-guide/LSM/ipe.rst +F: Documentation/security/ipe.rst F: scripts/ipe/ F: security/ipe/
Signature · 1 line
2.25.1
RFC PATCH v11 8/19 uapi|audit|ipe: add ipe auditing support
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Users of IPE require a way to identify when and why an operation fails, allowing them to both respond to violations of policy and be notified of potentially malicious actions on their systems with respect to IPE itself.
This patch introduces 3 new audit events.
AUDIT_IPE_ACCESS(1420) indicates the result of an IPE policy evaluation of a resource.AUDIT_IPE_CONFIG_CHANGE(1421) indicates the current active IPE policy has been changed to another loaded policy. AUDIT_IPE_POLICY_LOAD(1422) indicates a new IPE policy has been loaded into the kernel.
This patch also adds support for success auditing, allowing users to identify why an allow decision was made for a resource. However, it is recommended to use this option with caution, as it is quite noisy.
Here are some examples of the new audit record types:
AUDIT_IPE_ACCESS(1420):
audit: AUDIT1420 path="/root/vol/bin/hello" dev="sda"
ino=3897 rule="op=EXECUTE boot_verified=TRUE action=ALLOW"
audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0"
ino=2 rule="DEFAULT action=DENY"
audit: AUDIT1420 path="/tmp/tmpdp2h1lub/deny/bin/hello" dev="tmpfs"
ino=131 rule="DEFAULT action=DENY"
The above three records were generated when the active IPE policy only allows binaries from the initial booted drive(sda) to run. The three identical hello binary were placed at different locations, only the first hello from sda was allowed.
Field path followed by the file's path name.
Field dev followed by the device name as found in /dev where the file is from.
Note that for device mappers it will use the name dm-X instead of the name in /dev/mapper.
For a file in a temp file system, which is not from a device, it will use tmpfs for the field.
The implementation of this part is following another existing use case LSM_AUDIT_DATA_INODE in security/lsm_audit.c
Field ino followed by the file's inode number.
Field rule followed by the IPE rule made the access decision. The whole rule must be audited because the decision is based on the combination of all property conditions in the rule.
Along with the syscall audit event, user can know why a blocked happened. For example:
audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0"
ino=2 rule="DEFAULT action=DENY"
audit[1956]: SYSCALL arch=c000003e syscall=59
success=no exit=-13 a0=556790138df0 a1=556790135390 a2=5567901338b0
a3=ab2a41a67f4f1f4e items=1 ppid=147 pid=1956 auid=4294967295 uid=0
gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0
ses=4294967295 comm="bash" exe="/usr/bin/bash" key=(null)The above two records showed bash used execve to run "hello" and got blocked by IPE. Note that the IPE records are always prior to a SYSCALL record.
AUDIT_IPE_CONFIG_CHANGE(1421):
audit: AUDIT1421
old_active_pol_name="Allow_All" old_active_pol_version=0.0.0
old_policy_digest=sha256:E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649
new_active_pol_name="boot_verified" new_active_pol_version=0.0.0
new_policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F
auid=4294967295 ses=4294967295 lsm=ipe res=1The above record showed the current IPE active policy switch from Allow_All to boot_verified along with the version and the hash digest of the two policies. Note IPE can only have one policy active at a time, all access decision evaluation is based on the current active policy.
The normal procedure to deploy a policy is loading the policy to deploy into the kernel first, then switch the active policy to it.
AUDIT_IPE_POLICY_LOAD(1422):
audit: AUDIT1422 policy_name="boot_verified" policy_version=0.0.0 policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F26765076DD auid=4294967295 ses=4294967295 lsm=ipe res=1
The above record showed a new policy has been loaded into the kernel with the policy name, policy version and policy hash.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move ipe_load_properties to patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables with ipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ Use GFP_KERNEL for audit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Use rcu_access_pointer for rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12
v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.
v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.
v6:
+ No changes
v7:
+ Further split lsm creation, the audit system, the evaluation loop, and access control hooks into separate patches.
+ Further split audit system patch into two separate patches; one for include/uapi, and the usage of the new defines.
+ Split out the permissive functionality into another separate patch, for easier review.
+ Correct misuse of audit_log_n_untrusted string to audit_log_format
+ Use get_task_comm instead of comm directly.
+ Quote certain audit values
+ Remove unnecessary help text on choice options - these were previously
idented at the wrong level
+ Correct a stale string constant (ctx_ns_enforce to ctx_enforce)
v8:
+ Change dependency for CONFIG_AUDIT to CONFIG_AUDITSYSCALL
+ Drop ctx_* prefix
+ Reuse, where appropriate, the audit fields from the field
dictionary. This transforms:
ctx_pathname -> path
ctx_ino -> ino
ctx_dev -> dev + Add audit records and event examples to commit description.
+ Remove new_audit_ctx, replace with audit_log_start. All data that would provided by new_audit_ctx is already present in the syscall audit record, that is always emitted on these actions. The audit records should be correlated as such.
+ Change audit types:
+ AUDIT_TRUST_RESULT -> AUDIT_IPE_ACCESS
+ This prevents overloading of the AVC type.
+ AUDIT_TRUST_POLICY_ACTIVATE -> AUDIT_MAC_CONFIG_CHANGE
+ AUDIT_TRUST_POLICY_LOAD -> AUDIT_MAC_POLICY_LOAD
+ There were no significant difference in meaning between these types.
+ Remove enforcing parameter passed from the context structure for AUDIT_IPE_ACCESS.
+ This field can be inferred from the SYSCALL audit event, based on the success field.
+ Remove all fields already captured in the syscall record. "hook", an IPE specific field, can be determined via the syscall field in the syscall record itself, so it has been removed.
+ ino, path, and dev in IPE's record refer to the subject of the syscall, while the syscall record refers to the calling process.
+ remove IPE prefix from policy load/policy activation events
+ fix a bug wherein a policy change audit record was not fired when updating a policy
v9:
+ Merge the AUDIT_IPE_ACCESS definition with the audit support commit
+ Change the audit format of policy load and switch
+ Remove the ipe audit kernel switch
v10:
+ Create AUDIT_IPE_CONFIG_CHANGE and AUDIT_IPE_POLICY_LOAD
+ Change field names per upstream feedback
v11:
+ Fix style issues
--- include/uapi/linux/audit.h | 3 + security/ipe/Kconfig | 2 +- security/ipe/Makefile | 1 + security/ipe/audit.c | 195 +++++++++++++++++++++++++++++++++++++ security/ipe/audit.h | 18 ++++ security/ipe/eval.c | 32 ++++-- security/ipe/eval.h | 8 ++ security/ipe/fs.c | 70 +++++++++++++ security/ipe/policy.c | 5 + 9 files changed, 327 insertions(+), 7 deletions(-) create mode 100644 security/ipe/audit.c create mode 100644 security/ipe/audit.h
include/uapi/linux/audit.h +3 -0
@@ -143,6 +143,9 @@#define AUDIT_MAC_UNLBL_STCDEL 1417/* NetLabel: del a static label */ #define AUDIT_MAC_CALIPSO_ADD 1418/* NetLabel: add CALIPSO DOI entry */ #define AUDIT_MAC_CALIPSO_DEL 1419/* NetLabel: del CALIPSO DOI entry */ +#define AUDIT_IPE_ACCESS 1420/* IPE denial or grant */ +#define AUDIT_IPE_CONFIG_CHANGE 1421/* IPE config change */ +#define AUDIT_IPE_POLICY_LOAD 1422/* IPE policy load */ #define AUDIT_FIRST_KERN_ANOM_MSG 1700#define AUDIT_LAST_KERN_ANOM_MSG 1799
security/ipe/Kconfig +1 -1
@@ -5,7 +5,7 @@ menuconfig SECURITY_IPE bool "Integrity Policy Enforcement (IPE)" - depends on SECURITY && SECURITYFS + depends on SECURITY && SECURITYFS && AUDIT && AUDITSYSCALL select PKCS7_MESSAGE_PARSER select SYSTEM_DATA_VERIFICATION help
security/ipe/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_SECURITY_IPE) += \ policy.o \ policy_fs.o \ policy_parser.o \ + audit.o \
security/ipe/audit.c new file +195 -0
195 lines not on this page · raw message
security/ipe/audit.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef _IPE_AUDIT_H +#define _IPE_AUDIT_H + +#include "policy.h" + +void ipe_audit_match (const struct ipe_eval_ctx *const ctx, +enum ipe_match match_type, +enum ipe_action_type act,const struct ipe_rule *const r); +void ipe_audit_policy_load (const struct ipe_policy *const p); +void ipe_audit_policy_activation (const struct ipe_policy *const op, +const struct ipe_policy *const np); + +#endif /* _IPE_AUDIT_H */
security/ipe/eval.c +26 -6
@@ -10,12 +10,15 @@#include <linux/sched.h> #include <linux/rcupdate.h> #include <linux/spinlock.h> +#include <linux/moduleparam.h> #include "ipe.h" #include "eval.h" #include "policy.h" +#include "audit.h" struct ipe_policy __rcu *ipe_active_policy; +bool success_audit;static const struct super_block *pinned_sb;static DEFINE_SPINLOCK (pin_lock);
@@ -112,6 +115,7 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx) {bool match = false;enum ipe_action_type action; +enum ipe_match match_type;struct ipe_policy *pol =NULL ;const struct ipe_rule *rule =NULL ;const struct ipe_op_table *rules =NULL ;
@@ -127,9 +131,9 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)if (ctx->op ==IPE_OP_INVALID ) {rcu_read_unlock (); -if (pol->parsed->global_default_action ==IPE_ACTION_DENY ) -return -EACCES ; -return 0 ; + action = pol->parsed->global_default_action; + match_type =IPE_MATCH_GLOBAL ; + goto eval; } rules = &pol->parsed->rules[ctx->op];
@@ -147,14 +151,21 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)break ; } -if (match) +if (match) { action = rule->action; -else if (rules->default_action !=IPE_ACTION_INVALID ) + match_type =IPE_MATCH_RULE ; + }else if (rules->default_action !=IPE_ACTION_INVALID ) { action = rules->default_action; -else + match_type =IPE_MATCH_TABLE ; + }else { action = pol->parsed->global_default_action; + match_type =IPE_MATCH_GLOBAL ; + }rcu_read_unlock (); +eval: +ipe_audit_match (ctx, match_type, action, rule); +if (action ==IPE_ACTION_DENY )return -EACCES ;
@@ -178,3 +189,12 @@ void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)spin_unlock (&pin_lock); } + +/* Set the right module name */ +#ifdef KBUILD_MODNAME +#undef KBUILD_MODNAME +#define KBUILD_MODNAME "ipe" +#endif + +module_param (success_audit, bool,0400 ); +MODULE_PARM_DESC (success_audit,"Start IPE with success auditing enabled" );
security/ipe/eval.h +8 -0
@@ -14,6 +14,7 @@#define IPE_EVAL_CTX_INIT ((struct ipe_eval_ctx){ 0 })extern struct ipe_policy __rcu *ipe_active_policy; +extern bool success_audit;struct ipe_eval_ctx {enum ipe_op_type op;
@@ -22,6 +23,13 @@ struct ipe_eval_ctx {bool from_init_sb; }; +enum ipe_match { +IPE_MATCH_RULE =0 , +IPE_MATCH_TABLE , +IPE_MATCH_GLOBAL , + __IPE_MATCH_MAX +}; +void build_eval_ctx (struct ipe_eval_ctx *ctx,const struct file *file,enum ipe_op_type op);int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx);void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb);
security/ipe/fs.c +70 -0
105 lines not on this page · raw message
security/ipe/policy.c +5 -0
@@ -11,6 +11,7 @@#include "fs.h" #include "policy.h" #include "policy_parser.h" +#include "audit.h" /* lock for synchronizing writers across ipe policy */ DEFINE_MUTEX (ipe_policy_lock);
@@ -124,6 +125,8 @@ struct ipe_policy *ipe_update_policy(struct inode *root,swap (new->policyfs, old->policyfs); +ipe_audit_policy_load (new); +return old; err:ipe_free_policy (new);
@@ -209,5 +212,7 @@ int ipe_set_active_pol(const struct ipe_policy *p)rcu_assign_pointer (ipe_active_policy, p); +ipe_audit_policy_activation (ap, p); +return 0 ; }
Signature · 1 line
2.25.1
RFC PATCH v11 10/19 block|security: add LSM blob to block_device
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Some block devices have valuable security properties that is only accessible during the creation time.
For example, when creating a dm-verity block device, the dm-verity's roothash and roothash signature, which are extreme important security metadata, are passed to the kernel. However, the roothash will be saved privately in dm-verity, which prevents the seucrity subsystem to easily access that information. Worse, the roothash signature will be discarded after the verification, making it impossible to utilize the roothash signature by the security subsystem.
With this patch, an LSM blob is added to the block_device structure. This enables the security subsystem to store security-sensitive data related to block devices within the security blob. For example, LSM can use the new LSM blob to save the roothash signature of a dm-verity, and LSM can make access decision based on the data inside the signature, like the signer ceritificate.
The implementation follows the same approach used for security blobs in other structures like struct file, struct inode, and struct superblock. The initialization of the security blob occurs after the creation of the struct block_device, performed by the security subsystem. Similarly, the security blob is freed by the security subsystem before the struct block_device is deallocated or freed.
---
v2:
+ No Changes
v3:
+ Minor style changes from checkpatch --strict
v4:
+ No Changes
v5:
+ Allow multiple callers to call security_bdev_setsecurity
v6:
+ Simplify security_bdev_setsecurity break condition
v7:
+ Squash all dm-verity related patches to two patches, the additions to dm-verity/fs, and the consumption of the additions.
v8:
+ Split dm-verity related patches squashed in v7 to 3 commits based on topic:
+ New LSM hook
+ Consumption of hook outside LSM
+ Consumption of hook inside LSM.
+ change return of security_bdev_alloc / security_bdev_setsecurity to LSM_RET_DEFAULT instead of 0.
+ Change return code to -EOPNOTSUPP, bring inline with other setsecurity hooks.
v9:
+ Add Reviewed-by: Casey Schaufler <[email protected]>
+ Remove unlikely when calling LSM hook
+ Make the security field dependent on CONFIG_SECURITY
v10:
+ No changes
v11:
+ No changes
--- block/bdev.c | 7 +++ include/linux/blk_types.h | 3 ++ include/linux/lsm_hook_defs.h | 5 ++ include/linux/lsm_hooks.h | 1 + include/linux/security.h | 22 ++++++++ security/security.c | 99 +++++++++++++++++++++++++++++++++++ 6 files changed, 137 insertions(+)
block/bdev.c +7 -0
@@ -24,6 +24,7 @@#include <linux/pseudo_fs.h> #include <linux/uio.h> #include <linux/namei.h> +#include <linux/security.h> #include <linux/part_stat.h> #include <linux/uaccess.h> #include <linux/stat.h>
@@ -301,6 +302,11 @@ static struct inode *bdev_alloc_inode(struct super_block *sb)if (!ei)return NULL ;memset (&ei->bdev,0 ,sizeof (ei->bdev)); + +if (security_bdev_alloc (&ei->bdev)) { +kmem_cache_free (bdev_cachep, ei); +return NULL ; + }return &ei->vfs_inode; }
@@ -310,6 +316,7 @@ static void bdev_free_inode(struct inode *inode)free_percpu (bdev->bd_stats);kfree (bdev->bd_meta_info); +security_bdev_free (bdev);if (!bdev_is_partition (bdev)) {if (bdev->bd_disk && bdev->bd_disk->bdi)
include/linux/blk_types.h +3 -0
@@ -68,6 +68,9 @@ struct block_device {struct partition_meta_info *bd_meta_info;#ifdef CONFIG_FAIL_MAKE_REQUEST bool bd_make_it_fail; +#endif +#ifdef CONFIG_SECURITY +void *security;#endif /* * keep this out-of-line as it's both big and not needed in the fast
include/linux/lsm_hook_defs.h +5 -0
@@ -419,3 +419,8 @@ LSM_HOOK(int, 0, uring_override_creds, const struct cred *new) LSM_HOOK(int, 0, uring_sqpoll, void) LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd)#endif /* CONFIG_IO_URING */ + +LSM_HOOK(int, 0, bdev_alloc_security, struct block_device *bdev) +LSM_HOOK(void, LSM_RET_VOID, bdev_free_security, struct block_device *bdev) +LSM_HOOK(int, 0, bdev_setsecurity, struct block_device *bdev, const char *name, + const void *value, size_t size)
include/linux/lsm_hooks.h +1 -0
@@ -65,6 +65,7 @@ struct lsm_blob_sizes {int lbs_msg_msg;int lbs_task;int lbs_xattr_count;/* number of xattr slots in new_xattrs array */ +int lbs_bdev; };/**
include/linux/security.h +22 -0
@@ -484,6 +484,11 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen);int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen);int security_locked_down (enum lockdown_reason what); +int security_bdev_alloc (struct block_device *bdev); +void security_bdev_free (struct block_device *bdev); +int security_bdev_setsecurity (struct block_device *bdev, +const char *name,const void *value, +size_t size);#else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier (enum lsm_event event,void *data)
@@ -1395,6 +1400,23 @@ static inline int security_locked_down(enum lockdown_reason what) {return 0 ; } + +static inline int security_bdev_alloc (struct block_device *bdev) +{ +return 0 ; +} + +static inline void security_bdev_free (struct block_device *bdev) +{ +} + +static inline int security_bdev_setsecurity (struct block_device *bdev, +const char *name, +const void *value,size_t size) +{ +return 0 ; +} +#endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY ) && defined(CONFIG_WATCH_QUEUE )
security/security.c +99 -0
129 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH v11 18/19 ipe: kunit test for parser
In reply to Fan WuFrom: Deven Bowers <[email protected]>
Add various happy/unhappy unit tests for both IPE's parser.
---
v1-v6:
+ Not present
v7:
Introduced
v8:
+ Remove the kunit tests with respect to the fsverity digest, as these require significant changes to work with the new method of acquiring the digest at runtime.
v9:
+ Remove the kunit tests related to ipe_context
v10:
+ No changes
v11:
+ No changes
--- security/ipe/Kconfig | 17 +++ security/ipe/Makefile | 3 + security/ipe/policy_tests.c | 294 ++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+) create mode 100644 security/ipe/policy_tests.c
security/ipe/Kconfig +17 -0
@@ -55,4 +55,21 @@ config IPE_PROP_FS_VERITY endmenu +config SECURITY_IPE_KUNIT_TEST + bool "Build KUnit tests for IPE" if !KUNIT_ALL_TESTS + depends on KUNIT=y + default KUNIT_ALL_TESTS + help + This builds the IPE KUnit tests. + + KUnit tests run during boot and output the results to the debug log + in TAP format (https://testanything.org/). Only useful for kernel devs + running KUnit test harness and are not for inclusion into a + production build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + endif
security/ipe/Makefile +3 -0
@@ -26,3 +26,6 @@ obj-$(CONFIG_SECURITY_IPE) += \ audit.o \ clean-files := boot-policy.c \ + +obj-$(CONFIG_SECURITY_IPE_KUNIT_TEST) += \ + policy_tests.o \
security/ipe/policy_tests.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH v11 7/19 ipe: add userspace interface
In reply to Fan WuFrom: Deven Bowers <[email protected]>
As is typical with LSMs, IPE uses securityfs as its interface with userspace. for a complete list of the interfaces and the respective inputs/outputs, please see the documentation under admin-guide/LSM/ipe.rst
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move policy load and activation audit event to 03/12
+ Fix a potential panic when a policy failed to load.
+ use pr_warn for a failure to parse instead of an audit record
+ Remove comments from headers
+ Add lockdep assertions to ipe_update_active_policy and ipe_activate_policy
+ Fix up warnings with checkpatch --strict
+ Use file_ns_capable for CAP_MAC_ADMIN for securityfs nodes.
+ Use memdup_user instead of kzalloc+simple_write_to_buffer.
+ Remove strict_parse command line parameter, as it is added by the sysctl command line.
+ Prefix extern variables with ipe_
v4:
+ Remove securityfs to reverse-dependency
+ Add SHA1 reverse dependency.
+ Add versioning scheme for IPE properties, and associated interface to query the versioning scheme.
+ Cause a parser to always return an error on unknown syntax.
+ Remove strict_parse option
+ Change active_policy interface from sysctl, to securityfs, and change scheme.
v5:
+ Cause an error if a default action is not defined for each operation.
+ Minor function renames
v6:
+ No changes
v7:
+ Propagating changes to support the new ipe_context structure in the evaluation loop.
+ Further split the parser and userspace interface changes into separate commits.
+ "raw" was renamed to "pkcs7" and made read only
+ "raw"'s write functionality (update a policy) moved to "update"
+ introduced "version", "policy_name" nodes.
+ "content" renamed to "policy"
+ changes to allow the compiled-in policy to be treated identical to deployed-after-the-fact policies.
v8:
+ Prevent securityfs initialization if the LSM is disabled
v9:
+ Switch to securityfs_recursive_remove for policy folder deletion
v10:
+ Simplify and correct concurrency
+ Fix typos
v11:
+ Correct code comments
--- security/ipe/Makefile | 2 + security/ipe/fs.c | 101 ++++++++ security/ipe/fs.h | 16 ++ security/ipe/ipe.c | 3 + security/ipe/ipe.h | 2 + security/ipe/policy.c | 112 +++++++++ security/ipe/policy.h | 9 + security/ipe/policy_fs.c | 481 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 726 insertions(+) create mode 100644 security/ipe/fs.c create mode 100644 security/ipe/fs.h create mode 100644 security/ipe/policy_fs.c
security/ipe/Makefile +2 -0
@@ -8,6 +8,8 @@ obj-$(CONFIG_SECURITY_IPE) += \ eval.o \ hooks.o \ + fs.o \ ipe.o \ policy.o \ + policy_fs.o \ policy_parser.o \
security/ipe/fs.c new file +101 -0
101 lines not on this page · raw message
security/ipe/fs.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef _IPE_FS_H +#define _IPE_FS_H + +#include "policy.h" + +extern struct dentry *policy_root__ro_after_init ; + +int ipe_new_policyfs_node (struct ipe_policy *p); +void ipe_del_policyfs_node (struct ipe_policy *p); + +#endif /* _IPE_FS_H */
security/ipe/ipe.c +3 -0
@@ -6,6 +6,8 @@#include "ipe.h" #include "hooks.h" +bool ipe_enabled; +static struct lsm_blob_sizes ipe_blobs__ro_after_init = { };
@@ -31,6 +33,7 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {static int __init ipe_init (void ) {security_add_hooks (ipe_hooks,ARRAY_SIZE (ipe_hooks),"ipe" ); + ipe_enabled = true;return 0 ; }
security/ipe/ipe.h +2 -0
@@ -13,4 +13,6 @@#include <linux/lsm_hooks.h> +extern bool ipe_enabled; +#endif /* _IPE_H */
security/ipe/policy.c +112 -0
136 lines not on this page · raw message
security/ipe/policy.h +9 -0
@@ -7,6 +7,7 @@#include <linux/list.h> #include <linux/types.h> +#include <linux/fs.h> enum ipe_op_type {IPE_OP_EXEC =0 ,
@@ -76,10 +77,18 @@ struct ipe_policy {size_t textlen;struct ipe_parsed_policy *parsed; + + struct dentry *policyfs; };struct ipe_policy *ipe_new_policy (const char *text,size_t textlen,const char *pkcs7,size_t pkcs7len);void ipe_free_policy (struct ipe_policy *pol); +struct ipe_policy *ipe_update_policy (struct inode *root, +const char *text, +size_t textlen,const char *pkcs7, +size_t pkcs7len); +int ipe_set_active_pol (const struct ipe_policy *p); +extern struct mutex ipe_policy_lock;#endif /* _IPE_POLICY_H */
security/ipe/policy_fs.c new file +481 -0
481 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH v11 13/19 dm verity: consume root hash digest and signature data via LSM hook
In reply to Fan WuFrom: Deven Bowers <[email protected]>
dm-verity provides a strong guarantee of a block device's integrity. As a generic way to check the integrity of a block device, it provides those integrity guarantees to its higher layers, including the filesystem level.
An LSM that control access to a resource on the system based on the available integrity claims can use this transitive property of dm-verity, by querying the underlying block_device of a particular file.
The digest and signature information need to be stored in the block device to fulfill the next requirement of authorization via LSM policy. This will enable the LSM to perform revocation of devices that are still mounted, prohibiting execution of files that are no longer authorized by the LSM in question.
This patch added two security hook calls in dm-verity to save the dm-verity roothash and the roothash signature to the block device's LSM blobs.
---
v2:
+ No Changes
v3:
+ No changes
v4:
+ No changes
v5:
+ No changes
v6:
+ Fix an improper cleanup that can result in
a leak
v7:
+ Squash patch 08/12, 10/12 to [11/16]
+ Use part0 for block_device, to retrieve the block_device, when calling security_bdev_setsecurity
v8:
+ Undo squash of 08/12, 10/12 - separating drivers/md/ from security/ & block/
+ Use common-audit function for dmverity_signature.
+ Change implementation for storing the dm-verity digest to use the newly introduced dm_verity_digest structure introduced in patch 14/20.
+ Create new structure, dm_verity_digest, containing digest algorithm, size, and digest itself to pass to the LSM layer. V7 was missing the algorithm.
+ Create an associated public header containing this new structure and the key values for the LSM hook, specific to dm-verity.
+ Additional information added to commit, discussing the layering of the changes and how the information passed will be used.
v9:
+ No changes
v10:
+ No changes
v11:
+ Add an optional field to save signature
+ Move the security hook call to the new finalize hook
--- drivers/md/dm-verity-target.c | 71 +++++++++++++++++++++++++++++++++++ drivers/md/dm-verity.h | 6 +++ include/linux/dm-verity.h | 19 ++++++++++ 3 files changed, 96 insertions(+) create mode 100644 include/linux/dm-verity.h
drivers/md/dm-verity-target.c +71 -0
@@ -13,6 +13,7 @@* access behavior. */ +#include "dm-core.h" #include "dm-verity.h" #include "dm-verity-fec.h" #include "dm-verity-verify-sig.h"
@@ -22,6 +23,9 @@#include <linux/scatterlist.h> #include <linux/string.h> #include <linux/jump_label.h> +#include <linux/security.h> +#include <linux/dm-verity.h> +#include <crypto/hash_info.h> #define DM_MSG_PREFIX "verity"
@@ -952,6 +956,17 @@ static void verity_io_hints(struct dm_target *ti, struct queue_limits *limits)blk_limits_io_min (limits, limits->logical_block_size); } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static void verity_free_sig (struct dm_verity *v) +{ +kfree (v->root_digest_sig); +} +#else +static inline void verity_free_sig (struct dm_verity *v) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static void verity_dtr (struct dm_target *ti) {struct dm_verity *v = ti->private;
@@ -966,6 +981,7 @@ static void verity_dtr(struct dm_target *ti)kfree (v->salt);kfree (v->root_digest);kfree (v->zero_digest); +verity_free_sig (v);if (v->tfm)crypto_free_ahash (v->tfm);
@@ -1157,6 +1173,25 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,return r; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ + v->sig_size = sig_size; + v->root_digest_sig =kmalloc (v->sig_size,GFP_KERNEL ); +if (!v->root_digest) +return -ENOMEM ; + +return 0 ; +} +#else +static inline int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +/* * Target parameters: * <version> The current format is version 1.
@@ -1365,6 +1400,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error ="Root hash verification failed" ; goto bad; } + + r =verity_init_sig (v, verify_args.sig, verify_args.sig_size); +if (r <0 ) { + ti->error ="Cannot allocate root digest signature" ; + goto bad; + } + v->hash_per_block_bits =__fls ((1 << v->hash_dev_block_bits) / v->digest_size);
@@ -1501,6 +1543,32 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned ireturn 0 ; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_finalize (struct dm_target *ti) +{ +struct block_device *bdev; +struct dm_verity_digest root_digest; +struct dm_verity *v; +int r; + + v = ti->private; + bdev =dm_table_get_md (ti->table)->disk->part0; + root_digest.digest = v->root_digest; + root_digest.digest_len = v->digest_size; + root_digest.algo = v->alg_name; + + r =security_bdev_setsecurity (bdev,DM_VERITY_ROOTHASH_SEC_NAME , &root_digest, +sizeof (root_digest)); +if (r) +return r; + +return security_bdev_setsecurity (bdev, +DM_VERITY_SIGNATURE_SEC_NAME , + v->root_digest_sig, + v->sig_size); +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static struct target_type verity_target = { .name ="verity" , .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE ,
@@ -1513,6 +1581,9 @@ static struct target_type verity_target = { .prepare_ioctl = verity_prepare_ioctl, .iterate_devices = verity_iterate_devices, .io_hints = verity_io_hints, +#ifdef CONFIG_IPE_PROP_DM_VERITY + .finalize = verity_finalize, +#endif /* CONFIG_IPE_PROP_DM_VERITY */ };module_dm (verity);
drivers/md/dm-verity.h +6 -0
@@ -42,6 +42,9 @@ struct dm_verity {u8 *root_digest;/* digest of the root block */ u8 *salt;/* salt: its size is salt_size */ u8 *zero_digest;/* digest for a zero block */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +u8 *root_digest_sig;/* digest signature of the root block */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int salt_size;sector_t data_start;/* data offset in 512-byte sectors */ sector_t hash_start;/* hash start in blocks */
@@ -55,6 +58,9 @@ struct dm_verity { bool hash_failed:1; /* set if hash of any block failed */ bool use_tasklet:1; /* try to verify in tasklet before work-queue */unsigned int digest_size;/* digest size for the current hash algorithm */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +unsigned int sig_size;/* digest signature size */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int ahash_reqsize;/* the size of temporary space for crypto */ enum verity_mode mode;/* mode for handling verification errors */ unsigned int corrupted_errs;/* Number of errors for corrupted blocks */
include/linux/dm-verity.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_DM_VERITY_H +#define _LINUX_DM_VERITY_H + +#include <linux/types.h> +#include <crypto/hash_info.h> +#include <linux/device-mapper.h> + +struct dm_verity_digest { +const char *algo; +const u8 *digest; +size_t digest_len; +}; + +#define DM_VERITY_SIGNATURE_SEC_NAME DM_NAME ".verity-signature" +#define DM_VERITY_ROOTHASH_SEC_NAME DM_NAME ".verity-roothash" + +#endif /* _LINUX_DM_VERITY_H */
Signature · 1 line
2.25.1
RFC PATCH v11 16/19 ipe: enable support for fs-verity as a trust provider
In reply to Fan WuEnable IPE policy authors to indicate trust for a singular fsverity file, identified by the digest information, through "fsverity_digest" and all files using fsverity's builtin signatures via "fsverity_signature".
This enables file-level integrity claims to be expressed in IPE, allowing individual files to be authorized, giving some flexibility for policy authors. Such file-level claims are important to be expressed for enforcing the integrity of packages, as well as address some of the scalability issues in a sole dm-verity based solution (# of loop back devices, etc).
This solution cannot be done in userspace as the minimum threat that IPE should mitigate is an attacker downloads malicious payload with all required dependencies. These dependencies can lack the userspace check, bypassing the protection entirely. A similar attack succeeds if the userspace component is replaced with a version that does not perform the check. As a result, this can only be done in the common entry point - the kernel.
---
v1-v6:
+ Not present
v7:
Introduced
v8:
* Undo squash of 08/12, 10/12 - separating drivers/md/ from security/
* Use common-audit function for fsverity_signature.
+ Change fsverity implementation to use fsverity_get_digest
+ prevent unnecessary copy of fs-verity signature data, instead just check for presence of signature data.
+ Remove free_inode_security hook, as the digest is now acquired at runtime instead of via LSM blob.
v9:
+ Adapt to the new parser
v10:
+ Update the fsverity get digest call
v11:
+ No changes
--- security/ipe/Kconfig | 13 +++++ security/ipe/audit.c | 23 ++++++++ security/ipe/eval.c | 110 +++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 10 ++++ security/ipe/hooks.c | 30 ++++++++++ security/ipe/hooks.h | 7 +++ security/ipe/ipe.c | 13 +++++ security/ipe/ipe.h | 3 + security/ipe/policy.h | 3 + security/ipe/policy_parser.c | 8 +++ 10 files changed, 220 insertions(+)
security/ipe/Kconfig +13 -0
@@ -30,6 +30,19 @@ config IPE_PROP_DM_VERITY that was mounted with a signed root-hash or the volume's root hash matches the supplied value in the policy. + If unsure, answer Y. + +config IPE_PROP_FS_VERITY + bool "Enable property for fs-verity files" + depends on FS_VERITY && FS_VERITY_BUILTIN_SIGNATURES + help + This option enables the usage of properties "fsverity_signature" + and "fsverity_digest". These properties evaluates to TRUE when + a file is fsverity enabled and with a signed digest or its + diegst matches the supplied value in the policy. + + if unsure, answer Y. + endmenu endif
security/ipe/audit.c +23 -0
@@ -46,6 +46,11 @@ static const char *const audit_prop_names[__IPE_PROP_MAX] = {"dmverity_signature=FALSE" ,"dmverity_signature=TRUE" , #endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +"fsverity_digest=" , +"fsverity_signature=FALSE" , + "fsverity_signature=TRUE" +#endif /* CONFIG_IPE_PROP_FS_VERITY */ };#ifdef CONFIG_IPE_PROP_DM_VERITY
@@ -64,6 +69,22 @@ static void audit_dmv_roothash(struct audit_buffer *ab, const void *rh) }#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +/** +* audit_fsv_digest - audit a digest of a fsverity file. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @d: Supplies a pointer to the digest structure. +*/ +static void audit_fsv_digest (struct audit_buffer *ab,const void *d) +{ +ipe_digest_audit (ab, d); +} +#else +static void audit_fsv_digest (struct audit_buffer *ab,const void *d) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +/** * audit_rule - audit an IPE policy rule approximation. * @ab: Supplies a pointer to the audit_buffer to append to.
@@ -79,6 +100,8 @@ static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r)audit_log_format (ab,"%s" , audit_prop_names[ptr->type]);if (ptr->type ==IPE_PROP_DMV_ROOTHASH )audit_dmv_roothash (ab, ptr->value); +if (ptr->type ==IPE_PROP_FSV_DIGEST ) +audit_fsv_digest (ab, ptr->value);audit_log_format (ab," " ); }
security/ipe/eval.c +110 -0
140 lines not on this page · raw message
security/ipe/eval.h +10 -0
@@ -27,6 +27,12 @@ struct ipe_bdev { };#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +struct ipe_inode { +bool fs_verity_signed; +}; +#endif /* CONFIG_IPE_PROP_FS_VERITY */ +struct ipe_eval_ctx {enum ipe_op_type op;
@@ -35,6 +41,10 @@ struct ipe_eval_ctx {#ifdef CONFIG_IPE_PROP_DM_VERITY const struct ipe_bdev *ipe_bdev;#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +const struct inode *ino; +const struct ipe_inode *ipe_inode; +#endif /* CONFIG_IPE_PROP_FS_VERITY */ };enum ipe_match {
security/ipe/hooks.c +30 -0
@@ -244,3 +244,33 @@ int ipe_bdev_setsecurity(struct block_device *bdev, const char *key, return -EOPNOTSUPP; }#endif /* CONFIG_IPE_PROP_DM_VERITY */ + +#ifdef CONFIG_IPE_PROP_FS_VERITY +/** +* ipe_inode_setsecurity - Sets fields of a inode security blob from @key. +* @inode: The inode to source the security blob from. +* @name: The name representing the information to be stored. +* @value: The value to be stored. +* @size: The size of @value. +* @flags: unused +* +* Saves fsverity signature & digest into inode security blob +* +* Return: +* * 0 - OK +* * !0 - Error +*/ +int ipe_inode_setsecurity (struct inode *inode,const char *name, +const void *value,size_t size, +int flags) +{ +struct ipe_inode *inode_sec =ipe_inode (inode); + +if (!strcmp (name,FS_VERITY_INODE_SEC_NAME )) { + inode_sec->fs_verity_signed = size >0 && value; +return 0 ; + } + +return -EOPNOTSUPP ; +} +#endif /* CONFIG_CONFIG_IPE_PROP_FS_VERITY */
security/ipe/hooks.h +7 -0
@@ -9,6 +9,7 @@#include <linux/binfmts.h> #include <linux/security.h> #include <linux/blk_types.h> +#include <linux/fsverity.h> int ipe_bprm_check_security (struct linux_binprm *bprm);
@@ -32,4 +33,10 @@ int ipe_bdev_setsecurity(struct block_device *bdev, const char *key, const void *value, size_t len);#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +int ipe_inode_setsecurity (struct inode *inode,const char *name, +const void *value,size_t size, +int flags); +#endif /* CONFIG_IPE_PROP_FS_VERITY */ +#endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +13 -0
@@ -13,6 +13,9 @@ static struct lsm_blob_sizes ipe_blobs __ro_after_init = {#ifdef CONFIG_IPE_PROP_DM_VERITY .lbs_bdev = sizeof(struct ipe_bdev),#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY + .lbs_inode = sizeof(struct ipe_inode), +#endif /* CONFIG_IPE_PROP_FS_VERITY */ };#ifdef CONFIG_IPE_PROP_DM_VERITY
@@ -22,6 +25,13 @@ struct ipe_bdev *ipe_bdev(struct block_device *b) }#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +struct ipe_inode *ipe_inode (const struct inode *inode) +{ +return inode->i_security + ipe_blobs.lbs_inode; +} +#endif /* CONFIG_IPE_PROP_FS_VERITY */ +static struct security_hook_list ipe_hooks[]__ro_after_init = {LSM_HOOK_INIT (bprm_check_security, ipe_bprm_check_security),LSM_HOOK_INIT (mmap_file, ipe_mmap_file),
@@ -33,6 +43,9 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = { LSM_HOOK_INIT(bdev_free_security, ipe_bdev_free_security), LSM_HOOK_INIT(bdev_setsecurity, ipe_bdev_setsecurity),#endif +#ifdef CONFIG_IPE_PROP_FS_VERITY + LSM_HOOK_INIT(inode_setsecurity, ipe_inode_setsecurity), +#endif /* CONFIG_IPE_PROP_FS_VERITY */ };/**
security/ipe/ipe.h +3 -0
@@ -18,5 +18,8 @@ extern bool ipe_enabled;#ifdef CONFIG_IPE_PROP_DM_VERITY struct ipe_bdev *ipe_bdev (struct block_device *b);#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +struct ipe_inode *ipe_inode (const struct inode *inode); +#endif /* CONFIG_IPE_PROP_FS_VERITY */ #endif /* _IPE_H */
security/ipe/policy.h +3 -0
@@ -36,6 +36,9 @@ enum ipe_prop_type {IPE_PROP_DMV_ROOTHASH ,IPE_PROP_DMV_SIG_FALSE ,IPE_PROP_DMV_SIG_TRUE , +IPE_PROP_FSV_DIGEST , +IPE_PROP_FSV_SIG_FALSE , +IPE_PROP_FSV_SIG_TRUE , __IPE_PROP_MAX };
security/ipe/policy_parser.c +8 -0
@@ -275,6 +275,11 @@ static const match_table_t property_tokens = { {IPE_PROP_DMV_SIG_FALSE, "dmverity_signature=FALSE"}, {IPE_PROP_DMV_SIG_TRUE, "dmverity_signature=TRUE"}, #endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY + {IPE_PROP_FSV_DIGEST, "fsverity_digest=%s"}, + {IPE_PROP_FSV_SIG_FALSE, "fsverity_signature=FALSE"}, + {IPE_PROP_FSV_SIG_TRUE, "fsverity_signature=TRUE"}, +#endif /* CONFIG_IPE_PROP_FS_VERITY */ {IPE_PROP_INVALID, NULL} };
@@ -304,6 +309,7 @@ static int parse_property(char *t, struct ipe_rule *r)switch (token) {case IPE_PROP_DMV_ROOTHASH : +case IPE_PROP_FSV_DIGEST : dup =match_strdup (&args[0 ]);if (!dup) { rc = -ENOMEM ;
@@ -317,6 +323,8 @@ static int parse_property(char *t, struct ipe_rule *r)case IPE_PROP_BOOT_VERIFIED_TRUE :case IPE_PROP_DMV_SIG_FALSE :case IPE_PROP_DMV_SIG_TRUE : +case IPE_PROP_FSV_SIG_FALSE : +case IPE_PROP_FSV_SIG_TRUE : p->type = token;break ;default :
Signature · 1 line
2.25.1
RFC PATCH v11 12/19 dm: add finalize hook to target_type
In reply to Fan WuThis patch adds a target finalize hook.
The hook is triggered just before activating an inactive table of a mapped device. If it returns an error the __bind get cancelled.
The dm-verity target will use this hook to attach the dm-verity's roothash metadata to the block_device struct of the mapped device.
---
v1-v10:
+ Not present
--- drivers/md/dm.c | 12 ++++++++++++ include/linux/device-mapper.h | 7 +++++++ 2 files changed, 19 insertions(+)
drivers/md/dm.c +12 -0
@@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } +for (unsigned int i =0 ; i < t->num_targets; i++) { +struct dm_target *ti =dm_table_get_target (t, i); + +if (ti->type->finalize) { + ret = ti->type->finalize (ti); +if (ret) { + old_map =ERR_PTR (ret); + goto out; + } + } + } + old_map =rcu_dereference_protected (md->map,lockdep_is_held (&md->suspend_lock));rcu_assign_pointer (md->map, (void *)t); md->immutable_target_type =dm_table_get_immutable_target_type (t);
include/linux/device-mapper.h +7 -0
@@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,*/ typedef size_t (*dm_dax_recovery_write_fn )(struct dm_target *ti,pgoff_t pgoff,void *addr,size_t bytes,struct iov_iter *i); +/* +* Returns: +* < 0 : error +* = 0 : success +*/ +typedef int (*dm_finalize_fn ) (struct dm_target *target);void dm_error (const char *message);
@@ -209,6 +215,7 @@ struct target_type {dm_dax_direct_access_fn direct_access;dm_dax_zero_page_range_fn dax_zero_page_range;dm_dax_recovery_write_fn dax_recovery_write; +dm_finalize_fn finalize;/* For internal device-mapper use. */ struct list_head list;
Signature · 1 line
2.25.1
RFC PATCH v11 5/19 ipe: introduce 'boot_verified' as a trust provider
In reply to Fan WuFrom: Deven Bowers <[email protected]>
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and boot_verified property will always evaluate to false afterward.
We use a pointer with a spin_lock to "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.
---
v2:
+No Changes
v3:
+ Remove useless caching system
+ Move ipe_load_properties to this match
+ Minor changes from checkpatch --strict warnings
v4:
+ Remove comments from headers that was missed previously.
+ Grammatical corrections.
v5:
+ No significant changes
v6:
+ No changes
v7:
+ Reword and refactor patch 04/12 to [09/16], based on changes in the underlying system.
+ Add common audit function for boolean values
+ Use common audit function as implementation.
v8:
+ No changes
v9:
+ No changes
v10:
+ Replace struct file with struct super_block
v11:
+ Fix code style issues
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)
security/ipe/eval.c +71 -1
@@ -9,6 +9,7 @@#include <linux/file.h> #include <linux/sched.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> #include "ipe.h" #include "eval.h"
@@ -16,6 +17,44 @@struct ipe_policy __rcu *ipe_active_policy; +static const struct super_block *pinned_sb; +static DEFINE_SPINLOCK (pin_lock); +#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) + +/** +* pin_sb - Pin the underlying superblock of @f, marking it as trusted. +* @sb: Supplies a super_block structure to be pinned. +*/ +static void pin_sb (const struct super_block *sb) +{ +if (!sb) +return ; +spin_lock (&pin_lock); +if (!pinned_sb) + pinned_sb = sb; +spin_unlock (&pin_lock); +} + +/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block +*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock); +return rv; +} +/** * build_eval_ctx - Build an evaluation context. * @ctx: Supplies a pointer to the context to be populdated.
@@ -26,8 +65,14 @@ void build_eval_ctx(struct ipe_eval_ctx *ctx, const struct file *file, enum ipe_op_type op) { + if (op == IPE_OP_EXEC && file) + pin_sb(FILE_SUPERBLOCK(file)); + ctx->file = file; ctx->op = op; + +if (file) + ctx->from_init_sb =from_pinned (FILE_SUPERBLOCK (file)); }/**
@@ -42,7 +87,14 @@ void build_eval_ctx(struct ipe_eval_ctx *ctx,static bool evaluate_property (const struct ipe_eval_ctx *const ctx,struct ipe_prop *p) { -return false; +switch (p->type) { +case IPE_PROP_BOOT_VERIFIED_FALSE : +return !ctx->from_init_sb; +case IPE_PROP_BOOT_VERIFIED_TRUE : +return ctx->from_init_sb; +default : +return false; + } }/**
@@ -108,3 +160,21 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)return 0 ; } + +/** +* ipe_invalidate_pinned_sb - invalidate the ipe pinned super_block. +* @mnt_sb: super_block to check against the pinned super_block. +* +* This function is called a super_block like the initramfs's is freed, +* if the super_block is currently pinned by ipe it will be invalided, +* so ipe won't consider the block device is boot verified afterward. +*/ +void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb) +{ +spin_lock (&pin_lock); + +if (mnt_sb == pinned_sb) + pinned_sb =ERR_PTR (-EIO ); + +spin_unlock (&pin_lock); +}
security/ipe/eval.h +2 -0
@@ -19,9 +19,11 @@ struct ipe_eval_ctx {enum ipe_op_type op;const struct file *file; + bool from_init_sb; };void build_eval_ctx (struct ipe_eval_ctx *ctx,const struct file *file,enum ipe_op_type op);int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx); +void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb);#endif /* _IPE_EVAL_H */
security/ipe/hooks.c +12 -0
@@ -181,3 +181,15 @@ int ipe_kernel_load_data(enum kernel_load_data_id id, bool contents)build_eval_ctx (&ctx,NULL , op);return ipe_evaluate_event (&ctx); } + +/** +* ipe_sb_free_security - ipe security hook function for super_block. +* @mnt_sb: Supplies a pointer to a super_block is about to be freed. +* +* IPE does not have any structures with mnt_sb, but uses this hook to +* invalidate a pinned super_block. +*/ +void ipe_sb_free_security (struct super_block *mnt_sb) +{ +ipe_invalidate_pinned_sb (mnt_sb); +}
security/ipe/hooks.h +2 -0
@@ -22,4 +22,6 @@ int ipe_kernel_read_file(struct file *file, enum kernel_read_file_id id,int ipe_kernel_load_data (enum kernel_load_data_id id,bool contents); +void ipe_sb_free_security (struct super_block *mnt_sb); +#endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +1 -0
@@ -15,6 +15,7 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {LSM_HOOK_INIT (file_mprotect, ipe_file_mprotect),LSM_HOOK_INIT (kernel_read_file, ipe_kernel_read_file),LSM_HOOK_INIT (kernel_load_data, ipe_kernel_load_data), + LSM_HOOK_INIT(sb_free_security, ipe_sb_free_security), };/**
security/ipe/policy.h +2 -0
@@ -30,6 +30,8 @@ enum ipe_action_type {#define IPE_ACTION_INVALID __IPE_ACTION_MAXenum ipe_prop_type { +IPE_PROP_BOOT_VERIFIED_FALSE , +IPE_PROP_BOOT_VERIFIED_TRUE , __IPE_PROP_MAX };
security/ipe/policy_parser.c +34 -1
@@ -265,6 +265,12 @@ static enum ipe_action_type parse_action(char *t)return match_token (t, action_tokens, args); } +static const match_table_t property_tokens = { + {IPE_PROP_BOOT_VERIFIED_FALSE ,"boot_verified=FALSE" }, + {IPE_PROP_BOOT_VERIFIED_TRUE ,"boot_verified=TRUE" }, + {IPE_PROP_INVALID ,NULL } +}; +/** * parse_property - Parse the property type given a token string. * @t: Supplies the token string to be parsed.
@@ -277,7 +283,34 @@ static enum ipe_action_type parse_action(char *t)*/ static int parse_property (char *t,struct ipe_rule *r) { -return -EBADMSG ; +substring_t args[MAX_OPT_ARGS ]; +struct ipe_prop *p =NULL ; +int rc =0 ; +int token; + + p =kzalloc (sizeof (*p),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + token =match_token (t, property_tokens, args); + +switch (token) { +case IPE_PROP_BOOT_VERIFIED_FALSE : +case IPE_PROP_BOOT_VERIFIED_TRUE : + p->type = token; +break ; +default : + rc = -EBADMSG ; +break ; + } +if (rc) + goto err; +list_add_tail (&p->next, &r->props); + +return rc; +err: +kfree (p); +return rc; }/**
Signature · 1 line
2.25.1
RFC PATCH v11 6/19 security: add new securityfs delete function
In reply to Fan WuWhen deleting a directory in the security file system, the existing securityfs_remove requires the directory to be empty, otherwise it will do nothing. This leads to a potential risk that the security file system might be in an unclean state when the intentded deletion did not happen.
This commit introduces a new function securityfs_recursive_remove to recursively delete a directory without leaving an unclean state.
---
v1-v8:
+ Not present
v9:
+ Introduced
v10:
+ No changes
v11:
+ Fix code style issues
--- include/linux/security.h | 1 + security/inode.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/linux/security.h +1 -0
@@ -1985,6 +1985,7 @@ struct dentry *securityfs_create_symlink(const char *name,const char *target, const struct inode_operations *iops);extern void securityfs_remove (struct dentry *dentry); +extern void securityfs_recursive_remove (struct dentry *dentry);#else /* CONFIG_SECURITYFS */
security/inode.c +25 -0
@@ -313,6 +313,31 @@ void securityfs_remove(struct dentry *dentry) }EXPORT_SYMBOL_GPL (securityfs_remove); +static void remove_one (struct dentry *victim) +{ +simple_release_fs (&mount, &mount_count); +} + +/** +* securityfs_recursive_remove - recursively removes a file or directory +* +* @dentry: a pointer to a the dentry of the file or directory to be removed. +* +* This function recursively removes a file or directory in securityfs that was +* previously created with a call to another securityfs function (like +* securityfs_create_file() or variants thereof.) +*/ +void securityfs_recursive_remove (struct dentry *dentry) +{ +if (IS_ERR_OR_NULL (dentry)) +return ; + +simple_pin_fs (&fs_type, &mount, &mount_count); +simple_recursive_removal (dentry, remove_one); +simple_release_fs (&mount, &mount_count); +} +EXPORT_SYMBOL_GPL (securityfs_recursive_remove); +#ifdef CONFIG_SECURITY static struct dentry *lsm_dentry; static ssize_t lsm_read(struct file *filp, char __user *buf, size_t count,
Signature · 1 line
2.25.1
RFC PATCH v11 2/19 ipe: add policy parser
In reply to Fan WuFrom: Deven Bowers <[email protected]>
IPE's interpretation of the what the user trusts is accomplished through its policy. IPE's design is to not provide support for a single trust provider, but to support multiple providers to enable the end-user to choose the best one to seek their needs.
This requires the policy to be rather flexible and modular so that integrity providers, like fs-verity, dm-verity, dm-integrity, or some other system, can plug into the policy with minimal code changes.
---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limit
v3:
+ Move policy load and activation audit event to 03/12
+ Fix a potential panic when a policy failed to load.
+ use pr_warn for a failure to parse instead of an audit record
+ Remove comments from headers
+ Add lockdep assertions to ipe_update_active_policy and ipe_activate_policy
+ Fix up warnings with checkpatch --strict
+ Use file_ns_capable for CAP_MAC_ADMIN for securityfs nodes.
+ Use memdup_user instead of kzalloc+simple_write_to_buffer.
+ Remove strict_parse command line parameter, as it is added by the sysctl command line.
+ Prefix extern variables with ipe_
v4:
+ Remove securityfs to reverse-dependency
+ Add SHA1 reverse dependency.
+ Add versioning scheme for IPE properties, and associated interface to query the versioning scheme.
+ Cause a parser to always return an error on unknown syntax.
+ Remove strict_parse option
+ Change active_policy interface from sysctl, to securityfs, and change scheme.
v5:
+ Cause an error if a default action is not defined for each operation.
+ Minor function renames
v6:
+ No changes
v7:
+ Further split parser and userspace interface into two separate commits, for easier review.
+ Refactor policy parser to make code cleaner via introducing a more modular design, for easier extension of policy, and easier review.
v8:
+ remove unnecessary pr_info emission on parser loading
+ add explicit newline to the pr_err emitted when a parser fails to load.
v9:
+ switch to match table to parse policy
+ remove quote syntax and KERNEL_READ operation
v10:
+ Fix memory leaks in parser
+ Fix typos and change code styles
v11:
+ Fix code style issues
--- security/ipe/Makefile | 2 + security/ipe/policy.c | 101 ++++++++ security/ipe/policy.h | 83 ++++++ security/ipe/policy_parser.c | 487 +++++++++++++++++++++++++++++++++++ security/ipe/policy_parser.h | 11 + 5 files changed, 684 insertions(+) create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h create mode 100644 security/ipe/policy_parser.c create mode 100644 security/ipe/policy_parser.h
security/ipe/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ ipe.o \ + policy.o \ + policy_parser.o \
security/ipe/policy.c new file +101 -0
101 lines not on this page · raw message
security/ipe/policy.h new file +83 -0
83 lines not on this page · raw message
security/ipe/policy_parser.c new file +487 -0
487 lines not on this page · raw message
security/ipe/policy_parser.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef _IPE_POLICY_PARSER_H +#define _IPE_POLICY_PARSER_H + +int parse_policy (struct ipe_policy *p); +void free_parsed_policy (struct ipe_parsed_policy *p); + +#endif /* _IPE_POLICY_PARSER_H */
Signature · 1 line
2.25.1
Randy Dunlap
reviewerRe: [RFC PATCH v11 16/19] ipe: enable support for fs-verity as a trust provider
In reply to Fan WuOn 10/4/23 15:09, Fan Wu wrote:
| diff --git a/security/ipe/Kconfig b/security/ipe/Kconfig | index 7afb1ce0cb99..9dd5c4769d79 100644 | --- a/security/ipe/Kconfig | +++ b/security/ipe/Kconfig | @@ -30,6 +30,19 @@ config IPE_PROP_DM_VERITY | that was mounted with a signed root-hash or the volume's | root hash matches the supplied value in the policy. | | + If unsure, answer Y. | + | +config IPE_PROP_FS_VERITY | + bool "Enable property for fs-verity files" | + depends on FS_VERITY && FS_VERITY_BUILTIN_SIGNATURES | + help | + This option enables the usage of properties "fsverity_signature" | + and "fsverity_digest". These properties evaluates to TRUE when
evaluate
| + a file is fsverity enabled and with a signed digest or its | + diegst matches the supplied value in the policy.
digest
| + | + if unsure, answer Y. | + | endmenu | | endif
Signature · 1 line
~Randy
Eric Biggers
maintainerRe: [RFC PATCH v11 15/19] fsverity: consume builtin signature via LSM hook
In reply to Fan Wufs/verity/open.c static int compute_file_digest(const struct fsverity_hash_alg *hash_alg, · line 183
Quoted 8 lines · Fan Wu
fs/verity/open.c +8
-0+#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES +static int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return security_inode_setsecurity (inode,FS_VERITY_INODE_SEC_NAME , + desc->signature, +le32_to_cpu (desc->sig_size),0 ); +}
Why isn't the type of the second argument 'const struct fsverity_descriptor *'?
- Eric
Re: [RFC PATCH v11 16/19] ipe: enable support for fs-verity as a trust provider
In reply to Randy DunlapQuoted 26 lines · Randy Dunlap
On 10/4/23 15:09, Fan Wu wrote:
| diff --git a/security/ipe/Kconfig b/security/ipe/Kconfig | index 7afb1ce0cb99..9dd5c4769d79 100644 | --- a/security/ipe/Kconfig | +++ b/security/ipe/Kconfig | @@ -30,6 +30,19 @@ config IPE_PROP_DM_VERITY | that was mounted with a signed root-hash or the volume's | root hash matches the supplied value in the policy. | | + If unsure, answer Y. | + | +config IPE_PROP_FS_VERITY | + bool "Enable property for fs-verity files" | + depends on FS_VERITY && FS_VERITY_BUILTIN_SIGNATURES | + help | + This option enables the usage of properties "fsverity_signature" | + and "fsverity_digest". These properties evaluates to TRUE whenevaluate
| + a file is fsverity enabled and with a signed digest or its | + diegst matches the supplied value in the policy.
Quoted 10 lines
digest
| + | + if unsure, answer Y. | + | endmenu | | endif
Thanks for catching the typo/error. Not sure why my spell script didn't find them. Maybe I should consider using a better tool.
-Fan
Re: [RFC PATCH v11 15/19] fsverity: consume builtin signature via LSM hook
In reply to Eric BiggersQuoted 12 lines · Eric Biggers
fs/verity/open.c static int compute_file_digest(const struct fsverity_hash_alg *hash_alg, · line 183
Quoted 8 lines · Fan Wu
fs/verity/open.c +8
-0+#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES +static int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return security_inode_setsecurity (inode,FS_VERITY_INODE_SEC_NAME , + desc->signature, +le32_to_cpu (desc->sig_size),0 ); +}Why isn't the type of the second argument 'const struct
fsverity_descriptor*'?
Quoted 1 line
- Eric
Thanks for the suggestion. I agree that adding 'const' here is a better approach. I will update this in the next version.
-Fan
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
kernel test robot
build botRe: [RFC PATCH v11 04/19] ipe: add LSM hooks on execution and kernel read
In reply to Fan Wukernel test robot noticed the following build warnings:
Hi Fan,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on axboe-block/for-next lwn/docs-next linus/master v6.6-rc4 next-20231005] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Fan-Wu/security-add-ipe-lsm/20231005-061243 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next patch link: https://lore.kernel.org/r/1696457386-3010-5-git-send-email-wufan%40linux.microsoft.com patch subject: [RFC PATCH v11 04/19] ipe: add LSM hooks on execution and kernel read config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> security/ipe/hooks.c:51: warning: Function parameter or member '__always_unused' not described in 'ipe_mmap_file' >> security/ipe/hooks.c:51: warning: Excess function parameter 'reqprot' description in 'ipe_mmap_file' >> security/ipe/hooks.c:79: warning: Function parameter or member '__always_unused' not described in 'ipe_file_mprotect' >> security/ipe/hooks.c:79: warning: Excess function parameter 'reqprot' description in 'ipe_file_mprotect'
vim +51 security/ipe/hooks.c
33
34 /**
35 * ipe_mmap_file - ipe security hook function for mmap check.
36 * @f: File being mmap'd. Can be NULL in the case of anonymous memory.
37 * @reqprot: The requested protection on the mmap, passed from usermode.
38 * @prot: The effective protection on the mmap, resolved from reqprot and
39 * system configuration.
40 * @flags: Unused.
41 *
42 * This hook is called when a file is loaded through the mmap
43 * family of system calls.
44 *
45 * Return:
46 * * 0 - OK
47 * * !0 - Error
48 */
49 int ipe_mmap_file(struct file *f, unsigned long reqprot __always_unused,
50 unsigned long prot, unsigned long flags)
> 51 {
52 struct ipe_eval_ctx ctx = IPE_EVAL_CTX_INIT;
53
54 if (prot & PROT_EXEC) {
55 build_eval_ctx(&ctx, f, IPE_OP_EXEC);
56 return ipe_evaluate_event(&ctx);
57 }
58
59 return 0;
60 }
61
62 /**
63 * ipe_file_mprotect - ipe security hook function for mprotect check.
64 * @vma: Existing virtual memory area created by mmap or similar.
65 * @reqprot: The requested protection on the mmap, passed from usermode.
66 * @prot: The effective protection on the mmap, resolved from reqprot and
67 * system configuration.
68 *
69 * This LSM hook is called when a mmap'd region of memory is changing
70 * its protections via mprotect.
71 *
72 * Return:
73 * * 0 - OK
74 * * !0 - Error
75 */
76 int ipe_file_mprotect(struct vm_area_struct *vma,
77 unsigned long reqprot __always_unused,
78 unsigned long prot)
> 79 {
80 struct ipe_eval_ctx ctx = IPE_EVAL_CTX_INIT;
81
82 /* Already Executable */
83 if (vma->vm_flags & VM_EXEC)
84 return 0;
85
86 if (prot & PROT_EXEC) {
87 build_eval_ctx(&ctx, vma->vm_file, IPE_OP_EXEC);
88 return ipe_evaluate_event(&ctx);
89 }
90
91 return 0;
92 }
93 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC PATCH v11 07/19] ipe: add userspace interface
In reply to Fan Wukernel test robot noticed the following build warnings:
Hi Fan,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on axboe-block/for-next lwn/docs-next linus/master v6.6-rc4 next-20231005] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Fan-Wu/security-add-ipe-lsm/20231005-061243 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next patch link: https://lore.kernel.org/r/1696457386-3010-8-git-send-email-wufan%40linux.microsoft.com patch subject: [RFC PATCH v11 07/19] ipe: add userspace interface config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> security/ipe/policy_fs.c:21: warning: cannot understand function prototype: 'struct ipefs_file ' >> security/ipe/policy_fs.c:411: warning: cannot understand function prototype: 'const struct ipefs_file policy_subdir[] = '
vim +21 security/ipe/policy_fs.c
17
18 /**
19 * ipefs_file - defines a file in securityfs.
20 */
> 21 struct ipefs_file {
22 const char *name;
23 umode_t access;
24 const struct file_operations *fops;
25 };
26 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC PATCH v11 08/19] uapi|audit|ipe: add ipe auditing support
In reply to Fan Wukernel test robot noticed the following build warnings:
Hi Fan,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on axboe-block/for-next lwn/docs-next linus/master v6.6-rc4 next-20231005] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Fan-Wu/security-add-ipe-lsm/20231005-061243 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next patch link: https://lore.kernel.org/r/1696457386-3010-9-git-send-email-wufan%40linux.microsoft.com patch subject: [RFC PATCH v11 08/19] uapi|audit|ipe: add ipe auditing support config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> security/ipe/audit.c:76: warning: Excess function parameter 'enforce' description in 'ipe_audit_match' >> security/ipe/audit.c:118: warning: Function parameter or member 'audit_format' not described in 'audit_policy' >> security/ipe/audit.c:158: warning: Function parameter or member 'op' not described in 'ipe_audit_policy_activation' >> security/ipe/audit.c:158: warning: Function parameter or member 'np' not described in 'ipe_audit_policy_activation' >> security/ipe/audit.c:158: warning: Excess function parameter 'p' description in 'ipe_audit_policy_activation'
vim +76 security/ipe/audit.c
61
62 /**
63 * ipe_audit_match - audit a match for IPE policy.
64 * @ctx: Supplies a pointer to the evaluation context that was used in the
65 * evaluation.
66 * @match_type: Supplies the scope of the match: rule, operation default,
67 * global default.
68 * @act: Supplies the IPE's evaluation decision, deny or allow.
69 * @r: Supplies a pointer to the rule that was matched, if possible.
70 * @enforce: Supplies the enforcement/permissive state at the point
71 * the enforcement decision was made.
72 */
73 void ipe_audit_match(const struct ipe_eval_ctx *const ctx,
74 enum ipe_match match_type,
75 enum ipe_action_type act, const struct ipe_rule *const r)
> 76 {
77 struct inode *inode;
78 struct audit_buffer *ab;
79 const char *op = audit_op_names[ctx->op];
80
81 if (act != IPE_ACTION_DENY && !READ_ONCE(success_audit))
82 return;
83
84 ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_IPE_ACCESS);
85 if (!ab)
86 return;
87
88 if (ctx->file) {
89 audit_log_d_path(ab, "path=", &ctx->file->f_path);
90 inode = file_inode(ctx->file);
91 if (inode) {
92 audit_log_format(ab, " dev=");
93 audit_log_untrustedstring(ab, inode->i_sb->s_id);
94 audit_log_format(ab, " ino=%lu ", inode->i_ino);
95 }
96 }
97
98 if (match_type == IPE_MATCH_RULE)
99 audit_rule(ab, r);
100 else if (match_type == IPE_MATCH_TABLE)
101 audit_log_format(ab, "rule=\"DEFAULT op=%s action=%s\"", op,
102 ACTSTR(act));
103 else
104 audit_log_format(ab, "rule=\"DEFAULT action=%s\"",
105 ACTSTR(act));
106
107 audit_log_end(ab);
108 }
109
110 /**
111 * audit_policy - Audit a policy's name, version and thumbprint to @ab.
112 * @ab: Supplies a pointer to the audit buffer to append to.
113 * @p: Supplies a pointer to the policy to audit.
114 */
115 static void audit_policy(struct audit_buffer *ab,
116 const char *audit_format,
117 const struct ipe_policy *const p)
> 118 {
119 u8 *digest = NULL;
120 struct crypto_shash *tfm;
121 SHASH_DESC_ON_STACK(desc, tfm);
122
123 tfm = crypto_alloc_shash(IPE_AUDIT_HASH_ALG, 0, 0);
124 if (IS_ERR(tfm))
125 return;
126
127 desc->tfm = tfm;
128
129 digest = kzalloc(crypto_shash_digestsize(tfm), GFP_KERNEL);
130 if (!digest)
131 goto out;
132
133 if (crypto_shash_init(desc))
134 goto out;
135
136 if (crypto_shash_update(desc, p->pkcs7, p->pkcs7len))
137 goto out;
138
139 if (crypto_shash_final(desc, digest))
140 goto out;
141
142 audit_log_format(ab, audit_format, p->parsed->name,
143 p->parsed->version.major, p->parsed->version.minor,
144 p->parsed->version.rev);
145 audit_log_n_hex(ab, digest, crypto_shash_digestsize(tfm));
146
147 out:
148 kfree(digest);
149 crypto_free_shash(tfm);
150 }
151
152 /**
153 * ipe_audit_policy_activation - Audit a policy being made the active policy.
154 * @p: Supplies a pointer to the policy to audit.
155 */
156 void ipe_audit_policy_activation(const struct ipe_policy *const op,
157 const struct ipe_policy *const np)
> 158 { 159 struct audit_buffer *ab;
160
161 ab = audit_log_start(audit_context(), GFP_KERNEL,
162 AUDIT_IPE_CONFIG_CHANGE);
163 if (!ab)
164 return;
165
166 audit_policy(ab, AUDIT_OLD_ACTIVE_POLICY_FMT, op);
167 audit_log_format(ab, " ");
168 audit_policy(ab, AUDIT_NEW_ACTIVE_POLICY_FMT, np);
169 audit_log_format(ab, " auid=%u ses=%u lsm=ipe res=1",
170 from_kuid(&init_user_ns, audit_get_loginuid(current)),
171 audit_get_sessionid(current));
172
173 audit_log_end(ab);
174 }
175
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Paul Moore
maintainerRe: [PATCH RFC v11 2/19] ipe: add policy parser
In reply to Fan WuQuoted 85 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE's interpretation of the what the user trusts is accomplished through its policy. IPE's design is to not provide support for a single trust provider, but to support multiple providers to enable the end-user to choose the best one to seek their needs.
This requires the policy to be rather flexible and modular so that integrity providers, like fs-verity, dm-verity, dm-integrity, or some other system, can plug into the policy with minimal code changes.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Move policy load and activation audit event to 03/12
+ Fix a potential panic when a policy failed to load.
+ usepr_warnfor a failure to parse instead of an audit record
+ Remove comments from headers
+ Add lockdep assertions toipe_update_active_policyandipe_activate_policy
+ Fix up warnings with checkpatch --strict
+ Usefile_ns_capableforCAP_MAC_ADMINfor securityfs nodes.
+ Usememdup_userinstead of kzalloc+simple_write_to_buffer.
+ Removestrict_parsecommand line parameter, as it is added by the sysctl command line.
+ Prefix extern variables withipe_v4:
+ Remove securityfs to reverse-dependency
+ Add SHA1 reverse dependency.
+ Add versioning scheme for IPE properties, and associated interface to query the versioning scheme.
+ Cause a parser to always return an error on unknown syntax.
+ Removestrict_parseoption
+ Changeactive_policyinterface from sysctl, to securityfs, and change scheme.v5:
+ Cause an error if a default action is not defined for each operation.
+ Minor function renamesv6:
+ No changesv7:
+ Further split parser and userspace interface into two separate commits, for easier review.
+ Refactor policy parser to make code cleaner via introducing a more modular design, for easier extension of policy, and easier review.v8:
+ remove unnecessarypr_infoemission on parser loading
+ add explicit newline to thepr_erremitted when a parser fails to load.v9:
+ switch to match table to parse policy
+ remove quote syntax andKERNEL_READoperationv10:
+ Fix memory leaks in parser
+ Fix typos and change code stylesv11:
+ Fix code style issues--- security/ipe/Makefile | 2 + security/ipe/policy.c | 101 ++++++++ security/ipe/policy.h | 83 ++++++ security/ipe/policy_parser.c | 487 +++++++++++++++++++++++++++++++++++ security/ipe/policy_parser.h | 11 + 5 files changed, 684 insertions(+) create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h create mode 100644 security/ipe/policy_parser.c create mode 100644 security/ipe/policy_parser.h
...
Quoted 10 lines
security/ipe/policy.c new file +4
-0@@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/
...
security/ipe/policy.c line 44
Quoted 10 lines
security/ipe/policy.c new file +10
-0+static int set_pkcs7_data (void *ctx,const void *data,size_t len, +size_t asn1hdrlen) +{ +struct ipe_policy *p = ctx; + + p->text = (const char *)data; + p->textlen = len; + +return 0 ; +}
The @asn1hdrlen parameter isn't used in this function, at least at this point in the patchset, so you really should remove it. If it is needed later in the patchset you can always update the function.
Quoted 10 lines
security/ipe/policy_parser.c new file +4
-0@@ -0,0 +1,487 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/
...
security/ipe/policy_parser.c line 72
Quoted 13 lines
security/ipe/policy_parser.c new file +13
-0+/** +* remove_trailing_spaces - Truncate all trailing spaces in a string. +* +* @line: Supplies a poilcy line string for preprocessing. +* +* Return: The length of truncated string. +*/ +static size_t remove_trailing_spaces (char *line) +{ +size_t i =0 ; + +for (i =strlen (line); i >0 && (line[i -1 ] ==' ' || line[i -1 ] =='\t' ); --i) + ;
Maybe I've asked this before, I can't remember: could you use the isspace() macro here instead of explicitly checking for ' ' and '\t'?
i = strlen(line);
while (i > 0 && isspace(line[i - 1]))
i--;
line[i] = '\0';Quoted 26 lines
security/ipe/policy_parser.c new file +26
-0+ line[i] ='\0' ; + +return i; +} + +/** +* parse_version - Parse policy version. +* @ver: Supplies a version string to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * 0 - OK +* * !0 - Standard errno +*/ +static int parse_version (char *ver,struct ipe_parsed_policy *p) +{ +int rc =0 ; +size_t sep_count =0 ; +char *token; +u16 *const cv[] = { &p->version.major, &p->version.minor, &p->version.rev }; + +while ((token =strsep (&ver,"." )) !=NULL ) { +/* prevent overflow */ +if (sep_count >=ARRAY_SIZE (cv)) +return -EBADMSG ; +
security/ipe/policy_parser.c line 109
Quoted 10 lines
security/ipe/policy_parser.c new file +10
-0+ rc =kstrtou16 (token,10 , cv[sep_count]); +if (rc) +return rc; + + ++sep_count; + } + +/* prevent underflow */ +if (sep_count !=ARRAY_SIZE (cv)) + rc = -EBADMSG ;
You could always just 'return -EBADMSG' here and 'return 0' below to simplify things a little.
Quoted 62 lines
security/ipe/policy_parser.c new file +62
-0+return rc; +} + +enum header_opt { +IPE_HEADER_POLICY_NAME =0 , +IPE_HEADER_POLICY_VERSION , + __IPE_HEADER_MAX +}; + +static const match_table_t header_tokens = { + {IPE_HEADER_POLICY_NAME ,"policy_name=%s" }, + {IPE_HEADER_POLICY_VERSION ,"policy_version=%s" }, + {__IPE_HEADER_MAX,NULL } +}; + +/** +* parse_header - Parse policy header information. +* @line: Supplies header line to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * 0 - OK +* * !0 - Standard errno +*/ +static int parse_header (char *line,struct ipe_parsed_policy *p) +{ +int rc =0 ; +char *t, *ver =NULL ; +substring_t args[MAX_OPT_ARGS ]; +size_t idx =0 ; + +while ((t =strsep (&line,IPE_POLICY_DELIM )) !=NULL ) { +int token; + +if (*t =='\0' ) +continue ; +if (idx >= __IPE_HEADER_MAX) { + rc = -EBADMSG ; + goto out; + } + + token =match_token (t, header_tokens, args); +if (token != idx) { + rc = -EBADMSG ; + goto out; + } + +switch (token) { +case IPE_HEADER_POLICY_NAME : + p->name =match_strdup (&args[0 ]); +if (!p->name) + rc = -ENOMEM ; +break ; +case IPE_HEADER_POLICY_VERSION : + ver =match_strdup (&args[0 ]); +if (!ver) { + rc = -ENOMEM ; +break ; + } + rc =parse_version (ver, p); +break ; +default :
security/ipe/policy_parser.c line 182
Quoted 10 lines
security/ipe/policy_parser.c new file +10
-0+ rc = -EBADMSG ; + } +if (rc) + goto out; + ++idx; + } + +if (idx != __IPE_HEADER_MAX) { + rc = -EBADMSG ; + goto out;
You probably don't need to 'goto out' here.
Quoted 6 lines
security/ipe/policy_parser.c new file +6
-0+ } + +out: +kfree (ver); +return rc; +}
...
Quoted 65 lines
security/ipe/policy_parser.c new file +65
-0+/** +* parse_rule - parse a policy rule line. +* @line: Supplies rule line to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * !IS_ERR - OK +* * -ENOMEM - Out of memory +* * -EBADMSG - Policy syntax error +*/ +static int parse_rule (char *line,struct ipe_parsed_policy *p) +{ +int rc =0 ; +bool first_token = true, is_default_rule = false; +bool op_parsed = false; +enum ipe_op_type op =IPE_OP_INVALID ; +enum ipe_action_type action =IPE_ACTION_INVALID ; +struct ipe_rule *r =NULL ; +char *t; + + r =kzalloc (sizeof (*r),GFP_KERNEL ); +if (!r) +return -ENOMEM ; + +INIT_LIST_HEAD (&r->next); +INIT_LIST_HEAD (&r->props); + +while (t =strsep (&line,IPE_POLICY_DELIM ), line) { +if (*t =='\0' ) +continue ; +if (first_token &&token_default (t)) { + is_default_rule = true; + }else { +if (!op_parsed) { + op =parse_operation (t); +if (op ==IPE_OP_INVALID ) + rc = -EBADMSG ; +else + op_parsed = true; + }else { + rc =parse_property (t, r); + } + } + +if (rc) + goto err; + first_token = false; + } + + action =parse_action (t); +if (action ==IPE_ACTION_INVALID ) { + rc = -EBADMSG ; + goto err; + } + +if (is_default_rule) { +if (!list_empty (&r->props)) { + rc = -EBADMSG ; + }else if (op ==IPE_OP_INVALID ) { +if (p->global_default_action !=IPE_ACTION_INVALID ) + rc = -EBADMSG ; +else + p->global_default_action = action; + }else { +if (p->rules[op].default_action !=IPE_ACTION_INVALID )
security/ipe/policy_parser.c line 357
Quoted 10 lines
security/ipe/policy_parser.c new file +10
-0+ rc = -EBADMSG ; + else + p->rules[op].default_action = action; + } + }else if (op !=IPE_OP_INVALID && action !=IPE_ACTION_INVALID ) { + r->op = op; + r->action = action; + }else { + rc = -EBADMSG ; + }
I might be missing something important in the policy syntac, but could this function, and perhaps the ipe_parsed_policy struct, be simplified if the default action was an explicit rule?
"op=DEFAULT action=ALLOW"
Quoted 45 lines
security/ipe/policy_parser.c new file +45
-0+if (rc) + goto err; +if (!is_default_rule) +list_add_tail (&r->next, &p->rules[op].rules); +else +free_rule (r); + +return rc; +err: +free_rule (r); +return rc; +} + +/** +* free_parsed_policy - free a parsed policy structure. +* @p: Supplies the parsed policy. +*/ +void free_parsed_policy (struct ipe_parsed_policy *p) +{ +size_t i =0 ; +struct ipe_rule *pp, *t; + +if (IS_ERR_OR_NULL (p)) +return ; + +for (i =0 ; i <ARRAY_SIZE (p->rules); ++i) +list_for_each_entry_safe (pp, t, &p->rules[i].rules, next) { +list_del (&pp->next); +free_rule (pp); + } + +kfree (p->name); +kfree (p); +} + +/** +* validate_policy - validate a parsed policy. +* @p: Supplies the fully parsed policy. +* +* Given a policy structure that was just parsed, validate that all +* necessary fields are present, initialized correctly. +* +* A parsed policy can be in an invalid state for use (a default was +* undefined) by just parsing the policy. +*
security/ipe/policy_parser.c line 413
Quoted 10 lines
security/ipe/policy_parser.c new file +10
-0+* Return: +* * 0 - OK +* * -EBADMSG - Policy is invalid +*/ +static int validate_policy (const struct ipe_parsed_policy *p) +{ +size_t i =0 ; + +if (p->global_default_action !=IPE_ACTION_INVALID ) +return 0 ;
Should the if conditional above be "==" and not "!="?
security/ipe/policy_parser.c line 421
Quoted 7 lines
security/ipe/policy_parser.c new file +7
-0+for (i =0 ; i <ARRAY_SIZE (p->rules); ++i) { +if (p->rules[i].default_action ==IPE_ACTION_INVALID ) +return -EBADMSG ; + } + +return 0 ; +}
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 3/19] ipe: add evaluation loop
In reply to Fan WuQuoted 58 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE must have a centralized function to evaluate incoming callers against IPE's policy. This iteration of the policy for against the rules for that specific caller is known as the evaluation loop.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Moveipe_load_propertiesto patch 04.
+ Remove useless 0-initializations Prefix extern variables withipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ UseGFP_KERNELforaudit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Usercu_access_pointerfor rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+Move policy load and activation audit event to 03/12v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record,
+ reconstruct the exact rule.v6:
+ No changesv7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Propagating changes to support the newipe_contextstructure in the evaluation loop.v8:
+ Removeipe_hookenumeration; hooks can be correlated via syscall record.v9:
+ Removeipe_contextrelated code and simplify the evaluation loop.v10:
+ Split eval part andboot_verifiedpartv11:
+ Fix code style issues--- security/ipe/Makefile | 1 + security/ipe/eval.c | 96 +++++++++++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 24 +++++++++++ 3 files changed, 121 insertions(+) create mode 100644 security/ipe/eval.c create mode 100644 security/ipe/eval.h
...
Quoted 61 lines
security/ipe/eval.c new file +55
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/sched.h> +#include <linux/rcupdate.h> + +#include "ipe.h" +#include "eval.h" +#include "policy.h" + +struct ipe_policy __rcu *ipe_active_policy; + +/** +* evaluate_property - Analyze @ctx against a property. +* @ctx: Supplies a pointer to the context to be evaluated. +* @p: Supplies a pointer to the property to be evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_property (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return false; +} + +/** +* ipe_evaluate_event - Analyze @ctx against the current active policy. +* @ctx: Supplies a pointer to the context to be evaluated. +* +* This is the loop where all policy evaluation happens against IPE policy. +* +* Return: +* * 0 - OK +* * -EACCES - @ctx did not pass evaluation. +* * !0 - Error +*/ +int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx) +{ +bool match = false; +enum ipe_action_type action; +struct ipe_policy *pol =NULL ; +const struct ipe_rule *rule =NULL ; +const struct ipe_op_table *rules =NULL ; +struct ipe_prop *prop =NULL ; + +rcu_read_lock (); +
security/ipe/eval.c line 65
Quoted 10 lines
security/ipe/eval.c new file +10
-0+ pol =rcu_dereference (ipe_active_policy); +if (!pol) { +rcu_read_unlock (); +return 0 ; + } + +if (ctx->op ==IPE_OP_INVALID ) { +rcu_read_unlock (); +if (pol->parsed->global_default_action ==IPE_ACTION_DENY ) +return -EACCES ;
Assuming that the RCU lock protects @pol, shouldn't it be held until after the global_default_action comparison?
security/ipe/eval.c line 75
Quoted 10 lines
security/ipe/eval.c new file +10
-0+return 0 ; + } + + rules = &pol->parsed->rules[ctx->op]; + +list_for_each_entry (rule, &rules->rules, next) { + match = true; + +list_for_each_entry (prop, &rule->props, next) { + match = match &&evaluate_property (ctx, prop);
The @match variable will always be true on the right side above, or am I missing something?
Quoted 11 lines
security/ipe/eval.c new file +11
-0+if (!match) +break ; + } + +if (match) +break ; + } + +if (match) + action = rule->action; +else if (rules->default_action !=IPE_ACTION_INVALID )
security/ipe/eval.c line 96
Quoted 10 lines
security/ipe/eval.c new file +10
-0+ action = rules->default_action; + else + action = pol->parsed->global_default_action; + +rcu_read_unlock (); +if (action ==IPE_ACTION_DENY ) +return -EACCES ; + +return 0 ; +}
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 7/19] ipe: add userspace interface
In reply to Fan WuQuoted 87 lines · On Oct 4, 2023 kernel test robot <[email protected]> wrote:
As is typical with LSMs, IPE uses securityfs as its interface with userspace. for a complete list of the interfaces and the respective inputs/outputs, please see the documentation under
admin-guide/LSM/ipe.rstSigned-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Move policy load and activation audit event to 03/12
+ Fix a potential panic when a policy failed to load.
+ usepr_warnfor a failure to parse instead of an audit record
+ Remove comments from headers
+ Add lockdep assertions toipe_update_active_policyandipe_activate_policy
+ Fix up warnings with checkpatch --strict
+ Usefile_ns_capableforCAP_MAC_ADMINfor securityfs nodes.
+ Usememdup_userinstead of kzalloc+simple_write_to_buffer.
+ Removestrict_parsecommand line parameter, as it is added by the sysctl command line.
+ Prefix extern variables withipe_v4:
+ Remove securityfs to reverse-dependency
+ Add SHA1 reverse dependency.
+ Add versioning scheme for IPE properties, and associated interface to query the versioning scheme.
+ Cause a parser to always return an error on unknown syntax.
+ Removestrict_parseoption
+ Changeactive_policyinterface from sysctl, to securityfs, and change scheme.v5:
+ Cause an error if a default action is not defined for each operation.
+ Minor function renamesv6:
+ No changesv7:
+ Propagating changes to support the newipe_contextstructure in the evaluation loop.+ Further split the parser and userspace interface changes into separate commits.
+ "raw" was renamed to "pkcs7" and made read only
+ "raw"'s write functionality (update a policy) moved to "update"
+ introduced "version", "policy_name" nodes.
+ "content" renamed to "policy"
+ changes to allow the compiled-in policy to be treated identical to deployed-after-the-fact policies.v8:
+ Prevent securityfs initialization if the LSM is disabledv9:
+ Switch tosecurityfs_recursive_removefor policy folder deletionv10:
+ Simplify and correct concurrency
+ Fix typosv11:
+ Correct code comments--- security/ipe/Makefile | 2 + security/ipe/fs.c | 101 ++++++++ security/ipe/fs.h | 16 ++ security/ipe/ipe.c | 3 + security/ipe/ipe.h | 2 + security/ipe/policy.c | 112 +++++++++ security/ipe/policy.h | 9 + security/ipe/policy_fs.c | 481 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 726 insertions(+) create mode 100644 security/ipe/fs.c create mode 100644 security/ipe/fs.h create mode 100644 security/ipe/policy_fs.c
...
Quoted 47 lines
security/ipe/fs.c new file +41
-0@@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/dcache.h> +#include <linux/security.h> + +#include "ipe.h" +#include "fs.h" +#include "policy.h" + +static struct dentry *np__ro_after_init ; +static struct dentry *root__ro_after_init ; +struct dentry *policy_root__ro_after_init ; + +/** +* new_policy - Write handler for the securityfs node, "ipe/new_policy". +* @f: Supplies a file structure representing the securityfs node. +* @data: Suppleis a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t new_policy (struct file *f,const char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +char *copy =NULL ; +struct ipe_policy *p =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + copy =memdup_user_nul (data, len); +if (IS_ERR (copy)) +return PTR_ERR (copy); +
security/ipe/fs.c line 51
Quoted 10 lines
security/ipe/fs.c new file +10
-0+ p =ipe_new_policy (NULL ,0 , copy, len); +if (IS_ERR (p)) { + rc =PTR_ERR (p); + goto out; + } + + rc =ipe_new_policyfs_node (p); + +out: +if (rc <0 && !IS_ERR (p))
Since @p is check for error above after the call to ipe_new_policy() you shouldn't need to check it again here, right? I think all you need to do is check @rc.
Quoted 50 lines
security/ipe/fs.c new file +50
-0+ipe_free_policy (p); +kfree (copy); +return (rc <0 ) ? rc : len; +} + +static const struct file_operations np_fops = { + .write = new_policy, +}; + +/** +* ipe_init_securityfs - Initialize IPE's securityfs tree at fsinit. +* +* Return: +* * !0 - Error +* * 0 - OK +*/ +static int __init ipe_init_securityfs (void ) +{ +int rc =0 ; + +if (!ipe_enabled) +return -EOPNOTSUPP ; + + root =securityfs_create_dir ("ipe" ,NULL ); +if (IS_ERR (root)) { + rc =PTR_ERR (root); + goto err; + } + + policy_root =securityfs_create_dir ("policies" , root); +if (IS_ERR (policy_root)) { + rc =PTR_ERR (policy_root); + goto err; + } + + np =securityfs_create_file ("new_policy" ,0200 , root,NULL , &np_fops); +if (IS_ERR (np)) { + rc =PTR_ERR (np); + goto err; + } + +return 0 ; +err: +securityfs_remove (np); +securityfs_remove (policy_root); +securityfs_remove (root); +return rc; +} + +fs_initcall (ipe_init_securityfs);
...
Quoted 48 lines
security/ipe/policy.c +40
-0@@ -43,6 +71,65 @@ static int set_pkcs7_data(void *ctx, const void *data, size_t len,return 0 ; } +/** +* ipe_update_policy - parse a new policy and replace old with it. +* @root: Supplies a pointer to the securityfs inode saved the policy. +* @text: Supplies a pointer to the plain text policy. +* @textlen: Supplies the length of @text. +* @pkcs7: Supplies a pointer to a buffer containing a pkcs7 message. +* @pkcs7len: Supplies the length of @pkcs7len. +* +* @text/@textlen is mutually exclusive with @pkcs7/@pkcs7len - see +* ipe_new_policy. +* +* Context: Requires root->i_rwsem and ipe_policy_lock to be held. +* Return: +* * !IS_ERR - The existing policy saved in the inode before update +* * -ENOENT - Policy doesn't exist +* * -EINVAL - New policy is invalid +*/ +struct ipe_policy *ipe_update_policy (struct inode *root, +const char *text,size_t textlen, +const char *pkcs7,size_t pkcs7len) +{ +int rc =0 ; +struct ipe_policy *old, *ap, *new =NULL ; + +lockdep_assert_held (&ipe_policy_lock); + + old = (struct ipe_policy *)root->i_private; +if (!old) +return ERR_PTR (-ENOENT ); + + new =ipe_new_policy (text, textlen, pkcs7, pkcs7len); +if (IS_ERR (new)) +return new; + +if (strcmp (new->parsed->name, old->parsed->name)) { + rc = -EINVAL ; + goto err; + } + +if (ver_to_u64 (old) >ver_to_u64 (new)) {
security/ipe/policy.c static int set_pkcs7_data(void *ctx, const void *data, size_t len, · line 123
Quoted 10 lines
security/ipe/policy.c +10
-0+ rc = -EINVAL ; + goto err; + } + + root->i_private = new; + + ap =rcu_dereference_protected (ipe_active_policy, +lockdep_is_held (&ipe_policy_lock)); +if (old == ap) +rcu_assign_pointer (ipe_active_policy, new);
Is there any reason why you couldn't call ipe_set_active_pol() here and avoid duplicated code?
Quoted 25 lines
security/ipe/policy.c +18
-0+swap (new->policyfs, old->policyfs); + +return old; +err: +ipe_free_policy (new); +return ERR_PTR (rc); +} +/** * ipe_new_policy - Allocate and parse an ipe_policy structure. * @@ -99,3 +186,28 @@ struct ipe_policy *ipe_new_policy(const char *text, size_t textlen,ipe_free_policy (new);return ERR_PTR (rc); } + +/** +* ipe_set_active_pol - Make @p the active policy. +* @p: Supplies a pointer to the policy to make active. +* +* Context: Requires root->i_rwsem and ipe_policy_lock to be held. +* Return: +* * !IS_ERR - Success +* * -EINVAL - New active policy version is invalid +*/
security/ipe/policy.c struct ipe_policy *ipe_new_policy(const char *text, size_t textlen, · line 208
Quoted 10 lines
security/ipe/policy.c +10
-0+int ipe_set_active_pol (const struct ipe_policy *p) +{ +struct ipe_policy *ap =NULL ; + +lockdep_assert_held (&ipe_policy_lock); + + ap =rcu_dereference_protected (ipe_active_policy, +lockdep_is_held (&ipe_policy_lock)); +if (ap &&ver_to_u64 (ap) >ver_to_u64 (p)) +return -EINVAL ;
In ipe_update_policy() there is also a name check, is that important here, or is the policy name only important on an "update" op?
Quoted 4 lines
security/ipe/policy.c +4
-0+rcu_assign_pointer (ipe_active_policy, p); + +return 0 ; +}
...
Quoted 57 lines
security/ipe/policy_fs.c new file +51
-0@@ -0,0 +1,481 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#include <linux/fs.h> +#include <linux/namei.h> +#include <linux/types.h> +#include <linux/dcache.h> +#include <linux/security.h> + +#include "ipe.h" +#include "policy.h" +#include "eval.h" +#include "fs.h" + +#define MAX_VERSION_SIZE ARRAY_SIZE("65535.65535.65535") + +/** +* ipefs_file - defines a file in securityfs. +*/ +struct ipefs_file { +const char *name; +umode_t access; +const struct file_operations *fops; +}; + +/** +* read_pkcs7 - Read handler for "ipe/policies/$name/pkcs7". +* @f: Supplies a file structure representing the securityfs node. +* @data: Suppleis a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* @data will be populated with the pkcs7 blob representing the policy +* on success. If the policy is unsigned (like the boot policy), this +* will return -ENOENT. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t read_pkcs7 (struct file *f,char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +struct inode *root =NULL ; +const struct ipe_policy *p =NULL ; + + root =d_inode (f->f_path.dentry->d_parent); + +inode_lock_shared (root);
security/ipe/policy_fs.c line 61
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+ p = (struct ipe_policy *)root->i_private; +if (!p) { + rc = -ENOENT ; + goto out; + } + +if (!p->pkcs7) { + rc = -ENOENT ; + goto out; + }
All of the other "read" functions don't check for a previously read value, it might be nice to add a comment explaining why ipe_policy::pkcs7 is handled differently.
Quoted 7 lines
security/ipe/policy_fs.c new file +7
-0+ rc =simple_read_from_buffer (data, len, offset, p->pkcs7, p->pkcs7len); + +out: +inode_unlock_shared (root); + +return rc; +}
...
Quoted 24 lines
security/ipe/policy_fs.c new file +24
-0+/** +* read_version - Read handler for "ipe/policies/$name/version". +* @f: Supplies a file structure representing the securityfs node. +* @data: Suppleis a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* @data will be populated with the version string on success. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t read_version (struct file *f,char __user *data, +size_t len,loff_t *offset) +{ +ssize_t rc =0 ; +size_t bufsize =0 ; +struct inode *root =NULL ; +const struct ipe_policy *p =NULL ; +char buffer[MAX_VERSION_SIZE ] = {0 }; + + root =d_inode (f->f_path.dentry->d_parent); +
security/ipe/policy_fs.c line 180
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+inode_lock_shared (root); + p = (struct ipe_policy *)root->i_private; +if (!p) { + rc = -ENOENT ; + goto out; + } + + bufsize =scnprintf (buffer,ARRAY_SIZE (buffer),"%hu.%hu.%hu" , + p->parsed->version.major, p->parsed->version.minor, + p->parsed->version.rev);
I don't understand why scnprintf() is needed here, you know the size of @buffer, just use that; what am I missing?
bufsize = sizeof(buffer);
Quoted 43 lines
security/ipe/policy_fs.c new file +43
-0+ rc =simple_read_from_buffer (data, len, offset, buffer, bufsize); + +out: +inode_unlock_shared (root); + +return rc; +} + +/** +* setactive - Write handler for "ipe/policies/$name/active". +* @f: Supplies a file structure representing the securityfs node. +* @data: Supplies a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t setactive (struct file *f,const char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +bool value = false; +struct inode *root =NULL ; +const struct ipe_policy *p =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + rc =kstrtobool_from_user (data, len, &value); +if (rc) +return rc; + +if (!value) +return -EINVAL ; + + root =d_inode (f->f_path.dentry->d_parent); +inode_lock (root); +mutex_lock (&ipe_policy_lock); + + p = (struct ipe_policy *)root->i_private; +if (!p) {
security/ipe/policy_fs.c line 234
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+ rc = -ENOENT ; + goto out; + } + + rc =ipe_set_active_pol (p); + +out: +mutex_unlock (&ipe_policy_lock); +inode_unlock (root); +synchronize_rcu ();
Why the synchronize_rcu() call here? I'm guessing it is because of ipe_set_active_pol(), if that is the case, shouldn't it be calling synchronize_rcu()? Of course that would require some lock/unlock shuffling in this function, but that seems reasonable.
Quoted 27 lines
security/ipe/policy_fs.c new file +27
-0+return (rc <0 ) ? rc : len; +} + +/** +* getactive - Read handler for "ipe/policies/$name/active". +* @f: Supplies a file structure representing the securityfs node. +* @data: Suppleis a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* @data will be populated with the 1 or 0 depending on if the +* corresponding policy is active. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t getactive (struct file *f,char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +const char *str; +struct inode *root =NULL ; +const struct ipe_policy *p =NULL ; + + root =d_inode (f->f_path.dentry->d_parent); +
security/ipe/policy_fs.c line 271
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+inode_lock_shared (root); + p = (struct ipe_policy *)root->i_private; +if (!p) { +inode_unlock_shared (root); +return -ENOENT ; + } +inode_unlock_shared (root); + + str = (p ==rcu_access_pointer (ipe_active_policy)) ?"1" :"0" ; + rc =simple_read_from_buffer (data, len, offset, str,1 );
If @ipe_active_policy is an RCU protected pointer, shouldn't the RCU read lock be held here? If you are relying on a caller for that, 1) you can nest RCU read locks, and 2) it should ideally be noted in the functions header comment.
Quoted 28 lines
security/ipe/policy_fs.c new file +28
-0+return rc; +} + +/** +* update_policy - Write handler for "ipe/policies/$name/update". +* @f: Supplies a file structure representing the securityfs node. +* @data: Supplies a buffer passed to the write syscall. +* @len: Supplies the length of @data. +* @offset: unused. +* +* On success this updates the policy represented by $name, +* in-place. +* +* Return: +* * >0 - Success, Length of buffer written +* * <0 - Error +*/ +static ssize_t update_policy (struct file *f,const char __user *data, +size_t len,loff_t *offset) +{ +char *copy =NULL ; +struct inode *root =NULL ; +struct ipe_policy *old =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + copy =memdup_user (data, len);
security/ipe/policy_fs.c line 310
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+if (IS_ERR (copy)) +return PTR_ERR (copy); + + root =d_inode (f->f_path.dentry->d_parent); +inode_lock (root); +mutex_lock (&ipe_policy_lock); + old =ipe_update_policy (root,NULL ,0 , copy, len); +mutex_unlock (&ipe_policy_lock); +inode_unlock (root); +synchronize_rcu ();
See my synchronize_rcu() comment in setactive(), it seems relevant here.
Quoted 7 lines
security/ipe/policy_fs.c new file +7
-0+kfree (copy); +if (IS_ERR (old)) +return PTR_ERR (old); +ipe_free_policy (old); + +return len; +}
...
Quoted 23 lines
security/ipe/policy_fs.c new file +23
-0+/** +* ipe_new_policyfs_node - Create a securityfs entry for @p. +* @p: Supplies a pointer to the policy to create a securityfs entry for. +* +* Return: +* * 0 - OK +* * !0 - Error +*/ +int ipe_new_policyfs_node (struct ipe_policy *p) +{ +int rc =0 ; +size_t i =0 ; +struct dentry *d =NULL ; +struct dentry *policyfs =NULL ; +struct inode *root =NULL ; +const struct ipefs_file *f =NULL ; + +if (p->policyfs) +return 0 ; + + policyfs =securityfs_create_dir (p->parsed->name, policy_root); +if (IS_ERR (policyfs)) { + rc =PTR_ERR (policyfs);
security/ipe/policy_fs.c line 463
Quoted 10 lines
security/ipe/policy_fs.c new file +10
-0+ goto err; + } + + root =d_inode (policyfs); + +for (i =0 ; i <ARRAY_SIZE (policy_subdir); ++i) { + f = &policy_subdir[i]; + + d =securityfs_create_file (f->name, f->access, policyfs, +NULL , f->fops);
Is there a potential issue with the file being created in IPE's securityfs, but not yet present in ipe_policy::policyfs? Should IPE set '@p->policyfs = policyfs' before this for-loop, and reset/NULL it if an error occurs?
Quoted 20 lines
security/ipe/policy_fs.c new file +18
-0+if (IS_ERR (d)) { + rc =PTR_ERR (d); + goto err; + } + } + +inode_lock (root); +mutex_lock (&ipe_policy_lock); + p->policyfs = policyfs; + root->i_private = p; +mutex_unlock (&ipe_policy_lock); +inode_unlock (root); + +return 0 ; +err: +securityfs_recursive_remove (policyfs); +return rc; +}Signature · 1 line
2.25.1
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 4/19] ipe: add LSM hooks on execution and kernel read
In reply to Fan WuQuoted 71 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE's initial goal is to control both execution and the loading of kernel modules based on the system's definition of trust. It accomplishes this by plugging into the security hooks for
bprm_check_security,file_mprotect,mmap_file,kernel_load_data, andkernel_read_data.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Moveipe_load_propertiesto patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables withipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ UseGFP_KERNELforaudit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Usercu_access_pointerfor rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.v6:
+ No changesv7:
+ Further split lsm creation, the audit system, the evaluation loop and access control hooks into separate commits.v8:
+ Rename hook functions to follow thelsmname_hook_nameconvention
+ Removeipe_hookenumeration, can be derived from correlation with syscall audit record.v9:
+ Minor changes for adapting to the new parserv10:
+ Remove @reqprot partv11:
+ Fix code style issues--- security/ipe/Makefile | 1 + security/ipe/eval.c | 14 ++++ security/ipe/eval.h | 3 + security/ipe/hooks.c | 183 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 25 ++++++ security/ipe/ipe.c | 6 ++ 6 files changed, 232 insertions(+) create mode 100644 security/ipe/hooks.c create mode 100644 security/ipe/hooks.h
...
Quoted 10 lines
security/ipe/hooks.c new file +4
-0@@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/
...
Quoted 31 lines
security/ipe/hooks.c new file +31
-0+/** +* ipe_kernel_read_file - ipe security hook function for kernel read. +* @file: Supplies a pointer to the file structure being read in from disk. +* @id: Supplies the enumeration identifying the purpose of the read. +* @contents: Unused. +* +* This LSM hook is called when a file is being read in from disk from +* the kernel. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_kernel_read_file (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_op_type op; +struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ; + +switch (id) { +case READING_FIRMWARE : + op =IPE_OP_FIRMWARE ; +break ; +case READING_MODULE : + op =IPE_OP_KERNEL_MODULE ; +break ; +case READING_KEXEC_INITRAMFS : + op =IPE_OP_KEXEC_INITRAMFS ; +break ; +case READING_KEXEC_IMAGE : + op =IPE_OP_KEXEC_IMAGE ;
security/ipe/hooks.c line 134
Quoted 10 lines
security/ipe/hooks.c new file +10
-0+break ; +case READING_POLICY : + op =IPE_OP_IMA_POLICY ; +break ; +case READING_X509_CERTIFICATE : + op =IPE_OP_IMA_X509 ; +break ; +default : + op =IPE_OP_INVALID ; +WARN (op ==IPE_OP_INVALID ,"no rule setup for enum %d" , id);
I'm not sure you need to test @op above since you set @op on the line above, just use true/1 to simplify things. It also seems like it might be helpful to provice some context for the enum above in the WARN() message. For example:
WARN(1, "no rule setup for kernel_read_file %d", id);
Quoted 34 lines
security/ipe/hooks.c new file +34
-0+ } + +build_eval_ctx (&ctx, file, op); +return ipe_evaluate_event (&ctx); +} + +/** +* ipe_kernel_load_data - ipe security hook function for kernel load data. +* @id: Supplies the enumeration identifying the purpose of the read. +* @contents: Unused. +* +* This LSM hook is called when a buffer is being read in from disk. +* +* Return: +* * 0 - OK +* * !0 - Error +*/ +int ipe_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_op_type op; +struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ; + +switch (id) { +case LOADING_FIRMWARE : + op =IPE_OP_FIRMWARE ; +break ; +case LOADING_MODULE : + op =IPE_OP_KERNEL_MODULE ; +break ; +case LOADING_KEXEC_INITRAMFS : + op =IPE_OP_KEXEC_INITRAMFS ; +break ; +case LOADING_KEXEC_IMAGE : + op =IPE_OP_KEXEC_IMAGE ;
security/ipe/hooks.c line 178
Quoted 10 lines
security/ipe/hooks.c new file +10
-0+break ; +case LOADING_POLICY : + op =IPE_OP_IMA_POLICY ; +break ; +case LOADING_X509_CERTIFICATE : + op =IPE_OP_IMA_X509 ; +break ; +default : + op =IPE_OP_INVALID ; +WARN (op ==IPE_OP_INVALID ,"no rule setup for enum %d" , id);
See my comments in ipe_kernel_read_file(), they also apply here.
security/ipe/hooks.c line 183
Quoted 5 lines
security/ipe/hooks.c new file +5
-0+ } + +build_eval_ctx (&ctx,NULL , op); +return ipe_evaluate_event (&ctx); +}
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
In reply to Fan WuQuoted 106 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+No Changesv3:
+ Remove useless caching system
+ Moveipe_load_propertiesto this match
+ Minor changes from checkpatch --strict warningsv4:
+ Remove comments from headers that was missed previously.
+ Grammatical corrections.v5:
+ No significant changesv6:
+ No changesv7:
+ Reword and refactor patch 04/12 to [09/16], based on changes in the underlying system.
+ Add common audit function for boolean values
+ Use common audit function as implementation.v8:
+ No changesv9:
+ No changesv10:
+ Replace struct file with structsuper_blockv11:
+ Fix code style issues--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)security/ipe/eval.c +26
-0@@ -9,6 +9,7 @@#include <linux/file.h> #include <linux/sched.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> #include "ipe.h" #include "eval.h" @@ -16,6 +17,44 @@struct ipe_policy __rcu *ipe_active_policy; +static const struct super_block *pinned_sb; +static DEFINE_SPINLOCK (pin_lock); +#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) + +/** +* pin_sb - Pin the underlying superblock of @f, marking it as trusted. +* @sb: Supplies a super_block structure to be pinned. +*/ +static void pin_sb (const struct super_block *sb) +{ +if (!sb) +return ; +spin_lock (&pin_lock); +if (!pinned_sb) + pinned_sb = sb; +spin_unlock (&pin_lock); +} + +/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block
security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);
It's okay for an initial version, but I still think you need to get away from this spinlock in from_pinned() as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in super_block::security you could mark the superblock when it was mounted and do a lockless lookup here in from_pinned().
security/ipe/eval.c line 56
Quoted 2 lines
security/ipe/eval.c +2
-0+return rv; +}
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 8/19] uapi|audit|ipe: add ipe auditing support
In reply to Fan WuQuoted 210 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Users of IPE require a way to identify when and why an operation fails, allowing them to both respond to violations of policy and be notified of potentially malicious actions on their systems with respect to IPE itself.
This patch introduces 3 new audit events.
AUDIT_IPE_ACCESS(1420)indicates the result of an IPE policy evaluation of a resource.AUDIT_IPE_CONFIG_CHANGE(1421)indicates the current active IPE policy has been changed to another loaded policy.AUDIT_IPE_POLICY_LOAD(1422)indicates a new IPE policy has been loaded into the kernel.This patch also adds support for success auditing, allowing users to identify why an allow decision was made for a resource. However, it is recommended to use this option with caution, as it is quite noisy.
Here are some examples of the new audit record types:
AUDIT_IPE_ACCESS(1420):audit: AUDIT1420 path="/root/vol/bin/hello" dev="sda"
ino=3897 rule="op=EXECUTE boot_verified=TRUE action=ALLOW"audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0"
ino=2 rule="DEFAULT action=DENY"audit: AUDIT1420 path="/tmp/tmpdp2h1lub/deny/bin/hello" dev="tmpfs"
ino=131 rule="DEFAULT action=DENY"The above three records were generated when the active IPE policy only allows binaries from the initial booted drive(sda) to run. The three identical
hellobinary were placed at different locations, only the first hello from sda was allowed.Field path followed by the file's path name.
Field dev followed by the device name as found in /dev where the file is from.
Note that for device mappers it will use the namedm-Xinstead of the name in/dev/mapper.
For a file in a temp file system, which is not from a device, it will usetmpfsfor the field.
The implementation of this part is following another existing use caseLSM_AUDIT_DATA_INODEinsecurity/lsm_audit.cField ino followed by the file's inode number.
Field rule followed by the IPE rule made the access decision. The whole rule must be audited because the decision is based on the combination of all property conditions in the rule.
Along with the syscall audit event, user can know why a blocked happened. For example:
audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0" ino=2 rule="DEFAULT action=DENY" audit[1956]: SYSCALL arch=c000003e syscall=59 success=no exit=-13 a0=556790138df0 a1=556790135390 a2=5567901338b0 a3=ab2a41a67f4f1f4e items=1 ppid=147 pid=1956 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=4294967295 comm="bash" exe="/usr/bin/bash" key=(null)The above two records showed bash used execve to run "hello" and got blocked by IPE. Note that the IPE records are always prior to a SYSCALL record.
AUDIT_IPE_CONFIG_CHANGE(1421):audit: AUDIT1421 old_active_pol_name="Allow_All" old_active_pol_version=0.0.0 old_policy_digest=sha256:E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649 new_active_pol_name="boot_verified" new_active_pol_version=0.0.0 new_policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F auid=4294967295 ses=4294967295 lsm=ipe res=1The above record showed the current IPE active policy switch from
Allow_Alltoboot_verifiedalong with the version and the hash digest of the two policies. Note IPE can only have one policy active at a time, all access decision evaluation is based on the current active policy.
The normal procedure to deploy a policy is loading the policy to deploy into the kernel first, then switch the active policy to it.
AUDIT_IPE_POLICY_LOAD(1422):audit: AUDIT1422 policy_name="boot_verified" policy_version=0.0.0 policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F26765076DD auid=4294967295 ses=4294967295 lsm=ipe res=1
The above record showed a new policy has been loaded into the kernel with the policy name, policy version and policy hash.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Moveipe_load_propertiesto patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables withipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ UseGFP_KERNELforaudit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Usercu_access_pointerfor rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.v6:
+ No changesv7:
+ Further split lsm creation, the audit system, the evaluation loop, and access control hooks into separate patches.
+ Further split audit system patch into two separate patches; one forinclude/uapi, and the usage of the new defines.
+ Split out the permissive functionality into another separate patch, for easier review.
+ Correct misuse ofaudit_log_n_untrustedstring toaudit_log_format
+ Useget_task_comminstead of comm directly.
+ Quote certain audit values
+ Remove unnecessary help text on choice options - these were previously
idented at the wrong level
+ Correct a stale string constant (ctx_ns_enforcetoctx_enforce)v8:
+ Change dependency for
CONFIG_AUDITtoCONFIG_AUDITSYSCALL
+ Drop ctx_* prefix
+ Reuse, where appropriate, the audit fields from the fielddictionary. This transforms: ctx_pathname -> path ctx_ino -> ino ctx_dev -> dev+ Add audit records and event examples to commit description.
+ Removenew_audit_ctx, replace withaudit_log_start. All data that would provided bynew_audit_ctxis already present in the syscall audit record, that is always emitted on these actions. The audit records should be correlated as such.
+ Change audit types:
+AUDIT_TRUST_RESULT->AUDIT_IPE_ACCESS
+ This prevents overloading of the AVC type.
+AUDIT_TRUST_POLICY_ACTIVATE->AUDIT_MAC_CONFIG_CHANGE
+AUDIT_TRUST_POLICY_LOAD->AUDIT_MAC_POLICY_LOAD
+ There were no significant difference in meaning between these types.+ Remove enforcing parameter passed from the context structure for
AUDIT_IPE_ACCESS.
+ This field can be inferred from the SYSCALL audit event, based on the success field.+ Remove all fields already captured in the syscall record. "hook", an IPE specific field, can be determined via the syscall field in the syscall record itself, so it has been removed.
+ ino, path, and dev in IPE's record refer to the subject of the syscall, while the syscall record refers to the calling process.+ remove IPE prefix from policy load/policy activation events
+ fix a bug wherein a policy change audit record was not fired when updating a policyv9:
+ Merge theAUDIT_IPE_ACCESSdefinition with the audit support commit
+ Change the audit format of policy load and switch
+ Remove the ipe audit kernel switchv10:
+ CreateAUDIT_IPE_CONFIG_CHANGEandAUDIT_IPE_POLICY_LOAD
+ Change field names per upstream feedbackv11:
+ Fix style issues--- include/uapi/linux/audit.h | 3 + security/ipe/Kconfig | 2 +- security/ipe/Makefile | 1 + security/ipe/audit.c | 195 +++++++++++++++++++++++++++++++++++++ security/ipe/audit.h | 18 ++++ security/ipe/eval.c | 32 ++++-- security/ipe/eval.h | 8 ++ security/ipe/fs.c | 70 +++++++++++++ security/ipe/policy.c | 5 + 9 files changed, 327 insertions(+), 7 deletions(-) create mode 100644 security/ipe/audit.c create mode 100644 security/ipe/audit.h
...
Quoted 39 lines
security/ipe/audit.c new file +33
-0@@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/slab.h> +#include <linux/audit.h> +#include <linux/types.h> +#include <crypto/hash.h> + +#include "ipe.h" +#include "eval.h" +#include "hooks.h" +#include "policy.h" +#include "audit.h" + +#define ACTSTR (x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY") + +#define IPE_AUDIT_HASH_ALG "sha256" + +#define AUDIT_POLICY_LOAD_FMT "policy_name=\"%s\" policy_version=%hu.%hu.%hu "\ + "policy_digest=" IPE_AUDIT_HASH_ALG ":" +#define AUDIT_OLD_ACTIVE_POLICY_FMT "old_active_pol_name=\"%s\" "\ + "old_active_pol_version=%hu.%hu.%hu "\ + "old_policy_digest=" IPE_AUDIT_HASH_ALG ":" +#define AUDIT_NEW_ACTIVE_POLICY_FMT "new_active_pol_name=\"%s\" "\ + "new_active_pol_version=%hu.%hu.%hu "\ + "new_policy_digest=" IPE_AUDIT_HASH_ALG ":" + +static const char *const audit_op_names[__IPE_OP_MAX] = { +"EXECUTE" , +"FIRMWARE" , +"KMODULE" ,
security/ipe/audit.c line 43
Quoted 10 lines
security/ipe/audit.c new file +10
-0+"KEXEC_IMAGE" , +"KEXEC_INITRAMFS" , +"IMA_POLICY" , + "IMA_X509_CERT", +}; + +static const char *const audit_prop_names[__IPE_PROP_MAX] = { +"boot_verified=FALSE" , +"boot_verified=TRUE" , +};
I would suggest taking the same approach for both @audit_op_names and @audit_prop_names; either include the field name in the string array for both or leave it out of both.
Quoted 18 lines
security/ipe/audit.c new file +18
-0+/** +* audit_rule - audit an IPE policy rule approximation. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @r: Supplies a pointer to the ipe_rule to approximate a string form for. +*/ +static void audit_rule (struct audit_buffer *ab,const struct ipe_rule *r) +{ +const struct ipe_prop *ptr; + +audit_log_format (ab,"rule=\"op=%s " , audit_op_names[r->op]); + +list_for_each_entry (ptr, &r->props, next) +audit_log_format (ab,"%s " , audit_prop_names[ptr->type]); + +audit_log_format (ab,"action=%s\"" ,ACTSTR (r->action)); +} + +/**
security/ipe/audit.c line 72
Quoted 10 lines
security/ipe/audit.c new file +10
-0+* ipe_audit_match - audit a match for IPE policy. +* @ctx: Supplies a pointer to the evaluation context that was used in the +* evaluation. +* @match_type: Supplies the scope of the match: rule, operation default, +* global default. +* @act: Supplies the IPE's evaluation decision, deny or allow. +* @r: Supplies a pointer to the rule that was matched, if possible. +* @enforce: Supplies the enforcement/permissive state at the point +* the enforcement decision was made. +*/
Does it make sense to move @match_type into the ipe_eval_ctx struct?
Quoted 26 lines
security/ipe/audit.c new file +26
-0+void ipe_audit_match (const struct ipe_eval_ctx *const ctx, +enum ipe_match match_type, +enum ipe_action_type act,const struct ipe_rule *const r) +{ +struct inode *inode; +struct audit_buffer *ab; +const char *op = audit_op_names[ctx->op]; + +if (act !=IPE_ACTION_DENY && !READ_ONCE (success_audit)) +return ; + + ab =audit_log_start (audit_context (),GFP_KERNEL ,AUDIT_IPE_ACCESS ); +if (!ab) +return ; + +if (ctx->file) { +audit_log_d_path (ab,"path=" , &ctx->file->f_path); + inode =file_inode (ctx->file); +if (inode) { +audit_log_format (ab," dev=" ); +audit_log_untrustedstring (ab, inode->i_sb->s_id); +audit_log_format (ab," ino=%lu " , inode->i_ino); + } + } + +if (match_type ==IPE_MATCH_RULE )
security/ipe/audit.c line 108
Quoted 10 lines
security/ipe/audit.c new file +10
-0+audit_rule (ab, r); + else if (match_type == IPE_MATCH_TABLE) + audit_log_format(ab, "rule=\"DEFAULT op=%s action=%s\"", op, + ACTSTR(act)); + else + audit_log_format(ab, "rule=\"DEFAULT action=%s\"", + ACTSTR(act)); + +audit_log_end (ab); +}
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 9/19] ipe: add permissive toggle
In reply to Fan WuQuoted 94 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE, like SELinux, supports a permissive mode. This mode allows policy authors to test and evaluate IPE policy without it effecting their programs. When the mode is changed, a 1404
AUDIT_MAC_STATUSbe reported.This patch adds the following audit records:
audit: MAC_STATUS enforcing=0 old_enforcing=1 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1 audit: MAC_STATUS enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1The audit record only emit when the value from the user input is different from the current enforce value.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Moveipe_load_propertiesto patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables withipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ UseGFP_KERNELforaudit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Usercu_access_pointerfor rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.v6:
+ No changesv7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Propagating changes to support the newipe_contextstructure in the evaluation loop.
+ Split out permissive functionality into a separate patch for easier review.
+ Remove permissive switch compile-time configuration option - this is trivial to add later.v8:
+ Remove "IPE" prefix from permissive audit record
+ align fields to the linux-audit field dictionary. This causes the following fields to change:
enforce -> permissive+ Remove duplicated information correlated with syscall record, that will always be present in the audit event.
+ Change audit types:
+AUDIT_TRUST_STATUS->AUDIT_MAC_STATUS
+ There is no significant difference in meaning between these types.v9:
+ Clean upipe_contextrelated codev10:
+ Change audit format to comform with the existing format selinux is using
+ Remove the audit record emission during init to align with selinux, which does not perform this action.v11:
+ Remove redundant code--- security/ipe/audit.c | 22 ++++++++++++++ security/ipe/audit.h | 1 + security/ipe/eval.c | 14 +++++++-- security/ipe/eval.h | 1 + security/ipe/fs.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-)
...
security/ipe/eval.c int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx) · line 178
Quoted 13 lines
security/ipe/eval.c +4
-1@@ -167,9 +172,12 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)ipe_audit_match (ctx, match_type, action, rule);if (action ==IPE_ACTION_DENY ) -return -EACCES ; + rc = -EACCES ; + +if (!enforcing) + rc =0 ;
Why the local @enforcing variable? Why not:
if (!READ_ONCE(enforce))
rc = 0;security/ipe/eval.c void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb) · line 210
Quoted 11 lines
security/ipe/eval.c +3
-1-return 0 ; +return rc; }/** @@ -198,3 +206,5 @@ void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)module_param (success_audit, bool,0400 );MODULE_PARM_DESC (success_audit,"Start IPE with success auditing enabled" ); +module_param (enforce, bool,0400 ); +MODULE_PARM_DESC (enforce,"Start IPE in enforce or permissive mode" );
"enforcing"
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 11/19] dm verity: set DM_TARGET_SINGLETON feature flag
In reply to Fan WuQuoted 8 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
The device-mapper has a flag to mark targets as singleton, which is a required flag for immutable targets. Without this flag, multiple dm-verity targets can be added to a mapped device, which has no practical use cases and will let
dm_table_get_immutable_targetreturn NULL. This patch adds the missing flag, restricting only one dm-verity target per mapped device.
Quoted 7 lines
Signed-off-by Fan Wu <[email protected]>---
v1-v10:
+ Not present--- drivers/md/dm-verity-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
This seems reasonable to me and matches with other users of DM_TARGET_IMMUTABLE.
Alasdair, Mike, can we get an ACK on this?
Quoted 15 lines
drivers/md/dm-verity-target.c +1
-1@@ -1503,7 +1503,7 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned istatic struct target_type verity_target = { .name ="verity" , - .features =DM_TARGET_IMMUTABLE , + .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE , .version = {1 ,9 ,0 }, .module =THIS_MODULE , .ctr = verity_ctr,Signature · 1 line
2.25.1
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 12/19] dm: add finalize hook to target_type
In reply to Fan WuQuoted 9 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
This patch adds a target finalize hook.
The hook is triggered just before activating an inactive table of a mapped device. If it returns an error the
__bindget cancelled.The dm-verity target will use this hook to attach the dm-verity's roothash metadata to the
block_devicestruct of the mapped device.
Quoted 8 lines
Signed-off-by Fan Wu <[email protected]>---
v1-v10:
+ Not present--- drivers/md/dm.c | 12 ++++++++++++ include/linux/device-mapper.h | 7 +++++++ 2 files changed, 19 insertions(+)
We need an ACK and confirmation from Alasdair and/or Mike that this is the right approach.
Quoted 50 lines
drivers/md/dm.c +12
-0@@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } +for (unsigned int i =0 ; i < t->num_targets; i++) { +struct dm_target *ti =dm_table_get_target (t, i); + +if (ti->type->finalize) { + ret = ti->type->finalize (ti); +if (ret) { + old_map =ERR_PTR (ret); + goto out; + } + } + } + old_map =rcu_dereference_protected (md->map,lockdep_is_held (&md->suspend_lock));rcu_assign_pointer (md->map, (void *)t); md->immutable_target_type =dm_table_get_immutable_target_type (t);include/linux/device-mapper.h +7
-0@@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,*/ typedef size_t (*dm_dax_recovery_write_fn )(struct dm_target *ti,pgoff_t pgoff,void *addr,size_t bytes,struct iov_iter *i); +/* +* Returns: +* < 0 : error +* = 0 : success +*/ +typedef int (*dm_finalize_fn ) (struct dm_target *target);void dm_error (const char *message);@@ -209,6 +215,7 @@ struct target_type {dm_dax_direct_access_fn direct_access;dm_dax_zero_page_range_fn dax_zero_page_range;dm_dax_recovery_write_fn dax_recovery_write; +dm_finalize_fn finalize;/* For internal device-mapper use. */ struct list_head list;Signature · 1 line
2.25.1
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 13/19] dm verity: consume root hash digest and signature data via LSM hook
In reply to Fan WuQuoted 69 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
dm-verity provides a strong guarantee of a block device's integrity. As a generic way to check the integrity of a block device, it provides those integrity guarantees to its higher layers, including the filesystem level.
An LSM that control access to a resource on the system based on the available integrity claims can use this transitive property of dm-verity, by querying the underlying
block_deviceof a particular file.The digest and signature information need to be stored in the block device to fulfill the next requirement of authorization via LSM policy. This will enable the LSM to perform revocation of devices that are still mounted, prohibiting execution of files that are no longer authorized by the LSM in question.
This patch added two security hook calls in dm-verity to save the dm-verity roothash and the roothash signature to the block device's LSM blobs.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ No Changesv3:
+ No changesv4:
+ No changesv5:
+ No changesv6:
+ Fix an improper cleanup that can result in
a leakv7:
+ Squash patch 08/12, 10/12 to [11/16]
+ Use part0 forblock_device, to retrieve theblock_device, when callingsecurity_bdev_setsecurityv8:
+ Undo squash of 08/12, 10/12 - separatingdrivers/md/fromsecurity/&block/
+ Use common-audit function fordmverity_signature.
+ Change implementation for storing the dm-verity digest to use the newly introduceddm_verity_digeststructure introduced in patch 14/20.
+ Create new structure,dm_verity_digest, containing digest algorithm, size, and digest itself to pass to the LSM layer. V7 was missing the algorithm.
+ Create an associated public header containing this new structure and the key values for the LSM hook, specific to dm-verity.
+ Additional information added to commit, discussing the layering of the changes and how the information passed will be used.v9:
+ No changesv10:
+ No changesv11:
+ Add an optional field to save signature
+ Move the security hook call to the new finalize hook
Quoted 6 lines
--- drivers/md/dm-verity-target.c | 71 +++++++++++++++++++++++++++++++++++ drivers/md/dm-verity.h | 6 +++ include/linux/dm-verity.h | 19 ++++++++++ 3 files changed, 96 insertions(+) create mode 100644 include/linux/dm-verity.h
We need an ACK from Alasdair and/or Mike on this too.
Quoted 182 lines
drivers/md/dm-verity-target.c +71
-0@@ -13,6 +13,7 @@* access behavior. */ +#include "dm-core.h" #include "dm-verity.h" #include "dm-verity-fec.h" #include "dm-verity-verify-sig.h" @@ -22,6 +23,9 @@#include <linux/scatterlist.h> #include <linux/string.h> #include <linux/jump_label.h> +#include <linux/security.h> +#include <linux/dm-verity.h> +#include <crypto/hash_info.h> #define DM_MSG_PREFIX "verity"@@ -952,6 +956,17 @@ static void verity_io_hints(struct dm_target *ti, struct queue_limits *limits)blk_limits_io_min (limits, limits->logical_block_size); } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static void verity_free_sig (struct dm_verity *v) +{ +kfree (v->root_digest_sig); +} +#else +static inline void verity_free_sig (struct dm_verity *v) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static void verity_dtr (struct dm_target *ti) {struct dm_verity *v = ti->private;@@ -966,6 +981,7 @@ static void verity_dtr(struct dm_target *ti)kfree (v->salt);kfree (v->root_digest);kfree (v->zero_digest); +verity_free_sig (v);if (v->tfm)crypto_free_ahash (v->tfm);@@ -1157,6 +1173,25 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,return r; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ + v->sig_size = sig_size; + v->root_digest_sig =kmalloc (v->sig_size,GFP_KERNEL ); +if (!v->root_digest) +return -ENOMEM ; + +return 0 ; +} +#else +static inline int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +/* * Target parameters: * <version> The current format is version 1. @@ -1365,6 +1400,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error ="Root hash verification failed" ; goto bad; } + + r =verity_init_sig (v, verify_args.sig, verify_args.sig_size); +if (r <0 ) { + ti->error ="Cannot allocate root digest signature" ; + goto bad; + } + v->hash_per_block_bits =__fls ((1 << v->hash_dev_block_bits) / v->digest_size);@@ -1501,6 +1543,32 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned ireturn 0 ; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_finalize (struct dm_target *ti) +{ +struct block_device *bdev; +struct dm_verity_digest root_digest; +struct dm_verity *v; +int r; + + v = ti->private; + bdev =dm_table_get_md (ti->table)->disk->part0; + root_digest.digest = v->root_digest; + root_digest.digest_len = v->digest_size; + root_digest.algo = v->alg_name; + + r =security_bdev_setsecurity (bdev,DM_VERITY_ROOTHASH_SEC_NAME , &root_digest, +sizeof (root_digest)); +if (r) +return r; + +return security_bdev_setsecurity (bdev, +DM_VERITY_SIGNATURE_SEC_NAME , + v->root_digest_sig, + v->sig_size); +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static struct target_type verity_target = { .name ="verity" , .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE ,@@ -1513,6 +1581,9 @@ static struct target_type verity_target = { .prepare_ioctl = verity_prepare_ioctl, .iterate_devices = verity_iterate_devices, .io_hints = verity_io_hints, +#ifdef CONFIG_IPE_PROP_DM_VERITY + .finalize = verity_finalize, +#endif /* CONFIG_IPE_PROP_DM_VERITY */ };module_dm (verity);drivers/md/dm-verity.h +6
-0@@ -42,6 +42,9 @@ struct dm_verity {u8 *root_digest;/* digest of the root block */ u8 *salt;/* salt: its size is salt_size */ u8 *zero_digest;/* digest for a zero block */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +u8 *root_digest_sig;/* digest signature of the root block */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int salt_size;sector_t data_start;/* data offset in 512-byte sectors */ sector_t hash_start;/* hash start in blocks */ @@ -55,6 +58,9 @@ struct dm_verity { bool hash_failed:1; /* set if hash of any block failed */ bool use_tasklet:1; /* try to verify in tasklet before work-queue */unsigned int digest_size;/* digest size for the current hash algorithm */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +unsigned int sig_size;/* digest signature size */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int ahash_reqsize;/* the size of temporary space for crypto */ enum verity_mode mode;/* mode for handling verification errors */ unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ include/linux/dm-verity.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_DM_VERITY_H +#define _LINUX_DM_VERITY_H + +#include <linux/types.h> +#include <crypto/hash_info.h> +#include <linux/device-mapper.h> + +struct dm_verity_digest { +const char *algo; +const u8 *digest; +size_t digest_len; +}; + +#define DM_VERITY_SIGNATURE_SEC_NAME DM_NAME ".verity-signature" +#define DM_VERITY_ROOTHASH_SEC_NAME DM_NAME ".verity-roothash" + +#endif /* _LINUX_DM_VERITY_H */ Signature · 1 line
2.25.1
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 14/19] ipe: add support for dm-verity as a trust provider
In reply to Fan WuQuoted 60 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Allows author of IPE policy to indicate trust for a singular dm-verity volume, identified by roothash, through "
dmverity_roothash" and all signed dm-verity volumes, through "dmverity_signature".Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ No Changesv3:
+ No changesv4:
+ No changesv5:
+ No changesv6:
+ Fix an improper cleanup that can result in
a leakv7:
+ Squash patch 08/12, 10/12 to [11/16]v8:
+ Undo squash of 08/12, 10/12 - separatingdrivers/md/fromsecurity/&block/
+ Use common-audit function fordmverity_signature.
+ Change implementation for storing the dm-verity digest to use the newly introduceddm_verity_digeststructure introduced in patch 14/20.v9:
+ Adapt to the new parserv10:
+ Select theKconfigwhen all dependencies are enabledv11:
+ No changes--- security/ipe/Kconfig | 18 +++++ security/ipe/Makefile | 1 + security/ipe/audit.c | 31 +++++++- security/ipe/digest.c | 142 +++++++++++++++++++++++++++++++++++ security/ipe/digest.h | 26 +++++++ security/ipe/eval.c | 101 ++++++++++++++++++++++++- security/ipe/eval.h | 13 ++++ security/ipe/hooks.c | 51 +++++++++++++ security/ipe/hooks.h | 8 ++ security/ipe/ipe.c | 15 ++++ security/ipe/ipe.h | 4 + security/ipe/policy.h | 3 + security/ipe/policy_parser.c | 24 +++++- 13 files changed, 433 insertions(+), 4 deletions(-) create mode 100644 security/ipe/digest.c create mode 100644 security/ipe/digest.h
...
Quoted 28 lines
security/ipe/audit.c +11
-0@@ -13,6 +13,7 @@#include "hooks.h" #include "policy.h" #include "audit.h" +#include "digest.h" #define ACTSTR (x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY")@@ -40,8 +41,29 @@ static const char *const audit_op_names[__IPE_OP_MAX] = {static const char *const audit_prop_names[__IPE_PROP_MAX] = {"boot_verified=FALSE" ,"boot_verified=TRUE" , +#ifdef CONFIG_IPE_PROP_DM_VERITY +"dmverity_roothash=" , +"dmverity_signature=FALSE" , +"dmverity_signature=TRUE" , +#endif /* CONFIG_IPE_PROP_DM_VERITY */ }; +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* audit_dmv_roothash - audit a roothash of a dmverity volume. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @r: Supplies a pointer to the digest structure.
security/ipe/audit.c static const char *const audit_op_names[__IPE_OP_MAX] = { · line 65
Quoted 10 lines
security/ipe/audit.c +10
-0+*/ +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +ipe_digest_audit (ab, rh); +} +#else +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */
Since the "dmverity_roothash=" field name is going to be written to the audit record regardless of CONFIG_IPE_PROP_DM_VERITY we should ensure that it has a value of "?" instead of nothing. To fix that I would suggest something like this:
#else
static void audit_dmv_roothash(struct audit_buffer *ab, const void *rh)
{
audit_log_format(ab, "?");
}
#endif /* CONFIG_IPE_PROP_DM_VERITY */security/ipe/audit.c static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r) · line 81
Quoted 13 lines
security/ipe/audit.c +4
-2/** * audit_rule - audit an IPE policy rule approximation. * @ab: Supplies a pointer to the audit_buffer to append to. @@ -53,8 +75,13 @@ static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r)audit_log_format (ab,"rule=\"op=%s " , audit_op_names[r->op]); -list_for_each_entry (ptr, &r->props, next) -audit_log_format (ab,"%s " , audit_prop_names[ptr->type]); +list_for_each_entry (ptr, &r->props, next) { +audit_log_format (ab,"%s" , audit_prop_names[ptr->type]); +if (ptr->type ==IPE_PROP_DMV_ROOTHASH ) +audit_dmv_roothash (ab, ptr->value);
If you wanted to avoid the roothash change above, you could change the code here so it didn't always write "dmverity_roothash=" into the audit record.
Quoted 25 lines
security/ipe/audit.c +2
-0+audit_log_format (ab," " ); + }audit_log_format (ab,"action=%s\"" ,ACTSTR (r->action)); }security/ipe/digest.c new file +14
-0@@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "digest.h" + +/** +* ipe_digest_parse - parse a digest in IPE's policy. +* @valstr: Supplies the string parsed from the policy. +* @value: Supplies a pointer to be populated with the result. +* +* Digests in IPE are defined in a standard way: +* <alg_name>:<hex>
security/ipe/digest.c line 24
Quoted 10 lines
security/ipe/digest.c new file +10
-0+* +* Use this function to create a property to parse the digest +* consistently. The parsed digest will be saved in @value in IPE's +* policy. +* +* Return: +* * 0 - OK +* * !0 - Error +*/ +int ipe_digest_parse (const char *valstr,void **value)
Why is @value void? You should make it a digest_info type or simply skip the second parameter and return a digest_info pointer.
Quoted 16 lines
security/ipe/digest.c new file +16
-0+{ +char *sep, *raw_digest; +size_t raw_digest_len; +int rc =0 ; +u8 *digest =NULL ; +struct digest_info *info =NULL ; + + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + sep =strchr (valstr,':' ); +if (!sep) { + rc = -EBADMSG ; + goto err; + }
security/ipe/digest.c line 50
Quoted 10 lines
security/ipe/digest.c new file +10
-0+ + info->alg =kstrndup (valstr, sep - valstr,GFP_KERNEL ); +if (!info->alg) { + rc = -ENOMEM ; + goto err; + } + + raw_digest = sep +1 ; + raw_digest_len =strlen (raw_digest); + info->raw_digest =kstrndup (raw_digest, raw_digest_len,GFP_KERNEL );
Since you're running a strlen() over @raw_digest, you might as well just use kstrdup() instead of kstrndup().
Quoted 35 lines
security/ipe/digest.c new file +35
-0+if (!info->raw_digest) { + rc = -ENOMEM ; + goto err_free_alg; + } + + info->digest_len = (raw_digest_len +1 ) /2 ; + digest =kzalloc (info->digest_len,GFP_KERNEL ); +if (!digest) { + rc = -ENOMEM ; + goto err_free_raw; + } + + rc =hex2bin (digest, raw_digest, info->digest_len); +if (rc <0 ) { + rc = -EINVAL ; + goto err_free_raw; + } + + info->digest = digest; + *value = info; +return 0 ; + +err_free_raw: +kfree (info->raw_digest); +err_free_alg: +kfree (info->alg); +err: +kfree (digest); +kfree (info); +return rc; +} + +/** +* ipe_digest_eval - evaluate an IPE digest against another digest. +* @expect: Supplies the policy-provided digest value.
security/ipe/digest.c line 95
Quoted 10 lines
security/ipe/digest.c new file +10
-0+* @digest: Supplies the digest to compare against the policy digest value. +* @digest_len: The length of @digest. +* @alg: Supplies the name of the algorithm used to calculated @digest. +* +* Return: +* * true - digests match +* * false - digests do not match +*/ +bool ipe_digest_eval (const void *expect,const u8 *digest,size_t digest_len, +const char *alg)
Similar to the above, why not make the @expect parameter a digest_info type? Also, why not pass a second digest_info parameter instead of a separate @digest, @digest_len, and @alg?
security/ipe/digest.c line 107
Quoted 12 lines
security/ipe/digest.c new file +12
-0+{ +const struct digest_info *info = (struct digest_info *)expect; + +return (digest_len == info->digest_len) && !strcmp (alg, info->alg) && + (!memcmp (info->digest, digest, info->digest_len)); +} + +/** +* ipe_digest_free - free an IPE digest. +* @value: Supplies a pointer the policy-provided digest value to free. +*/ +void ipe_digest_free (void **value)
Another digest_info parameter/type issue.
Quoted 18 lines
security/ipe/digest.c new file +18
-0+{ +struct digest_info *info = (struct digest_info *)(*value); + +if (IS_ERR_OR_NULL (info)) +return ; + +kfree (info->alg); +kfree (info->raw_digest); +kfree (info->digest); +kfree (info); +} + +/** +* ipe_digest_audit - audit a digest that was sourced from IPE's policy. +* @ab: Supplies the audit_buffer to append the formatted result. +* @val: Supplies a pointer to source the audit record from. +* +* Digests in IPE are defined in a standard way:
security/ipe/digest.c line 135
Quoted 10 lines
security/ipe/digest.c new file +10
-0+* <alg_name>:<hex> +* +* Use this function to create a property to audit the digest +* consistently. +* +* Return: +* 0 - OK +* !0 - Error +*/ +void ipe_digest_audit (struct audit_buffer *ab,const void *val)
Another digest_info parameter/type issue.
Quoted 7 lines
security/ipe/digest.c new file +7
-0+{ +const struct digest_info *info = (struct digest_info *)val; + +audit_log_untrustedstring (ab, info->alg); +audit_log_format (ab,":" ); +audit_log_untrustedstring (ab, info->raw_digest); +}
...
Quoted 11 lines
security/ipe/eval.c +2
-0@@ -69,15 +88,89 @@ void build_eval_ctx(struct ipe_eval_ctx *ctx, const struct file *file, enum ipe_op_type op) { +struct inode *ino =NULL ; +if (op ==IPE_OP_EXEC && file)
security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 102
Quoted 10 lines
security/ipe/eval.c +3
-1pin_sb (FILE_SUPERBLOCK (file)); ctx->file = file; ctx->op = op; -if (file) +if (file) { ctx->from_init_sb =from_pinned (FILE_SUPERBLOCK (file)); + ino =d_real_inode (file->f_path.dentry); +build_ipe_bdev_ctx (ctx, ino);
You don't need @ino.
build_ipe_bdev_ctx(ctx, d_real_inode(file->f_path.dentry));
Quoted 11 lines
security/ipe/eval.c +11
-0+ } +} + +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* evaluate_dmv_roothash - Evaluate @ctx against a dmv roothash property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p
security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 123
Quoted 10 lines
security/ipe/eval.c +10
-0+* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_roothash (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return !!ctx->ipe_bdev && +ipe_digest_eval (p->value, + ctx->ipe_bdev->digest, + ctx->ipe_bdev->digest_len, + ctx->ipe_bdev->digest_algo);
Building on my comments above in ipe_digest_eval(), if you convert it to use digest_info structs this is simplified:
ipe_digest_eval(p->vlaue, ctx->ipe_bdev)
Quoted 21 lines
security/ipe/eval.c +21
-0+} + +/** +* evaluate_dmv_sig_false: Analyze @ctx against a dmv sig false property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_sig_false (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return !ctx->ipe_bdev || (!ctx->ipe_bdev->dm_verity_signed); +} + +/** +* evaluate_dmv_sig_true: Analyze @ctx against a dmv sig true property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated.
security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 154
Quoted 10 lines
security/ipe/eval.c +10
-0+* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_sig_true (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return ctx->ipe_bdev && (!!ctx->ipe_bdev->dm_verity_signed); +}
Do you need both evaluate_dmv_sig_true() and evaluate_dmv_sig_false()? If yes, you should make one call the other and return the inverse to help ensure there are no oddities.
Quoted 35 lines
security/ipe/hooks.c +27
-0@@ -193,3 +196,51 @@ void ipe_sb_free_security(struct super_block *mnt_sb) {ipe_invalidate_pinned_sb (mnt_sb); } + +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* ipe_bdev_free_security - free IPE's LSM blob of block_devices. +* @bdev: Supplies a pointer to a block_device that contains the structure +* to free. +*/ +void ipe_bdev_free_security (struct block_device *bdev) +{ +struct ipe_bdev *blob =ipe_bdev (bdev); + +kfree (blob->digest); +kfree (blob->digest_algo); +} + +/** +* ipe_bdev_setsecurity - save data from a bdev to IPE's LSM blob. +* @bdev: Supplies a pointer to a block_device that contains the LSM blob. +* @key: Supplies the string key that uniquely identifies the value. +* @value: Supplies the value to store. +* @len: The length of @value. +*/ +int ipe_bdev_setsecurity (struct block_device *bdev,const char *key, +const void *value,size_t len) +{ +struct ipe_bdev *blob =ipe_bdev (bdev); +
security/ipe/hooks.c void ipe_sb_free_security(struct super_block *mnt_sb) · line 235
Quoted 10 lines
security/ipe/hooks.c +10
-0+if (!strcmp (key,DM_VERITY_ROOTHASH_SEC_NAME )) { +const struct dm_verity_digest *digest = value; + + blob->digest =kmemdup (digest->digest, digest->digest_len,GFP_KERNEL ); +if (!blob->digest) +return -ENOMEM ; + + blob->digest_algo =kstrdup_const (digest->algo,GFP_KERNEL ); +if (!blob->digest_algo) +return -ENOMEM ;
You need to cleanup @blob on error so you don't leak ipe_bdev::digest.
security/ipe/hooks.c void ipe_sb_free_security(struct super_block *mnt_sb) · line 246
Quoted 10 lines
security/ipe/hooks.c +10
-0+ blob->digest_len = digest->digest_len; + return 0; + }else if (!strcmp (key,DM_VERITY_SIGNATURE_SEC_NAME )) { + blob->dm_verity_signed = true; +return 0 ; + } + +return -EOPNOTSUPP ; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 15/19] fsverity: consume builtin signature via LSM hook
In reply to Fan WuQuoted 50 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
fsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Splitfs/verity/changes andsecurity/changes into separate patches
+ Change signature offsverity_create_infoto accept non-const inode
+ Change signature offsverity_verify_signatureto accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns-EOPNOTSUPP, causing errors.v9:
+ No changesv10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends onCONFIG_FS_VERITY_BUILTIN_SIGNATURES
Quoted 7 lines
v11:
+ No changes--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)
We need an ACK from some VFS folks on this.
Quoted 82 lines
fs/verity/fsverity_private.h +1
-1@@ -108,7 +108,7 @@ int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,unsigned int log_blocksize, const u8 *salt, size_t salt_size); -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc);void fsverity_set_info (struct inode *inode,struct fsverity_info *vi);fs/verity/open.c +25
-1@@ -8,6 +8,7 @@#include "fsverity_private.h" #include <linux/mm.h> +#include <linux/security.h> #include <linux/slab.h> static struct kmem_cache *fsverity_info_cachep;@@ -172,12 +173,28 @@ static int compute_file_digest(const struct fsverity_hash_alg *hash_alg,return err; } +#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES +static int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return security_inode_setsecurity (inode,FS_VERITY_INODE_SEC_NAME , + desc->signature, +le32_to_cpu (desc->sig_size),0 ); +} +#else +static inline int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_FS_VERITY*/ +/* * Create a new fsverity_info from the given fsverity_descriptor (with optional * appended builtin signature), and check the signature if present. The * fsverity_descriptor must have already undergone basic validation. */ -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc) {struct fsverity_info *vi;@@ -242,6 +259,13 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,spin_lock_init (&vi->hash_page_init_lock); } + err =fsverity_inode_setsecurity (inode, desc); +if (err == -EOPNOTSUPP ) + err =0 ; + +if (err) + goto fail; +return vi; fail:include/linux/fsverity.h +2
-0@@ -319,4 +319,6 @@ static inline int fsverity_prepare_setattr(struct dentry *dentry, return 0; } +#define FS_VERITY_INODE_SEC_NAME "fsverity.builtin-sig" +#endif /* _LINUX_FSVERITY_H */ Signature · 1 line
2.25.1
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 16/19] ipe: enable support for fs-verity as a trust provider
In reply to Fan WuQuoted 59 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Enable IPE policy authors to indicate trust for a singular fsverity file, identified by the digest information, through "
fsverity_digest" and all files using fsverity's builtin signatures via "fsverity_signature".This enables file-level integrity claims to be expressed in IPE, allowing individual files to be authorized, giving some flexibility for policy authors. Such file-level claims are important to be expressed for enforcing the integrity of packages, as well as address some of the scalability issues in a sole dm-verity based solution (# of loop back devices, etc).
This solution cannot be done in userspace as the minimum threat that IPE should mitigate is an attacker downloads malicious payload with all required dependencies. These dependencies can lack the userspace check, bypassing the protection entirely. A similar attack succeeds if the userspace component is replaced with a version that does not perform the check. As a result, this can only be done in the common entry point - the kernel.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
* Undo squash of 08/12, 10/12 - separatingdrivers/md/fromsecurity/
* Use common-audit function forfsverity_signature.
+ Change fsverity implementation to usefsverity_get_digest
+ prevent unnecessary copy of fs-verity signature data, instead just check for presence of signature data.
+ Removefree_inode_securityhook, as the digest is now acquired at runtime instead of via LSM blob.v9:
+ Adapt to the new parserv10:
+ Update the fsverity get digest callv11:
+ No changes--- security/ipe/Kconfig | 13 +++++ security/ipe/audit.c | 23 ++++++++ security/ipe/eval.c | 110 +++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 10 ++++ security/ipe/hooks.c | 30 ++++++++++ security/ipe/hooks.h | 7 +++ security/ipe/ipe.c | 13 +++++ security/ipe/ipe.h | 3 + security/ipe/policy.h | 3 + security/ipe/policy_parser.c | 8 +++ 10 files changed, 220 insertions(+)
...
security/ipe/audit.c static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r) · line 104
Quoted 10 lines
security/ipe/audit.c +2
-0@@ -79,6 +100,8 @@ static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r)audit_log_format (ab,"%s" , audit_prop_names[ptr->type]);if (ptr->type ==IPE_PROP_DMV_ROOTHASH )audit_dmv_roothash (ab, ptr->value); +if (ptr->type ==IPE_PROP_FSV_DIGEST ) +audit_fsv_digest (ab, ptr->value);
My comments on audit_dmv_roothash() also apply here.
Quoted 65 lines
security/ipe/audit.c +0
-0audit_log_format (ab," " ); }security/ipe/eval.c +55
-0@@ -172,6 +191,91 @@ static bool evaluate_dmv_sig_true(const struct ipe_eval_ctx *const ctx, }#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_FS_VERITY +/** +* evaluate_fsv_digest - Analyze @ctx against a fsv digest property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_fsv_digest (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +enum hash_algo alg; +u8 digest[FS_VERITY_MAX_DIGEST_SIZE ]; + +if (!ctx->ino) +return false; +if (!fsverity_get_digest ((struct inode *)ctx->ino, + digest, +NULL , + &alg)) +return false; + +return ipe_digest_eval (p->value, + digest, + hash_digest_size[alg], + hash_algo_name[alg]); +} + +/** +* evaluate_fsv_sig_false - Analyze @ctx against a fsv sig false property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_fsv_sig_false (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return !ctx->ino || + !IS_VERITY (ctx->ino) || + !ctx->ipe_inode || + !ctx->ipe_inode->fs_verity_signed; +} + +/** +* evaluate_fsv_sig_true - Analyze @ctx against a fsv sig true property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p
security/ipe/eval.c static bool evaluate_dmv_sig_true(const struct ipe_eval_ctx *const ctx, · line 258
Quoted 10 lines
security/ipe/eval.c +10
-0+* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_fsv_sig_true (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return ctx->ino && +IS_VERITY (ctx->ino) && + ctx->ipe_inode && + ctx->ipe_inode->fs_verity_signed; +}
See my previous comments about the false/true functions.
security/ipe/eval.c static bool evaluate_dmv_sig_true(const struct ipe_eval_ctx *const ctx, · line 259
Quoted 1 line
security/ipe/eval.c +1
-0+#else
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 17/19] scripts: add boot policy generation program
In reply to Fan WuQuoted 61 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Enables an IPE policy to be enforced from kernel start, enabling access control based on trust from kernel startup. This is accomplished by transforming an IPE policy indicated by
CONFIG_IPE_BOOT_POLICYinto a c-string literal that is parsed at kernel startup as an unsigned policy.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ No Changesv3:
+ No Changesv4:
+ No Changesv5:
+ No Changesv6:
+ No Changesv7:
+ Move from 01/11 to 14/16
+ Don't return errno directly.
+ Make output of script more user-friendly
+ Add escaping for tab and '?'
+ Mark argv pointer const
+ Invert return code check in the boot policy parsing code path.v8:
+ No significant changes.v9:
+ No changesv10:
+ Update the init part code for rcu changes in the eval loop patchv11:
+ Fix code style issues--- MAINTAINERS | 1 + scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 6 ++ scripts/ipe/polgen/polgen.c | 145 ++++++++++++++++++++++++++++++++++ security/ipe/.gitignore | 1 + security/ipe/Kconfig | 10 +++ security/ipe/Makefile | 11 +++ security/ipe/fs.c | 8 ++ security/ipe/ipe.c | 12 +++ 11 files changed, 198 insertions(+) create mode 100644 scripts/ipe/Makefile create mode 100644 scripts/ipe/polgen/.gitignore create mode 100644 scripts/ipe/polgen/Makefile create mode 100644 scripts/ipe/polgen/polgen.c create mode 100644 security/ipe/.gitignore
...
Quoted 6 lines
scripts/ipe/polgen/polgen.c new file +0
-0@@ -0,0 +1,145 @@
...
Quoted 24 lines
scripts/ipe/polgen/polgen.c new file +24
-0+static int write_boot_policy (const char *pathname,const char *buf,size_t size) +{ +int rc =0 ; +FILE *fd; +size_t i; + + fd =fopen (pathname,"w" ); +if (!fd) { + rc = errno; + goto err; + } + +fprintf (fd,"/* This file is automatically generated." ); +fprintf (fd," Do not edit. */\n" ); +fprintf (fd,"#include <linux/stddef.h>\n" ); +fprintf (fd,"\nextern const char *const ipe_boot_policy;\n\n" ); +fprintf (fd,"const char *const ipe_boot_policy =\n" ); + +if (!buf || size ==0 ) { +fprintf (fd,"\tNULL;\n" ); +fclose (fd); +return 0 ; + } +
scripts/ipe/polgen/polgen.c line 95
Quoted 10 lines
scripts/ipe/polgen/polgen.c new file +10
-0+fprintf (fd,"\t\"" ); + +for (i =0 ; i < size; ++i) { +switch (buf[i]) { +case '"' : +fprintf (fd,"\\\"" ); +break ; +case '\'' : +fprintf (fd,"'" ); +break ;
The revision of IPE proposed in this patchset doesn't support parsing single or double quotes, yes?
scripts/ipe/polgen/polgen.c line 107
Quoted 12 lines
scripts/ipe/polgen/polgen.c new file +12
-0+case '\n' : +fprintf (fd,"\\n\"\n\t\"" ); +break ; +case '\\' : +fprintf (fd,"\\\\" ); +break ; +case '\t' : +fprintf (fd,"\\t" ); +break ; +case '\?' : +fprintf (fd,"\\?" ); +break ;
Similar, are question marks supported by the parser?
Quoted 14 lines
scripts/ipe/polgen/polgen.c new file +14
-0+default : +fprintf (fd,"%c" , buf[i]); + } + } +fprintf (fd,"\";\n" ); +fclose (fd); + +return 0 ; + +err: +if (fd) +fclose (fd); +return rc; +}
...
security/ipe/.gitignore line 1
Quoted 8 lines
security/ipe/.gitignore new file +1
-0@@ -0,0 +1 @@ +boot-policy.c
Add a newline please.
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 18/19] ipe: kunit test for parser
In reply to Fan WuQuoted 2 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Add various happy/unhappy unit tests for both IPE's parser.
I'm going to suggest: "... for IPE's policy parser."
Also, aside from the policy parser tests, are there any other IPE functional tests? We do have a testing guideline for new LSM submissions:
"New LSMs must be accompanied by a test suite to verify basic
functionality and help identify regressions. The test suite must be publicly available without download restrictions requiring accounts, subscriptions, etc. Test coverage does not need to reach a specific percentage, but core functionality and any user interfaces should be well covered by the test suite. Maintaining the test suite in a public git repository is preferable over tarball snapshots. Integrating the test suite with existing automated Linux kernel testing services is encouraged."
https://github.com/LinuxSecurityModule/kernel/blob/main/README.md#new-lsm-guidelines
Quoted 20 lines
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Remove the kunit tests with respect to the fsverity digest, as these require significant changes to work with the new method of acquiring the digest at runtime.v9:
+ Remove the kunit tests related toipe_contextv10:
+ No changes
Quoted 8 lines
v11:
+ No changes--- security/ipe/Kconfig | 17 +++ security/ipe/Makefile | 3 + security/ipe/policy_tests.c | 294 ++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+) create mode 100644 security/ipe/policy_tests.c
--
paul-moore.com
Re: [PATCH RFC v11 2/19] ipe: add policy parser
In reply to Paul MooreQuoted 13 lines · Paul Moore
Quoted 12 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE's interpretation of the what the user trusts is accomplished through its policy. IPE's design is to not provide support for a single trust provider, but to support multiple providers to enable the end-user to choose the best one to seek their needs.
This requires the policy to be rather flexible and modular so that integrity providers, like fs-verity, dm-verity, dm-integrity, or some other system, can plug into the policy with minimal code changes.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>
...
Quoted 27 lines
Quoted 11 lines
--- security/ipe/Makefile | 2 + security/ipe/policy.c | 101 ++++++++ security/ipe/policy.h | 83 ++++++ security/ipe/policy_parser.c | 487 +++++++++++++++++++++++++++++++++++ security/ipe/policy_parser.h | 11 + 5 files changed, 684 insertions(+)create mode 100644
security/ipe/policy.c
create mode 100644security/ipe/policy.h
create mode 100644security/ipe/policy_parser.c
create mode 100644security/ipe/policy_parser.h...
Quoted 10 lines
security/ipe/policy.c new file +4
-0@@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ ...
Quoted 15 lines
security/ipe/policy.c line 44
Quoted 10 lines
security/ipe/policy.c new file +10
-0+static int set_pkcs7_data (void *ctx,const void *data,size_t len, +size_t asn1hdrlen) +{ +struct ipe_policy *p = ctx; + + p->text = (const char *)data; + p->textlen = len; + +return 0 ; +}The @asn1hdrlen parameter isn't used in this function, at least at this point in the patchset, so you really should remove it. If it is needed later in the patchset you can always update the function.
Although the @asn1hdrlen is not used, it's a required parameter for the pkcs7 callback. I guess adding a __always_unused might be the right solution?
Quoted 67 lines
Quoted 10 lines
security/ipe/policy_parser.c new file +4
-0@@ -0,0 +1,487 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ ...
security/ipe/policy_parser.c line 72
Quoted 13 lines
security/ipe/policy_parser.c new file +13
-0+/** +* remove_trailing_spaces - Truncate all trailing spaces in a string. +* +* @line: Supplies a poilcy line string for preprocessing. +* +* Return: The length of truncated string. +*/ +static size_t remove_trailing_spaces (char *line) +{ +size_t i =0 ; + +for (i =strlen (line); i >0 && (line[i -1 ] ==' ' || line[i -1 ] =='\t' ); --i) + ;Maybe I've asked this before, I can't remember: could you use the
isspace()macro here instead of explicitly checking for ' ' and '\t'? Yes,isspace()works here. I will update this part.i = strlen(line); while (i > 0 && isspace(line[i - 1])) i--; line[i] = '\0';Quoted 31 lines
security/ipe/policy_parser.c new file +31
-0+ line[i] ='\0' ; + +return i; +} + +/** +* parse_version - Parse policy version. +* @ver: Supplies a version string to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * 0 - OK +* * !0 - Standard errno +*/ +static int parse_version (char *ver,struct ipe_parsed_policy *p) +{ +int rc =0 ; +size_t sep_count =0 ; +char *token; +u16 *const cv[] = { &p->version.major, &p->version.minor, &p->version.rev }; + +while ((token =strsep (&ver,"." )) !=NULL ) { +/* prevent overflow */ +if (sep_count >=ARRAY_SIZE (cv)) +return -EBADMSG ; + + rc =kstrtou16 (token,10 , cv[sep_count]); +if (rc) +return rc; + + ++sep_count;
Quoted 9 lines
security/ipe/policy_parser.c line 109
Quoted 5 lines
security/ipe/policy_parser.c new file +5
-0+ } + +/* prevent underflow */ +if (sep_count !=ARRAY_SIZE (cv)) + rc = -EBADMSG ;You could always just 'return
-EBADMSG' here and 'return 0' below to simplify things a little.
I agree, this part is kind of unnecessary. I will update accordingly.
Quoted 66 lines
Quoted 66 lines
security/ipe/policy_parser.c new file +66
-0+return rc; +} + +enum header_opt { +IPE_HEADER_POLICY_NAME =0 , +IPE_HEADER_POLICY_VERSION , + __IPE_HEADER_MAX +}; + +static const match_table_t header_tokens = { + {IPE_HEADER_POLICY_NAME ,"policy_name=%s" }, + {IPE_HEADER_POLICY_VERSION ,"policy_version=%s" }, + {__IPE_HEADER_MAX,NULL } +}; + +/** +* parse_header - Parse policy header information. +* @line: Supplies header line to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * 0 - OK +* * !0 - Standard errno +*/ +static int parse_header (char *line,struct ipe_parsed_policy *p) +{ +int rc =0 ; +char *t, *ver =NULL ; +substring_t args[MAX_OPT_ARGS ]; +size_t idx =0 ; + +while ((t =strsep (&line,IPE_POLICY_DELIM )) !=NULL ) { +int token; + +if (*t =='\0' ) +continue ; +if (idx >= __IPE_HEADER_MAX) { + rc = -EBADMSG ; + goto out; + } + + token =match_token (t, header_tokens, args); +if (token != idx) { + rc = -EBADMSG ; + goto out; + } + +switch (token) { +case IPE_HEADER_POLICY_NAME : + p->name =match_strdup (&args[0 ]); +if (!p->name) + rc = -ENOMEM ; +break ; +case IPE_HEADER_POLICY_VERSION : + ver =match_strdup (&args[0 ]); +if (!ver) { + rc = -ENOMEM ; +break ; + } + rc =parse_version (ver, p); +break ; +default : + rc = -EBADMSG ; + } +if (rc) + goto out;
Quoted 9 lines
security/ipe/policy_parser.c line 182
Quoted 6 lines
security/ipe/policy_parser.c new file +6
-0+ ++idx; + } + +if (idx != __IPE_HEADER_MAX) { + rc = -EBADMSG ; + goto out;You probably don't need to 'goto out' here.
Yes it's unnecessary, thanks for pointing that out.
Quoted 89 lines
Quoted 6 lines
security/ipe/policy_parser.c new file +6
-0+ } + +out: +kfree (ver); +return rc; +}...
Quoted 65 lines
security/ipe/policy_parser.c new file +65
-0+/** +* parse_rule - parse a policy rule line. +* @line: Supplies rule line to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * !IS_ERR - OK +* * -ENOMEM - Out of memory +* * -EBADMSG - Policy syntax error +*/ +static int parse_rule (char *line,struct ipe_parsed_policy *p) +{ +int rc =0 ; +bool first_token = true, is_default_rule = false; +bool op_parsed = false; +enum ipe_op_type op =IPE_OP_INVALID ; +enum ipe_action_type action =IPE_ACTION_INVALID ; +struct ipe_rule *r =NULL ; +char *t; + + r =kzalloc (sizeof (*r),GFP_KERNEL ); +if (!r) +return -ENOMEM ; + +INIT_LIST_HEAD (&r->next); +INIT_LIST_HEAD (&r->props); + +while (t =strsep (&line,IPE_POLICY_DELIM ), line) { +if (*t =='\0' ) +continue ; +if (first_token &&token_default (t)) { + is_default_rule = true; + }else { +if (!op_parsed) { + op =parse_operation (t); +if (op ==IPE_OP_INVALID ) + rc = -EBADMSG ; +else + op_parsed = true; + }else { + rc =parse_property (t, r); + } + } + +if (rc) + goto err; + first_token = false; + } + + action =parse_action (t); +if (action ==IPE_ACTION_INVALID ) { + rc = -EBADMSG ; + goto err; + } + +if (is_default_rule) { +if (!list_empty (&r->props)) { + rc = -EBADMSG ; + }else if (op ==IPE_OP_INVALID ) { +if (p->global_default_action !=IPE_ACTION_INVALID ) + rc = -EBADMSG ; +else + p->global_default_action = action; + }else { +if (p->rules[op].default_action !=IPE_ACTION_INVALID )security/ipe/policy_parser.c line 357
Quoted 10 lines
security/ipe/policy_parser.c new file +10
-0+ rc = -EBADMSG ; + else + p->rules[op].default_action = action; + } + }else if (op !=IPE_OP_INVALID && action !=IPE_ACTION_INVALID ) { + r->op = op; + r->action = action; + }else { + rc = -EBADMSG ; + }I might be missing something important in the policy syntac, but could this function, and perhaps the
ipe_parsed_policystruct, be simplified if the default action was an explicit rule?
Quoted 2 lines
"op=DEFAULT action=ALLOW"
The complexity here arises from our need for two types of default rules: one for global settings and another for operation-specific settings.
To illustrate the flexibility of operation-specific default rules, users can set their policy to have a default rule of 'DENY' for execution, meaning all execution actions are prohibited by default. This let users to create an allow-list for execution. At the same time, the default rule for read can be set to 'ALLOW'. This let users to create an deny-list for read.
Adding explicit default rules can simplify ipe_parsed_policy struct, but that impose a burden on users that requires users always add the default rules the end of the policy. In contrast, our current design allows users to place the default rule anywhere in the policy. In practice, we often position the default rule at the beginning of the policy, which makes it more convenient for users to add new rules.
Quoted 50 lines
Quoted 50 lines
security/ipe/policy_parser.c new file +50
-0+if (rc) + goto err; +if (!is_default_rule) +list_add_tail (&r->next, &p->rules[op].rules); +else +free_rule (r); + +return rc; +err: +free_rule (r); +return rc; +} + +/** +* free_parsed_policy - free a parsed policy structure. +* @p: Supplies the parsed policy. +*/ +void free_parsed_policy (struct ipe_parsed_policy *p) +{ +size_t i =0 ; +struct ipe_rule *pp, *t; + +if (IS_ERR_OR_NULL (p)) +return ; + +for (i =0 ; i <ARRAY_SIZE (p->rules); ++i) +list_for_each_entry_safe (pp, t, &p->rules[i].rules, next) { +list_del (&pp->next); +free_rule (pp); + } + +kfree (p->name); +kfree (p); +} + +/** +* validate_policy - validate a parsed policy. +* @p: Supplies the fully parsed policy. +* +* Given a policy structure that was just parsed, validate that all +* necessary fields are present, initialized correctly. +* +* A parsed policy can be in an invalid state for use (a default was +* undefined) by just parsing the policy. +* +* Return: +* * 0 - OK +* * -EBADMSG - Policy is invalid +*/ +static int validate_policy (const struct ipe_parsed_policy *p)
Quoted 8 lines
security/ipe/policy_parser.c line 413
Quoted 5 lines
security/ipe/policy_parser.c new file +5
-0+{ +size_t i =0 ; + +if (p->global_default_action !=IPE_ACTION_INVALID ) +return 0 ;Should the if conditional above be "==" and not "!="? No, "!=" is the correct one.
The purpose of validation is to ensure that we have enough default rules to cover all cases. If the global default action not invalid, it means we have a global default rule in the policy to cover all cases, thus we simply return 0.
However, if there is no global default rule, then we need to ensure that for each operation, there is a operation specific default rule, this is validated in the for loop below.
-Fan
Quoted 10 lines
security/ipe/policy_parser.c line 421
Quoted 7 lines
security/ipe/policy_parser.c new file +7
-0+for (i =0 ; i <ARRAY_SIZE (p->rules); ++i) { +if (p->rules[i].default_action ==IPE_ACTION_INVALID ) +return -EBADMSG ; + } + +return 0 ; +}--
paul-moore.com
Re: [PATCH RFC v11 3/19] ipe: add evaluation loop
In reply to Paul MooreQuoted 8 lines · Paul Moore
Quoted 7 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE must have a centralized function to evaluate incoming callers against IPE's policy. This iteration of the policy for against the rules for that specific caller is known as the evaluation loop.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>
...
Quoted 76 lines
Quoted 7 lines
--- security/ipe/Makefile | 1 + security/ipe/eval.c | 96 +++++++++++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 24 +++++++++++ 3 files changed, 121 insertions(+)create mode 100644
security/ipe/eval.c
create mode 100644security/ipe/eval.h...
Quoted 66 lines
security/ipe/eval.c new file +60
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/sched.h> +#include <linux/rcupdate.h> + +#include "ipe.h" +#include "eval.h" +#include "policy.h" + +struct ipe_policy __rcu *ipe_active_policy; + +/** +* evaluate_property - Analyze @ctx against a property. +* @ctx: Supplies a pointer to the context to be evaluated. +* @p: Supplies a pointer to the property to be evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_property (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return false; +} + +/** +* ipe_evaluate_event - Analyze @ctx against the current active policy. +* @ctx: Supplies a pointer to the context to be evaluated. +* +* This is the loop where all policy evaluation happens against IPE policy. +* +* Return: +* * 0 - OK +* * -EACCES - @ctx did not pass evaluation. +* * !0 - Error +*/ +int ipe_evaluate_event (const struct ipe_eval_ctx *const ctx) +{ +bool match = false; +enum ipe_action_type action; +struct ipe_policy *pol =NULL ; +const struct ipe_rule *rule =NULL ; +const struct ipe_op_table *rules =NULL ; +struct ipe_prop *prop =NULL ; + +rcu_read_lock (); + + pol =rcu_dereference (ipe_active_policy); +if (!pol) { +rcu_read_unlock (); +return 0 ; + }
Quoted 9 lines
security/ipe/eval.c line 65
Quoted 5 lines
security/ipe/eval.c new file +5
-0+ +if (ctx->op ==IPE_OP_INVALID ) { +rcu_read_unlock (); +if (pol->parsed->global_default_action ==IPE_ACTION_DENY ) +return -EACCES ;Assuming that the RCU lock protects @pol, shouldn't it be held until after the
global_default_actioncomparison?
Yes for this part the unlock should be moved after the comparison. Thanks for spotting this.
Quoted 5 lines
Quoted 5 lines
security/ipe/eval.c new file +5
-0+return 0 ; + } + + rules = &pol->parsed->rules[ctx->op]; +
Quoted 9 lines
security/ipe/eval.c line 75
Quoted 5 lines
security/ipe/eval.c new file +5
-0+list_for_each_entry (rule, &rules->rules, next) { + match = true; + +list_for_each_entry (prop, &rule->props, next) { + match = match &&evaluate_property (ctx, prop);The @match variable will always be true on the right side above, or am I missing something?
Yes the "match &&" are completely unnecessary. I will remove them.
-Fan
Quoted 24 lines
Quoted 11 lines
security/ipe/eval.c new file +11
-0+if (!match) +break ; + } + +if (match) +break ; + } + +if (match) + action = rule->action; +else if (rules->default_action !=IPE_ACTION_INVALID )security/ipe/eval.c line 96
Quoted 10 lines
security/ipe/eval.c new file +10
-0+ action = rules->default_action; + else + action = pol->parsed->global_default_action; + +rcu_read_unlock (); +if (action ==IPE_ACTION_DENY ) +return -EACCES ; + +return 0 ; +}--
paul-moore.com
Re: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
In reply to Paul MooreQuoted 21 lines · Paul Moore
Quoted 20 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>
...
Quoted 66 lines
Quoted 51 lines
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)security/ipe/eval.c +26
-0@@ -9,6 +9,7 @@#include <linux/file.h> #include <linux/sched.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> #include "ipe.h" #include "eval.h" @@ -16,6 +17,44 @@struct ipe_policy __rcu *ipe_active_policy; +static const struct super_block *pinned_sb; +static DEFINE_SPINLOCK (pin_lock); +#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) + +/** +* pin_sb - Pin the underlying superblock of @f, marking it as trusted. +* @sb: Supplies a super_block structure to be pinned. +*/ +static void pin_sb (const struct super_block *sb) +{ +if (!sb) +return ; +spin_lock (&pin_lock); +if (!pinned_sb) + pinned_sb = sb; +spin_unlock (&pin_lock); +} + +/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);It's okay for an initial version, but I still think you need to get away from this spinlock in
from_pinned()as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.
Quoted 5 lines
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in
super_block::securityyou could mark the superblock when it was mounted and do a lockless lookup here infrom_pinned().
Thank you for the suggestion. After some testing, I discovered that switching to RCU to pin the super block and using a security blob to mark a pinned super block works. This approach do avoid many spinlock operations. I'll incorporate these changes in the next version of the patch.
-Fan
Quoted 5 lines
security/ipe/eval.c line 56
Quoted 2 lines
security/ipe/eval.c +2
-0+return rv; +}--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 2/19] ipe: add policy parser
In reply to Fan WuQuoted 57 lines · Fan Wu
Quoted 13 lines · Paul Moore
Quoted 12 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE's interpretation of the what the user trusts is accomplished through its policy. IPE's design is to not provide support for a single trust provider, but to support multiple providers to enable the end-user to choose the best one to seek their needs.
This requires the policy to be rather flexible and modular so that integrity providers, like fs-verity, dm-verity, dm-integrity, or some other system, can plug into the policy with minimal code changes.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>...
Quoted 27 lines
Quoted 11 lines
--- security/ipe/Makefile | 2 + security/ipe/policy.c | 101 ++++++++ security/ipe/policy.h | 83 ++++++ security/ipe/policy_parser.c | 487 +++++++++++++++++++++++++++++++++++ security/ipe/policy_parser.h | 11 + 5 files changed, 684 insertions(+)create mode 100644
security/ipe/policy.c
create mode 100644security/ipe/policy.h
create mode 100644security/ipe/policy_parser.c
create mode 100644security/ipe/policy_parser.h...
Quoted 10 lines
security/ipe/policy.c new file +4
-0@@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ ...
Quoted 14 lines
security/ipe/policy.c line 44
Quoted 10 lines
security/ipe/policy.c new file +10
-0+static int set_pkcs7_data (void *ctx,const void *data,size_t len, +size_t asn1hdrlen) +{ +struct ipe_policy *p = ctx; + + p->text = (const char *)data; + p->textlen = len; + +return 0 ; +}The @asn1hdrlen parameter isn't used in this function, at least at this point in the patchset, so you really should remove it. If it is needed later in the patchset you can always update the function.
Quoted 3 lines
Although the @asn1hdrlen is not used, it's a required parameter for the pkcs7 callback. I guess adding a
__always_unusedmight be the right solution?
Ah gotcha, I'm sorry for the noise, I obviously didn't catch that. As for the __always_unused marking, yes, that's probably a good idea.
Quoted 92 lines
Quoted 80 lines
Quoted 65 lines
security/ipe/policy.c new file +65
-0+/** +* parse_rule - parse a policy rule line. +* @line: Supplies rule line to be parsed. +* @p: Supplies the partial parsed policy. +* +* Return: +* * !IS_ERR - OK +* * -ENOMEM - Out of memory +* * -EBADMSG - Policy syntax error +*/ +static int parse_rule (char *line,struct ipe_parsed_policy *p) +{ +int rc =0 ; +bool first_token = true, is_default_rule = false; +bool op_parsed = false; +enum ipe_op_type op =IPE_OP_INVALID ; +enum ipe_action_type action =IPE_ACTION_INVALID ; +struct ipe_rule *r =NULL ; +char *t; + + r =kzalloc (sizeof (*r),GFP_KERNEL ); +if (!r) +return -ENOMEM ; + +INIT_LIST_HEAD (&r->next); +INIT_LIST_HEAD (&r->props); + +while (t =strsep (&line,IPE_POLICY_DELIM ), line) { +if (*t =='\0' ) +continue ; +if (first_token &&token_default (t)) { + is_default_rule = true; + }else { +if (!op_parsed) { + op =parse_operation (t); +if (op ==IPE_OP_INVALID ) + rc = -EBADMSG ; +else + op_parsed = true; + }else { + rc =parse_property (t, r); + } + } + +if (rc) + goto err; + first_token = false; + } + + action =parse_action (t); +if (action ==IPE_ACTION_INVALID ) { + rc = -EBADMSG ; + goto err; + } + +if (is_default_rule) { +if (!list_empty (&r->props)) { + rc = -EBADMSG ; + }else if (op ==IPE_OP_INVALID ) { +if (p->global_default_action !=IPE_ACTION_INVALID ) + rc = -EBADMSG ; +else + p->global_default_action = action; + }else { +if (p->rules[op].default_action !=IPE_ACTION_INVALID )security/ipe/policy.c
Quoted 10 lines
security/ipe/policy.c new file +10
-0+ rc = -EBADMSG ; + else + p->rules[op].default_action = action; + } + }else if (op !=IPE_OP_INVALID && action !=IPE_ACTION_INVALID ) { + r->op = op; + r->action = action; + }else { + rc = -EBADMSG ; + }I might be missing something important in the policy syntac, but could this function, and perhaps the
ipe_parsed_policystruct, be simplified if the default action was an explicit rule?Quoted 1 line
"op=DEFAULT action=ALLOW"
The complexity here arises from our need for two types of default rules:
one for global settings and another for operation-specific settings.To illustrate the flexibility of operation-specific default rules, users can set their policy to have a default rule of 'DENY' for execution, meaning all execution actions are prohibited by default. This let users to create an allow-list for execution. At the same time, the default rule for read can be set to 'ALLOW'. This let users to create an deny-list for read.
Quoted 6 lines
Adding explicit default rules can simplify
ipe_parsed_policystruct, but that impose a burden on users that requires users always add the default rules the end of the policy. In contrast, our current design allows users to place the default rule anywhere in the policy. In practice, we often position the default rule at the beginning of the policy, which makes it more convenient for users to add new rules.
Okay, thanks for the explanation.
Quoted 47 lines
Quoted 45 lines
Quoted 32 lines
security/ipe/policy.c new file +32
-0+/** +* free_parsed_policy - free a parsed policy structure. +* @p: Supplies the parsed policy. +*/ +void free_parsed_policy (struct ipe_parsed_policy *p) +{ +size_t i =0 ; +struct ipe_rule *pp, *t; + +if (IS_ERR_OR_NULL (p)) +return ; + +for (i =0 ; i <ARRAY_SIZE (p->rules); ++i) +list_for_each_entry_safe (pp, t, &p->rules[i].rules, next) { +list_del (&pp->next); +free_rule (pp); + } + +kfree (p->name); +kfree (p); +} + +/** +* validate_policy - validate a parsed policy. +* @p: Supplies the fully parsed policy. +* +* Given a policy structure that was just parsed, validate that all +* necessary fields are present, initialized correctly. +* +* A parsed policy can be in an invalid state for use (a default was +* undefined) by just parsing the policy. +* security/ipe/policy.c
Quoted 10 lines
security/ipe/policy.c new file +10
-0+* Return: +* * 0 - OK +* * -EBADMSG - Policy is invalid +*/ +static int validate_policy (const struct ipe_parsed_policy *p) +{ +size_t i =0 ; + +if (p->global_default_action !=IPE_ACTION_INVALID ) +return 0 ;Should the if conditional above be "==" and not "!="?
Quoted 1 line
No, "!=" is the correct one.
Quoted 8 lines
The purpose of validation is to ensure that we have enough default rules to cover all cases. If the global default action not invalid, it means we have a global default rule in the policy to cover all cases, thus we simply return 0.
However, if there is no global default rule, then we need to ensure that for each operation, there is a operation specific default rule, this is validated in the for loop below.
Makes sense, thanks.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
In reply to Fan WuQuoted 94 lines · Fan Wu
Quoted 21 lines · Paul Moore
Quoted 20 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>...
Quoted 66 lines
Quoted 51 lines
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)security/ipe/eval.c +26
-0@@ -9,6 +9,7 @@#include <linux/file.h> #include <linux/sched.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> #include "ipe.h" #include "eval.h" @@ -16,6 +17,44 @@struct ipe_policy __rcu *ipe_active_policy; +static const struct super_block *pinned_sb; +static DEFINE_SPINLOCK (pin_lock); +#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) + +/** +* pin_sb - Pin the underlying superblock of @f, marking it as trusted. +* @sb: Supplies a super_block structure to be pinned. +*/ +static void pin_sb (const struct super_block *sb) +{ +if (!sb) +return ; +spin_lock (&pin_lock); +if (!pinned_sb) + pinned_sb = sb; +spin_unlock (&pin_lock); +} + +/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);It's okay for an initial version, but I still think you need to get away from this spinlock in
from_pinned()as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.Quoted 4 lines
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in
super_block::securityyou could mark the superblock when it was mounted and do a lockless lookup here infrom_pinned().
Quoted 4 lines
Thank you for the suggestion. After some testing, I discovered that switching to RCU to pin the super block and using a security blob to mark a pinned super block works. This approach do avoid many spinlock operations. I'll incorporate these changes in the next version of the patch.
I probably wasn't as clear as I should have been, I was thinking of doing away with the @pinned_sb global variable entirely, as well as its associated lock problems and simply marking the initramfs/initrd superblock when it was mounted. I will admit that I haven't fully thought about all the implementation details, but I think you could leverage the security_sb_mount() hook to set a flag in IPE's superblock metadata when the initramfs was mounted.
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 15/19] fsverity: consume builtin signature via LSM hook
In reply to Paul MooreQuoted 59 lines · Paul Moore
Quoted 50 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
fsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Splitfs/verity/changes andsecurity/changes into separate patches
+ Change signature offsverity_create_infoto accept non-const inode
+ Change signature offsverity_verify_signatureto accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns-EOPNOTSUPP, causing errors.v9:
+ No changesv10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends onCONFIG_FS_VERITY_BUILTIN_SIGNATURESQuoted 7 lines
v11:
+ No changes--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)
Quoted 1 line
We need an ACK from some VFS folks on this.
Eric and/or Ted, can we get either an ACK or some feedback on this patch?
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Quoted 82 lines
Quoted 82 lines
fs/verity/fsverity_private.h +1
-1@@ -108,7 +108,7 @@ int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,unsigned int log_blocksize, const u8 *salt, size_t salt_size); -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc);void fsverity_set_info (struct inode *inode,struct fsverity_info *vi);fs/verity/open.c +25
-1@@ -8,6 +8,7 @@#include "fsverity_private.h" #include <linux/mm.h> +#include <linux/security.h> #include <linux/slab.h> static struct kmem_cache *fsverity_info_cachep;@@ -172,12 +173,28 @@ static int compute_file_digest(const struct fsverity_hash_alg *hash_alg,return err; } +#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES +static int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return security_inode_setsecurity (inode,FS_VERITY_INODE_SEC_NAME , + desc->signature, +le32_to_cpu (desc->sig_size),0 ); +} +#else +static inline int fsverity_inode_setsecurity (struct inode *inode, +struct fsverity_descriptor *desc) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_FS_VERITY*/ +/* * Create a new fsverity_info from the given fsverity_descriptor (with optional * appended builtin signature), and check the signature if present. The * fsverity_descriptor must have already undergone basic validation. */ -struct fsverity_info *fsverity_create_info (const struct inode *inode, +struct fsverity_info *fsverity_create_info (struct inode *inode,struct fsverity_descriptor *desc) {struct fsverity_info *vi;@@ -242,6 +259,13 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,spin_lock_init (&vi->hash_page_init_lock); } + err =fsverity_inode_setsecurity (inode, desc); +if (err == -EOPNOTSUPP ) + err =0 ; + +if (err) + goto fail; +return vi; fail:include/linux/fsverity.h +2
-1@@ -319,4 +319,6 @@ static inline int fsverity_prepare_setattr(struct dentry *dentry, return 0; } +#define FS_VERITY_INODE_SEC_NAME "fsverity.builtin-sig" +#endif /* _LINUX_FSVERITY_H */ --2.25.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 11/19] dm verity: set DM_TARGET_SINGLETON feature flag
In reply to Paul MooreQuoted 17 lines · Paul Moore
Quoted 8 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
The device-mapper has a flag to mark targets as singleton, which is a required flag for immutable targets. Without this flag, multiple dm-verity targets can be added to a mapped device, which has no practical use cases and will let
dm_table_get_immutable_targetreturn NULL. This patch adds the missing flag, restricting only one dm-verity target per mapped device.Quoted 7 lines
Signed-off-by Fan Wu <[email protected]>---
v1-v10:
+ Not present--- drivers/md/dm-verity-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
This seems reasonable to me and matches with other users of
DM_TARGET_IMMUTABLE.Alasdair, Mike, can we get an ACK on this?
A gentle ping with a reminder ...
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Quoted 15 lines
Quoted 15 lines
drivers/md/dm-verity-target.c +1
-2@@ -1503,7 +1503,7 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned istatic struct target_type verity_target = { .name ="verity" , - .features =DM_TARGET_IMMUTABLE , + .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE , .version = {1 ,9 ,0 }, .module =THIS_MODULE , .ctr = verity_ctr, --2.25.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 12/19] dm: add finalize hook to target_type
In reply to Paul MooreQuoted 19 lines · Paul Moore
Quoted 9 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
This patch adds a target finalize hook.
The hook is triggered just before activating an inactive table of a mapped device. If it returns an error the
__bindget cancelled.The dm-verity target will use this hook to attach the dm-verity's roothash metadata to the
block_devicestruct of the mapped device.Quoted 8 lines
Signed-off-by Fan Wu <[email protected]>---
v1-v10:
+ Not present--- drivers/md/dm.c | 12 ++++++++++++ include/linux/device-mapper.h | 7 +++++++ 2 files changed, 19 insertions(+)
Quoted 2 lines
We need an ACK and confirmation from Alasdair and/or Mike that this is the right approach.
A gentle ping with a reminder ...
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Quoted 50 lines
Quoted 50 lines
drivers/md/dm.c +12
-0@@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } +for (unsigned int i =0 ; i < t->num_targets; i++) { +struct dm_target *ti =dm_table_get_target (t, i); + +if (ti->type->finalize) { + ret = ti->type->finalize (ti); +if (ret) { + old_map =ERR_PTR (ret); + goto out; + } + } + } + old_map =rcu_dereference_protected (md->map,lockdep_is_held (&md->suspend_lock));rcu_assign_pointer (md->map, (void *)t); md->immutable_target_type =dm_table_get_immutable_target_type (t);include/linux/device-mapper.h +7
-1@@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,*/ typedef size_t (*dm_dax_recovery_write_fn )(struct dm_target *ti,pgoff_t pgoff,void *addr,size_t bytes,struct iov_iter *i); +/* +* Returns: +* < 0 : error +* = 0 : success +*/ +typedef int (*dm_finalize_fn ) (struct dm_target *target);void dm_error (const char *message);@@ -209,6 +215,7 @@ struct target_type {dm_dax_direct_access_fn direct_access;dm_dax_zero_page_range_fn dax_zero_page_range;dm_dax_recovery_write_fn dax_recovery_write; +dm_finalize_fn finalize;/* For internal device-mapper use. */ struct list_head list; --2.25.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 13/19] dm verity: consume root hash digest and signature data via LSM hook
In reply to Paul MooreQuoted 78 lines · Paul Moore
Quoted 69 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
dm-verity provides a strong guarantee of a block device's integrity. As a generic way to check the integrity of a block device, it provides those integrity guarantees to its higher layers, including the filesystem level.
An LSM that control access to a resource on the system based on the available integrity claims can use this transitive property of dm-verity, by querying the underlying
block_deviceof a particular file.The digest and signature information need to be stored in the block device to fulfill the next requirement of authorization via LSM policy. This will enable the LSM to perform revocation of devices that are still mounted, prohibiting execution of files that are no longer authorized by the LSM in question.
This patch added two security hook calls in dm-verity to save the dm-verity roothash and the roothash signature to the block device's LSM blobs.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ No Changesv3:
+ No changesv4:
+ No changesv5:
+ No changesv6:
+ Fix an improper cleanup that can result in
a leakv7:
+ Squash patch 08/12, 10/12 to [11/16]
+ Use part0 forblock_device, to retrieve theblock_device, when callingsecurity_bdev_setsecurityv8:
+ Undo squash of 08/12, 10/12 - separatingdrivers/md/fromsecurity/&block/
+ Use common-audit function fordmverity_signature.
+ Change implementation for storing the dm-verity digest to use the newly introduceddm_verity_digeststructure introduced in patch 14/20.
+ Create new structure,dm_verity_digest, containing digest algorithm, size, and digest itself to pass to the LSM layer. V7 was missing the algorithm.
+ Create an associated public header containing this new structure and the key values for the LSM hook, specific to dm-verity.
+ Additional information added to commit, discussing the layering of the changes and how the information passed will be used.v9:
+ No changesv10:
+ No changesv11:
+ Add an optional field to save signature
+ Move the security hook call to the new finalize hookQuoted 6 lines
--- drivers/md/dm-verity-target.c | 71 +++++++++++++++++++++++++++++++++++ drivers/md/dm-verity.h | 6 +++ include/linux/dm-verity.h | 19 ++++++++++ 3 files changed, 96 insertions(+) create mode 100644 include/linux/dm-verity.h
Quoted 1 line
We need an ACK from Alasdair and/or Mike on this too.
A gentle ping with a reminder ...
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Quoted 182 lines
Quoted 182 lines
drivers/md/dm-verity-target.c +71
-0@@ -13,6 +13,7 @@* access behavior. */ +#include "dm-core.h" #include "dm-verity.h" #include "dm-verity-fec.h" #include "dm-verity-verify-sig.h" @@ -22,6 +23,9 @@#include <linux/scatterlist.h> #include <linux/string.h> #include <linux/jump_label.h> +#include <linux/security.h> +#include <linux/dm-verity.h> +#include <crypto/hash_info.h> #define DM_MSG_PREFIX "verity"@@ -952,6 +956,17 @@ static void verity_io_hints(struct dm_target *ti, struct queue_limits *limits)blk_limits_io_min (limits, limits->logical_block_size); } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static void verity_free_sig (struct dm_verity *v) +{ +kfree (v->root_digest_sig); +} +#else +static inline void verity_free_sig (struct dm_verity *v) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static void verity_dtr (struct dm_target *ti) {struct dm_verity *v = ti->private;@@ -966,6 +981,7 @@ static void verity_dtr(struct dm_target *ti)kfree (v->salt);kfree (v->root_digest);kfree (v->zero_digest); +verity_free_sig (v);if (v->tfm)crypto_free_ahash (v->tfm);@@ -1157,6 +1173,25 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,return r; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ + v->sig_size = sig_size; + v->root_digest_sig =kmalloc (v->sig_size,GFP_KERNEL ); +if (!v->root_digest) +return -ENOMEM ; + +return 0 ; +} +#else +static inline int verity_init_sig (struct dm_verity *v,const void *sig, +size_t sig_size) +{ +return 0 ; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +/* * Target parameters: * <version> The current format is version 1. @@ -1365,6 +1400,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error ="Root hash verification failed" ; goto bad; } + + r =verity_init_sig (v, verify_args.sig, verify_args.sig_size); +if (r <0 ) { + ti->error ="Cannot allocate root digest signature" ; + goto bad; + } + v->hash_per_block_bits =__fls ((1 << v->hash_dev_block_bits) / v->digest_size);@@ -1501,6 +1543,32 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned ireturn 0 ; } +#ifdef CONFIG_IPE_PROP_DM_VERITY +static int verity_finalize (struct dm_target *ti) +{ +struct block_device *bdev; +struct dm_verity_digest root_digest; +struct dm_verity *v; +int r; + + v = ti->private; + bdev =dm_table_get_md (ti->table)->disk->part0; + root_digest.digest = v->root_digest; + root_digest.digest_len = v->digest_size; + root_digest.algo = v->alg_name; + + r =security_bdev_setsecurity (bdev,DM_VERITY_ROOTHASH_SEC_NAME , &root_digest, +sizeof (root_digest)); +if (r) +return r; + +return security_bdev_setsecurity (bdev, +DM_VERITY_SIGNATURE_SEC_NAME , + v->root_digest_sig, + v->sig_size); +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ +static struct target_type verity_target = { .name ="verity" , .features =DM_TARGET_SINGLETON |DM_TARGET_IMMUTABLE ,@@ -1513,6 +1581,9 @@ static struct target_type verity_target = { .prepare_ioctl = verity_prepare_ioctl, .iterate_devices = verity_iterate_devices, .io_hints = verity_io_hints, +#ifdef CONFIG_IPE_PROP_DM_VERITY + .finalize = verity_finalize, +#endif /* CONFIG_IPE_PROP_DM_VERITY */ };module_dm (verity);drivers/md/dm-verity.h +6
-0@@ -42,6 +42,9 @@ struct dm_verity {u8 *root_digest;/* digest of the root block */ u8 *salt;/* salt: its size is salt_size */ u8 *zero_digest;/* digest for a zero block */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +u8 *root_digest_sig;/* digest signature of the root block */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int salt_size;sector_t data_start;/* data offset in 512-byte sectors */ sector_t hash_start;/* hash start in blocks */ @@ -55,6 +58,9 @@ struct dm_verity { bool hash_failed:1; /* set if hash of any block failed */ bool use_tasklet:1; /* try to verify in tasklet before work-queue */unsigned int digest_size;/* digest size for the current hash algorithm */ +#ifdef CONFIG_IPE_PROP_DM_VERITY +unsigned int sig_size;/* digest signature size */ +#endif /* CONFIG_IPE_PROP_DM_VERITY */ unsigned int ahash_reqsize;/* the size of temporary space for crypto */ enum verity_mode mode;/* mode for handling verification errors */ unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ include/linux/dm-verity.h new file +19
-1@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_DM_VERITY_H +#define _LINUX_DM_VERITY_H + +#include <linux/types.h> +#include <crypto/hash_info.h> +#include <linux/device-mapper.h> + +struct dm_verity_digest { +const char *algo; +const u8 *digest; +size_t digest_len; +}; + +#define DM_VERITY_SIGNATURE_SEC_NAME DM_NAME ".verity-signature" +#define DM_VERITY_ROOTHASH_SEC_NAME DM_NAME ".verity-roothash" + +#endif /* _LINUX_DM_VERITY_H */ --2.25.1
Signature · 1 line
paul-moore.com
Eric Biggers
maintainerRe: [PATCH RFC v11 15/19] fsverity: consume builtin signature via LSM hook
In reply to Paul MooreQuoted 60 lines · Paul Moore
Quoted 59 lines · Paul Moore
Quoted 57 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
fsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Splitfs/verity/changes andsecurity/changes into separate patches
+ Change signature offsverity_create_infoto accept non-const inode
+ Change signature offsverity_verify_signatureto accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns-EOPNOTSUPP, causing errors.v9:
+ No changesv10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends onCONFIG_FS_VERITY_BUILTIN_SIGNATURESv11:
+ No changes--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 1 line
We need an ACK from some VFS folks on this.
Eric and/or Ted, can we get either an ACK or some feedback on this patch?
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Well, technically I already gave some (minor) feedback on this exact patch, and it's not yet been addressed:
https://lore.kernel.org/linux-security-module/[email protected]/
Of course, it would also be nice if the commit message mentioned what the patch actually does.
At a higher level, I've said before, I'm not super happy about the use of fsverity builtin signatures growing. (For some of the reasons why, see the guidance in the fsverity documentation at
https://docs.kernel.org/filesystems/fsverity.html#built-in-signature-verification)
That being said, if the people who are doing the broader review of IPE believe this is how its fsverity integration should work, I can live with that; I don't intend to block the IPE patchset if enough people want it to be merged. I've really been hoping to see engagement with the people involved in IMA, as IPE basically duplicates/replaces IMA. But I haven't seen that, so maybe things need to move on without them.
- Eric
Paul Moore
maintainerRe: [PATCH RFC v11 15/19] fsverity: consume builtin signature via LSM hook
Quoted 65 lines · Eric Biggers
Quoted 64 lines · Paul Moore
Quoted 59 lines · Paul Moore
Quoted 50 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
fsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Splitfs/verity/changes andsecurity/changes into separate patches
+ Change signature offsverity_create_infoto accept non-const inode
+ Change signature offsverity_verify_signatureto accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns-EOPNOTSUPP, causing errors.v9:
+ No changesv10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends onCONFIG_FS_VERITY_BUILTIN_SIGNATURESQuoted 7 lines
v11:
+ No changes--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)Quoted 1 line
We need an ACK from some VFS folks on this.
Eric and/or Ted, can we get either an ACK or some feedback on this patch?
Quoted 7 lines
Quoted 3 lines
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Well, technically I already gave some (minor) feedback on this exact patch, and it's not yet been addressed:
https://lore.kernel.org/linux-security-module/[email protected]/
Hopefully Fan can comment on that, unless I'm forgetting some implementation details it seems like a reasonable request.
Quoted 2 lines
Of course, it would also be nice if the commit message mentioned what the patch actually does.
While I think the commit description does provide a reasonable summary of IPE as it relates to fsverify, I agree that the specifics of the changes presented in the patch are lacking. Fan, could you update the commit description to add a paragraph explaining what IPE would do in the security_inode_setsecurity() hook called from within fsverity_inode_setsecurity()?
Quoted 6 lines
At a higher level, I've said before, I'm not super happy about the use of fsverity builtin signatures growing. (For some of the reasons why, see the guidance in the fsverity documentation at
https://docs.kernel.org/filesystems/fsverity.html#built-in-signature-verification)
That being said, if the people who are doing the broader review of IPE believe this is how its fsverity integration should work, I can live with that ...
Fan can surely elaborate on this more, but my understanding is that IPE can help provide the missing authorization piece.
Quoted 5 lines
... I don't
intend to block the IPE patchset if enough people want it to be merged. I've really been hoping to see engagement with the people involved in IMA, as IPE basically duplicates/replaces IMA. But I haven't seen that, so maybe things need to move on without them.
We are getting a bit beyond the integration of IPE and fsverity so I don't want to spend a lot of time here, but IPE and IMA work quite a bit differently as they serve different purposes. IPE provides a file authorization mechanism that grants access based on the specified policy and the file's underlying backing store; IPE does not measure files like IMA to provide additional integrity checking, it relies on the storage medium's integrity mechanisms.
I have no doubt Fan could provide a much better summary if needed, and of course there are the documentation patches in the patchset too.
Signature · 1 line
paul-moore.com
Re: [PATCH RFC v11 15/19] fsverity: consume builtin signature via LSM hook
Quoted 66 lines · Paul Moore
Quoted 65 lines · Eric Biggers
Quoted 64 lines · Paul Moore
Quoted 59 lines · Paul Moore
Quoted 50 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
fsverity represents a mechanism to support both integrity and authenticity protection of a file, supporting both signed and unsigned digests.
An LSM which controls access to a resource based on authenticity and integrity of said resource, can then use this data to make an informed decision on the authorization (provided by the LSM's policy) of said claim.
This effectively allows the extension of a policy enforcement layer in LSM for fsverity, allowing for more granular control of how a particular authenticity claim can be used. For example, "all (built-in) signed fsverity files should be allowed to execute, but only these hashes are allowed to be loaded as kernel modules".
This enforcement must be done in kernel space, as a userspace only solution would fail a simple litmus test: Download a self-contained malicious binary that never touches the userspace stack. This binary would still be able to execute.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Splitfs/verity/changes andsecurity/changes into separate patches
+ Change signature offsverity_create_infoto accept non-const inode
+ Change signature offsverity_verify_signatureto accept non-const inode
+ Don't cast-away const from inode.
+ Digest functionality dropped in favor of:
("fs-verity: define a function to return the integrity protected
file digest")
+ Reworded commit description and title to match changes.
+ Fix a bug wherein no LSM implements the particular fsverity @name (or LSM is disabled), and returns-EOPNOTSUPP, causing errors.v9:
+ No changesv10:
+ Rename the signature blob key
+ Cleanup redundant code
+ Make the hook call depends onCONFIG_FS_VERITY_BUILTIN_SIGNATURESQuoted 7 lines
v11:
+ No changes--- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 26 +++++++++++++++++++++++++- include/linux/fsverity.h | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-)Quoted 1 line
We need an ACK from some VFS folks on this.
Eric and/or Ted, can we get either an ACK or some feedback on this patch?
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
For reference, the full patchset can be found on lore at the link below:
https://lore.kernel.org/linux-security-module/[email protected]/
Well, technically I already gave some (minor) feedback on this exact patch, and it's not yet been addressed:
https://lore.kernel.org/linux-security-module/[email protected]/
Yes thanks for the review. We will certainly add the parameter constification in the next version.
Quoted 7 lines
Hopefully Fan can comment on that, unless I'm forgetting some implementation details it seems like a reasonable request.
Quoted 2 lines
Of course, it would also be nice if the commit message mentioned what the patch actually does.
Quoted 7 lines
While I think the commit description does provide a reasonable summary of IPE as it relates to fsverify, I agree that the specifics of the changes presented in the patch are lacking. Fan, could you update the commit description to add a paragraph explaining what IPE would do in the
security_inode_setsecurity()hook called from withinfsverity_inode_setsecurity()?
Sorry for the lack of clarity. The hook call happens right after the built-in signature verification in fsverity. This hook's main job is to allow LSM to store the verified signature so that it can be used for future LSM checks.
Quoted 10 lines
Quoted 6 lines
At a higher level, I've said before, I'm not super happy about the use of fsverity builtin signatures growing. (For some of the reasons why, see the guidance in the fsverity documentation at
https://docs.kernel.org/filesystems/fsverity.html#built-in-signature-verification)
That being said, if the people who are doing the broader review of IPE believe this is how its fsverity integration should work, I can live with that ...Fan can surely elaborate on this more, but my understanding is that IPE can help provide the missing authorization piece.
As Paul mentioned, with IPE, we can add kernel enforcement that only files with the fs-verity built-in signature enabled are allowed. Currently, IPE uses the above hook to save the signature in the file's security blob, and then it decides whether to permit or deny file operations based on the presence of the fs-verity built-in signature.
But our plans don't end there. In the future, we intend to add more features to address the security gaps mentioned in the documentation related to the fs-verity built-in signature. For instance, we will introduce a certificate policy rule to limit which signatures can be trusted, thus resolving issues related to the validity period of certificates. Additionally, we will implement file path rules, allowing different certificates to permit or deny access to different files.
Quoted 14 lines
Quoted 5 lines
... I don't
intend to block the IPE patchset if enough people want it to be merged. I've really been hoping to see engagement with the people involved in IMA, as IPE basically duplicates/replaces IMA. But I haven't seen that, so maybe things need to move on without them.We are getting a bit beyond the integration of IPE and fsverity so I don't want to spend a lot of time here, but IPE and IMA work quite a bit differently as they serve different purposes. IPE provides a file authorization mechanism that grants access based on the specified policy and the file's underlying backing store; IPE does not measure files like IMA to provide additional integrity checking, it relies on the storage medium's integrity mechanisms.
Quoted 3 lines
I have no doubt Fan could provide a much better summary if needed, and of course there are the documentation patches in the patchset too.
I would like to emphasize that IPE is not meant to replace IMA.
IPE is a different approach, specifically designed for a particular part of IMA's capabilities, which is "appraisal. While IPE's approach also limits IPE's use cases to highly secure, locked-down devices where almost everything is made read-only. In contrast, IMA is a versatile solution suitable for a wide range of scenarios, and IPE cannot address all of these.
In practice, we often use both IMA (including measurement and appraisal) and IPE simultaneously in production. These two solutions can coexist and complement each other, and they are not mutually exclusive.
-Fan
Re: [PATCH RFC v11 14/19] ipe: add support for dm-verity as a trust provider
In reply to Paul MooreQuoted 9 lines · Paul Moore
Quoted 8 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Allows author of IPE policy to indicate trust for a singular dm-verity volume, identified by roothash, through "
dmverity_roothash" and all signed dm-verity volumes, through "dmverity_signature".Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
...
Quoted 77 lines
Quoted 16 lines
security/ipe/Kconfig | 18 +++++ security/ipe/Makefile | 1 + security/ipe/audit.c | 31 +++++++- security/ipe/digest.c | 142 +++++++++++++++++++++++++++++++++++ security/ipe/digest.h | 26 +++++++ security/ipe/eval.c | 101 ++++++++++++++++++++++++- security/ipe/eval.h | 13 ++++ security/ipe/hooks.c | 51 +++++++++++++ security/ipe/hooks.h | 8 ++ security/ipe/ipe.c | 15 ++++ security/ipe/ipe.h | 4 + security/ipe/policy.h | 3 + security/ipe/policy_parser.c | 24 +++++- 13 files changed, 433 insertions(+), 4 deletions(-)create mode 100644
security/ipe/digest.c
create mode 100644security/ipe/digest.h...
Quoted 28 lines
security/ipe/audit.c +11
-0@@ -13,6 +13,7 @@#include "hooks.h" #include "policy.h" #include "audit.h" +#include "digest.h" #define ACTSTR (x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY")@@ -40,8 +41,29 @@ static const char *const audit_op_names[__IPE_OP_MAX] = {static const char *const audit_prop_names[__IPE_PROP_MAX] = {"boot_verified=FALSE" ,"boot_verified=TRUE" , +#ifdef CONFIG_IPE_PROP_DM_VERITY +"dmverity_roothash=" , +"dmverity_signature=FALSE" , +"dmverity_signature=TRUE" , +#endif /* CONFIG_IPE_PROP_DM_VERITY */ }; +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* audit_dmv_roothash - audit a roothash of a dmverity volume. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @r: Supplies a pointer to the digest structure. security/ipe/audit.c static const char *const audit_op_names[__IPE_OP_MAX] = { · line 65
Quoted 10 lines
security/ipe/audit.c +10
-0+*/ +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +ipe_digest_audit (ab, rh); +} +#else +static void audit_dmv_roothash (struct audit_buffer *ab,const void *rh) +{ +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ Since the "dmverity_roothash=" field name is going to be written to the audit record regardless of
CONFIG_IPE_PROP_DM_VERITYwe should ensure that it has a value of "?" instead of nothing. To fix that I would suggest something like this:#else static void audit_dmv_roothash(struct audit_buffer *ab, const void *rh) { audit_log_format(ab, "?"); } #endif /* CONFIG_IPE_PROP_DM_VERITY */Quoted 7 lines
security/ipe/audit.c +0
-0/** * audit_rule - audit an IPE policy rule approximation. * @ab: Supplies a pointer to the audit_buffer to append to. @@ -53,8 +75,13 @@ static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r)audit_log_format (ab,"rule=\"op=%s " , audit_op_names[r->op]);
Quoted 11 lines
security/ipe/audit.c static void audit_rule(struct audit_buffer *ab, const struct ipe_rule *r) · line 81
Quoted 6 lines
security/ipe/audit.c +4
-2-list_for_each_entry (ptr, &r->props, next) -audit_log_format (ab,"%s " , audit_prop_names[ptr->type]); +list_for_each_entry (ptr, &r->props, next) { +audit_log_format (ab,"%s" , audit_prop_names[ptr->type]); +if (ptr->type ==IPE_PROP_DMV_ROOTHASH ) +audit_dmv_roothash (ab, ptr->value);If you wanted to avoid the roothash change above, you could change the code here so it didn't always write "dmverity_roothash=" into the audit record.
Yes this sounds more reasonable to me, I will change this part to a switch case statement to avoid unnessary logging.
Quoted 30 lines
Quoted 30 lines
security/ipe/audit.c +2
-0+audit_log_format (ab," " ); + }audit_log_format (ab,"action=%s\"" ,ACTSTR (r->action)); }security/ipe/digest.c new file +19
-0@@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "digest.h" + +/** +* ipe_digest_parse - parse a digest in IPE's policy. +* @valstr: Supplies the string parsed from the policy. +* @value: Supplies a pointer to be populated with the result. +* +* Digests in IPE are defined in a standard way: +* <alg_name>:<hex> +* +* Use this function to create a property to parse the digest +* consistently. The parsed digest will be saved in @value in IPE's +* policy. +*
Quoted 9 lines
security/ipe/digest.c line 24
Quoted 5 lines
security/ipe/digest.c new file +5
-0+* Return: +* * 0 - OK +* * !0 - Error +*/ +int ipe_digest_parse (const char *valstr,void **value)Why is @value void? You should make it a
digest_infotype or simply skip the second parameter and return adigest_infopointer.
Yes it should better just return a digest_info type pointer. I will update this part.
Quoted 21 lines
Quoted 21 lines
security/ipe/digest.c new file +21
-0+{ +char *sep, *raw_digest; +size_t raw_digest_len; +int rc =0 ; +u8 *digest =NULL ; +struct digest_info *info =NULL ; + + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + sep =strchr (valstr,':' ); +if (!sep) { + rc = -EBADMSG ; + goto err; + } + + info->alg =kstrndup (valstr, sep - valstr,GFP_KERNEL ); +if (!info->alg) { + rc = -ENOMEM ; + goto err;
Quoted 9 lines
security/ipe/digest.c line 50
Quoted 5 lines
security/ipe/digest.c new file +5
-0+ } + + raw_digest = sep +1 ; + raw_digest_len =strlen (raw_digest); + info->raw_digest =kstrndup (raw_digest, raw_digest_len,GFP_KERNEL );Since you're running a
strlen()over @raw_digest, you might as well just usekstrdup()instead ofkstrndup().
Thanks I will update this part.
Quoted 41 lines
Quoted 41 lines
security/ipe/digest.c new file +41
-0+if (!info->raw_digest) { + rc = -ENOMEM ; + goto err_free_alg; + } + + info->digest_len = (raw_digest_len +1 ) /2 ; + digest =kzalloc (info->digest_len,GFP_KERNEL ); +if (!digest) { + rc = -ENOMEM ; + goto err_free_raw; + } + + rc =hex2bin (digest, raw_digest, info->digest_len); +if (rc <0 ) { + rc = -EINVAL ; + goto err_free_raw; + } + + info->digest = digest; + *value = info; +return 0 ; + +err_free_raw: +kfree (info->raw_digest); +err_free_alg: +kfree (info->alg); +err: +kfree (digest); +kfree (info); +return rc; +} + +/** +* ipe_digest_eval - evaluate an IPE digest against another digest. +* @expect: Supplies the policy-provided digest value. +* @digest: Supplies the digest to compare against the policy digest value. +* @digest_len: The length of @digest. +* @alg: Supplies the name of the algorithm used to calculated @digest. +* +* Return: +* * true - digests match
Quoted 9 lines
security/ipe/digest.c line 95
Quoted 4 lines
security/ipe/digest.c new file +4
-0+* * false - digests do not match +*/ +bool ipe_digest_eval (const void *expect,const u8 *digest,size_t digest_len, +const char *alg)Similar to the above, why not make the @expect parameter a
digest_infotype? Also, why not pass a seconddigest_infoparameter instead of a separate @digest, @digest_len, and @alg?
The digest_info was inteneded to be used for policy only, which also contains a raw string of digest in the policy that can be used during audit. After second thought I start to think the raw_digest seems unnecessary and I can refactor them all to use digest_info instead.
Quoted 80 lines
security/ipe/digest.c line 107
Quoted 12 lines
security/ipe/digest.c new file +12
-0+{ +const struct digest_info *info = (struct digest_info *)expect; + +return (digest_len == info->digest_len) && !strcmp (alg, info->alg) && + (!memcmp (info->digest, digest, info->digest_len)); +} + +/** +* ipe_digest_free - free an IPE digest. +* @value: Supplies a pointer the policy-provided digest value to free. +*/ +void ipe_digest_free (void **value)Another
digest_infoparameter/type issue.Quoted 18 lines
security/ipe/digest.c new file +18
-0+{ +struct digest_info *info = (struct digest_info *)(*value); + +if (IS_ERR_OR_NULL (info)) +return ; + +kfree (info->alg); +kfree (info->raw_digest); +kfree (info->digest); +kfree (info); +} + +/** +* ipe_digest_audit - audit a digest that was sourced from IPE's policy. +* @ab: Supplies the audit_buffer to append the formatted result. +* @val: Supplies a pointer to source the audit record from. +* +* Digests in IPE are defined in a standard way: security/ipe/digest.c line 135
Quoted 10 lines
security/ipe/digest.c new file +10
-0+* <alg_name>:<hex> +* +* Use this function to create a property to audit the digest +* consistently. +* +* Return: +* 0 - OK +* !0 - Error +*/ +void ipe_digest_audit (struct audit_buffer *ab,const void *val)Another
digest_infoparameter/type issue.Quoted 7 lines
security/ipe/digest.c new file +7
-0+{ +const struct digest_info *info = (struct digest_info *)val; + +audit_log_untrustedstring (ab, info->alg); +audit_log_format (ab,":" ); +audit_log_untrustedstring (ab, info->raw_digest); +}...
Quoted 11 lines
security/ipe/eval.c +2
-0@@ -69,15 +88,89 @@ void build_eval_ctx(struct ipe_eval_ctx *ctx, const struct file *file, enum ipe_op_type op) { +struct inode *ino =NULL ; +if (op ==IPE_OP_EXEC && file)security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 102
Quoted 10 lines
security/ipe/eval.c +3
-1pin_sb (FILE_SUPERBLOCK (file)); ctx->file = file; ctx->op = op; -if (file) +if (file) { ctx->from_init_sb =from_pinned (FILE_SUPERBLOCK (file)); + ino =d_real_inode (file->f_path.dentry); +build_ipe_bdev_ctx (ctx, ino);You don't need @ino.
Quoted 2 lines
build_ipe_bdev_ctx(ctx, d_real_inode(file->f_path.dentry));
This variable will make sense in the fsverity patch, I do agree it doesn't make sense for this one. Will remove it.
Quoted 25 lines
Quoted 11 lines
security/ipe/eval.c +11
-0+ } +} + +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* evaluate_dmv_roothash - Evaluate @ctx against a dmv roothash property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 123
Quoted 10 lines
security/ipe/eval.c +10
-0+* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_roothash (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return !!ctx->ipe_bdev && +ipe_digest_eval (p->value, + ctx->ipe_bdev->digest, + ctx->ipe_bdev->digest_len, + ctx->ipe_bdev->digest_algo);Building on my comments above in
ipe_digest_eval(), if you convert it to usedigest_infostructs this is simplified:
Quoted 2 lines
ipe_digest_eval(p->vlaue, ctx->ipe_bdev)
Yep but the seucrity blob also contains signature information. I will make it like ipe_digest_eval(p->vlaue, ctx->ipe_bdev->dmv_digest_info)
Quoted 27 lines
Quoted 27 lines
security/ipe/eval.c +27
-0+} + +/** +* evaluate_dmv_sig_false: Analyze @ctx against a dmv sig false property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_sig_false (const struct ipe_eval_ctx *const ctx, +struct ipe_prop *p) +{ +return !ctx->ipe_bdev || (!ctx->ipe_bdev->dm_verity_signed); +} + +/** +* evaluate_dmv_sig_true: Analyze @ctx against a dmv sig true property. +* @ctx: Supplies a pointer to the context being evaluated. +* @p: Supplies a pointer to the property being evaluated. +* +* Return: +* * true - The current @ctx match the @p +* * false - The current @ctx doesn't match the @p +*/ +static bool evaluate_dmv_sig_true(const struct ipe_eval_ctx *const ctx,
Quoted 9 lines
security/ipe/eval.c void build_eval_ctx(struct ipe_eval_ctx *ctx, · line 154
Quoted 4 lines
security/ipe/eval.c +4
-0+ struct ipe_prop *p) +{ +return ctx->ipe_bdev && (!!ctx->ipe_bdev->dm_verity_signed); +}Do you need both
evaluate_dmv_sig_true()andevaluate_dmv_sig_false()? If yes, you should make one call the other and return the inverse to help ensure there are no oddities.
Yes this code is redundant. I also found the ipe_prop *p variable is necssary. Will clean them up in the next version.
Quoted 39 lines
Quoted 39 lines
security/ipe/hooks.c +31
-0@@ -193,3 +196,51 @@ void ipe_sb_free_security(struct super_block *mnt_sb) {ipe_invalidate_pinned_sb (mnt_sb); } + +#ifdef CONFIG_IPE_PROP_DM_VERITY +/** +* ipe_bdev_free_security - free IPE's LSM blob of block_devices. +* @bdev: Supplies a pointer to a block_device that contains the structure +* to free. +*/ +void ipe_bdev_free_security (struct block_device *bdev) +{ +struct ipe_bdev *blob =ipe_bdev (bdev); + +kfree (blob->digest); +kfree (blob->digest_algo); +} + +/** +* ipe_bdev_setsecurity - save data from a bdev to IPE's LSM blob. +* @bdev: Supplies a pointer to a block_device that contains the LSM blob. +* @key: Supplies the string key that uniquely identifies the value. +* @value: Supplies the value to store. +* @len: The length of @value. +*/ +int ipe_bdev_setsecurity (struct block_device *bdev,const char *key, +const void *value,size_t len) +{ +struct ipe_bdev *blob =ipe_bdev (bdev); + +if (!strcmp (key,DM_VERITY_ROOTHASH_SEC_NAME )) { +const struct dm_verity_digest *digest = value; + + blob->digest =kmemdup (digest->digest, digest->digest_len,GFP_KERNEL );
Quoted 9 lines
security/ipe/hooks.c void ipe_sb_free_security(struct super_block *mnt_sb) · line 235
Quoted 6 lines
security/ipe/hooks.c +6
-0+if (!blob->digest) +return -ENOMEM ; + + blob->digest_algo =kstrdup_const (digest->algo,GFP_KERNEL ); +if (!blob->digest_algo) +return -ENOMEM ;You need to cleanup @blob on error so you don't leak
ipe_bdev::digest.
Thanks for catching that. I will fix this.
-Fan
Quoted 13 lines
security/ipe/hooks.c void ipe_sb_free_security(struct super_block *mnt_sb) · line 246
Quoted 10 lines
security/ipe/hooks.c +10
-0+ blob->digest_len = digest->digest_len; + return 0; + }else if (!strcmp (key,DM_VERITY_SIGNATURE_SEC_NAME )) { + blob->dm_verity_signed = true; +return 0 ; + } + +return -EOPNOTSUPP ; +} +#endif /* CONFIG_IPE_PROP_DM_VERITY */ --
paul-moore.com
Re: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
In reply to Paul MooreQuoted 108 lines · Paul Moore
Quoted 94 lines · Fan Wu
Quoted 21 lines · Paul Moore
Quoted 20 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>...
Quoted 66 lines
Quoted 51 lines
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)security/ipe/eval.c +26
-0@@ -9,6 +9,7 @@#include <linux/file.h> #include <linux/sched.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> #include "ipe.h" #include "eval.h" @@ -16,6 +17,44 @@struct ipe_policy __rcu *ipe_active_policy; +static const struct super_block *pinned_sb; +static DEFINE_SPINLOCK (pin_lock); +#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) + +/** +* pin_sb - Pin the underlying superblock of @f, marking it as trusted. +* @sb: Supplies a super_block structure to be pinned. +*/ +static void pin_sb (const struct super_block *sb) +{ +if (!sb) +return ; +spin_lock (&pin_lock); +if (!pinned_sb) + pinned_sb = sb; +spin_unlock (&pin_lock); +} + +/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);It's okay for an initial version, but I still think you need to get away from this spinlock in
from_pinned()as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.Quoted 4 lines
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in
super_block::securityyou could mark the superblock when it was mounted and do a lockless lookup here infrom_pinned().Quoted 4 lines
Thank you for the suggestion. After some testing, I discovered that switching to RCU to pin the super block and using a security blob to mark a pinned super block works. This approach do avoid many spinlock operations. I'll incorporate these changes in the next version of the patch.
I probably wasn't as clear as I should have been, I was thinking of doing away with the @pinned_sb global variable entirely, as well as its associated lock problems and simply marking the initramfs/initrd superblock when it was mounted. I will admit that I haven't fully thought about all the implementation details, but I think you could leverage the
security_sb_mount()hook to set a flag in IPE's superblock metadata when the initramfs was mounted.
Quoted 2 lines
--
paul-moore.com
I wasn't able to find a way to let LSM pin initramfs/initrd during mount time. But I think we could replace the global variable with a flag variable ipe_sb_state so we could use atomic operation to only mark one drive as pinned without any lock. The code will be like:
static void pin_sb(const struct super_block *sb)
{
if (!sb)
return;
if (!test_and_set_bit_lock(IPE_SB_PINNED, &ipe_sb_state)) {
ipe_sb(sb)->pinned = true;
}
}Would this sound better?
-Fan
Re: [PATCH RFC v11 8/19] uapi|audit|ipe: add ipe auditing support
In reply to Paul MooreQuoted 98 lines · Paul Moore
Quoted 97 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Users of IPE require a way to identify when and why an operation fails, allowing them to both respond to violations of policy and be notified of potentially malicious actions on their systems with respect to IPE itself.
This patch introduces 3 new audit events.
AUDIT_IPE_ACCESS(1420)indicates the result of an IPE policy evaluation of a resource.AUDIT_IPE_CONFIG_CHANGE(1421)indicates the current active IPE policy has been changed to another loaded policy.AUDIT_IPE_POLICY_LOAD(1422)indicates a new IPE policy has been loaded into the kernel.This patch also adds support for success auditing, allowing users to identify why an allow decision was made for a resource. However, it is recommended to use this option with caution, as it is quite noisy.
Here are some examples of the new audit record types:
AUDIT_IPE_ACCESS(1420):audit: AUDIT1420 path="/root/vol/bin/hello" dev="sda"
ino=3897 rule="op=EXECUTE boot_verified=TRUE action=ALLOW"audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0"
ino=2 rule="DEFAULT action=DENY"audit: AUDIT1420 path="/tmp/tmpdp2h1lub/deny/bin/hello" dev="tmpfs"
ino=131 rule="DEFAULT action=DENY"The above three records were generated when the active IPE policy only allows binaries from the initial booted drive(sda) to run. The three identical
hellobinary were placed at different locations, only the first hello from sda was allowed.Field path followed by the file's path name.
Field dev followed by the device name as found in /dev where the file is from.
Note that for device mappers it will use the namedm-Xinstead of the name in/dev/mapper.
For a file in a temp file system, which is not from a device, it will usetmpfsfor the field.
The implementation of this part is following another existing use caseLSM_AUDIT_DATA_INODEinsecurity/lsm_audit.cField ino followed by the file's inode number.
Field rule followed by the IPE rule made the access decision. The whole rule must be audited because the decision is based on the combination of all property conditions in the rule.
Along with the syscall audit event, user can know why a blocked happened. For example:
audit: AUDIT1420 path="/mnt/ipe/bin/hello" dev="dm-0" ino=2 rule="DEFAULT action=DENY" audit[1956]: SYSCALL arch=c000003e syscall=59 success=no exit=-13 a0=556790138df0 a1=556790135390 a2=5567901338b0 a3=ab2a41a67f4f1f4e items=1 ppid=147 pid=1956 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=4294967295 comm="bash" exe="/usr/bin/bash" key=(null)The above two records showed bash used execve to run "hello" and got blocked by IPE. Note that the IPE records are always prior to a SYSCALL record.
AUDIT_IPE_CONFIG_CHANGE(1421):audit: AUDIT1421 old_active_pol_name="Allow_All" old_active_pol_version=0.0.0 old_policy_digest=sha256:E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649 new_active_pol_name="boot_verified" new_active_pol_version=0.0.0 new_policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F auid=4294967295 ses=4294967295 lsm=ipe res=1The above record showed the current IPE active policy switch from
Allow_Alltoboot_verifiedalong with the version and the hash digest of the two policies. Note IPE can only have one policy active at a time, all access decision evaluation is based on the current active policy.
The normal procedure to deploy a policy is loading the policy to deploy into the kernel first, then switch the active policy to it.
AUDIT_IPE_POLICY_LOAD(1422):audit: AUDIT1422 policy_name="boot_verified" policy_version=0.0.0 policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F26765076DD auid=4294967295 ses=4294967295 lsm=ipe res=1
The above record showed a new policy has been loaded into the kernel with the policy name, policy version and policy hash.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>
...
Quoted 61 lines
Quoted 13 lines
--- include/uapi/linux/audit.h | 3 + security/ipe/Kconfig | 2 +- security/ipe/Makefile | 1 + security/ipe/audit.c | 195 +++++++++++++++++++++++++++++++++++++ security/ipe/audit.h | 18 ++++ security/ipe/eval.c | 32 ++++-- security/ipe/eval.h | 8 ++ security/ipe/fs.c | 70 +++++++++++++ security/ipe/policy.c | 5 + 9 files changed, 327 insertions(+), 7 deletions(-)create mode 100644
security/ipe/audit.c
create mode 100644security/ipe/audit.h...
Quoted 45 lines
security/ipe/audit.c new file +39
-0@@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/slab.h> +#include <linux/audit.h> +#include <linux/types.h> +#include <crypto/hash.h> + +#include "ipe.h" +#include "eval.h" +#include "hooks.h" +#include "policy.h" +#include "audit.h" + +#define ACTSTR (x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY") + +#define IPE_AUDIT_HASH_ALG "sha256" + +#define AUDIT_POLICY_LOAD_FMT "policy_name=\"%s\" policy_version=%hu.%hu.%hu "\ + "policy_digest=" IPE_AUDIT_HASH_ALG ":" +#define AUDIT_OLD_ACTIVE_POLICY_FMT "old_active_pol_name=\"%s\" "\ + "old_active_pol_version=%hu.%hu.%hu "\ + "old_policy_digest=" IPE_AUDIT_HASH_ALG ":" +#define AUDIT_NEW_ACTIVE_POLICY_FMT "new_active_pol_name=\"%s\" "\ + "new_active_pol_version=%hu.%hu.%hu "\ + "new_policy_digest=" IPE_AUDIT_HASH_ALG ":" + +static const char *const audit_op_names[__IPE_OP_MAX] = { +"EXECUTE" , +"FIRMWARE" , +"KMODULE" , +"KEXEC_IMAGE" , +"KEXEC_INITRAMFS" , +"IMA_POLICY" , +"IMA_X509_CERT" , +}; +
Quoted 9 lines
security/ipe/audit.c line 43
Quoted 4 lines
security/ipe/audit.c new file +4
-0+static const char *const audit_prop_names[__IPE_PROP_MAX] = { +"boot_verified=FALSE" , +"boot_verified=TRUE" , +};I would suggest taking the same approach for both @audit_op_names and @audit_prop_names; either include the field name in the string array for both or leave it out of both.
Yes sure, I will move the "op=" into audit_op_names.
Quoted 22 lines
Quoted 22 lines
security/ipe/audit.c new file +22
-0+/** +* audit_rule - audit an IPE policy rule approximation. +* @ab: Supplies a pointer to the audit_buffer to append to. +* @r: Supplies a pointer to the ipe_rule to approximate a string form for. +*/ +static void audit_rule (struct audit_buffer *ab,const struct ipe_rule *r) +{ +const struct ipe_prop *ptr; + +audit_log_format (ab,"rule=\"op=%s " , audit_op_names[r->op]); + +list_for_each_entry (ptr, &r->props, next) +audit_log_format (ab,"%s " , audit_prop_names[ptr->type]); + +audit_log_format (ab,"action=%s\"" ,ACTSTR (r->action)); +} + +/** +* ipe_audit_match - audit a match for IPE policy. +* @ctx: Supplies a pointer to the evaluation context that was used in the +* evaluation. +* @match_type: Supplies the scope of the match: rule, operation default,
Quoted 9 lines
security/ipe/audit.c line 72
Quoted 6 lines
security/ipe/audit.c new file +6
-0+* global default. +* @act: Supplies the IPE's evaluation decision, deny or allow. +* @r: Supplies a pointer to the rule that was matched, if possible. +* @enforce: Supplies the enforcement/permissive state at the point +* the enforcement decision was made. +*/ Does it make sense to move @match_type into the
ipe_eval_ctxstruct?
I feel the @match_type is part of the evaluation result information, which is the result of the context against the active policy. So I prefer keeping it as a local variable in the evaluation loop.
-Fan
Quoted 39 lines
Quoted 26 lines
security/ipe/audit.c new file +26
-0+void ipe_audit_match (const struct ipe_eval_ctx *const ctx, +enum ipe_match match_type, +enum ipe_action_type act,const struct ipe_rule *const r) +{ +struct inode *inode; +struct audit_buffer *ab; +const char *op = audit_op_names[ctx->op]; + +if (act !=IPE_ACTION_DENY && !READ_ONCE (success_audit)) +return ; + + ab =audit_log_start (audit_context (),GFP_KERNEL ,AUDIT_IPE_ACCESS ); +if (!ab) +return ; + +if (ctx->file) { +audit_log_d_path (ab,"path=" , &ctx->file->f_path); + inode =file_inode (ctx->file); +if (inode) { +audit_log_format (ab," dev=" ); +audit_log_untrustedstring (ab, inode->i_sb->s_id); +audit_log_format (ab," ino=%lu " , inode->i_ino); + } + } + +if (match_type ==IPE_MATCH_RULE )security/ipe/audit.c line 108
Quoted 10 lines
security/ipe/audit.c new file +10
-0+audit_rule (ab, r); + else if (match_type == IPE_MATCH_TABLE) + audit_log_format(ab, "rule=\"DEFAULT op=%s action=%s\"", op, + ACTSTR(act)); + else + audit_log_format(ab, "rule=\"DEFAULT action=%s\"", + ACTSTR(act)); + +audit_log_end (ab); +}--
paul-moore.com
Re: [PATCH RFC v11 9/19] ipe: add permissive toggle
In reply to Paul MooreQuoted 114 lines · Paul Moore
Quoted 94 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE, like SELinux, supports a permissive mode. This mode allows policy authors to test and evaluate IPE policy without it effecting their programs. When the mode is changed, a 1404
AUDIT_MAC_STATUSbe reported.This patch adds the following audit records:
audit: MAC_STATUS enforcing=0 old_enforcing=1 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1 audit: MAC_STATUS enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1The audit record only emit when the value from the user input is different from the current enforce value.
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ Split evaluation loop, access control hooks, and evaluation loop from policy parser and userspace interface to pass mailing list character limitv3:
+ Moveipe_load_propertiesto patch 04.
+ Remove useless 0-initializations
+ Prefix extern variables withipe_
+ Remove kernel module parameters, as these are exposed through sysctls.
+ Add more prose to the IPE base config option help text.
+ UseGFP_KERNELforaudit_log_start.
+ Remove unnecessary caching system.
+ Remove comments from headers
+ Usercu_access_pointerfor rcu-pointer null check
+ Remove usage of reqprot; use prot only.
+ Move policy load and activation audit event to 03/12v4:
+ Remove sysctls in favor of securityfs nodes
+ Re-add kernel module parameters, as these are now exposed through securityfs.
+ Refactor property audit loop to a separate function.v5:
+ fix minor grammatical errors
+ do not group rule by curly-brace in audit record, reconstruct the exact rule.v6:
+ No changesv7:
+ Further split lsm creation into a separate commit from the evaluation loop and audit system, for easier review.
+ Propagating changes to support the newipe_contextstructure in the evaluation loop.
+ Split out permissive functionality into a separate patch for easier review.
+ Remove permissive switch compile-time configuration option - this is trivial to add later.v8:
+ Remove "IPE" prefix from permissive audit record
+ align fields to the linux-audit field dictionary. This causes the following fields to change:
enforce -> permissive+ Remove duplicated information correlated with syscall record, that will always be present in the audit event.
+ Change audit types:
+AUDIT_TRUST_STATUS->AUDIT_MAC_STATUS
+ There is no significant difference in meaning between these types.v9:
+ Clean upipe_contextrelated codev10:
+ Change audit format to comform with the existing format selinux is using
+ Remove the audit record emission during init to align with selinux, which does not perform this action.v11:
+ Remove redundant code--- security/ipe/audit.c | 22 ++++++++++++++ security/ipe/audit.h | 1 + security/ipe/eval.c | 14 +++++++-- security/ipe/eval.h | 1 + security/ipe/fs.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-)...
security/ipe/eval.c int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx) · line 178
Quoted 13 lines
security/ipe/eval.c +4
-1@@ -167,9 +172,12 @@ int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)ipe_audit_match (ctx, match_type, action, rule);if (action ==IPE_ACTION_DENY ) -return -EACCES ; + rc = -EACCES ; + +if (!enforcing) + rc =0 ;Why the local @enforcing variable? Why not:
Quoted 3 lines
if (!READ_ONCE(enforce))
rc = 0;Yes the variable is unnecessary, I will remove it. -Fan
Quoted 16 lines
security/ipe/eval.c void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb) · line 210
Quoted 11 lines
security/ipe/eval.c +3
-1-return 0 ; +return rc; }/** @@ -198,3 +206,5 @@ void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)module_param (success_audit, bool,0400 );MODULE_PARM_DESC (success_audit,"Start IPE with success auditing enabled" ); +module_param (enforce, bool,0400 ); +MODULE_PARM_DESC (enforce,"Start IPE in enforce or permissive mode" );"enforcing"
--
paul-moore.com
Re: [PATCH RFC v11 17/19] scripts: add boot policy generation program
In reply to Paul MooreQuoted 103 lines · Paul Moore
Quoted 61 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Enables an IPE policy to be enforced from kernel start, enabling access control based on trust from kernel startup. This is accomplished by transforming an IPE policy indicated by
CONFIG_IPE_BOOT_POLICYinto a c-string literal that is parsed at kernel startup as an unsigned policy.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v2:
+ No Changesv3:
+ No Changesv4:
+ No Changesv5:
+ No Changesv6:
+ No Changesv7:
+ Move from 01/11 to 14/16
+ Don't return errno directly.
+ Make output of script more user-friendly
+ Add escaping for tab and '?'
+ Mark argv pointer const
+ Invert return code check in the boot policy parsing code path.v8:
+ No significant changes.v9:
+ No changesv10:
+ Update the init part code for rcu changes in the eval loop patchv11:
+ Fix code style issues--- MAINTAINERS | 1 + scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 6 ++ scripts/ipe/polgen/polgen.c | 145 ++++++++++++++++++++++++++++++++++ security/ipe/.gitignore | 1 + security/ipe/Kconfig | 10 +++ security/ipe/Makefile | 11 +++ security/ipe/fs.c | 8 ++ security/ipe/ipe.c | 12 +++ 11 files changed, 198 insertions(+)create mode 100644
scripts/ipe/Makefilecreate mode 100644scripts/ipe/polgen/.gitignorecreate mode 100644scripts/ipe/polgen/Makefilecreate mode 100644scripts/ipe/polgen/polgen.ccreate mode 100644security/ipe/.gitignore...
Quoted 6 lines
scripts/ipe/polgen/polgen.c new file +0
-0@@ -0,0 +1,145 @@...
Quoted 29 lines
scripts/ipe/polgen/polgen.c new file +29
-0+static int write_boot_policy (const char *pathname,const char *buf,size_t size) +{ +int rc =0 ; +FILE *fd; +size_t i; + + fd =fopen (pathname,"w" ); +if (!fd) { + rc = errno; + goto err; + } + +fprintf (fd,"/* This file is automatically generated." ); +fprintf (fd," Do not edit. */\n" ); +fprintf (fd,"#include <linux/stddef.h>\n" ); +fprintf (fd,"\nextern const char *const ipe_boot_policy;\n\n" ); +fprintf (fd,"const char *const ipe_boot_policy =\n" ); + +if (!buf || size ==0 ) { +fprintf (fd,"\tNULL;\n" ); +fclose (fd); +return 0 ; + } + +fprintf (fd,"\t\"" ); + +for (i =0 ; i < size; ++i) { +switch (buf[i]) { +case '"' :
Quoted 8 lines
scripts/ipe/polgen/polgen.c line 95
Quoted 5 lines
scripts/ipe/polgen/polgen.c new file +5
-0+fprintf (fd,"\\\"" ); +break ; +case '\'' : +fprintf (fd,"'" ); +break ;The revision of IPE proposed in this patchset doesn't support parsing single or double quotes, yes? >
Actually all characters can be used in the policy. The previous revision was removing the quote syntax, which supports having space in the policy name like policy_name="example policy". But that is not related to the boot policy generation code here.
The code here is to generate a C source code that will be linked into IPE. Thus we have to escape these characters to conform with the C language string literal standard.
-Fan
Quoted 45 lines
scripts/ipe/polgen/polgen.c line 107
Quoted 12 lines
scripts/ipe/polgen/polgen.c new file +12
-0+case '\n' : +fprintf (fd,"\\n\"\n\t\"" ); +break ; +case '\\' : +fprintf (fd,"\\\\" ); +break ; +case '\t' : +fprintf (fd,"\\t" ); +break ; +case '\?' : +fprintf (fd,"\\?" ); +break ;Similar, are question marks supported by the parser?
Quoted 14 lines
scripts/ipe/polgen/polgen.c new file +14
-0+default : +fprintf (fd,"%c" , buf[i]); + } + } +fprintf (fd,"\";\n" ); +fclose (fd); + +return 0 ; + +err: +if (fd) +fclose (fd); +return rc; +}...
security/ipe/.gitignore line 1
Quoted 8 lines
security/ipe/.gitignore new file +1
-0@@ -0,0 +1 @@ +boot-policy.cAdd a newline please.
--
paul-moore.com
Re: [PATCH RFC v11 18/19] ipe: kunit test for parser
In reply to Paul MooreQuoted 5 lines · Paul Moore
Quoted 2 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
Add various happy/unhappy unit tests for both IPE's parser.
I'm going to suggest: "... for IPE's policy parser."
Yeah this sounds more precise.
Quoted 16 lines
Also, aside from the policy parser tests, are there any other IPE functional tests? We do have a testing guideline for new LSM submissions:
"New LSMs must be accompanied by a test suite to verify basic
functionality and help identify regressions. The test suite must be publicly available without download restrictions requiring accounts, subscriptions, etc. Test coverage does not need to reach a specific percentage, but core functionality and any user interfaces should be well covered by the test suite. Maintaining the test suite in a public git repository is preferable over tarball snapshots. Integrating the test suite with existing automated Linux kernel testing services is encouraged."
Yes we do have a test suite. I will add it in the next version. -Fan
Quoted 31 lines
Quoted 20 lines
Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>---
v1-v6:
+ Not presentv7:
Introducedv8:
+ Remove the kunit tests with respect to the fsverity digest, as these require significant changes to work with the new method of acquiring the digest at runtime.v9:
+ Remove the kunit tests related toipe_contextv10:
+ No changesQuoted 8 lines
v11:
+ No changes--- security/ipe/Kconfig | 17 +++ security/ipe/Makefile | 3 + security/ipe/policy_tests.c | 294 ++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+)create mode 100644
security/ipe/policy_tests.c--
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
In reply to Fan WuQuoted 34 lines · Fan Wu
Quoted 33 lines · Paul Moore
Quoted 32 lines · Fan Wu
Quoted 21 lines · Paul Moore
Quoted 20 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>...
Quoted 9 lines
Quoted 9 lines
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)
...
Quoted 40 lines
Quoted 32 lines
Quoted 27 lines
Quoted 22 lines
Quoted 7 lines
security/ipe/eval.c +7
-0+/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);It's okay for an initial version, but I still think you need to get away from this spinlock in
from_pinned()as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.Quoted 4 lines
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in
super_block::securityyou could mark the superblock when it was mounted and do a lockless lookup here infrom_pinned().Quoted 4 lines
Thank you for the suggestion. After some testing, I discovered that switching to RCU to pin the super block and using a security blob to mark a pinned super block works. This approach do avoid many spinlock operations. I'll incorporate these changes in the next version of the patch.
Quoted 7 lines
I probably wasn't as clear as I should have been, I was thinking of doing away with the @pinned_sb global variable entirely, as well as its associated lock problems and simply marking the initramfs/initrd superblock when it was mounted. I will admit that I haven't fully thought about all the implementation details, but I think you could leverage the
security_sb_mount()hook to set a flag in IPE's superblock metadata when the initramfs was mounted.
Quoted 2 lines
I wasn't able to find a way to let LSM pin initramfs/initrd during mount time ...
I haven't had to look at the kernel init code in a while, and I don't recall ever looking at the initramfs code, but I spent some time digging through the code and I wonder if it would be possible to mark the initramfs superblock in wait_for_initramfs() via a new LSM hook using @current->fs->root.mnt->mnt_sb? Although I'm not completely sure that it's populated. Have you already looked at an approach like this?
Quoted 17 lines
But I think we could replace the global variable with a flag variable
ipe_sb_stateso we could use atomic operation to only mark one drive as pinned without any lock. The code will be like:static void
pin_sb(const struct super_block *sb){ if (!sb) return; if (!test_and_set_bit_lock(IPE_SB_PINNED, &ipe_sb_state)) { ipe_sb(sb)->pinned = true; } }Would this sound better?
-Fan
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH RFC v11 5/19] ipe: introduce 'boot_verified' as a trust provider
Quoted 81 lines · Paul Moore
Quoted 34 lines · Fan Wu
Quoted 33 lines · Paul Moore
Quoted 32 lines · Fan Wu
Quoted 21 lines · Paul Moore
Quoted 20 lines · On Oct 4, 2023 Fan Wu <[email protected]> wrote:
IPE is designed to provide system level trust guarantees, this usually implies that trust starts from bootup with a hardware root of trust, which validates the bootloader. After this, the bootloader verifies the kernel and the initramfs.
As there's no currently supported integrity method for initramfs, and it's typically already verified by the bootloader, introduce a property that causes the first superblock to have an execution to be "pinned", which is typically initramfs.
When the "pinned" device is unmounted, it will be "unpinned" and
boot_verifiedproperty will always evaluate to false afterward.We use a pointer with a
spin_lockto "pin" the device instead of rcu because rcu synchronization may sleep, which is not allowed when unmounting a device.Signed-off-by Deven Bowers <[email protected]>Signed-off-by Fan Wu <[email protected]>...
Quoted 9 lines
Quoted 9 lines
--- security/ipe/eval.c | 72 +++++++++++++++++++++++++++++++++++- security/ipe/eval.h | 2 + security/ipe/hooks.c | 12 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/policy.h | 2 + security/ipe/policy_parser.c | 35 +++++++++++++++++- 7 files changed, 124 insertions(+), 2 deletions(-)...
Quoted 40 lines
Quoted 32 lines
Quoted 27 lines
Quoted 22 lines
Quoted 7 lines
security/ipe/eval.c +7
-0+/** +* from_pinned - Determine whether @sb is the pinned super_block. +* @sb: Supplies a super_block to check against the pinned super_block. +* +* Return: +* * true - @sb is the pinned super_block +* * false - @sb is not the pinned super_block security/ipe/eval.c line 54
Quoted 10 lines
security/ipe/eval.c +10
-0+*/ +static bool from_pinned (const struct super_block *sb) +{ +bool rv; + +if (!sb) +return false; +spin_lock (&pin_lock); + rv = !IS_ERR_OR_NULL (pinned_sb) && pinned_sb == sb; +spin_unlock (&pin_lock);It's okay for an initial version, but I still think you need to get away from this spinlock in
from_pinned()as quickly as possible. Maybe I'm wrong, but this looks like a major source of lock contention.Quoted 4 lines
I understand the issue around RCU and the potential for matching on a reused buffer/address, but if you modified IPE to have its own LSM security blob in
super_block::securityyou could mark the superblock when it was mounted and do a lockless lookup here infrom_pinned().Quoted 4 lines
Thank you for the suggestion. After some testing, I discovered that switching to RCU to pin the super block and using a security blob to mark a pinned super block works. This approach do avoid many spinlock operations. I'll incorporate these changes in the next version of the patch.
Quoted 7 lines
I probably wasn't as clear as I should have been, I was thinking of doing away with the @pinned_sb global variable entirely, as well as its associated lock problems and simply marking the initramfs/initrd superblock when it was mounted. I will admit that I haven't fully thought about all the implementation details, but I think you could leverage the
security_sb_mount()hook to set a flag in IPE's superblock metadata when the initramfs was mounted.Quoted 2 lines
I wasn't able to find a way to let LSM pin initramfs/initrd during mount time ...
Quoted 7 lines
I haven't had to look at the kernel init code in a while, and I don't recall ever looking at the initramfs code, but I spent some time digging through the code and I wonder if it would be possible to mark the initramfs superblock in
wait_for_initramfs()via a new LSM hook using @current->fs->root.mnt->mnt_sb? Although I'm not completely sure that it's populated. Have you already looked at an approach like this?
Thinking about this more, the current IPE approach of treating the first file access as being present in the initramfs is not correct (one could build a system without an initramfs). I think we need to do something like the above where the initramfs is explicitly marked in the initramfs code.
Quoted 15 lines
Quoted 15 lines
But I think we could replace the global variable with a flag variable
ipe_sb_stateso we could use atomic operation to only mark one drive as pinned without any lock. The code will be like:static void
pin_sb(const struct super_block *sb){ if (!sb) return; if (!test_and_set_bit_lock(IPE_SB_PINNED, &ipe_sb_state)) { ipe_sb(sb)->pinned = true; } }Would this sound better?
Signature · 1 line
paul-moore.com