Integrity Policy Enforcement (IPE)
Subsystems (11)
RFC PATCH v7 1/16 security: add ipe lsm & initial context creation
In reply to [email protected]From: 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 that every process in the kernel is associated with a context that determines the policy for what is trusted by said process and its descendents, starting with 'init'.
---
Relevant changes since v6:
* Split up patch 02/11 into three parts:
1. context creation (new) [this patch]
2. parser (refactored)
3. evaluation loop
* Refactor series to:
1. Support a context structure, enabling easier testing
--- MAINTAINERS | 6 ++ security/Kconfig | 11 +-- security/Makefile | 1 + security/ipe/Kconfig | 19 +++++ security/ipe/Makefile | 11 +++ security/ipe/ctx.c | 161 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/ctx.h | 28 ++++++++ security/ipe/hooks.c | 58 +++++++++++++++ security/ipe/hooks.h | 16 +++++ security/ipe/ipe.c | 57 +++++++++++++++ security/ipe/ipe.h | 19 +++++ 11 files changed, 382 insertions(+), 5 deletions(-) create mode 100644 security/ipe/Kconfig create mode 100644 security/ipe/Makefile create mode 100644 security/ipe/ctx.c create mode 100644 security/ipe/ctx.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
MAINTAINERS +6 -0
@@ -9279,6 +9279,12 @@ S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git F: security/integrity/ima/ +INTEGRITY POLICY ENFORCEMENT (IPE) +M: Deven Bowers <[email protected]> +M: Fan Wu <[email protected]> +S: Supported +F: security/ipe/ + INTEL 810/815 FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]> L: [email protected]
security/Kconfig +6 -5
@@ -239,6 +239,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"
@@ -278,11 +279,11 @@ endchoice config LSM string "Ordered list of enabled LSMs" - default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC - default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" + default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf,ipe" if DEFAULT_SECURITY_SMACK + default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf,ipe" if DEFAULT_SECURITY_APPARMOR + default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf,ipe" if DEFAULT_SECURITY_TOMOYO + default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf,ipe" if DEFAULT_SECURITY_DAC + default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf,ipe" help A comma-separated list of LSMs, in initialization order. Any LSMs left off this list will be ignored. This can be
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 +19 -0
@@ -0,0 +1,19 @@ +# 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 subsystem + allowing systems to enforce integrity having no dependencies + on filesystem metadata, making its decisions based off of kernel- + resident features and data structures. A key feature of IPE is a + customizable policy to allow admins to reconfigure integrity + requirements on the fly. + + If unsure, answer N.
security/ipe/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# 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) += \ + ctx.o \ + hooks.o \ + ipe.o \
security/ipe/ctx.c new file +161 -0
161 lines not on this page · raw message
security/ipe/ctx.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef IPE_CONTEXT_H +#define IPE_CONTEXT_H + +#include <linux/sched.h> +#include <linux/types.h> +#include <linux/refcount.h> +#include <linux/spinlock.h> +#include <linux/workqueue.h> + +struct ipe_context { +refcount_t refcount; +/* Protects concurrent writers */ +spinlock_t lock; + +struct work_struct free_work; +}; + +int __init ipe_init_ctx (void ); +struct ipe_context __rcu **ipe_tsk_ctx (struct task_struct *tsk); +struct ipe_context *ipe_current_ctx (void ); +struct ipe_context *ipe_get_ctx_rcu (struct ipe_context __rcu *ctx); +void ipe_put_ctx (struct ipe_context *ctx); + +#endif /* IPE_CONTEXT_H */
security/ipe/hooks.c new file +58 -0
58 lines not on this page · raw message
security/ipe/hooks.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef IPE_HOOKS_H +#define IPE_HOOKS_H + +#include <linux/types.h> +#include <linux/sched.h> + +int ipe_task_alloc (struct task_struct *task, +unsigned long clone_flags); + +void ipe_task_free (struct task_struct *task); + +#endif /* IPE_HOOKS_H */
security/ipe/ipe.c new file +57 -0
57 lines not on this page · raw message
security/ipe/ipe.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef IPE_H +#define IPE_H + +#define pr_fmt (fmt) "IPE " fmt "\n" + +#include "ctx.h" + +#include <linux/types.h> +#include <linux/sched.h> +#include <linux/lsm_hooks.h> + +extern struct lsm_blob_sizes ipe_blobs; + +#endif /* IPE_H */
Signature · 1 line
2.33.0
v7 cover Integrity Policy Enforcement (IPE)
From: Deven Bowers <[email protected]>
Overview:
---------
IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing systems approach use labels or paths which control access to a resource, IPE controls access to a resource based on the system's trust of said resource.
Trust requirements are established via IPE's policy, sourcing multiple different implementations within the kernel to build a cohesive trust model, based on how the system was built.
Trust, with respect to computing, is a concept that designates a set of entities who will endorse a set of resources as non-malicious. Traditionally, this is done via signatures, which is the act of endorsing a resource.
Integrity, on the other hand, is the concept of ensuring that a resource has not been modified since a point of time. This is typically done through cryptographic hashes or signatures.
Trust and integrity are very closely tied together concepts, as integrity is the way you can prove trust for a resource; otherwise it could have been modified by an entity who is untrusted.
IPE provides a way for a user to express trust requirements of resources, by using pre-existing systems which provide the integrity half of the equation.
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. Instead, IPE supports the PKI Trust Model, which generally designates a set of entities that provide a measure absolute trust.
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.
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 (NOT the policy syntax version). 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 properties: "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 will allow any execution. 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. Available properties for IPE described in the documentation patch of this series.
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. 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. User mode can interrogate the kernel to understand what properties and the associated versions through the securityfs node, $securityfs/ipe/config, which will return a string of form:
key1=version1
key2=version2
.
.
.
keyN=versionN
User-mode should correlate these versions with the supported values identified in the documentation to determine whether a policy should be accepted by the system without actually trying to deploy 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, 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 userland 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:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE dmverity_roothash=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="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec146938 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" -binary -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: The securityfs commands 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_SECURITY_IPE=y
CONFIG_SECURITY_IPE_KUNIT_TEST=y
CONFIG_IPE_PROP_BOOT_VERIFIED=y
CONFIG_IPE_PROP_DM_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_DM_VERITY_ROOTHASH=y
CONFIG_IPE_PROP_FS_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_FS_VERITY_DIGEST=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. This includes architectural block diagrams.
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. However, there is a patchset that is looking to address this gap [1].
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/all/[email protected]/
FAQ:
----
Q: What's the difference between other LSMs which provide trust-based
access control, for instance, IMA?
A: IMA is a fantastic option when needing measurement in addition to the
trust-based access model. All of IMA is centered around their measurement hashes, so you save time when doing both actions. IPE, on the other hand, is a highly performant system that does not rely (and explicitly prohibits), generating its own integrity mechanisms - separating measurement and access control. Simply put, IPE provides only the enforcement of trust, while other subsystems provide the integrity guarantee that IPE needs to determine the trust of a resource. IMA provides both the integrity guarantee, the enforcement of trust, and a whole host of other features that may not be needed.
Changelog:
----------
Changes since v1:
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.
Changes since v2:
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.
Changes since v3:
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.
Changes since v4:
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.
Changes since v5:
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.
Changes since v6:
* 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
Deven Bowers (14):
security: add ipe lsm & initial context creation
ipe: add policy parser
ipe: add evaluation loop
ipe: add userspace interface
ipe: add LSM hooks on execution and kernel read uapi|audit: add trust audit message definitions
ipe: add auditing support
ipe: add permissive toggle
ipe: introduce 'boot_verified' as a trust provider fs|dm-verity: add block_dev LSM blob and submit dm-verity data
ipe: add support for dm-verity as a trust provider
scripts: add boot policy generation program
ipe: kunit tests
documentation: add ipe documentation
Fan Wu (2):
fsverity|security: add security hooks to fsverity digest and signature
ipe: enable support for fs-verity as a trust provider
Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 587 ++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 339 ++++++ MAINTAINERS | 9 + block/bdev.c | 7 + drivers/md/dm-verity-target.c | 20 +- drivers/md/dm-verity-verify-sig.c | 16 +- drivers/md/dm-verity-verify-sig.h | 10 +- fs/verity/open.c | 12 + fs/verity/signature.c | 5 +- include/asm-generic/vmlinux.lds.h | 16 + include/linux/blk_types.h | 1 + include/linux/device-mapper.h | 3 + include/linux/fsverity.h | 3 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 12 + include/linux/security.h | 22 + include/uapi/linux/audit.h | 4 + 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/ipe/.gitignore | 1 + security/ipe/Kconfig | 100 ++ security/ipe/Makefile | 39 + security/ipe/audit.c | 304 +++++ security/ipe/audit.h | 41 + security/ipe/ctx.c | 381 ++++++ security/ipe/ctx.h | 43 + security/ipe/ctx_test.c | 732 ++++++++++++ security/ipe/eval.c | 237 ++++ security/ipe/eval.h | 57 + security/ipe/fs.c | 327 ++++++ security/ipe/fs.h | 13 + security/ipe/hooks.c | 328 ++++++ security/ipe/hooks.h | 56 + security/ipe/ipe.c | 143 +++ security/ipe/ipe.h | 27 + security/ipe/ipe_parser.h | 59 + security/ipe/modules.c | 134 +++ security/ipe/modules.h | 17 + security/ipe/modules/Kconfig | 66 ++ security/ipe/modules/Makefile | 12 + security/ipe/modules/boot_verified.c | 24 + security/ipe/modules/dmverity_roothash.c | 80 ++ security/ipe/modules/dmverity_signature.c | 25 + security/ipe/modules/fsverity_digest.c | 80 ++ security/ipe/modules/fsverity_signature.c | 33 + security/ipe/modules/ipe_module.h | 40 + security/ipe/parsers.c | 139 +++ security/ipe/parsers/Makefile | 12 + security/ipe/parsers/default.c | 106 ++ security/ipe/parsers/policy_header.c | 126 ++ security/ipe/policy.c | 1037 +++++++++++++++++ security/ipe/policy.h | 113 ++ security/ipe/policy_parser_tests.c | 299 +++++ security/ipe/policyfs.c | 528 +++++++++ security/security.c | 76 +- 63 files changed, 7069 insertions(+), 18 deletions(-) create mode 100644 Documentation/admin-guide/LSM/ipe.rst create mode 100644 Documentation/security/ipe.rst 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/ctx.c create mode 100644 security/ipe/ctx.h create mode 100644 security/ipe/ctx_test.c 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/ipe_parser.h create mode 100644 security/ipe/modules.c create mode 100644 security/ipe/modules.h create mode 100644 security/ipe/modules/Kconfig create mode 100644 security/ipe/modules/Makefile create mode 100644 security/ipe/modules/boot_verified.c create mode 100644 security/ipe/modules/dmverity_roothash.c create mode 100644 security/ipe/modules/dmverity_signature.c create mode 100644 security/ipe/modules/fsverity_digest.c create mode 100644 security/ipe/modules/fsverity_signature.c create mode 100644 security/ipe/modules/ipe_module.h create mode 100644 security/ipe/parsers.c create mode 100644 security/ipe/parsers/Makefile create mode 100644 security/ipe/parsers/default.c create mode 100644 security/ipe/parsers/policy_header.c create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h create mode 100644 security/ipe/policy_parser_tests.c create mode 100644 security/ipe/policyfs.c
Signature · 1 line
2.33.0
RFC PATCH v7 4/16 ipe: add userspace interface
From: 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
---
Relevant changes since v6:
* Refactor series to:
1. Support a context structure, enabling easier testing
* Split up patch 03/12 into two parts:
1. parser [02/16]
2. userspace interface [04/16] (this patch)
* 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.
--- security/ipe/Makefile | 2 + security/ipe/ctx.c | 121 +++++++++ security/ipe/ctx.h | 6 + security/ipe/fs.c | 170 +++++++++++++ security/ipe/fs.h | 13 + security/ipe/policy.c | 41 ++++ security/ipe/policy.h | 4 + security/ipe/policyfs.c | 528 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 885 insertions(+) create mode 100644 security/ipe/fs.c create mode 100644 security/ipe/fs.h create mode 100644 security/ipe/policyfs.c
security/ipe/Makefile +2 -0
@@ -10,9 +10,11 @@ ccflags-y := -I$(srctree)/security/ipe/modules obj-$(CONFIG_SECURITY_IPE) += \ ctx.o \ eval.o \ + fs.o \ hooks.o \ ipe.o \ modules.o \ parsers/ \ parsers.o \ policy.o \ + policyfs.o \
security/ipe/ctx.c +121 -0
146 lines not on this page · raw message
security/ipe/ctx.h +6 -0
@@ -7,6 +7,7 @@#include <linux/sched.h> #include <linux/types.h> +#include <linux/dcache.h> #include <linux/refcount.h> #include <linux/spinlock.h> #include <linux/workqueue.h>
@@ -20,6 +21,8 @@ struct ipe_context {struct list_head policies;/* type: ipe_policy */ +struct dentry *policy_root; +struct work_struct free_work; };
@@ -30,5 +33,8 @@ struct ipe_context *ipe_get_ctx_rcu(struct ipe_context __rcu *ctx);void ipe_put_ctx (struct ipe_context *ctx);void ipe_add_policy (struct ipe_context *ctx,struct ipe_policy *p);void ipe_remove_policy (struct ipe_policy *p); +int ipe_replace_policy (struct ipe_policy *old,struct ipe_policy *new); +int ipe_set_active_pol (const struct ipe_policy *p); +bool ipe_is_policy_active (const struct ipe_policy *p);#endif /* IPE_CONTEXT_H */
security/ipe/fs.c new file +170 -0
170 lines not on this page · raw message
security/ipe/fs.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef IPE_FS_H +#define IPE_FS_H + +void ipe_soft_del_policyfs (struct ipe_policy *p); +int ipe_new_policyfs_node (struct ipe_context *ctx,struct ipe_policy *p); +void ipe_del_policyfs_node (struct ipe_policy *p); + +#endif /* IPE_FS_H */
security/ipe/policy.c +41 -0
59 lines not on this page · raw message
security/ipe/policy.h +4 -0
@@ -88,12 +88,16 @@ struct ipe_policy {refcount_t refcount; +struct dentry *policyfs;struct list_head next;/* type: ipe_policy */ struct ipe_context __rcu *ctx; };struct ipe_policy *ipe_new_policy (const char *text,size_t textlen,const char *pkcs7,size_t pkcs7len); +struct ipe_policy *ipe_update_policy (struct ipe_policy *old,const char *text, +size_t textlen,const char *pkcs7, +size_t pkcs7len);void ipe_put_policy (struct ipe_policy *pol);bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size);struct ipe_policy *ipe_get_policy_rcu (struct ipe_policy __rcu *p);
security/ipe/policyfs.c new file +528 -0
528 lines not on this page · raw message
Signature · 1 line
2.33.0
RFC PATCH v7 2/16 ipe: add policy parser
In reply to [email protected]From: 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 trust/integrity providers, like fs-verity or dm-verity, can plug into the policy with minimal code changes.
---
Relevant changes since v6:
* Refactor policy parser to make code cleaner via introducing clearly defined passes, with specific goal states.
* Split up patch 03/12 into two parts:
1. parser [02/16] (this patch)
2. userspace interface [04/16]
--- include/asm-generic/vmlinux.lds.h | 16 + security/ipe/Makefile | 6 + security/ipe/ipe.c | 63 ++ security/ipe/ipe.h | 4 + security/ipe/ipe_parser.h | 59 ++ security/ipe/modules.c | 109 +++ security/ipe/modules.h | 17 + security/ipe/modules/ipe_module.h | 33 + security/ipe/parsers.c | 139 ++++ security/ipe/parsers/Makefile | 12 + security/ipe/parsers/default.c | 106 +++ security/ipe/parsers/policy_header.c | 126 ++++ security/ipe/policy.c | 946 +++++++++++++++++++++++++++ security/ipe/policy.h | 97 +++ 14 files changed, 1733 insertions(+) create mode 100644 security/ipe/ipe_parser.h create mode 100644 security/ipe/modules.c create mode 100644 security/ipe/modules.h create mode 100644 security/ipe/modules/ipe_module.h create mode 100644 security/ipe/parsers.c create mode 100644 security/ipe/parsers/Makefile create mode 100644 security/ipe/parsers/default.c create mode 100644 security/ipe/parsers/policy_header.c create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h
include/asm-generic/vmlinux.lds.h +16 -0
@@ -278,6 +278,20 @@#define EARLY_LSM_TABLE ()#endif +#ifdef CONFIG_SECURITY_IPE +#define IPE_PARSER_TABLE () . = ALIGN(8); \ + __start_ipe_parsers = .; \ + KEEP(*(.ipe_parsers)) \ + __end_ipe_parsers = .; +#define IPE_MODULE_TABLE () . = ALIGN(8); \ + __start_ipe_modules = .; \ + KEEP(*(.ipe_modules)) \ + __end_ipe_modules = .; +#else +#define IPE_PARSER_TABLE () +#define IPE_MODULE_TABLE () +#endif +#define ___OF_TABLE (cfg, name) _OF_TABLE_##cfg(name)#define __OF_TABLE (cfg, name) ___OF_TABLE(cfg, name)#define OF_TABLE (cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
@@ -436,6 +450,8 @@ KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ __stop___tracepoints_ptrs = .; \ *(__tracepoints_strings)/* Tracepoints: strings */ \ + IPE_PARSER_TABLE() \ +IPE_MODULE_TABLE () \ } \ \ .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
security/ipe/Makefile +6 -0
@@ -5,7 +5,13 @@ # Makefile for building the IPE module as part of the kernel tree. # +ccflags-y := -I$(srctree)/security/ipe/modules + obj-$(CONFIG_SECURITY_IPE) += \ ctx.o \ hooks.o \ ipe.o \ + modules.o \ + parsers/ \ + parsers.o \ + policy.o \
security/ipe/ipe.c +63 -0
81 lines not on this page · raw message
security/ipe/ipe.h +4 -0
@@ -9,11 +9,15 @@#define pr_fmt (fmt) "IPE " fmt "\n"#include "ctx.h" +#include "ipe_parser.h" +#include "modules/ipe_module.h" #include <linux/types.h> #include <linux/sched.h> #include <linux/lsm_hooks.h> extern struct lsm_blob_sizes ipe_blobs; +extern struct ipe_parser __start_ipe_parsers[], __end_ipe_parsers[]; +extern struct ipe_module __start_ipe_modules[], __end_ipe_modules[];#endif /* IPE_H */
security/ipe/ipe_parser.h new file +59 -0
59 lines not on this page · raw message
security/ipe/modules.c new file +109 -0
109 lines not on this page · raw message
security/ipe/modules.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef IPE_MODULES_H +#define IPE_MODULES_H + +#include "ipe.h" +#include "ipe_module.h" + +#include <linux/types.h> +#include <linux/rbtree.h> + +const struct ipe_module *ipe_lookup_module (const char *key); +int ipe_register_module (struct ipe_module *m); + +#endif /* IPE_MODULES_H */
security/ipe/modules/ipe_module.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef IPE_MODULE_H +#define IPE_MODULE_H + +#include <linux/types.h> + +/** +* ipe_module: definition of an extensible module for IPE properties. +* These structures are used to implement 'key=value' pairs +* in IPE policy, which will be evaluated on every IPE policy +* evaluation. +* +* Integrity mechanisms should be define as a module, and modules +* should manage their own dependencies via KConfig. @name is both +* the key half of the key=value pair in the policy, and the unique +* identifier for the module. +*/ +struct ipe_module { +const char *const name;/* required */ +u16 version;/* required */ +int (*parse)(const char *valstr,void **value);/* required */ +int (*free)(void **value);/* optional */ +}; + +#define IPE_MODULE (parser) \ + static struct ipe_module __ipe_module_##parser \ + __used __section(".ipe_modules") \ + __aligned(sizeof(unsigned long)) + +#endif /* IPE_MODULE_H */
security/ipe/parsers.c new file +139 -0
139 lines not on this page · raw message
security/ipe/parsers/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# 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. +# + +ccflags-y := -I$(srctree)/security/ipe + +obj-$(CONFIG_SECURITY_IPE) += \ + default.o \ + policy_header.o \
security/ipe/parsers/default.c new file +106 -0
106 lines not on this page · raw message
security/ipe/parsers/policy_header.c new file +126 -0
126 lines not on this page · raw message
security/ipe/policy.c new file +946 -0
946 lines not on this page · raw message
security/ipe/policy.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.33.0
RFC PATCH v7 3/16 ipe: add evaluation loop
In reply to [email protected]From: 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.
---
Relevant changes since v6:
* Refactor patch to support a context structure, enabling easier testing
* Split up patch 02/12 into four parts:
1. context creation [01/16]
2. audit [07/16]
3. evaluation loop [03/16] (this patch)
4. access control hooks [05/16]
--- security/ipe/Makefile | 1 + security/ipe/ctx.c | 57 ++++++++++++ security/ipe/ctx.h | 6 ++ security/ipe/eval.c | 142 ++++++++++++++++++++++++++++++ security/ipe/eval.h | 26 ++++++ security/ipe/hooks.h | 4 + security/ipe/modules/ipe_module.h | 3 + security/ipe/policy.c | 27 ++++++ security/ipe/policy.h | 4 + 9 files changed, 270 insertions(+) create mode 100644 security/ipe/eval.c create mode 100644 security/ipe/eval.h
security/ipe/Makefile +1 -0
@@ -9,6 +9,7 @@ ccflags-y := -I$(srctree)/security/ipe/modules obj-$(CONFIG_SECURITY_IPE) += \ ctx.o \ + eval.o \ hooks.o \ ipe.o \ modules.o \
security/ipe/ctx.c +57 -0
85 lines not on this page · raw message
security/ipe/ctx.h +6 -0
@@ -12,10 +12,14 @@#include <linux/workqueue.h> struct ipe_context { +struct ipe_policy __rcu *active_policy; +refcount_t refcount;/* Protects concurrent writers */ spinlock_t lock; +struct list_head policies;/* type: ipe_policy */ +struct work_struct free_work; };
@@ -24,5 +28,7 @@ struct ipe_context __rcu **ipe_tsk_ctx(struct task_struct *tsk);struct ipe_context *ipe_current_ctx (void );struct ipe_context *ipe_get_ctx_rcu (struct ipe_context __rcu *ctx);void ipe_put_ctx (struct ipe_context *ctx); +void ipe_add_policy (struct ipe_context *ctx,struct ipe_policy *p); +void ipe_remove_policy (struct ipe_policy *p);#endif /* IPE_CONTEXT_H */
security/ipe/eval.c new file +142 -0
142 lines not on this page · raw message
security/ipe/eval.h new file +26 -0
@@ -0,0 +1,26 @@ +/* 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 "ctx.h" +#include "hooks.h" +#include "policy.h" + +struct ipe_eval_ctx { +enum ipe_hook hook; +enum ipe_operation op; + +const struct file *file; +struct ipe_context *ci_ctx; +}; + +int ipe_process_event (const struct file *file,enum ipe_operation op, +enum ipe_hook hook); + +#endif /* IPE_EVAL_H */
security/ipe/hooks.h +4 -0
@@ -8,6 +8,10 @@#include <linux/types.h> #include <linux/sched.h> +enum ipe_hook { + ipe_hook_max =0 +}; +int ipe_task_alloc (struct task_struct *task,unsigned long clone_flags);
security/ipe/modules/ipe_module.h +3 -0
@@ -6,6 +6,7 @@#define IPE_MODULE_H #include <linux/types.h> +#include "../eval.h" /** * ipe_module: definition of an extensible module for IPE properties.
@@ -23,6 +24,8 @@ struct ipe_module {u16 version;/* required */ int (*parse)(const char *valstr,void **value);/* required */ int (*free)(void **value);/* optional */ +bool (*eval)(const struct ipe_eval_ctx *ctx,/* required */ +const void *val); };#define IPE_MODULE (parser) \
security/ipe/policy.c +27 -0
@@ -874,6 +874,32 @@ void ipe_put_policy(struct ipe_policy *p)kfree (p); } +/** +* ipe_get_policy_rcu: Dereference rcu-protected @p and increase the reference +* count. +* @p: rcu-protected pointer to dereference +* +* Not safe to call on IS_ERR. +* +* Return: +* !NULL - reference count of @p was valid, and increased by one. +* NULL - reference count of @p is not valid. +*/ +struct ipe_policy *ipe_get_policy_rcu (struct ipe_policy __rcu *p) +{ +struct ipe_policy *rv =NULL ; + +rcu_read_lock (); + + rv =rcu_dereference (p); +if (!rv || !refcount_inc_not_zero (&rv->refcount)) + rv =NULL ; + +rcu_read_unlock (); + +return rv; +} +static int set_pkcs7_data (void *ctx,const void *data,size_t len,size_t asn1hdrlen) {
@@ -912,6 +938,7 @@ struct ipe_policy *ipe_new_policy(const char *text, size_t textlen,return ERR_PTR (-ENOMEM );refcount_set (&new->refcount,1 ); +INIT_LIST_HEAD (&new->next);if (!text) { new->pkcs7len = pkcs7len;
security/ipe/policy.h +4 -0
@@ -87,11 +87,15 @@ struct ipe_policy {struct ipe_parsed_policy *parsed;refcount_t refcount; + +struct list_head next;/* type: ipe_policy */ + struct ipe_context __rcu *ctx; };struct ipe_policy *ipe_new_policy (const char *text,size_t textlen,const char *pkcs7,size_t pkcs7len);void ipe_put_policy (struct ipe_policy *pol);bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size); +struct ipe_policy *ipe_get_policy_rcu (struct ipe_policy __rcu *p);#endif /* IPE_POLICY_H */
Signature · 1 line
2.33.0
RFC PATCH v7 10/16 fs|dm-verity: add block_dev LSM blob and submit dm-verity data
In reply to [email protected]From: Deven Bowers <[email protected]>
dm-verity operates on the block_device level. In order to allow IPE to determine if a file is sourced from a dm-verity volume, and how that dm-verity volume was created, create an LSM blob with the signature data and roothash information, allowing IPE to make decisions about controls to a resource based on dm-verity information.
---
Relevant changes since v5:
* Change if statement condition in security_bdev_setsecurity to be more concise, as suggested by Casey Schaufler and Al Viro
Relevant changes since v6:
* Squash patch 05/12, 07/12, 09/12 to [10/16]
--- block/bdev.c | 7 ++++ drivers/md/dm-verity-target.c | 20 ++++++++- drivers/md/dm-verity-verify-sig.c | 16 +++++-- drivers/md/dm-verity-verify-sig.h | 10 +++-- include/linux/blk_types.h | 1 + include/linux/device-mapper.h | 3 ++ include/linux/lsm_hook_defs.h | 5 +++ include/linux/lsm_hooks.h | 12 ++++++ include/linux/security.h | 22 ++++++++++ security/security.c | 70 +++++++++++++++++++++++++++++++ 10 files changed, 157 insertions(+), 9 deletions(-)
block/bdev.c +7 -0
@@ -23,6 +23,7 @@#include <linux/pseudo_fs.h> #include <linux/uio.h> #include <linux/namei.h> +#include <linux/security.h> #include <linux/cleancache.h> #include <linux/part_stat.h> #include <linux/uaccess.h>
@@ -393,6 +394,11 @@ static struct inode *bdev_alloc_inode(struct super_block *sb)if (!ei)return NULL ;memset (&ei->bdev,0 ,sizeof (ei->bdev)); + +if (unlikely (security_bdev_alloc (&ei->bdev))) { +kmem_cache_free (bdev_cachep, ei); +return NULL ; + }return &ei->vfs_inode; }
@@ -402,6 +408,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)
drivers/md/dm-verity-target.c +18 -2
@@ -13,11 +13,14 @@* access behavior. */ +#include "dm-core.h" #include "dm-verity.h" #include "dm-verity-fec.h" #include "dm-verity-verify-sig.h" +#include "dm-core.h" #include <linux/module.h> #include <linux/reboot.h> +#include <linux/security.h> #define DM_MSG_PREFIX "verity"
@@ -1051,6 +1054,7 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)sector_t hash_position;char dummy;char *root_hash_digest_to_validate; +struct block_device *bdev; v =kzalloc (sizeof (struct dm_verity ),GFP_KERNEL );if (!v) {
@@ -1084,6 +1088,13 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) } v->version = num; + bdev =dm_table_get_md (ti->table)->disk->part0; +if (!bdev) { + ti->error ="Mapped device lookup failed" ; + r = -ENOMEM ; + goto bad; + } + r =dm_get_device (ti, argv[1 ],FMODE_READ , &v->data_dev);if (r) { ti->error ="Data device lookup failed" ;
@@ -1216,7 +1227,7 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) }/* Root hash signature is a optional parameter*/ - r =verity_verify_root_hash (root_hash_digest_to_validate, + r =verity_verify_root_hash (bdev, root_hash_digest_to_validate,strlen (root_hash_digest_to_validate), verify_args.sig, verify_args.sig_size);
@@ -1289,12 +1300,17 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) ti->per_io_data_size =roundup (ti->per_io_data_size, __alignof__(struct dm_verity_io )); + r =security_bdev_setsecurity (bdev, +DM_VERITY_ROOTHASH_SEC_NAME , + v->root_digest, v->digest_size); +if (r) + goto bad; +verity_verify_sig_opts_cleanup (&verify_args);return 0 ; bad: -verity_verify_sig_opts_cleanup (&verify_args);verity_dtr (ti);
drivers/md/dm-verity-verify-sig.c +13 -3
@@ -8,7 +8,10 @@#include <linux/device-mapper.h> #include <linux/verification.h> #include <keys/user-type.h> +#include <linux/security.h> +#include <linux/list.h> #include <linux/module.h> +#include "dm-core.h" #include "dm-verity.h" #include "dm-verity-verify-sig.h"
@@ -97,14 +100,17 @@ int verity_verify_sig_parse_opt_args(struct dm_arg_set *as,* verify_verify_roothash - Verify the root hash of the verity hash device * using builtin trusted keys. * +* @bdev: block_device representing the device-mapper created block device. +* Used by the security hook, to set information about the block_device. * @root_hash: For verity, the roothash/data to be verified. * @root_hash_len: Size of the roothash/data to be verified. * @sig_data: The trusted signature that verifies the roothash/data. * @sig_len: Size of the signature. * */ -int verity_verify_root_hash (const void *root_hash,size_t root_hash_len, -const void *sig_data,size_t sig_len) +int verity_verify_root_hash (struct block_device *bdev,const void *root_hash, +size_t root_hash_len,const void *sig_data, +size_t sig_len) {int ret;
@@ -126,8 +132,12 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,NULL , #endif VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL); +if (ret) +return ret; - return ret; +return security_bdev_setsecurity (bdev, +DM_VERITY_SIGNATURE_SEC_NAME , + sig_data, sig_len); }void verity_verify_sig_opts_cleanup (struct dm_verity_sig_opts *sig_opts)
drivers/md/dm-verity-verify-sig.h +6 -4
@@ -20,8 +20,9 @@ struct dm_verity_sig_opts {#define DM_VERITY_ROOT_HASH_VERIFICATION_OPTS 2 -int verity_verify_root_hash (const void *data,size_t data_len, -const void *sig_data,size_t sig_len); +int verity_verify_root_hash (struct block_device *bdev,const void *data, +size_t data_len,const void *sig_data, +size_t sig_len);bool verity_verify_is_sig_opt_arg (const char *arg_name); int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
@@ -34,8 +35,9 @@ void verity_verify_sig_opts_cleanup(struct dm_verity_sig_opts *sig_opts);#define DM_VERITY_ROOT_HASH_VERIFICATION_OPTS 0 -static inline int verity_verify_root_hash (const void *data,size_t data_len, -const void *sig_data,size_t sig_len) +int verity_verify_root_hash (struct block_device *bdev,const void *data, +size_t data_len,const void *sig_data, +size_t sig_len) {return 0 ; }
include/linux/blk_types.h +1 -0
@@ -49,6 +49,7 @@ struct block_device {#ifdef CONFIG_FAIL_MAKE_REQUEST bool bd_make_it_fail;#endif +void *security; } __randomize_layout;#define bdev_whole (_bdev) \
include/linux/device-mapper.h +3 -0
@@ -665,4 +665,7 @@ static inline unsigned long to_bytes(sector_t n) return (n << SECTOR_SHIFT); } +#define DM_VERITY_SIGNATURE_SEC_NAME DM_NAME ".verity-sig" +#define DM_VERITY_ROOTHASH_SEC_NAME DM_NAME ".verity-rh" +#endif /* _LINUX_DEVICE_MAPPER_H */
include/linux/lsm_hook_defs.h +5 -0
@@ -402,3 +402,8 @@ LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event) LSM_HOOK(int, 0, perf_event_read, struct perf_event *event) LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)#endif /* CONFIG_PERF_EVENTS */ + +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 +12 -0
@@ -1545,6 +1545,17 @@* * @what: kernel feature being accessed * +* @bdev_alloc_security: +* Initialize the security field inside a block_device structure. +* +* @bdev_free_security: +* Cleanup the security information stored inside a block_device structure. +* +* @bdev_setsecurity: +* Set a security property associated with @name for @bdev with +* value @value. @size indicates the size of @value in bytes. +* If a @name is not implemented, return -ENOSYS. +* * Security hooks for perf events * * @perf_event_open:
@@ -1592,6 +1603,7 @@ struct lsm_blob_sizes {int lbs_ipc;int lbs_msg_msg;int lbs_task; +int lbs_bdev; };/*
include/linux/security.h +22 -0
@@ -472,6 +472,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)
@@ -1348,6 +1353,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 +70 -0
100 lines not on this page · raw message
Signature · 1 line
2.33.0
RFC PATCH v7 15/16 ipe: kunit tests
In reply to [email protected]From: Deven Bowers <[email protected]>
Add various happy/unhappy unit tests for both IPE's parser and evaluation loop, testing the core of IPE. The missing test gap remains the interface with userspace.
---
Relevant changes since v6:
* Add Kunit tests (Introduced)
--- security/ipe/Kconfig | 17 + security/ipe/Makefile | 3 + security/ipe/ctx_test.c | 732 +++++++++++++++++++++++++++++ security/ipe/eval.c | 4 + security/ipe/policy_parser_tests.c | 299 ++++++++++++ 5 files changed, 1055 insertions(+) create mode 100644 security/ipe/ctx_test.c create mode 100644 security/ipe/policy_parser_tests.c
security/ipe/Kconfig +17 -0
@@ -80,4 +80,21 @@ config IPE_AUDIT_HASH_ALG source "security/ipe/modules/Kconfig" +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
@@ -33,4 +33,7 @@ obj-$(CONFIG_SECURITY_IPE) += \ obj-$(CONFIG_AUDIT) += audit.o +obj-$(CONFIG_SECURITY_IPE_KUNIT_TEST) += \ + policy_parser_tests.o \ + clean-files := boot-policy.c \
security/ipe/ctx_test.c new file +732 -0
732 lines not on this page · raw message
security/ipe/eval.c +4 -0
@@ -231,3 +231,7 @@ void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)spin_unlock (&pin_lock); } + +#ifdef CONFIG_SECURITY_IPE_KUNIT_TEST +#include "ctx_test.c" +#endif /* CONFIG_SECURITY_IPE_KUNIT_TEST */
security/ipe/policy_parser_tests.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
2.33.0
RFC PATCH v7 16/16 documentation: add ipe documentation
In reply to [email protected]From: Deven Bowers <[email protected]>
Add IPE's admin and developer documentation to the kernel tree.
---
Relevant changes since v6:
* Add additional developer-level documentation
* Update admin-guide docs to reflect changes.
* Drop Acked-by due to significant changes
--- Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 587 ++++++++++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 339 ++++++++++ MAINTAINERS | 2 + 6 files changed, 942 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 +587 -0
587 lines not on this page · raw message
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -2096,6 +2096,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
@@ -17,3 +17,4 @@ Security Documentation tpm/index digsig landlock + ipe
Documentation/security/ipe.rst new file +339 -0
339 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -9283,6 +9283,8 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> M: Fan Wu <[email protected]> S: Supported +F: Documentation/admin-guide/LSM/ipe.rst +F: Documentation/security/ipe.rst F: scripts/ipe/ F: security/ipe/
Signature · 1 line
2.33.0
RFC PATCH v7 13/16 ipe: enable support for fs-verity as a trust provider
In reply to [email protected]From: Fan Wu <[email protected]>
Enable IPE policy authors to indicate trust for a singular fsverity file, identified by the digest information, through "fsverity_digest" and all fsverity signed by a key via "fsverity_signature".
---
Relevant changes since v6:
* Add FSVerity Support (Introduced)
--- security/ipe/eval.c | 1 + security/ipe/eval.h | 9 +++ security/ipe/hooks.c | 58 ++++++++++++++++ security/ipe/hooks.h | 7 ++ security/ipe/ipe.c | 8 +++ security/ipe/ipe.h | 1 + security/ipe/modules/Kconfig | 23 +++++++ security/ipe/modules/Makefile | 2 + security/ipe/modules/fsverity_digest.c | 80 +++++++++++++++++++++++ security/ipe/modules/fsverity_signature.c | 33 ++++++++++ 10 files changed, 222 insertions(+) create mode 100644 security/ipe/modules/fsverity_digest.c create mode 100644 security/ipe/modules/fsverity_signature.c
security/ipe/eval.c +1 -0
@@ -97,6 +97,7 @@ static struct ipe_eval_ctx *build_ctx(const struct file *file, ctx->ci_ctx =ipe_current_ctx (); ctx->from_init_sb =from_pinned (file);if (file) { + ctx->ipe_inode =ipe_inode (file->f_inode);if (FILE_BLOCK_DEV (file)) ctx->ipe_bdev =ipe_bdev (FILE_BLOCK_DEV (file)); }
security/ipe/eval.h +9 -0
@@ -21,6 +21,14 @@ struct ipe_bdev {size_t hashlen; }; +struct ipe_inode { +const u8 *sigdata; +size_t siglen; + +const u8 *hash; +size_t hashlen; +}; +struct ipe_eval_ctx {enum ipe_hook hook;enum ipe_operation op;
@@ -29,6 +37,7 @@ struct ipe_eval_ctx {struct ipe_context *ci_ctx;const struct ipe_bdev *ipe_bdev; +const struct ipe_inode *ipe_inode;bool from_init_sb; };
security/ipe/hooks.c +58 -0
61 lines not on this page · raw message
security/ipe/hooks.h +7 -0
@@ -10,6 +10,7 @@#include <linux/sched.h> #include <linux/binfmts.h> #include <linux/security.h> +#include <linux/fsverity.h> #include <linux/device-mapper.h> enum ipe_hook {
@@ -46,4 +47,10 @@ 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); +void ipe_inode_free_security (struct inode *inode); + +int ipe_inode_setsecurity (struct inode *inode,const char *name, +const void *value,size_t size, +int flags); +#endif /* IPE_HOOKS_H */
security/ipe/ipe.c +8 -0
@@ -22,6 +22,7 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { .lbs_task =sizeof (struct ipe_context __rcu *), .lbs_bdev =sizeof (struct ipe_bdev ), + .lbs_inode =sizeof (struct ipe_inode ), };struct ipe_bdev *ipe_bdev (struct block_device *b)
@@ -29,6 +30,11 @@ struct ipe_bdev *ipe_bdev(struct block_device *b)return b->security + ipe_blobs.lbs_bdev; } +struct ipe_inode *ipe_inode (const struct inode *inode) +{ +return inode->i_security + ipe_blobs.lbs_inode; +} + static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free),
@@ -40,6 +46,8 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (sb_free_security, ipe_sb_free_security),LSM_HOOK_INIT (bdev_free_security, ipe_bdev_free_security),LSM_HOOK_INIT (bdev_setsecurity, ipe_bdev_setsecurity), +LSM_HOOK_INIT (inode_setsecurity, ipe_inode_setsecurity), + LSM_HOOK_INIT(inode_free_security, ipe_inode_free_security), };/**
security/ipe/ipe.h +1 -0
@@ -22,5 +22,6 @@ extern struct ipe_parser __start_ipe_parsers[], __end_ipe_parsers[];extern struct ipe_module __start_ipe_modules[], __end_ipe_modules[];struct ipe_bdev *ipe_bdev (struct block_device *b); +struct ipe_inode *ipe_inode (const struct inode *inode);#endif /* IPE_H */
security/ipe/modules/Kconfig +23 -0
@@ -40,4 +40,27 @@ config IPE_PROP_DM_VERITY_ROOTHASH If unsure, answer Y. +config IPE_PROP_FS_VERITY_SIGNATURE + bool "Enable property for signed fs-verity files" + depends on FS_VERITY_BUILTIN_SIGNATURES + help + This option enables IPE's integration with FSVerity's + signed hashes. This enables the usage of the property, + "fsverity_signature" in IPE's policy. + + if unsure, answer Y. + +config IPE_PROP_FS_VERITY_DIGEST + bool "Enable property for authorizing fs-verity files via digest" + depends on FS_VERITY + help + This option enables IPE's integration with FSVerity. + This enables the usage of the property "fsverity_digest" in IPE's + policy. This property allows authorization or revocation via a + a hex-string representing the digest of a fsverity file. + + if unsure, answer Y. + + + endmenu
security/ipe/modules/Makefile +2 -0
@@ -8,3 +8,5 @@ obj-$(CONFIG_IPE_PROP_BOOT_VERIFIED) += boot_verified.o obj-$(CONFIG_IPE_PROP_DM_VERITY_SIGNATURE) += dmverity_signature.o obj-$(CONFIG_IPE_PROP_DM_VERITY_ROOTHASH) += dmverity_roothash.o +obj-$(CONFIG_IPE_PROP_FS_VERITY_SIGNATURE) += fsverity_signature.o +obj-$(CONFIG_IPE_PROP_FS_VERITY_DIGEST) += fsverity_digest.o
security/ipe/modules/fsverity_digest.c new file +80 -0
80 lines not on this page · raw message
security/ipe/modules/fsverity_signature.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/slab.h> +#include <linux/audit.h> +#include <linux/mount.h> + +static bool evaluate (const struct ipe_eval_ctx *ctx,const void *value) +{ +bool expect = (bool )value; + +if (!ctx->file) +return false; + +if (!IS_VERITY (ctx->file->f_inode) || !ctx->ipe_inode) +return false; + +return (!!ctx->ipe_inode->sigdata) == expect; +} + +IPE_MODULE (fsvs) = { + .name ="fsverity_signature" , + .version =1 , + .parse = ipe_bool_parse, + .free =NULL , + .eval = evaluate, +};
Signature · 1 line
2.33.0
RFC PATCH v7 12/16 fsverity|security: add security hooks to fsverity digest and signature
In reply to [email protected]From: Fan Wu <[email protected]>
Add security_inode_setsecurity to fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.
Also changes the implementaion inside the hook function to let multiple LSMs can add hooks.
--- fs/verity/open.c | 12 ++++++++++++ fs/verity/signature.c | 5 ++++- include/linux/fsverity.h | 3 +++ security/ipe/hooks.c | 1 + security/security.c | 6 +++--- 5 files changed, 23 insertions(+), 4 deletions(-)
fs/verity/open.c +12 -0
@@ -7,6 +7,7 @@#include "fsverity_private.h" +#include <linux/security.h> #include <linux/slab.h> static struct kmem_cache *fsverity_info_cachep;
@@ -177,6 +178,17 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,fsverity_err (inode,"Error %d computing file digest" , err); goto out; } + + err =security_inode_setsecurity ((struct inode *)inode, +FS_VERITY_DIGEST_SEC_NAME , + vi->file_digest, + vi->tree_params.hash_alg->digest_size, +0 ); +if (err) { +fsverity_err (inode,"Error %d inode setsecurity hook" , err); + goto out; + } +pr_debug ("Computed file digest: %s:%*phN\n" , vi->tree_params.hash_alg->name, vi->tree_params.digest_size, vi->file_digest);
fs/verity/signature.c +4 -1
@@ -9,6 +9,7 @@#include <linux/cred.h> #include <linux/key.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/verification.h>
@@ -84,7 +85,9 @@ int fsverity_verify_signature(const struct fsverity_info *vi,pr_debug ("Valid signature for file digest %s:%*phN\n" , hash_alg->name, hash_alg->digest_size, vi->file_digest); -return 0 ; +return security_inode_setsecurity ((struct inode *)inode, +FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size,0 ); }#ifdef CONFIG_SYSCTL
include/linux/fsverity.h +3 -0
@@ -233,4 +233,7 @@ static inline bool fsverity_active(const struct inode *inode) return fsverity_get_info(inode) != NULL; } +#define FS_VERITY_SIGNATURE_SEC_NAME "fsverity.verity-sig" +#define FS_VERITY_DIGEST_SEC_NAME "fsverity.verity-digest" +#endif /* _LINUX_FSVERITY_H */
security/ipe/hooks.c +1 -0
@@ -232,6 +232,7 @@ void ipe_bdev_free_security(struct block_device *bdev)struct ipe_bdev *blob =ipe_bdev (bdev);kfree (blob->sigdata); +kfree (blob->hash); }/**
security/security.c +3 -3
@@ -1462,7 +1462,7 @@ int security_inode_getsecurity(struct user_namespace *mnt_userns,int security_inode_setsecurity (struct inode *inode,const char *name,const void *value,size_t size,int flags) {struct security_hook_list *hp; -int rc; +int rc =LSM_RET_DEFAULT (inode_setsecurity);if (unlikely (IS_PRIVATE (inode)))return LSM_RET_DEFAULT (inode_setsecurity);
@@ -1472,10 +1472,10 @@ int security_inode_setsecurity(struct inode *inode, const char *name, const voidhlist_for_each_entry (hp, &security_hook_heads.inode_setsecurity, list) { rc = hp->hook.inode_setsecurity (inode, name, value, size, flags); -if (rc !=LSM_RET_DEFAULT (inode_setsecurity)) +if (rc && rc !=LSM_RET_DEFAULT (inode_setsecurity))return rc; } -return LSM_RET_DEFAULT (inode_setsecurity); +return rc; }int security_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size)
Signature · 1 line
2.33.0
RFC PATCH v7 14/16 scripts: add boot policy generation program
In reply to [email protected]From: 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.
---
Relevant changes since v6:
* Move patch 01/12 to [14/16] of the series
--- 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 | 13 +++ security/ipe/ctx.c | 18 +++++ 10 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
@@ -9283,6 +9283,7 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> M: Fan Wu <[email protected]> S: Supported +F: scripts/ipe/ F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVER
scripts/Makefile +1 -0
@@ -41,6 +41,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
@@ -20,6 +20,16 @@ menuconfig SECURITY_IPE 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. + choice prompt "Hash algorithm used in auditing policies" default IPE_AUDIT_HASH_SHA1
security/ipe/Makefile +13 -0
@@ -7,7 +7,18 @@ ccflags-y := -I$(srctree)/security/ipe/modules +quiet_cmd_polgen = IPE_POL $(2) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/boot-policy.c $(2) + +$(eval $(call config_filename,IPE_BOOT_POLICY)) + +targets += boot-policy.c + +$(obj)/boot-policy.c: scripts/ipe/polgen/polgen $(IPE_BOOT_POLICY_FILENAME) FORCE + $(call if_changed,polgen,$(IPE_BOOT_POLICY_FILENAME)) + obj-$(CONFIG_SECURITY_IPE) += \ + boot-policy.o \ ctx.o \ eval.o \ fs.o \
@@ -21,3 +32,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ policyfs.o \ obj-$(CONFIG_AUDIT) += audit.o + +clean-files := boot-policy.c \
security/ipe/ctx.c +18 -0
@@ -15,6 +15,7 @@#include <linux/spinlock.h> #include <linux/moduleparam.h> +extern const char *const ipe_boot_policy;static bool success_audit;static bool enforce = true;
@@ -329,6 +330,7 @@ void ipe_put_ctx(struct ipe_context *ctx)int __init ipe_init_ctx (void ) {int rc =0 ; +struct ipe_policy *p =NULL ;struct ipe_context *lns =NULL ; lns =create_ctx ();
@@ -342,10 +344,26 @@ int __init ipe_init_ctx(void)WRITE_ONCE (lns->enforce, enforce);spin_unlock (&lns->lock); +if (ipe_boot_policy) { + p =ipe_new_policy (ipe_boot_policy,strlen (ipe_boot_policy), +NULL ,0 ); +if (IS_ERR (p)) { + rc =PTR_ERR (lns); + goto err; + } + +ipe_add_policy (lns, p); + rc =ipe_set_active_pol (p); +if (!rc) + goto err; + } +rcu_assign_pointer (*ipe_tsk_ctx (current), lns); +ipe_put_policy (p);return 0 ; err: +ipe_put_policy (p);ipe_put_ctx (lns);return rc; }
Signature · 1 line
2.33.0
RFC PATCH v7 11/16 ipe: add support for dm-verity as a trust provider
In reply to [email protected]From: 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".
---
Relevant changes since v6:
* Squash patch 08/12, 10/12 to [11/16]
--- security/ipe/eval.c | 5 ++ security/ipe/eval.h | 10 +++ security/ipe/hooks.c | 48 ++++++++++++++ security/ipe/hooks.h | 6 ++ security/ipe/ipe.c | 9 +++ security/ipe/ipe.h | 3 + security/ipe/modules/Kconfig | 23 +++++++ security/ipe/modules/Makefile | 2 + security/ipe/modules/dmverity_roothash.c | 80 +++++++++++++++++++++++ security/ipe/modules/dmverity_signature.c | 25 +++++++ 10 files changed, 211 insertions(+) create mode 100644 security/ipe/modules/dmverity_roothash.c create mode 100644 security/ipe/modules/dmverity_signature.c
security/ipe/eval.c +5 -0
@@ -23,6 +23,7 @@ static struct super_block *pinned_sb;static DEFINE_SPINLOCK (pin_lock);#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) +#define FILE_BLOCK_DEV (f) (FILE_SUPERBLOCK(f)->s_bdev)/** * pin_sb: pin the underlying superblock of @f, marking it as trusted
@@ -95,6 +96,10 @@ static struct ipe_eval_ctx *build_ctx(const struct file *file, ctx->hook = hook; ctx->ci_ctx =ipe_current_ctx (); ctx->from_init_sb =from_pinned (file); +if (file) { +if (FILE_BLOCK_DEV (file)) + ctx->ipe_bdev =ipe_bdev (FILE_BLOCK_DEV (file)); + }return ctx; }
security/ipe/eval.h +10 -0
@@ -13,6 +13,14 @@#include "hooks.h" #include "policy.h" +struct ipe_bdev { +const u8 *sigdata; +size_t siglen; + +const u8 *hash; +size_t hashlen; +}; +struct ipe_eval_ctx {enum ipe_hook hook;enum ipe_operation op;
@@ -20,6 +28,8 @@ struct ipe_eval_ctx {const struct file *file;struct ipe_context *ci_ctx; +const struct ipe_bdev *ipe_bdev; +bool from_init_sb; };
security/ipe/hooks.c +48 -0
57 lines not on this page · raw message
security/ipe/hooks.h +6 -0
@@ -10,6 +10,7 @@#include <linux/sched.h> #include <linux/binfmts.h> #include <linux/security.h> +#include <linux/device-mapper.h> enum ipe_hook { ipe_hook_exec =0 ,
@@ -40,4 +41,9 @@ int ipe_on_kernel_load_data(enum kernel_load_data_id id, bool contents);void ipe_sb_free_security (struct super_block *mnt_sb); +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 /* IPE_HOOKS_H */
security/ipe/ipe.c +9 -0
@@ -9,6 +9,7 @@#include "ipe_parser.h" #include "modules/ipe_module.h" #include "modules.h" +#include "eval.h" #include <linux/fs.h> #include <linux/sched.h>
@@ -20,8 +21,14 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { .lbs_task =sizeof (struct ipe_context __rcu *), + .lbs_bdev =sizeof (struct ipe_bdev ), }; +struct ipe_bdev *ipe_bdev (struct block_device *b) +{ +return b->security + ipe_blobs.lbs_bdev; +} + static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free),
@@ -31,6 +38,8 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read),LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data),LSM_HOOK_INIT (sb_free_security, ipe_sb_free_security), +LSM_HOOK_INIT (bdev_free_security, ipe_bdev_free_security), + LSM_HOOK_INIT(bdev_setsecurity, ipe_bdev_setsecurity), };/**
security/ipe/ipe.h +3 -0
@@ -14,10 +14,13 @@#include <linux/types.h> #include <linux/sched.h> +#include <linux/blk_types.h> #include <linux/lsm_hooks.h> extern struct lsm_blob_sizes ipe_blobs;extern struct ipe_parser __start_ipe_parsers[], __end_ipe_parsers[];extern struct ipe_module __start_ipe_modules[], __end_ipe_modules[]; +struct ipe_bdev *ipe_bdev (struct block_device *b); +#endif /* IPE_H */
security/ipe/modules/Kconfig +23 -0
@@ -16,5 +16,28 @@ config IPE_PROP_BOOT_VERIFIED If unsure, answer N. +config IPE_PROP_DM_VERITY_SIGNATURE + bool "Enable support for signed dm-verity volumes" + depends on DM_VERITY_VERIFY_ROOTHASH_SIG + default Y + help + This option enables the property 'dmverity_signature' in + IPE policy. This property evaluates to TRUE when a file + is evaluated against a dm-verity volume that was mounted + with a signed root-hash. + + If unsure, answer Y. + +config IPE_PROP_DM_VERITY_ROOTHASH + bool "Enable support for dm-verity volumes" + depends on DM_VERITY + default Y + help + This option enables the property 'dmverity_roothash' in + IPE policy. This property evaluates to TRUE when a file + is evaluated against a dm-verity volume whose root hash + matches the supplied value. + + If unsure, answer Y. endmenu
security/ipe/modules/Makefile +2 -0
@@ -6,3 +6,5 @@ # obj-$(CONFIG_IPE_PROP_BOOT_VERIFIED) += boot_verified.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_SIGNATURE) += dmverity_signature.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_ROOTHASH) += dmverity_roothash.o
security/ipe/modules/dmverity_roothash.c new file +80 -0
80 lines not on this page · raw message
security/ipe/modules/dmverity_signature.c new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +static bool dvv_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +bool expect = (bool )val; +bool eval = ctx->ipe_bdev && (!!ctx->ipe_bdev->sigdata); + +return expect == eval; +} + +IPE_MODULE (dvv) = { + .name ="dmverity_signature" , + .version =1 , + .parse = ipe_bool_parse, + .free =NULL , + .eval = dvv_eval, +};
Signature · 1 line
2.33.0
RFC PATCH v7 9/16 ipe: introduce 'boot_verified' as a trust provider
In reply to [email protected]From: 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.
---
Relevant changes since v6:
* Reword and refactor patch 04/12 to [09/16]
--- security/ipe/Kconfig | 2 + security/ipe/Makefile | 1 + security/ipe/eval.c | 71 ++++++++++++++++++++++++++++ security/ipe/eval.h | 5 ++ security/ipe/hooks.c | 14 ++++++ security/ipe/hooks.h | 2 + security/ipe/ipe.c | 1 + security/ipe/modules.c | 25 ++++++++++ security/ipe/modules/Kconfig | 20 ++++++++ security/ipe/modules/Makefile | 8 ++++ security/ipe/modules/boot_verified.c | 24 ++++++++++ security/ipe/modules/ipe_module.h | 2 + 12 files changed, 175 insertions(+) create mode 100644 security/ipe/modules/Kconfig create mode 100644 security/ipe/modules/Makefile create mode 100644 security/ipe/modules/boot_verified.c
security/ipe/Kconfig +2 -0
@@ -68,4 +68,6 @@ config IPE_AUDIT_HASH_ALG default "sha384" if IPE_AUDIT_HASH_SHA384 default "sha512" if IPE_AUDIT_HASH_SHA512 +source "security/ipe/modules/Kconfig" + endif
security/ipe/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_SECURITY_IPE) += \ fs.o \ hooks.o \ ipe.o \ + modules/ \ modules.o \ parsers/ \ parsers.o \
security/ipe/eval.c +71 -0
96 lines not on this page · raw message
security/ipe/eval.h +5 -0
@@ -7,6 +7,7 @@#define IPE_EVAL_H #include <linux/file.h> +#include <linux/types.h> #include "ctx.h" #include "hooks.h"
@@ -18,6 +19,8 @@ struct ipe_eval_ctx {const struct file *file;struct ipe_context *ci_ctx; + +bool from_init_sb; };enum ipe_match {
@@ -30,4 +33,6 @@ enum ipe_match {int ipe_process_event (const struct file *file,enum ipe_operation op,enum ipe_hook hook); +void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb); +#endif /* IPE_EVAL_H */
security/ipe/hooks.c +14 -0
@@ -205,3 +205,17 @@ int ipe_on_kernel_load_data(enum kernel_load_data_id id, bool contents)return ipe_process_event (NULL , op, ipe_hook_kernel_load); } + +/** +* ipe_bdev_free_security: free nested structures within IPE's LSM blob +* in super_blocks +* @mnt_sb: Supplies a pointer to a super_block that contains the structure +* to free. +* +* 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
@@ -38,4 +38,6 @@ int ipe_on_kernel_read(struct file *file, enum kernel_read_file_id id,int ipe_on_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
@@ -30,6 +30,7 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect),LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read),LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data), + LSM_HOOK_INIT(sb_free_security, ipe_sb_free_security), };/**
security/ipe/modules.c +25 -0
@@ -107,3 +107,28 @@ int ipe_register_module(struct ipe_module *m)return 0 ; } + +/** +* ipe_bool_parse: parse a boolean in IPE's policy and associate +* it as @value in IPE's policy. +* @valstr: Supplies the string parsed from the policy +* @value: Supplies a pointer to be populated with the result. +* +* Modules can use this function for simple true/false values +* instead of defining their own. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_bool_parse (const char *valstr,void **value) +{ +if (!strcmp (valstr,"TRUE" )) + *value = (void *)true; +else if (!strcmp (valstr,"FALSE" )) + *value = (void *)false; +else +return -EBADMSG ; + +return 0 ; +}
security/ipe/modules/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ + +menu "IPE Trust Providers" + +config IPE_PROP_BOOT_VERIFIED + bool "Enable trust for initramfs" + depends on SECURITY_IPE + default N + help + This option enables the property 'boot_verified' in IPE policy. + This property 'pins' the initial superblock when something + is evaluated as an execution. This property will evaluate + to true when the file being evaluated originates from this + superblock. + + This property is useful to authorize a signed initramfs. + + If unsure, answer N. + + +endmenu
security/ipe/modules/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# 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_IPE_PROP_BOOT_VERIFIED) += boot_verified.o
security/ipe/modules/boot_verified.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +static bool bv_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +bool expect = (bool )val; + +return expect == ctx->from_init_sb; +} + +IPE_MODULE (bv) = { + .name ="boot_verified" , + .version =1 , + .parse = ipe_bool_parse, + .free =NULL , + .eval = bv_eval, +};
security/ipe/modules/ipe_module.h +2 -0
@@ -9,6 +9,8 @@#include <linux/audit.h> #include "../eval.h" +int ipe_bool_parse (const char *valstr,void **value); +/** * ipe_module: definition of an extensible module for IPE properties. * These structures are used to implement 'key=value' pairs
Signature · 1 line
2.33.0
RFC PATCH v7 6/16 uapi|audit: add trust audit message definitions
In reply to [email protected]From: Deven Bowers <[email protected]>
Introduce new definitions to audit.h centered around trust decisions and policy loading and activation, as an extension of the mandatory access control fields.
---
Relevant changes since v6:
* Change audit records to MAC region (14XX) from Integrity region (18XX), as IPE is an effectively a MAC system around trust versus an extension to the integrity subsystem.
* Generalize the #defines to support the class of trust-based Access-Control LSMs.
--- include/uapi/linux/audit.h | 4 ++++ 1 file changed, 4 insertions(+)
include/uapi/linux/audit.h +4 -0
@@ -139,6 +139,10 @@#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_TRUST_RESULT 1420/* IPE Denial or Grant */ +#define AUDIT_TRUST_POLICY_LOAD 1421/* IPE Policy Load */ +#define AUDIT_TRUST_POLICY_ACTIVATE 1422/* IPE Policy Activate */ +#define AUDIT_TRUST_STATUS 1423/* IPE enforcing,permissive */ #define AUDIT_FIRST_KERN_ANOM_MSG 1700#define AUDIT_LAST_KERN_ANOM_MSG 1799
Signature · 1 line
2.33.0
RFC PATCH v7 5/16 ipe: add LSM hooks on execution and kernel read
In reply to [email protected]From: 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 execve, mprotect, mmap, kernel_load_data and kernel_read_data.
---
Relevant changes since v6:
* 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] (this patch)
--- security/ipe/hooks.c | 149 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)
security/ipe/hooks.c +149 -0
@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure.
@@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ +return ipe_process_event (bprm->file, ipe_operation_exec, ipe_hook_exec); +} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* @flags: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) +return ipe_process_event (f, ipe_operation_exec, ipe_hook_mmap); + +return 0 ; +} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing +* its protections via mprotect. +* @vma: Existing virtual memory area created by mmap or similar +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from +* disk. +* @id: Supplies the enumeration identifying the purpose of the read. +* @contents: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}
security/ipe/hooks.h +22 -1
@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,
@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */
security/ipe/ipe.c +5 -0
@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data), };/**
security/ipe/policy.c +23 -0
@@ -483,6 +483,14 @@ int ipe_parse_op(const struct ipe_policy_token *tok, {substring_t match[MAX_OPT_ARGS ] = {0 };const match_table_t ops = { + { ipe_operation_exec,"EXECUTE" }, + { ipe_operation_firmware,"FIRMWARE" }, + { ipe_operation_kernel_module,"KMODULE" }, + { ipe_operation_kexec_image,"KEXEC_IMAGE" }, + { ipe_operation_kexec_initramfs,"KEXEC_INITRAMFS" }, + { ipe_operation_ima_policy,"IMA_POLICY" }, + { ipe_operation_ima_x509,"IMA_X509_CERT" }, + { ipe_op_alias_kernel_read,"KERNEL_READ" }, { ipe_op_alias_max,NULL }, };
@@ -838,6 +846,15 @@ static int parse_policy(struct ipe_policy *p)return rc; } +static const enum ipe_operation alias_kread[] = { + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, +}; +/** * ipe_is_op_alias: Determine if @op is an alias for one or more operations * @op: Supplies the operation to check. Should be either ipe_operation or
@@ -852,9 +869,15 @@ static int parse_policy(struct ipe_policy *p)bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size) {switch (op) { +case ipe_op_alias_kernel_read: + *map = alias_kread; + *size =ARRAY_SIZE (alias_kread); +break ;default :return false; } + +return true; }/**
security/ipe/policy.h +10 -2
@@ -26,7 +26,14 @@ struct ipe_policy_line {struct ipe_module ;enum ipe_operation { - ipe_operation_max =0 , + ipe_operation_exec =0 , + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_max };/*
@@ -34,7 +41,8 @@ enum ipe_operation {* that are just one or more operations under the hood */ enum ipe_op_alias { - ipe_op_alias_max = ipe_operation_max, + ipe_op_alias_kernel_read = ipe_operation_max, + ipe_op_alias_max, };enum ipe_action {
Signature · 1 line
2.33.0
RFC PATCH v7 7/16 ipe: add auditing support
In reply to [email protected]From: 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 systens with respect to IPE itself.
---
Relevant changes since v6:
* Split up patch 02/12 into four parts:
1. context creation [01/16]
2. audit [07/16] (this patch)
3. evaluation loop [03/16]
4. access control hooks [05/16]
--- security/ipe/Kconfig | 52 ++++++ security/ipe/Makefile | 2 + security/ipe/audit.c | 264 ++++++++++++++++++++++++++++++ security/ipe/audit.h | 36 ++++ security/ipe/ctx.c | 18 ++ security/ipe/ctx.h | 2 + security/ipe/eval.c | 8 + security/ipe/eval.h | 7 + security/ipe/fs.c | 79 +++++++++ security/ipe/modules/ipe_module.h | 2 + 10 files changed, 470 insertions(+) create mode 100644 security/ipe/audit.c create mode 100644 security/ipe/audit.h
security/ipe/Kconfig +52 -0
@@ -17,3 +17,55 @@ menuconfig SECURITY_IPE requirements on the fly. If unsure, answer N. + +if SECURITY_IPE + +choice + prompt "Hash algorithm used in auditing policies" + default IPE_AUDIT_HASH_SHA1 + depends on AUDIT + help + Specify the hash algorithm used when auditing policies. + The hash is used to uniquely identify a policy from other + policies on the system. + + If unsure, leave default. + + config IPE_AUDIT_HASH_SHA1 + bool "sha1" + depends on CRYPTO_SHA1 + help + Use the SHA128 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA256 + bool "sha256" + depends on CRYPTO_SHA256 + help + Use the SHA256 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA384 + bool "sha384" + depends on CRYPTO_SHA512 + help + Use the SHA384 algorithm to hash policies + in the audit records + + config IPE_AUDIT_HASH_SHA512 + bool "sha512" + depends on CRYPTO_SHA512 + help + Use the SHA512 algorithm to hash policies + in the audit records +endchoice + +config IPE_AUDIT_HASH_ALG + string + depends on AUDIT + default "sha1" if IPE_AUDIT_HASH_SHA1 + default "sha256" if IPE_AUDIT_HASH_SHA256 + default "sha384" if IPE_AUDIT_HASH_SHA384 + default "sha512" if IPE_AUDIT_HASH_SHA512 + +endif
security/ipe/Makefile +2 -0
@@ -18,3 +18,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ parsers.o \ policy.o \ policyfs.o \ + +obj-$(CONFIG_AUDIT) += audit.o
security/ipe/audit.c new file +264 -0
264 lines not on this page · raw message
security/ipe/audit.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef IPE_AUDIT_H +#define IPE_AUDIT_H + +#include "ipe.h" +#include "eval.h" + +#ifdef CONFIG_AUDIT +void ipe_audit_match (const struct ipe_eval_ctx *const ctx, +enum ipe_match match_type, +enum ipe_action act,const struct ipe_rule *const r, +bool enforce); +void ipe_audit_policy_load (const struct ipe_policy *const p); +void ipe_audit_policy_activation (const struct ipe_policy *const p); +#else +static inline void ipe_audit_match (const struct ipe_eval_ctx *const ctx, +enum ipe_match match_type, +enum ipe_action act,const struct ipe_rule *const r, +bool enforce) +{ +} + +static inline void ipe_audit_policy_load (const struct ipe_policy *const p) +{ +} + +static inline void ipe_audit_policy_activation (const struct ipe_policy *const p) +{ +} +#endif /* CONFIG_AUDIT */ + +#endif /* IPE_AUDIT_H */
security/ipe/ctx.c +18 -0
@@ -6,12 +6,16 @@#include "ipe.h" #include "ctx.h" #include "policy.h" +#include "audit.h" #include <linux/slab.h> #include <linux/types.h> #include <linux/parser.h> #include <linux/refcount.h> #include <linux/spinlock.h> +#include <linux/moduleparam.h> + +static bool success_audit;/** * ver_to_u64: convert an internal ipe_policy_version to a u64
@@ -265,6 +269,7 @@ int ipe_set_active_pol(const struct ipe_policy *p)spin_unlock (&ctx->lock);synchronize_rcu (); +ipe_audit_policy_activation (p); out:ipe_put_policy (ap);ipe_put_ctx (ctx);
@@ -330,6 +335,10 @@ int __init ipe_init_ctx(void) goto err; } +spin_lock (&lns->lock); +WRITE_ONCE (lns->success_audit, success_audit); +spin_unlock (&lns->lock); +rcu_assign_pointer (*ipe_tsk_ctx (current), lns);return 0 ;
@@ -337,3 +346,12 @@ int __init ipe_init_ctx(void)ipe_put_ctx (lns);return rc; } + +/* 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/ctx.h +2 -0
@@ -15,6 +15,8 @@struct ipe_context {struct ipe_policy __rcu *active_policy; +bool __rcu success_audit; +refcount_t refcount;/* Protects concurrent writers */ spinlock_t lock;
security/ipe/eval.c +8 -0
@@ -9,6 +9,7 @@#include "hooks.h" #include "policy.h" #include "modules/ipe_module.h" +#include "audit.h" #include <linux/slab.h> #include <linux/file.h>
@@ -73,7 +74,9 @@ static int evaluate(const struct ipe_eval_ctx *const ctx) {int rc =0 ;bool match = false; +bool enforcing = true;enum ipe_action action; +enum ipe_match match_type;struct ipe_policy *pol =NULL ;const struct ipe_rule *rule =NULL ;const struct ipe_policy_mod *module =NULL ;
@@ -97,12 +100,17 @@ static int evaluate(const struct ipe_eval_ctx *const ctx)if (match) { action = rule->action; + match_type = ipe_match_rule; }else if (rules->default_action != ipe_action_max) { action = rules->default_action; + match_type = ipe_match_table; }else { action = pol->parsed->global_default; + match_type = ipe_match_global; } +ipe_audit_match (ctx, match_type, action, rule, enforcing); +if (action == ipe_action_deny) rc = -EACCES ;
security/ipe/eval.h +7 -0
@@ -20,6 +20,13 @@ struct ipe_eval_ctx {struct ipe_context *ci_ctx; }; +enum ipe_match { + ipe_match_rule =0 , + ipe_match_table, + ipe_match_global, + ipe_match_max +}; +int ipe_process_event (const struct file *file,enum ipe_operation op,enum ipe_hook hook);
security/ipe/fs.c +79 -0
115 lines not on this page · raw message
security/ipe/modules/ipe_module.h +2 -0
@@ -6,6 +6,7 @@#define IPE_MODULE_H #include <linux/types.h> +#include <linux/audit.h> #include "../eval.h" /**
@@ -26,6 +27,7 @@ struct ipe_module {int (*free)(void **value);/* optional */ bool (*eval)(const struct ipe_eval_ctx *ctx,/* required */ const void *val); +void (*audit)(struct audit_buffer *ab,const void *val);/* required */ };#define IPE_MODULE (parser) \
Signature · 1 line
2.33.0
RFC PATCH v7 8/16 ipe: add permissive toggle
In reply to [email protected]From: 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.
---
Relevant changes since v6:
* Refactor series to:
1. Support a context structure, enabling easier testing
2. Make parser code cleaner
* 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]
--- security/ipe/audit.c | 40 +++++++++++++++++++++++ security/ipe/audit.h | 5 +++ security/ipe/ctx.c | 6 ++++ security/ipe/ctx.h | 1 + security/ipe/eval.c | 6 ++++ security/ipe/fs.c | 78 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+)
security/ipe/audit.c +40 -0
@@ -262,3 +262,43 @@ 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 +* @ctx: Supplies a pointer to the contexts whose state changed. +*/ +void ipe_audit_enforce (const struct ipe_context *const ctx) +{ +struct audit_buffer *ab; +bool enforcing = false; + + ab =audit_log_start (audit_context (),GFP_KERNEL ,AUDIT_TRUST_STATUS ); +if (!ab) +return ; + +rcu_read_lock (); + enforcing =READ_ONCE (ctx->enforce); +rcu_read_unlock (); + +audit_log_format (ab,"IPE enforce=%d" , enforcing); + +audit_log_end (ab); +} + +/** +* emit_enforcement: Emit the enforcement state of IPE started with. +* +* Return: +* 0 - Always +*/ +static int emit_enforcement (void ) +{ +struct ipe_context *ctx =NULL ; + + ctx =ipe_current_ctx (); +ipe_audit_enforce (ctx); +ipe_put_ctx (ctx); +return 0 ; +} + +late_initcall (emit_enforcement);
security/ipe/audit.h +5 -0
@@ -16,6 +16,7 @@ void ipe_audit_match(const struct ipe_eval_ctx *const ctx, bool enforce);void ipe_audit_policy_load (const struct ipe_policy *const p);void ipe_audit_policy_activation (const struct ipe_policy *const p); +void ipe_audit_enforce (const struct ipe_context *const ctx);#else static inline void ipe_audit_match(const struct ipe_eval_ctx *const ctx, enum ipe_match match_type,
@@ -31,6 +32,10 @@ static inline void ipe_audit_policy_load(const struct ipe_policy *const p)static inline void ipe_audit_policy_activation (const struct ipe_policy *const p) { } + +static inline void ipe_audit_enforce (const struct ipe_context *const ctx) +{ +}#endif /* CONFIG_AUDIT */ #endif /* IPE_AUDIT_H */
security/ipe/ctx.c +6 -0
@@ -16,6 +16,7 @@#include <linux/moduleparam.h> static bool success_audit; +static bool enforce = true;/** * ver_to_u64: convert an internal ipe_policy_version to a u64
@@ -151,6 +152,7 @@ static struct ipe_context *create_ctx(void)INIT_LIST_HEAD (&ctx->policies);refcount_set (&ctx->refcount,1 );spin_lock_init (&ctx->lock); +WRITE_ONCE (ctx->enforce, true);return ctx;
@@ -337,6 +339,7 @@ int __init ipe_init_ctx(void)spin_lock (&lns->lock);WRITE_ONCE (lns->success_audit, success_audit); +WRITE_ONCE (lns->enforce, enforce);spin_unlock (&lns->lock);rcu_assign_pointer (*ipe_tsk_ctx (current), lns);
@@ -355,3 +358,6 @@ int __init ipe_init_ctx(void)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/ctx.h +1 -0
@@ -14,6 +14,7 @@struct ipe_context {struct ipe_policy __rcu *active_policy; +bool __rcu enforce;bool __rcu success_audit;
security/ipe/eval.c +6 -0
@@ -86,6 +86,10 @@ static int evaluate(const struct ipe_eval_ctx *const ctx)if (!pol) goto out; +rcu_read_lock (); + enforcing =READ_ONCE (ctx->ci_ctx->enforce); +rcu_read_unlock (); + rules = &pol->parsed->rules[ctx->op];list_for_each_entry (rule, &rules->rules, next) {
@@ -114,6 +118,8 @@ static int evaluate(const struct ipe_eval_ctx *const ctx)if (action == ipe_action_deny) rc = -EACCES ; +if (!enforcing) + rc =0 ; out:ipe_put_policy (pol);return rc;
security/ipe/fs.c +78 -0
104 lines not on this page · raw message
Signature · 1 line
2.33.0
Eric Biggers
maintainerRe: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to [email protected]Quoted 5 lines · On Wed, Oct 13, 2021 at 12:06:31PM -0700, [email protected] wrote:
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.
Can you elaborate on why LSMs need this information?
Quoted 3 lines
Also changes the implementaion inside the hook function to let multiple LSMs can add hooks.
Please split fs/verity/ changes and security/ changes into separate patches, if possible.
fs/verity/open.c struct fsverity_info *fsverity_create_info(const struct inode *inode, · line 182
Quoted 10 lines
Signed-off-by Fan Wu <[email protected]>Signed-off-by Deven Bowers <[email protected]>fs/verity/open.c +2
-0@@ -177,6 +178,17 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,fsverity_err (inode,"Error %d computing file digest" , err); goto out; } + + err = security_inode_setsecurity((struct inode *)inode,
If a non-const inode is needed, please propagate that into the callers rather than randomly casting away the const.
fs/verity/open.c struct fsverity_info *fsverity_create_info(const struct inode *inode, · line 186
Quoted 4 lines
fs/verity/open.c +4
-0+FS_VERITY_DIGEST_SEC_NAME , + vi->file_digest, + vi->tree_params.hash_alg->digest_size, + 0);
The digest isn't meaningful without knowing the hash algorithm it uses. It's available here, but you aren't passing it to this function.
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 88
Quoted 6 lines
fs/verity/signature.c +1
-1@@ -84,7 +85,9 @@ int fsverity_verify_signature(const struct fsverity_info *vi,pr_debug ("Valid signature for file digest %s:%*phN\n" , hash_alg->name, hash_alg->digest_size, vi->file_digest); -return 0 ; + return security_inode_setsecurity((struct inode *)inode,
Likewise, please don't cast away const.
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);
This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for? Can you elaborate on your use case for fs-verity built-in signatures, and what the LSM hook will do with them?
- Eric
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to [email protected]Hello,
Quoted 4 lines · On Wednesday, October 13, 2021 3:06:26 PM EDT [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 systens with respect to IPE itself.
Would you mind sending examples of audit events so that we can see what the end result is? Some people add them to the commit text. But we still need to see what they look like.
Thanks,
-Steve
Re: [RFC PATCH v7 05/16] ipe: add LSM hooks on execution and kernel read
In reply to [email protected]Quoted 242 lines · On 10/13/2021 12:06 PM, [email protected] wrote:
From: 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 execve, mprotect, mmap,
kernel_load_dataandkernel_read_data.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* 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] (this patch)--- security/ipe/hooks.c | 149 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)security/ipe/hooks.c +149
-0@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure. @@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ +return ipe_process_event (bprm->file, ipe_operation_exec, ipe_hook_exec); +} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* @flags: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) +return ipe_process_event (f, ipe_operation_exec, ipe_hook_mmap); + +return 0 ; +} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing +* its protections via mprotect. +* @vma: Existing virtual memory area created by mmap or similar +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from +* disk. +* @id: Supplies the enumeration identifying the purpose of the read. +* @contents: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}security/ipe/hooks.h +22
-1@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */ security/ipe/ipe.c +0
-0
security/ipe/ipe.c struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { · line 32
Quoted 8 lines
security/ipe/ipe.c +5
-0@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data),
Please stick with the lsmname_hook_name convention, as you did with ipe_task_alloc and ipe_task_free. Anyone who is looking at more than one LSM is going to have a much harder time working with your code the way you have it. Think
% find security | xargs grep '_bprm_check_security('
Quoted 84 lines
security/ipe/ipe.c +0
-0};/** security/ipe/policy.c +23
-0@@ -483,6 +483,14 @@ int ipe_parse_op(const struct ipe_policy_token *tok, {substring_t match[MAX_OPT_ARGS ] = {0 };const match_table_t ops = { + { ipe_operation_exec,"EXECUTE" }, + { ipe_operation_firmware,"FIRMWARE" }, + { ipe_operation_kernel_module,"KMODULE" }, + { ipe_operation_kexec_image,"KEXEC_IMAGE" }, + { ipe_operation_kexec_initramfs,"KEXEC_INITRAMFS" }, + { ipe_operation_ima_policy,"IMA_POLICY" }, + { ipe_operation_ima_x509,"IMA_X509_CERT" }, + { ipe_op_alias_kernel_read,"KERNEL_READ" }, { ipe_op_alias_max,NULL }, };@@ -838,6 +846,15 @@ static int parse_policy(struct ipe_policy *p)return rc; } +static const enum ipe_operation alias_kread[] = { + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, +}; +/** * ipe_is_op_alias: Determine if @op is an alias for one or more operations * @op: Supplies the operation to check. Should be either ipe_operation or @@ -852,9 +869,15 @@ static int parse_policy(struct ipe_policy *p)bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size) {switch (op) { +case ipe_op_alias_kernel_read: + *map = alias_kread; + *size =ARRAY_SIZE (alias_kread); +break ;default :return false; } + +return true; }/** security/ipe/policy.h +10
-2@@ -26,7 +26,14 @@ struct ipe_policy_line {struct ipe_module ;enum ipe_operation { - ipe_operation_max =0 , + ipe_operation_exec =0 , + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_max };/* @@ -34,7 +41,8 @@ enum ipe_operation {* that are just one or more operations under the hood */ enum ipe_op_alias { - ipe_op_alias_max = ipe_operation_max, + ipe_op_alias_kernel_read = ipe_operation_max, + ipe_op_alias_max, };enum ipe_action {
Randy Dunlap
reviewerRe: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to [email protected]Hi,
Quoted 50 lines · On 10/13/21 12:06 PM, [email protected] wrote:
security/ipe/Kconfig +42
-0@@ -17,3 +17,55 @@ menuconfig SECURITY_IPE requirements on the fly. If unsure, answer N. + +if SECURITY_IPE + +choice + prompt "Hash algorithm used in auditing policies" + default IPE_AUDIT_HASH_SHA1 + depends on AUDIT + help + Specify the hash algorithm used when auditing policies. + The hash is used to uniquely identify a policy from other + policies on the system. + + If unsure, leave default. + + config IPE_AUDIT_HASH_SHA1 + bool "sha1" + depends on CRYPTO_SHA1 + help + Use the SHA128 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA256 + bool "sha256" + depends on CRYPTO_SHA256 + help + Use the SHA256 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA384 + bool "sha384" + depends on CRYPTO_SHA512 + help + Use the SHA384 algorithm to hash policies + in the audit records + + config IPE_AUDIT_HASH_SHA512 + bool "sha512" + depends on CRYPTO_SHA512 + help + Use the SHA512 algorithm to hash policies + in the audit records +endchoice
security/ipe/Kconfig menuconfig SECURITY_IPE · line 71
Quoted 10 lines
security/ipe/Kconfig +10
-0+ +config IPE_AUDIT_HASH_ALG + string + depends on AUDIT + default "sha1" if IPE_AUDIT_HASH_SHA1 + default "sha256" if IPE_AUDIT_HASH_SHA256 + default "sha384" if IPE_AUDIT_HASH_SHA384 + default "sha512" if IPE_AUDIT_HASH_SHA512 + +endif
Please follow coding-style for Kconfig files:
(from Documentation/process/coding-style.rst, section 10):
For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.
thanks.
Signature · 1 line
~Randy
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Steve GrubbQuoted 8 lines · Steve Grubb
Hello,
Quoted 4 lines · On Wednesday, October 13, 2021 3:06:26 PM EDT [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 systens with respect to IPE itself.
Quoted 6 lines
Would you mind sending examples of audit events so that we can see what the end result is? Some people add them to the commit text. But we still need to see what they look like.
Thanks,
-Steve
Sure, sorry. I’ll add them to the commit description (and the documentation patch at the end) for v8 – In the interest of asynchronous feedback, I’ve copied the relevant examples:
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT op=EXECUTE action=DENY"
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT action=DENY"
AUDIT1420 IPE ctx_pid=253 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=1 ctx_comm="anon" rule="DEFAULT op=EXECUTE action=DENY"
These three audit records represent various types of results after evaluating the trust of a resource. The first two differ in the rule that was matched in IPE's policy, the first being an operation-specific default, the second being a global default. The third is an example of what is audited when anonymous memory is blocked (as there is no way to verify the trust of an anonymous page).
The remaining three events, AUDIT_TRUST_POLICY_LOAD (1421), AUDIT_TRUST_POLICY_ACTIVATE (1422), and AUDIT_TRUST_STATUS (1423) have this form:
AUDIT1421 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash> AUDIT1422 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash> AUDIT1423 IPE enforce=1
The 1421 (AUDIT_TRUST_POLICY_LOAD) event represents a new policy was loaded into the kernel, but not is not marked as the policy to enforce. The
The 1422 (AUDIT_TRUST_POLICY_ACTIVATE) event represents a policy that was already loaded was made the enforcing policy.
The 1423 (AUDIT_TRUST_STATUS) event represents a switch between permissive and enforce, it is added in 08/16 (the following patch)
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Randy DunlapQuoted 65 lines · Randy Dunlap
Hi,
Quoted 49 lines · On 10/13/21 12:06 PM, [email protected] wrote:
security/ipe/Kconfig +0
-0@@ -17,3 +17,55 @@ menuconfig SECURITY_IPErequirements on the fly.
If unsure, answer N.security/ipe/Kconfig +42
-0+ +if SECURITY_IPE + +choice + prompt "Hash algorithm used in auditing policies" + default IPE_AUDIT_HASH_SHA1 + depends on AUDIT + help + Specify the hash algorithm used when auditing policies. + The hash is used to uniquely identify a policy from other + policies on the system. + + If unsure, leave default. + + config IPE_AUDIT_HASH_SHA1 + bool "sha1" + depends on CRYPTO_SHA1 + help + Use the SHA128 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA256 + bool "sha256" + depends on CRYPTO_SHA256 + help + Use the SHA256 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA384 + bool "sha384" + depends on CRYPTO_SHA512 + help + Use the SHA384 algorithm to hash policies + in the audit records + + config IPE_AUDIT_HASH_SHA512 + bool "sha512" + depends on CRYPTO_SHA512 + help + Use the SHA512 algorithm to hash policies + in the audit records +endchoicesecurity/ipe/Kconfig menuconfig SECURITY_IPE · line 71
Quoted 10 lines
security/ipe/Kconfig +10
-0+ +config IPE_AUDIT_HASH_ALG + string + depends on AUDIT + default "sha1" if IPE_AUDIT_HASH_SHA1 + default "sha256" if IPE_AUDIT_HASH_SHA256 + default "sha384" if IPE_AUDIT_HASH_SHA384 + default "sha512" if IPE_AUDIT_HASH_SHA512 + +endifPlease follow coding-style for
Kconfigfiles:
Quoted 7 lines
(from
Documentation/process/coding-style.rst, section 10):For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.
Oof. That's embarrassing. Sorry, I'll fix this for v8.
While I'm at it, is the help text required for choice configs? checkpatch --strict complains with a warning without them, but I see other places in the tree where help text is omitted for these configs attached to a choice.
Documentation/process/* doesn't seem to have any guidance, nor Documentation/kbuild/* on whether it is safe to ignore that checkpatch warning.
Re: [RFC PATCH v7 05/16] ipe: add LSM hooks on execution and kernel read
In reply to Casey SchauflerQuoted 256 lines · Casey Schaufler
Quoted 242 lines · On 10/13/2021 12:06 PM, [email protected] wrote:
From: 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 execve, mprotect, mmap,
kernel_load_dataandkernel_read_data.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* 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] (this patch)--- security/ipe/hooks.c | 149 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)security/ipe/hooks.c +149
-0@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure. @@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ +return ipe_process_event (bprm->file, ipe_operation_exec, ipe_hook_exec); +} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* @flags: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) +return ipe_process_event (f, ipe_operation_exec, ipe_hook_mmap); + +return 0 ; +} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing +* its protections via mprotect. +* @vma: Existing virtual memory area created by mmap or similar +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from +* disk. +* @id: Supplies the enumeration identifying the purpose of the read. +* @contents: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}security/ipe/hooks.h +22
-1@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */ security/ipe/ipe.c +0
-0security/ipe/ipe.c struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { · line 32
Quoted 8 lines
security/ipe/ipe.c +5
-0@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data),Please stick with the
lsmname_hook_nameconvention, as you did withipe_task_allocandipe_task_free. Anyone who is looking at more than one LSM is going to have a much harder time working with your code the way you have it. Think
Quoted 1 line
% find security | xargs grep '_bprm_check_security('
Sure. I'll make this change with the v8 series.
Re: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Eric BiggersQuoted 7 lines · Eric Biggers
Quoted 5 lines · On Wed, Oct 13, 2021 at 12:06:31PM -0700, [email protected] wrote:
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case. IPE does not want to recalculate a digest, that’s expensive and doesn’t provide any value. IPE, in this case, treats this as a buffer to compare the policy-provided one above to make a policy decision about access to the resource.
Quoted 4 lines
Quoted 2 lines
Also changes the implementaion inside the hook function to let multiple LSMs can add hooks.
Please split
fs/verity/changes andsecurity/changes into separate patches, if possible.
Sorry, will do, not a problem.
Quoted 15 lines
fs/verity/open.c struct fsverity_info *fsverity_create_info(const struct inode *inode, · line 182
Quoted 6 lines
fs/verity/open.c +2
-0@@ -177,6 +178,17 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,fsverity_err (inode,"Error %d computing file digest" , err); goto out; } + + err = security_inode_setsecurity((struct inode *)inode,If a non-const inode is needed, please propagate that into the callers rather than randomly casting away the const.
Quoted 6 lines
fs/verity/open.c +4
-0+FS_VERITY_DIGEST_SEC_NAME , + vi->file_digest, + vi->tree_params.hash_alg->digest_size, + 0);@@ -84,7 +85,9 @@ int fsverity_verify_signature(const struct fsverity_info *vi,
Quoted 6 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 92
Quoted 5 lines
fs/verity/signature.c +1
-1pr_debug ("Valid signature for file digest %s:%*phN\n" , hash_alg->name, hash_alg->digest_size, vi->file_digest); -return 0 ; + return security_inode_setsecurity((struct inode *)inode,Likewise, please don't cast away const.
Sorry, I should've caught these myself. I'll change fsverity_create_info to accept the non-const inode, and change fsverity_verify_signature to accept an additional inode struct as the first arg instead of changing the fsverity_info structure to have a non-const inode field.
Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Quoted 1 line
and what the LSM hook will do with them?
At the moment, this will just signal to IPE that these fs-verity files were enabled with a built-in signature as opposed to enabled without a signature. In v7, it copies the signature data into IPE's LSM blob attached to the inode. In v8+, I'm changing this to store “true” in IPE's LSM blob instead, as copying the signature data is an unnecessary waste of space and point of failure. This has a _slightly_ different functionality then fs.verity.require_signatures, because even if someone were to disable the require signatures option, IPE would still know if these files were signed or not and be able to make the access control decision based IPE's policy.
Very concretely, this powers this kind of rule in IPE:
op=EXECUTE fsverity_signature=TRUE action=ALLOW
if that fsverity_signature value in IPE’s LSM blob attached to the inode is true, then fsverity_signature in IPE’s policy will evaluate to true and match this rule. The inverse is also applicable.
Randy Dunlap
reviewerRe: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Deven BowersQuoted 73 lines · Deven Bowers
Quoted 65 lines · Randy Dunlap
Hi,
Quoted 49 lines · On 10/13/21 12:06 PM, [email protected] wrote:
security/ipe/Kconfig +0
-0@@ -17,3 +17,55 @@ menuconfig SECURITY_IPErequirements on the fly.
If unsure, answer N.security/ipe/Kconfig +42
-0+ +if SECURITY_IPE + +choice + prompt "Hash algorithm used in auditing policies" + default IPE_AUDIT_HASH_SHA1 + depends on AUDIT + help + Specify the hash algorithm used when auditing policies. + The hash is used to uniquely identify a policy from other + policies on the system. + + If unsure, leave default. + + config IPE_AUDIT_HASH_SHA1 + bool "sha1" + depends on CRYPTO_SHA1 + help + Use the SHA128 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA256 + bool "sha256" + depends on CRYPTO_SHA256 + help + Use the SHA256 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA384 + bool "sha384" + depends on CRYPTO_SHA512 + help + Use the SHA384 algorithm to hash policies + in the audit records + + config IPE_AUDIT_HASH_SHA512 + bool "sha512" + depends on CRYPTO_SHA512 + help + Use the SHA512 algorithm to hash policies + in the audit records +endchoicesecurity/ipe/Kconfig menuconfig SECURITY_IPE · line 71
Quoted 10 lines
security/ipe/Kconfig +10
-0+ +config IPE_AUDIT_HASH_ALG + string + depends on AUDIT + default "sha1" if IPE_AUDIT_HASH_SHA1 + default "sha256" if IPE_AUDIT_HASH_SHA256 + default "sha384" if IPE_AUDIT_HASH_SHA384 + default "sha512" if IPE_AUDIT_HASH_SHA512 + +endifPlease follow coding-style for
Kconfigfiles:Quoted 7 lines
(from
Documentation/process/coding-style.rst, section 10):For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.
Quoted 6 lines
Oof. That's embarrassing. Sorry, I'll fix this for v8.
While I'm at it, is the help text required for choice configs? checkpatch --strict complains with a warning without them, but I see other places in the tree where help text is omitted for these configs attached to a choice.
Does checkpatch complain about what you have above or did you add that help text to keep it from complaining?
Quoted 3 lines
Documentation/process/*doesn't seem to have any guidance, norDocumentation/kbuild/*on whether it is safe to ignore that checkpatch warning.
Yeah, I don't think that we have any good guidance on that.
I would say that if the choice prompt provides good/adequate help info, then each 'config' inside the choice block does not need help text. OTOH, if the choice prompt has little/no help info, then each 'config' under it should have some useful info.
I only looked in arch/x86/Kconfig, init/Kconfig, and lib/Kconfig.debug, but you can see either help text method being used in those.
And then if the help text is adequate in either one of those methods, I would just ignore the checkpatch complaints. It's just a guidance tool.
HTH.
Signature · 1 line
~Randy
Eric Biggers
maintainerRe: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Deven BowersQuoted 8 lines · Deven Bowers
Quoted 6 lines · Eric Biggers
Quoted 5 lines · On Wed, Oct 13, 2021 at 12:06:31PM -0700, [email protected] wrote:
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.
Quoted 6 lines
Quoted 1 line
Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
Quoted 7 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
Quoted 8 lines
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Quoted 6 lines
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case.
No, it's not.
Digests are meaningless without knowing what algorithm they were created with.
If your security policy is something like "Trust the file with digest $foo" and multiple hash algorithms are possible, then the alorithm intended to be used needs to be explicitly specified. Otherwise any algorithm with the same length digest will be accepted. That's a fatal flaw if any of these algorithms is cryptographically broken or was never intended to be a cryptographic algorithm in the first place (e.g., a non-cryptographic checksum).
Cryptosystems always need to specify the crypto algorithm(s) used; the adversary must not be allowed to choose the algorithms.
I'm not sure how these patches can be taken seriously when they're getting this sort of thing wrong.
Quoted 14 lines
Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 8 lines
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Most users of fs-verity built-in signatures have actually been enforcing their security policy in userspace, by checking whether specific files have the fs-verity bit set or not. Such users could just store and verify signatures in userspace instead, without any kernel involvement. So that's what I've been recommending (with limited success, unfortunately).
If you really do need in-kernel signature verification, then that may be a legitimate use case for the fs-verity built-in signatures, although I do wonder why you aren't using IMA and its signature mechanism instead.
- Eric
RE: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
Quoted 41 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Friday, October 15, 2021 10:11 PMQuoted 3 lines · Deven Bowers
Quoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 11 lines · [email protected] wrote:
Quoted 6 lines
Quoted 5 lines
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
Quoted 7 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
Quoted 8 lines
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Quoted 2 lines
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
I was wondering if the following use case can be supported:
allow the execution of files protected with fsverity if the root digest is found among reference values (instead of providing them one by one in the policy).
Something like:
op=EXECUTE fsverity_digest=diglim action=ALLOW
DIGLIM is a component I'm working on that generically stores digests. The current use case is to store file digests from RPMTAG_FILEDIGESTS and use them with IMA, but the fsverity use case could be easily supported (if the root digest is stored in the RPM header).
DIGLIM also tells whether or not the signature of the source containing file digests (or fsverity digests) is valid (the signature of the RPM header is taken from RPMTAG_RSAHEADER).
The memory occupation is relatively small for executables and shared libraries. I published a demo for Fedora and openSUSE some time ago:
https://lore.kernel.org/linux-integrity/[email protected]/
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 60 lines
Quoted 6 lines
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case.
No, it's not.
Digests are meaningless without knowing what algorithm they were created with.
If your security policy is something like "Trust the file with digest $foo" and multiple hash algorithms are possible, then the alorithm intended to be used needs to be explicitly specified. Otherwise any algorithm with the same length digest will be accepted. That's a fatal flaw if any of these algorithms is cryptographically broken or was never intended to be a cryptographic algorithm in the first place (e.g., a non-cryptographic checksum).
Cryptosystems always need to specify the crypto algorithm(s) used; the adversary
must not be allowed to choose the algorithms.I'm not sure how these patches can be taken seriously when they're getting this sort of thing wrong.
Quoted 14 lines
Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 8 lines
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Most users of fs-verity built-in signatures have actually been enforcing their security policy in userspace, by checking whether specific files have the fs-verity bit set or not. Such users could just store and verify signatures in userspace instead, without any kernel involvement. So that's what I've been recommending (with limited success, unfortunately).
If you really do need in-kernel signature verification, then that may be a legitimate use case for the fs-verity built-in signatures, although I do wonder why you aren't using IMA and its signature mechanism instead.
- Eric
RE: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
Quoted 46 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, October 20, 2021 5:09 PMQuoted 41 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Friday, October 15, 2021 10:11 PMQuoted 3 lines · Deven Bowers
Quoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 11 lines · [email protected] wrote:
Quoted 6 lines
Quoted 5 lines
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
Quoted 7 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
Quoted 8 lines
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Quoted 2 lines
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Quoted 8 lines
I was wondering if the following use case can be supported:
allow the execution of files protected with fsverity if the root digest is found among reference values (instead of providing them one by one in the policy).Something like:
op=EXECUTE fsverity_digest=diglim action=ALLOW
Looks like it works. I modified IPE to query the root digest of an fsverity-protected file in DIGLIM.
# cat ipe-policy policy_name="AllowFSVerityKmodules" policy_version=0.0.1 DEFAULT action=ALLOW DEFAULT op=KMODULE action=DENY op=KMODULE fsverity_digest=diglim action=ALLOW
IPE setup:
# cat ipe-policy.p7s > /sys/kernel/security/ipe/new_policy # echo -n 1 > /sys/kernel/security/ipe/policies/AllowFSVerityKmodules/active # echo 1 > /sys/kernel/security/ipe/enforce
IPE denies loading of kernel modules not protected by fsverity:
# insmod /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko insmod: ERROR: could not insert module /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko: Permission denied
Protect fat.ko with fsverity:
# cp /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko /fsverity # fsverity enable /fsverity/fat.ko # fsverity measure /fsverity/fat.ko sha256:079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 /fsverity/fat.ko
IPE still denies the loading of fat.ko (root digest not uploaded to the kernel):
# insmod /fsverity/fat.ko insmod: ERROR: could not insert module /fsverity/fat.ko: Permission denied
Generate a digest list with the root digest above and upload it to the kernel:
# ./compact_gen -i 079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 -a sha256 -d test -s -t file -f # echo $PWD/test/0-file_list-compact-079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 > /sys/kernel/security/integrity/diglim/digest_list_add
IPE allows the loading of fat.ko:
# insmod /fsverity/fat.ko #
Regarding authenticity, not shown in this demo, IPE will also ensure that the root digest is signed (diglim_digest_get_info() reports this information).
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 87 lines
DIGLIM is a component I'm working on that generically stores digests. The current use case is to store file digests from
RPMTAG_FILEDIGESTSand use them with IMA, but the fsverity use case could be easily supported (if the root digest is stored in the RPM header).DIGLIM also tells whether or not the signature of the source containing file digests (or fsverity digests) is valid (the signature of the RPM header is taken from
RPMTAG_RSAHEADER).The memory occupation is relatively small for executables and shared libraries. I published a demo for Fedora and openSUSE some time ago:
https://lore.kernel.org/linux-
integrity/[email protected]/Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 9 lines
Quoted 6 lines
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case.
No, it's not.
Quoted 8 lines
Digests are meaningless without knowing what algorithm they were created with.
If your security policy is something like "Trust the file with digest $foo" and multiple hash algorithms are possible, then the alorithm intended to be used needs to be explicitly specified. Otherwise any algorithm with the same length digest will be accepted. That's a fatal flaw if any of these algorithms is cryptographically broken or was never intended to be a cryptographic
algorithm
Quoted 7 lines
in the first place (e.g., a non-cryptographic checksum).
Cryptosystems always need to specify the crypto algorithm(s) used; the adversary
must not be allowed to choose the algorithms.I'm not sure how these patches can be taken seriously when they're getting
this
Quoted 3 lines
sort of thing wrong.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
FS_VERITY_SIGNATURE_SEC_NAME,Quoted 33 lines
Quoted 13 lines
Quoted 3 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 1 line
fs/verity/signature.c +1
-0+ signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 8 lines
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Most users of fs-verity built-in signatures have actually been enforcing their security policy in userspace, by checking whether specific files have the fs-verity bit set or not. Such users could just store and verify signatures in userspace instead, without any kernel involvement. So that's what I've been recommending (with limited success, unfortunately).
If you really do need in-kernel signature verification, then that may be a legitimate use case for the fs-verity built-in signatures, although I do wonder why you aren't using IMA and its signature mechanism instead.
- Eric
Quoted 11 lines
From: [email protected] [mailto:[email protected]]
From: Deven Bowers <[email protected]>Overview:
---------IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing systems approach use labels or paths which control access to a resource, IPE controls access to a resource based on the system's trust of said resource.
To me, it does not give a particularly precise idea of what IPE is about.
It would have been more clear, assuming that I understood it correctly, if you have said:
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.
Quoted 31 lines
Trust requirements are established via IPE's policy, sourcing multiple different implementations within the kernel to build a cohesive trust model, based on how the system was built.
Trust, with respect to computing, is a concept that designates a set of entities who will endorse a set of resources as non-malicious. Traditionally, this is done via signatures, which is the act of endorsing a resource.
Integrity, on the other hand, is the concept of ensuring that a resource has not been modified since a point of time. This is typically done through cryptographic hashes or signatures.
Trust and integrity are very closely tied together concepts, as integrity is the way you can prove trust for a resource; otherwise it could have been modified by an entity who is untrusted.
IPE provides a way for a user to express trust requirements of resources, by using pre-existing systems which provide the integrity half of the equation.
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.
Quoted 5 lines
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. Instead, IPE supports the PKI Trust Model, which generally designates a set of entities that provide a measure absolute trust.
It is true that packages are signed with PGP, which is decentralized, but there is a special case where Linux distribution vendors trust their own keys. This, at least, would allow to trust the software built by a particular vendor (I ported David Howells's work on PGP keys and signature to the current kernel).
Quoted 5 lines
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.
Yes, RPMs don't have per file signatures but have a signature of the list of file digests, which is equivalent. They could have also the fsverity digests (instead of the fsverity signatures) to reduce size overhead.
Given that the authenticity of RPMs headers can be verified, if the PGP key of the vendor is included in the primary keyring of the kernel, being able to protect file or fsverity digests against tampering by user space and being able to query them (e.g. with DIGLIM) extends the applicability of IPE to general purpose OSes.
Quoted 8 lines
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:
Quoted 8 lines
policy_name="Ex Policy" policy_version=0.0.0
The policy version indicates the current version of the policy (NOT the policy syntax version). 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 properties: "action",
Better:
IPE rules require two keys:
Quoted 142 lines
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 will allow any execution. 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. Available properties for IPE described in the documentation patch of this series.
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. 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. User mode can interrogate the kernel to understand what properties and the associated versions through the securityfs node, $securityfs/ipe/config, which will return a string of form:
key1=version1
key2=version2
.
.
.
keyN=versionNUser-mode should correlate these versions with the supported values identified in the documentation to determine whether a policy should be accepted by the system without actually trying to deploy 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, 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 userland 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=ALLOWAllow 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=ALLOWProhibit execution from a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec 146938 action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_signature=TRUE action=ALLOWAllow only a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec 146938 action=ALLOWDeploying Policies:
-------------------First sign a plain text policy, with a certificate that is present in the
SYSTEM_TRUSTED_KEYRINGof your test machine. Through openssl, the signing can be done via:openssl smime -sign -in "$MY_POLICY" -signer "$MY_CERTIFICATE" \ -inkey "$MY_PRIVATE_KEY" -binary -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_policyThe 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_versionattribute 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: The securityfs commands will require
CAP_MAC_ADMIN.
Quoted 7 lines
Integrations:
-------------This patch series adds support for fsverity via digest and signature (
fsverity_signatureandfsverity_digest), dm-verity by digest and signature (dmverity_signatureanddmverity_roothash), and trust for the initramfs (boot_verified).
Verifying the initial ram disk looks like a big problem. On general purpose OSes, having a reference value for it would be very hard.
Instead, we would still be able to use per file reference values. Executable and shared libraries in the initial ram disk are copied from the main OS. Without fsverity support in tmpfs, I wonder if it would be still possible to mark the file as immutable and do an on the fly calculation of the root digest.
As an alternative, the IMA approach of calculating the file digest could be used (or IPE could get the file digest as a property from the integrity subsystem).
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 327 lines
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_SECURITY_IPE=y
CONFIG_SECURITY_IPE_KUNIT_TEST=y
CONFIG_IPE_PROP_BOOT_VERIFIED=y
CONFIG_IPE_PROP_DM_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_DM_VERITY_ROOTHASH=y
CONFIG_IPE_PROP_FS_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_FS_VERITY_DIGEST=ySimply run:
make ARCH=um mrproper
./tools/testing/kunit/kunit.pyrun --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. This includes architectural block diagrams.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. However, there is a patchset that is looking to address this gap [1].
Appendix:
---------A. IPE Github Repository: https://github.com/microsoft/ipe
B. IPE Users' Guide:Documentation/admin-guide/LSM/ipe.rstReferences:
-----------[1] https://lore.kernel.org/all/[email protected]/
FAQ:
----Q: What's the difference between other LSMs which provide trust-based
access control, for instance, IMA?A: IMA is a fantastic option when needing measurement in addition to the
trust-based access model. All of IMA is centered around their measurement hashes, so you save time when doing both actions. IPE, on the other hand, is a highly performant system that does not rely (and explicitly prohibits), generating its own integrity mechanisms - separating measurement and access control. Simply put, IPE provides only the enforcement of trust, while other subsystems provide the integrity guarantee that IPE needs to determine the trust of a resource. IMA provides both the integrity guarantee, the enforcement of trust, and a whole host of other features that may not be needed.Changelog:
----------Changes since v1:
Split the second patch of the previous series into two. Minor corrections in the cover-letter and documentation comments regardingCAP_MAC_ADMINchecks in IPE.Changes since v2:
Address various comments by Jann Horn. Highlights:
Switch various audit allocators toGFP_KERNEL. Utilizercu_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.Changes since v3:
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.Changes since v4:
Correct some grammatical errors reported by Randy Dunlap. Fix some warnings reported by kernel test bot.
Change convention aroundsecurity_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.Changes since v5:
Change if statement condition insecurity_bdev_setsecurityto 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.Changes since v6:
* 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
* DroppedCONFIG_SECURITY_IPE_PERMISSIVE_SWITCH- functionality can easily come later with a small patch.
* Use partition0 forblock_devicefor dm-verity patchDeven Bowers (14):
security: add ipe lsm & initial context creation
ipe: add policy parser
ipe: add evaluation loop
ipe: add userspace interface
ipe: add LSM hooks on execution and kernel read uapi|audit: add trust audit message definitions
ipe: add auditing support
ipe: add permissive toggle
ipe: introduce 'boot_verified' as a trust provider fs|dm-verity: addblock_devLSM blob and submit dm-verity data
ipe: add support for dm-verity as a trust provider
scripts: add boot policy generation program
ipe: kunit tests
documentation: add ipe documentationFan Wu (2):
fsverity|security: add security hooks to fsverity digest and signature
ipe: enable support for fs-verity as a trust providerDocumentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 587 ++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 339 ++++++ MAINTAINERS | 9 + block/bdev.c | 7 + drivers/md/dm-verity-target.c | 20 +- drivers/md/dm-verity-verify-sig.c | 16 +- drivers/md/dm-verity-verify-sig.h | 10 +- fs/verity/open.c | 12 + fs/verity/signature.c | 5 +- include/asm-generic/vmlinux.lds.h | 16 + include/linux/blk_types.h | 1 + include/linux/device-mapper.h | 3 + include/linux/fsverity.h | 3 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 12 + include/linux/security.h | 22 + include/uapi/linux/audit.h | 4 + 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/ipe/.gitignore | 1 + security/ipe/Kconfig | 100 ++ security/ipe/Makefile | 39 + security/ipe/audit.c | 304 +++++ security/ipe/audit.h | 41 + security/ipe/ctx.c | 381 ++++++ security/ipe/ctx.h | 43 + security/ipe/ctx_test.c | 732 ++++++++++++ security/ipe/eval.c | 237 ++++ security/ipe/eval.h | 57 + security/ipe/fs.c | 327 ++++++ security/ipe/fs.h | 13 + security/ipe/hooks.c | 328 ++++++ security/ipe/hooks.h | 56 + security/ipe/ipe.c | 143 +++ security/ipe/ipe.h | 27 + security/ipe/ipe_parser.h | 59 + security/ipe/modules.c | 134 +++ security/ipe/modules.h | 17 + security/ipe/modules/Kconfig | 66 ++ security/ipe/modules/Makefile | 12 + security/ipe/modules/boot_verified.c | 24 + security/ipe/modules/dmverity_roothash.c | 80 ++ security/ipe/modules/dmverity_signature.c | 25 + security/ipe/modules/fsverity_digest.c | 80 ++ security/ipe/modules/fsverity_signature.c | 33 + security/ipe/modules/ipe_module.h | 40 + security/ipe/parsers.c | 139 +++ security/ipe/parsers/Makefile | 12 + security/ipe/parsers/default.c | 106 ++ security/ipe/parsers/policy_header.c | 126 ++ security/ipe/policy.c | 1037 +++++++++++++++++ security/ipe/policy.h | 113 ++ security/ipe/policy_parser_tests.c | 299 +++++ security/ipe/policyfs.c | 528 +++++++++ security/security.c | 76 +- 63 files changed, 7069 insertions(+), 18 deletions(-) create mode 100644 Documentation/admin-guide/LSM/ipe.rst create mode 100644 Documentation/security/ipe.rst 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/ctx.c create mode 100644 security/ipe/ctx.h create mode 100644 security/ipe/ctx_test.c 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/ipe_parser.h create mode 100644 security/ipe/modules.c create mode 100644 security/ipe/modules.h create mode 100644 security/ipe/modules/Kconfig create mode 100644 security/ipe/modules/Makefile create mode 100644 security/ipe/modules/boot_verified.c create mode 100644 security/ipe/modules/dmverity_roothash.c create mode 100644 security/ipe/modules/dmverity_signature.c create mode 100644 security/ipe/modules/fsverity_digest.c create mode 100644 security/ipe/modules/fsverity_signature.c create mode 100644 security/ipe/modules/ipe_module.h create mode 100644 security/ipe/parsers.c create mode 100644 security/ipe/parsers/Makefile create mode 100644 security/ipe/parsers/default.c create mode 100644 security/ipe/parsers/policy_header.c create mode 100644 security/ipe/policy.c create mode 100644 security/ipe/policy.h create mode 100644 security/ipe/policy_parser_tests.c create mode 100644 security/ipe/policyfs.c
Quoted 2 lines
--
2.33.0
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
RE: [RFC PATCH v7 05/16] ipe: add LSM hooks on execution and kernel read
In reply to [email protected]Quoted 145 lines
From: [email protected] [mailto:[email protected]]
From: 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 execve, mprotect, mmap,
kernel_load_dataandkernel_read_data.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* 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] (this patch)--- security/ipe/hooks.c | 149 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)security/ipe/hooks.c +18
-0@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure. @@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ + return ipe_process_event(bprm->file, ipe_operation_exec,
ipe_hook_exec);security/ipe/hooks.c +20
-0+} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* @flags: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) + return ipe_process_event(f, ipe_operation_exec,
ipe_hook_mmap);security/ipe/hooks.c +6
-0+ +return 0 ; +} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing
+ * its protections via mprotect.
+ * @vma: Existing virtual memory area created by mmap or similar
+ * @reqprot: The requested protection on the mmap, passed from usermode.
+ * @prot: The effective protection on the mmap, resolved from reqprot and
+ * system configuration.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +41
-0+int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE :
security/ipe/hooks.c void ipe_task_free(struct task_struct *task) · line 163
Quoted 10 lines
security/ipe/hooks.c +10
-0+ op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max;
Possible problem here. If someone (like me) adds a new file type and forgets to add a case, there will be an out of bound access in evaluate():
rules = &pol->parsed->rules[ctx->op];
due to the static definition of the rules array in the ipe_parsed_policy structure (array length: ipe_operation_max).
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 187 lines
security/ipe/hooks.c +7
-0+ } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from
+ * disk.
+ * @id: Supplies the enumeration identifying the purpose of the read.
+ * @contents: Unused.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +29
-0+int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}security/ipe/hooks.h +22
-1@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */ security/ipe/ipe.c +5
-0@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data), };/** security/ipe/policy.c +23
-0@@ -483,6 +483,14 @@ int ipe_parse_op(const struct ipe_policy_token *tok, {substring_t match[MAX_OPT_ARGS ] = {0 };const match_table_t ops = { + { ipe_operation_exec,"EXECUTE" }, + { ipe_operation_firmware,"FIRMWARE" }, + { ipe_operation_kernel_module,"KMODULE" }, + { ipe_operation_kexec_image,"KEXEC_IMAGE" }, + { ipe_operation_kexec_initramfs,"KEXEC_INITRAMFS" }, + { ipe_operation_ima_policy,"IMA_POLICY" }, + { ipe_operation_ima_x509,"IMA_X509_CERT" }, + { ipe_op_alias_kernel_read,"KERNEL_READ" }, { ipe_op_alias_max,NULL }, };@@ -838,6 +846,15 @@ static int parse_policy(struct ipe_policy *p)return rc; } +static const enum ipe_operation alias_kread[] = { + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, +}; +/** * ipe_is_op_alias: Determine if @op is an alias for one or more operations * @op: Supplies the operation to check. Should be either ipe_operation or @@ -852,9 +869,15 @@ static int parse_policy(struct ipe_policy *p)bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size) {switch (op) { +case ipe_op_alias_kernel_read: + *map = alias_kread; + *size =ARRAY_SIZE (alias_kread); +break ;default :return false; } + +return true; }/** security/ipe/policy.h +10
-3@@ -26,7 +26,14 @@ struct ipe_policy_line {struct ipe_module ;enum ipe_operation { - ipe_operation_max =0 , + ipe_operation_exec =0 , + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_max };/* @@ -34,7 +41,8 @@ enum ipe_operation {* that are just one or more operations under the hood */ enum ipe_op_alias { - ipe_op_alias_max = ipe_operation_max, + ipe_op_alias_kernel_read = ipe_operation_max, + ipe_op_alias_max, };enum ipe_action { --2.33.0
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Randy DunlapQuoted 76 lines · Randy Dunlap
Quoted 75 lines · Deven Bowers
Quoted 65 lines · Randy Dunlap
Hi,
Quoted 49 lines · On 10/13/21 12:06 PM, [email protected] wrote:
security/ipe/Kconfig +0
-0@@ -17,3 +17,55 @@ menuconfig SECURITY_IPErequirements on the fly.
If unsure, answer N.security/ipe/Kconfig +42
-0+ +if SECURITY_IPE + +choice + prompt "Hash algorithm used in auditing policies" + default IPE_AUDIT_HASH_SHA1 + depends on AUDIT + help + Specify the hash algorithm used when auditing policies. + The hash is used to uniquely identify a policy from other + policies on the system. + + If unsure, leave default. + + config IPE_AUDIT_HASH_SHA1 + bool "sha1" + depends on CRYPTO_SHA1 + help + Use the SHA128 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA256 + bool "sha256" + depends on CRYPTO_SHA256 + help + Use the SHA256 algorithm to hash policies + in the audit records. + + config IPE_AUDIT_HASH_SHA384 + bool "sha384" + depends on CRYPTO_SHA512 + help + Use the SHA384 algorithm to hash policies + in the audit records + + config IPE_AUDIT_HASH_SHA512 + bool "sha512" + depends on CRYPTO_SHA512 + help + Use the SHA512 algorithm to hash policies + in the audit records +endchoicesecurity/ipe/Kconfig menuconfig SECURITY_IPE · line 71
Quoted 10 lines
security/ipe/Kconfig +10
-0+ +config IPE_AUDIT_HASH_ALG + string + depends on AUDIT + default "sha1" if IPE_AUDIT_HASH_SHA1 + default "sha256" if IPE_AUDIT_HASH_SHA256 + default "sha384" if IPE_AUDIT_HASH_SHA384 + default "sha512" if IPE_AUDIT_HASH_SHA512 + +endifPlease follow coding-style for
Kconfigfiles:Quoted 7 lines
(from
Documentation/process/coding-style.rst, section 10):For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.
Oof. That's embarrassing. Sorry, I'll fix this for v8.
Quoted 7 lines
Quoted 4 lines
While I'm at it, is the help text required for choice configs? checkpatch --strict complains with a warning without them, but I see other places in the tree where help text is omitted for these configs attached to a choice.
Does checkpatch complain about what you have above or did you add that help text to keep it from complaining?
I added the help text to keep it from complaining (and added it incorrectly, clearly).
Quoted 13 lines
Quoted 5 lines
Documentation/process/*doesn't seem to have any guidance, norDocumentation/kbuild/*on whether it is safe to ignore that checkpatch warning.Yeah, I don't think that we have any good guidance on that.
I would say that if the choice prompt provides good/adequate help info, then each 'config' inside the choice block does not need help text. OTOH, if the choice prompt has little/no help info, then each 'config' under it should have some useful info.
Quoted 6 lines
I only looked in
arch/x86/Kconfig, init/Kconfig, andlib/Kconfig.debug, but you can see either help text method being used in those.And then if the help text is adequate in either one of those methods, I would just ignore the checkpatch complaints. It's just a guidance tool.
Alright. I think the choice guidance is pretty clear:
Specify the hash algorithm used when auditing policies. The hash is used to uniquely identify a policy from other policies on the system.
So I'll remove the help text for these choices.
At worst, I can make the choice text more clear.
Quoted 3 lines
HTH.
Quoted 26 lines · Roberto Sassu
Quoted 11 lines
From:[email protected] [mailto:[email protected]]
From: Deven Bowers<[email protected]>Overview:
---------IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing systems approach use labels or paths which control access to a resource, IPE controls access to a resource based on the system's trust of said resource.
To me, it does not give a particularly precise idea of what IPE is about.
It would have been more clear, assuming that I understood it correctly, if you have said:
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.
Quoted 6 lines
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.
You understood it perfectly, and managed to word in a much more clear way than I did. I'll apply these changes in the next posting! Thanks.
Quoted 36 lines
Quoted 31 lines
Trust requirements are established via IPE's policy, sourcing multiple different implementations within the kernel to build a cohesive trust model, based on how the system was built.
Trust, with respect to computing, is a concept that designates a set of entities who will endorse a set of resources as non-malicious. Traditionally, this is done via signatures, which is the act of endorsing a resource.
Integrity, on the other hand, is the concept of ensuring that a resource has not been modified since a point of time. This is typically done through cryptographic hashes or signatures.
Trust and integrity are very closely tied together concepts, as integrity is the way you can prove trust for a resource; otherwise it could have been modified by an entity who is untrusted.
IPE provides a way for a user to express trust requirements of resources, by using pre-existing systems which provide the integrity half of the equation.
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.
Quoted 5 lines
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. Instead, IPE supports the PKI Trust Model, which generally designates a set of entities that provide a measure absolute trust.
Quoted 5 lines
It is true that packages are signed with PGP, which is decentralized, but there is a special case where Linux distribution vendors trust their own keys. This, at least, would allow to trust the software built by a particular vendor (I ported David Howells's work on PGP keys and signature to the current kernel).
Yes, that is true. I figured that this scenario was somewhat obvious, as it is, at a high level, similar to PKI but I can certainly add it explicitly.
Quoted 9 lines
Quoted 5 lines
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.
Yes, RPMs don't have per file signatures but have a signature of the list of file digests, which is equivalent. They could have also the fsverity digests (instead of the fsverity signatures) to reduce size overhead.
Quoted 5 lines
Given that the authenticity of RPMs headers can be verified, if the PGP key of the vendor is included in the primary keyring of the kernel, being able to protect file or fsverity digests against tampering by user space and being able to query them (e.g. with DIGLIM) extends the applicability of IPE to general purpose OSes.
Agreed. With these two functionalities, it does appear that IPE + DIGLIM can be used for general purpose RPM-based OSes. I'll add a reference to your recent posting (v3?) as a way to extend the functionality to general purposes OSes in the next revision.
Quoted 14 lines
Quoted 14 lines
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 (NOT the policy syntax version). This is used to prevent roll-back of policy to potentially insecure previous versions of the policy.
Quoted 5 lines
Quoted 2 lines
The next portion of IPE policy, are rules. Rules are formed by key=value pairs, known as properties. IPE rules require two properties: "action",
Better:
IPE rules require two keys:
Ack.
Quoted 149 lines
Quoted 142 lines
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 will allow any execution. 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. Available properties for IPE described in the documentation patch of this series.
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. 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. User mode can interrogate the kernel to understand what properties and the associated versions through the securityfs node, $securityfs/ipe/config, which will return a string of form:
key1=version1 key2=version2 . . . keyN=versionNUser-mode should correlate these versions with the supported values identified in the documentation to determine whether a policy should be accepted by the system without actually trying to deploy 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, 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 userland 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=ALLOWAllow 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:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec 146938 action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_signature=TRUE action=ALLOWAllow only a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec 146938 action=ALLOWDeploying Policies:
-------------------First sign a plain text policy, with a certificate that is present in the
SYSTEM_TRUSTED_KEYRINGof your test machine. Through openssl, the signing can be done via:openssl smime -sign -in "$MY_POLICY" -signer "$MY_CERTIFICATE" \ -inkey "$MY_PRIVATE_KEY" -binary -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_policyThe 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_versionattribute 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: The securityfs commands will require
CAP_MAC_ADMIN.Quoted 7 lines
Integrations:
-------------This patch series adds support for fsverity via digest and signature (
fsverity_signatureandfsverity_digest), dm-verity by digest and signature (dmverity_signatureanddmverity_roothash), and trust for the initramfs (boot_verified).
Quoted 8 lines
Verifying the initial ram disk looks like a big problem. On general purpose OSes, having a reference value for it would be very hard.
Instead, we would still be able to use per file reference values. Executable and shared libraries in the initial ram disk are copied from the main OS. Without fsverity support in tmpfs, I wonder if it would be still possible to mark the file as immutable and do an on the fly calculation of the root digest.
Yes, verifying the initial ramdisk is very difficult. "boot_verified", is largely an assumption of trust as all the warning shows in the documentation; it assumes the boot stack verified the initramfs somehow (i.e. u-boot verified boot with it in the fitImage), and 'pins' (similar to loadpin) the superblock to allow execution from that superblock.
Quoted 3 lines
As an alternative, the IMA approach of calculating the file digest could be used (or IPE could get the file digest as a property from the integrity subsystem).
In general, I would like to keep as much of the implementation of the integrity mechanisms out of IPE as much as possible - there are likely much better layers to implement new ways of providing integrity / authenticity claims than at the lsm layer within IPE.
Quoted 334 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 329 lines
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_SECURITY_IPE=y
CONFIG_SECURITY_IPE_KUNIT_TEST=y
CONFIG_IPE_PROP_BOOT_VERIFIED=y
CONFIG_IPE_PROP_DM_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_DM_VERITY_ROOTHASH=y
CONFIG_IPE_PROP_FS_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_FS_VERITY_DIGEST=ySimply run:
make ARCH=um mrproper
./tools/testing/kunit/kunit.pyrun --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. This includes architectural block diagrams.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. However, there is a patchset that is looking to address this gap [1].
Appendix:
---------A. IPE Github Repository:https://github.com/microsoft/ipe B. IPE Users' Guide:
Documentation/admin-guide/LSM/ipe.rstReferences:
-----------[1]https://lore.kernel.org/all/[email protected]/
FAQ:
----Q: What's the difference between other LSMs which provide trust-based
access control, for instance, IMA?A: IMA is a fantastic option when needing measurement in addition to the
trust-based access model. All of IMA is centered around their measurement hashes, so you save time when doing both actions. IPE, on the other hand, is a highly performant system that does not rely (and explicitly prohibits), generating its own integrity mechanisms - separating measurement and access control. Simply put, IPE provides only the enforcement of trust, while other subsystems provide the integrity guarantee that IPE needs to determine the trust of a resource. IMA provides both the integrity guarantee, the enforcement of trust, and a whole host of other features that may not be needed.Changelog:
----------Changes since v1:
Split the second patch of the previous series into two. Minor corrections in the cover-letter and documentation comments regardingCAP_MAC_ADMINchecks in IPE.Changes since v2:
Address various comments by Jann Horn. Highlights:
Switch various audit allocators toGFP_KERNEL. Utilizercu_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.Changes since v3:
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.Changes since v4:
Correct some grammatical errors reported by Randy Dunlap. Fix some warnings reported by kernel test bot.
Change convention aroundsecurity_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.Changes since v5:
Change if statement condition insecurity_bdev_setsecurityto 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.Changes since v6:
* 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
* DroppedCONFIG_SECURITY_IPE_PERMISSIVE_SWITCH- functionality can easily come later with a small patch.
* Use partition0 forblock_devicefor dm-verity patchDeven Bowers (14):
security: add ipe lsm & initial context creation
ipe: add policy parser
ipe: add evaluation loop
ipe: add userspace interface
ipe: add LSM hooks on execution and kernel read uapi|audit: add trust audit message definitions
ipe: add auditing support
ipe: add permissive toggle
ipe: introduce 'boot_verified' as a trust provider fs|dm-verity: addblock_devLSM blob and submit dm-verity data
ipe: add support for dm-verity as a trust provider
scripts: add boot policy generation program
ipe: kunit tests
documentation: add ipe documentationFan Wu (2):
fsverity|security: add security hooks to fsverity digest and signature
ipe: enable support for fs-verity as a trust providerDocumentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 587 ++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 339 ++++++ MAINTAINERS | 9 + block/bdev.c | 7 + drivers/md/dm-verity-target.c | 20 +- drivers/md/dm-verity-verify-sig.c | 16 +- drivers/md/dm-verity-verify-sig.h | 10 +- fs/verity/open.c | 12 + fs/verity/signature.c | 5 +- include/asm-generic/vmlinux.lds.h | 16 + include/linux/blk_types.h | 1 + include/linux/device-mapper.h | 3 + include/linux/fsverity.h | 3 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 12 + include/linux/security.h | 22 + include/uapi/linux/audit.h | 4 + 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/ipe/.gitignore | 1 + security/ipe/Kconfig | 100 ++ security/ipe/Makefile | 39 + security/ipe/audit.c | 304 +++++ security/ipe/audit.h | 41 + security/ipe/ctx.c | 381 ++++++ security/ipe/ctx.h | 43 + security/ipe/ctx_test.c | 732 ++++++++++++ security/ipe/eval.c | 237 ++++ security/ipe/eval.h | 57 + security/ipe/fs.c | 327 ++++++ security/ipe/fs.h | 13 + security/ipe/hooks.c | 328 ++++++ security/ipe/hooks.h | 56 + security/ipe/ipe.c | 143 +++ security/ipe/ipe.h | 27 + security/ipe/ipe_parser.h | 59 + security/ipe/modules.c | 134 +++ security/ipe/modules.h | 17 + security/ipe/modules/Kconfig | 66 ++ security/ipe/modules/Makefile | 12 + security/ipe/modules/boot_verified.c | 24 + security/ipe/modules/dmverity_roothash.c | 80 ++ security/ipe/modules/dmverity_signature.c | 25 + security/ipe/modules/fsverity_digest.c | 80 ++ security/ipe/modules/fsverity_signature.c | 33 + security/ipe/modules/ipe_module.h | 40 + security/ipe/parsers.c | 139 +++ security/ipe/parsers/Makefile | 12 + security/ipe/parsers/default.c | 106 ++ security/ipe/parsers/policy_header.c | 126 ++ security/ipe/policy.c | 1037 +++++++++++++++++ security/ipe/policy.h | 113 ++ security/ipe/policy_parser_tests.c | 299 +++++ security/ipe/policyfs.c | 528 +++++++++ security/security.c | 76 +- 63 files changed, 7069 insertions(+), 18 deletions(-)create mode 100644
Documentation/admin-guide/LSM/ipe.rstcreate mode 100644Documentation/security/ipe.rstcreate mode 100644scripts/ipe/Makefile
create mode 100644scripts/ipe/polgen/.gitignorecreate mode 100644scripts/ipe/polgen/Makefilecreate mode 100644scripts/ipe/polgen/polgen.ccreate mode 100644security/ipe/.gitignore
create mode 100644security/ipe/Kconfig
create mode 100644security/ipe/Makefile
create mode 100644security/ipe/audit.c
create mode 100644security/ipe/audit.h
create mode 100644security/ipe/ctx.c
create mode 100644security/ipe/ctx.h
create mode 100644security/ipe/ctx_test.c
create mode 100644security/ipe/eval.c
create mode 100644security/ipe/eval.h
create mode 100644security/ipe/fs.c
create mode 100644security/ipe/fs.h
create mode 100644security/ipe/hooks.c
create mode 100644security/ipe/hooks.h
create mode 100644security/ipe/ipe.c
create mode 100644security/ipe/ipe.h
create mode 100644security/ipe/ipe_parser.hcreate mode 100644security/ipe/modules.c
create mode 100644security/ipe/modules.h
create mode 100644security/ipe/modules/Kconfigcreate mode 100644security/ipe/modules/Makefilecreate mode 100644security/ipe/modules/boot_verified.ccreate mode 100644security/ipe/modules/dmverity_roothash.ccreate mode 100644security/ipe/modules/dmverity_signature.ccreate mode 100644security/ipe/modules/fsverity_digest.ccreate mode 100644security/ipe/modules/fsverity_signature.ccreate mode 100644security/ipe/modules/ipe_module.hcreate mode 100644security/ipe/parsers.c
create mode 100644security/ipe/parsers/Makefilecreate mode 100644security/ipe/parsers/default.ccreate mode 100644security/ipe/parsers/policy_header.ccreate mode 100644security/ipe/policy.c
create mode 100644security/ipe/policy.h
create mode 100644security/ipe/policy_parser_tests.ccreate mode 100644security/ipe/policyfs.c--
2.33.0
Re: [RFC PATCH v7 05/16] ipe: add LSM hooks on execution and kernel read
In reply to Roberto SassuQuoted 159 lines · Roberto Sassu
Quoted 145 lines
From:[email protected] [mailto:[email protected]]
From: 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 execve, mprotect, mmap,
kernel_load_dataandkernel_read_data.Signed-off-by Deven Bowers<[email protected]>---
Relevant changes since v6:
* 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] (this patch)--- security/ipe/hooks.c | 149 ++++++++++++++++++++++++++++++++++++++++++ security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)security/ipe/hooks.c +18
-0@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure. @@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ + return ipe_process_event(bprm->file, ipe_operation_exec,
ipe_hook_exec);security/ipe/hooks.c +20
-0+} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode. +* @prot: The effective protection on the mmap, resolved from reqprot and +* system configuration. +* @flags: Unused. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) + return ipe_process_event(f, ipe_operation_exec,
ipe_hook_mmap);security/ipe/hooks.c +6
-0+ +return 0 ; +} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing
+ * its protections via mprotect.
+ * @vma: Existing virtual memory area created by mmap or similar
+ * @reqprot: The requested protection on the mmap, passed from usermode.
+ * @prot: The effective protection on the mmap, resolved from reqprot and
+ * system configuration.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +41
-0+int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE :security/ipe/hooks.c void ipe_task_free(struct task_struct *task) · line 163
Quoted 10 lines
security/ipe/hooks.c +10
-0+ op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max;Possible problem here. If someone (like me) adds a new file type and forgets to add a case, there will be an out of bound access in
evaluate():
Quoted 4 lines
rules = &pol->parsed->rules[ctx->op];due to the static definition of the rules array in the
ipe_parsed_policystructure (array length:ipe_operation_max).
Yeah, that's a problem. I can fix this down in the eval loop by matching the global default and emitting a WARN here.
Quoted 192 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 187 lines
security/ipe/hooks.c +7
-0+ } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from
+ * disk.
+ * @id: Supplies the enumeration identifying the purpose of the read.
+ * @contents: Unused.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +29
-0+int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}security/ipe/hooks.h +22
-1@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); + +int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */ security/ipe/ipe.c +5
-0@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data), };/** security/ipe/policy.c +23
-0@@ -483,6 +483,14 @@ int ipe_parse_op(const struct ipe_policy_token *tok, {substring_t match[MAX_OPT_ARGS ] = {0 };const match_table_t ops = { + { ipe_operation_exec,"EXECUTE" }, + { ipe_operation_firmware,"FIRMWARE" }, + { ipe_operation_kernel_module,"KMODULE" }, + { ipe_operation_kexec_image,"KEXEC_IMAGE" }, + { ipe_operation_kexec_initramfs,"KEXEC_INITRAMFS" }, + { ipe_operation_ima_policy,"IMA_POLICY" }, + { ipe_operation_ima_x509,"IMA_X509_CERT" }, + { ipe_op_alias_kernel_read,"KERNEL_READ" }, { ipe_op_alias_max,NULL }, };@@ -838,6 +846,15 @@ static int parse_policy(struct ipe_policy *p)return rc; } +static const enum ipe_operation alias_kread[] = { + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, +}; +/** * ipe_is_op_alias: Determine if @op is an alias for one or more operations * @op: Supplies the operation to check. Should be either ipe_operation or @@ -852,9 +869,15 @@ static int parse_policy(struct ipe_policy *p)bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size) {switch (op) { +case ipe_op_alias_kernel_read: + *map = alias_kread; + *size =ARRAY_SIZE (alias_kread); +break ;default :return false; } + +return true; }/** security/ipe/policy.h +10
-3@@ -26,7 +26,14 @@ struct ipe_policy_line {struct ipe_module ;enum ipe_operation { - ipe_operation_max =0 , + ipe_operation_exec =0 , + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_max };/* @@ -34,7 +41,8 @@ enum ipe_operation {* that are just one or more operations under the hood */ enum ipe_op_alias { - ipe_op_alias_max = ipe_operation_max, + ipe_op_alias_kernel_read = ipe_operation_max, + ipe_op_alias_max, };enum ipe_action { --2.33.0
Re: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Roberto SassuQuoted 81 lines · Roberto Sassu
Quoted 41 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, October 20, 2021 5:09 PMQuoted 31 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Friday, October 15, 2021 10:11 PMQuoted 2 lines · Deven Bowers
Quoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 10 lines · [email protected] wrote:
Quoted 6 lines
Quoted 5 lines
From: Fan Wu<[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
Quoted 9 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
Quoted 8 lines
Quoted 6 lines
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Quoted 8 lines
I was wondering if the following use case can be supported:
allow the execution of files protected with fsverity if the root digest is found among reference values (instead of providing them one by one in the policy).Something like:
op=EXECUTE fsverity_digest=diglim action=ALLOW
Looks like it works. I modified IPE to query the root digest of an fsverity-protected file in DIGLIM.
# cat ipe-policy policy_name="AllowFSVerityKmodules" policy_version=0.0.1 DEFAULT action=ALLOW DEFAULT op=KMODULE action=DENY op=KMODULE fsverity_digest=diglim action=ALLOWIPE setup:
# cat ipe-policy.p7s > /sys/kernel/security/ipe/new_policy # echo -n 1 > /sys/kernel/security/ipe/policies/AllowFSVerityKmodules/active # echo 1 > /sys/kernel/security/ipe/enforceIPE denies loading of kernel modules not protected by fsverity:
# insmod /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko insmod: ERROR: could not insert module /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko: Permission deniedProtect fat.ko with fsverity:
# cp /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko /fsverity # fsverity enable /fsverity/fat.ko # fsverity measure /fsverity/fat.ko sha256:079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 /fsverity/fat.koIPE still denies the loading of fat.ko (root digest not uploaded to the kernel):
# insmod /fsverity/fat.ko insmod: ERROR: could not insert module /fsverity/fat.ko: Permission deniedGenerate a digest list with the root digest above and upload it to the kernel:
# ./compact_gen -i 079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 -a sha256 -d test -s -t file -f # echo $PWD/test/0-file_list-compact-079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803 > /sys/kernel/security/integrity/diglim/digest_list_add
Quoted 7 lines
IPE allows the loading of fat.ko:
# insmod /fsverity/fat.ko #Regarding authenticity, not shown in this demo, IPE will also ensure that the root digest is signed (
diglim_digest_get_info()reports this information).
I apologize for the delay in responses, but it looks like you've figured it out.
This kind of thing is exactly what IPE's design is supposed to solve, you have some other system which provides the integrity mechanism and (optionally) determine if it is trusted or not, and IPE can provide the policy aspect very easily to make a set of system-wide requirements around your mechanism.
I'm very supportive of adding the functionality, but I wonder if it makes more sense to have digilm's extension be a separate key instead of tied to the fsverity_digest key - something like
op=EXECUTE diglim_fsverity=TRUE action=DENY
that way the condition that enables this property can depend on digilm in the build, and it separates the two systems' integrations in a slightly more clean way.
As an aside, did you find it difficult to extend?
Quoted 28 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 23 lines
DIGLIM is a component I'm working on that generically stores digests. The current use case is to store file digests from
RPMTAG_FILEDIGESTSand use them with IMA, but the fsverity use case could be easily supported (if the root digest is stored in the RPM header).DIGLIM also tells whether or not the signature of the source containing file digests (or fsverity digests) is valid (the signature of the RPM header is taken from
RPMTAG_RSAHEADER).The memory occupation is relatively small for executables and shared libraries. I published a demo for Fedora and openSUSE some time ago:
https://lore.kernel.org/linux-
integrity/[email protected]/Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Re: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Eric BiggersQuoted 8 lines · Eric Biggers
Quoted 7 lines · Deven Bowers
Quoted 6 lines · Eric Biggers
Quoted 5 lines · On Wed, Oct 13, 2021 at 12:06:31PM -0700,[email protected] wrote:
From: Fan Wu<[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
I’ve heard a lot of people use these terms in overloaded ways.
If we’re working with the definition of authenticity being “the property that a resource was _actually_ sent/created by a party”, and integrity being “the property that a resource was not modified from a point of time”, then yes. Though the statement isn’t false, though, because you’d need to prove integrity in the process of proving authenticity.
If not, could you clarify what you mean by authenticity and integrity, so that we can use consistent definitions?
Quoted 3 lines
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
We looked at extending IMA to cover our requirements extensively the past year based on feedback the last time I posted these patches. We implemented a prototype that had half of our requirements, but found it resulted in a large change list that would result in a large amount of pain in respect to maintenance, in addition to other more architectural concerns about the implementation. We weren’t convinced it was the correct direction, for our needs.
There was a presentation done at LSS 2021 around this prototype done by my colleague, Fan, who authored this patch and implemented the aforementioned prototype.
In general, IMA provides a whole suite of amazing functionality when it comes to everything integrity, as the fs-verity documentation states itself:
IMA specifies a system-wide policy that specifies which files are hashed and what to do with those hashes, such as log them, authenticate them, or add them to a measurement list.
Instead, IPE provides a fine-tuned way to _only_ enforce an access control policy to these files based on the defined trust requirements in the policy, under various contexts, (you might have different requirements for what executes in a general purpose, versus loadable kernel modules, for example). It will never provide bother to log, measure, or revalidate these hashes because that’s not its purpose. This is why it belongs at the LSM layer instead of the integrity subsystem layer, as it is providing access control based on a policy, versus providing deep integrations with the actual integrity claim.
IPE is trying to be agnostic to how precisely “trust” is provided, as opposed to be deeply integrated into the mechanism that provides “trust”.
Quoted 9 lines
Quoted 9 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
Quoted 8 lines
Quoted 6 lines
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Here’s a more complete example:
policy_name=”fs-exec-only” policy_version=0.0.1 DEFAULT action=ALLOW
DEFAULT op=EXECUTE action=DENY op=EXECUTE fsverity_digest=<Digest> action=DENY op=EXECUTE fsverity_signature=TRUE action=ALLOW
Execution is prohibited unless it is a signed fs-verity file; However, after one of those executables was signed and published, an exploitable vulnerability in said executable was found, a new version was published without that vulnerability. We need to revoke trust for that executable since it could be used to exploit the system, so the first rule prevents it from matching the second.
Quoted 17 lines
Quoted 6 lines
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case.
No, it's not.
Digests are meaningless without knowing what algorithm they were created with.
If your security policy is something like "Trust the file with digest $foo" and multiple hash algorithms are possible, then the alorithm intended to be used needs to be explicitly specified. Otherwise any algorithm with the same length digest will be accepted. That's a fatal flaw if any of these algorithms is cryptographically broken or was never intended to be a cryptographic algorithm in the first place (e.g., a non-cryptographic checksum).
Quoted 2 lines
Cryptosystems always need to specify the crypto algorithm(s) used; the adversary must not be allowed to choose the algorithms.
Oof. You’re completely right. The part I was missing is that as time goes on, the secure status of these cryptographic algorithms will change, and then we’ll need a way to migrate between algorithms. Additionally, tooling and the like will likely need a way to identify this from the policy text without consulting anything else. This is a major oversight for general use, the system that this was originally designed for only had support for a subset of the sha2-family (all separate lengths) so I hadn’t even considered it.
It's trivial to correct in a minimal amount of code, making the policy express the digest like so:
fsverity_digest=<algo>:<digest>
and change the argument passed to the LSM hook to accept a structure containing these two fields.
Quoted 2 lines
I'm not sure how these patches can be taken seriously when they're getting this sort of thing wrong.
That said, I, personally, hope that an honest mistake, in a series submitted as an RFC submitted in good faith, is not a reason to discount an entire patch series.
I hope you continue to provide feedback, as it is invaluable to making this system better, and making me, personally, a better developer.
Quoted 21 lines
Quoted 13 lines
Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 8 lines
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Quoted 5 lines
Most users of fs-verity built-in signatures have actually been enforcing their security policy in userspace, by checking whether specific files have the fs-verity bit set or not. Such users could just store and verify signatures in userspace instead, without any kernel involvement. So that's what I've been recommending (with limited success, unfortunately).
I believe the difference in security models comes from this line (emphasis, mine):
Quoted 1 line
by checking whether
_specificfiles_have the fs-verity bit set or not.
IPE policy is written by a system author who owns the system, but may not have 100% control over all of the application code running on the system. In the case of applications which are not aware of IPE, the policy can still enforce that all of the code running on the system is trusted.
An example attack of what we're trying to mitigate: A hostile actor could downloads a binary off the internet with all required dependencies into tmpfs and runs their malicious executable.
With us validating this information in the kernel, even if the attacker downloaded their malicious executable to /tmp and executed it, it would still fail to pass policy and be denied, as the kernel is the common entrypoint across all executables.
Operationally, this _could_ be done by digest, but the policies would quickly become gigantic on a cartoonish proportion, as you'll have to authorize every single executable and dependency by digest - and there would be a complicated update story as the policy would have to be updated to onboard new digests.
By using signatures, we can prevent the policy update, and keep the policy size small.
Quoted 5 lines
If you really do need in-kernel signature verification, then that may be a legitimate use case for the fs-verity built-in signatures, although I do wonder why you aren't using IMA and its signature mechanism instead.
- Eric
kernel test robot
build botRe: [RFC PATCH v7 01/16] security: add ipe lsm & initial context creation
In reply to [email protected][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]
Hi,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master jmorris-security/next-testing v5.15-rc7 next-20211026] [cannot apply to fscrypt/fsverity]
[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]
url: https://github.com/0day-ci/linux/commits/deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: openrisc-randconfig-r002-20211027 (attached as .config) compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/43fd1c739758d83fa9d152a3338148de74a85107
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 git checkout 43fd1c739758d83fa9d152a3338148de74a85107
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash security/ipe/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> security/ipe/ctx.c:126: warning: expecting prototype for ipe_put_ns(). Prototype was for ipe_put_ctx() instead
vim +126 security/ipe/ctx.c
116
117 /**
118 * ipe_put_ns: Decrement the reference of an ipe_context structure,
119 * scheduling a free as necessary.s
120 * @ctx: Structure to free
121 *
122 * This function no-ops on error and null values for @ctx, and the
123 * deallocation will only occur if the refcount is 0.
124 */
125 void ipe_put_ctx(struct ipe_context *ctx)
> 126 { 127 if (IS_ERR_OR_NULL(ctx) || !refcount_dec_and_test(&ctx->refcount))
128 return;
129
130 schedule_work(&ctx->free_work);
131 }
132
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC PATCH v7 02/16] ipe: add policy parser
In reply to [email protected][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]
Hi,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master jmorris-security/next-testing v5.15-rc7 next-20211026] [cannot apply to fscrypt/fsverity]
[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]
url: https://github.com/0day-ci/linux/commits/deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: openrisc-randconfig-r002-20211027 (attached as .config) compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f209aa6c4ffb6565951bbbe0d0ccec06fd214fac
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 git checkout f209aa6c4ffb6565951bbbe0d0ccec06fd214fac
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash security/ipe/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> security/ipe/policy.c:327: warning: expecting prototype for ipe_tokenize_line(). Prototype was for tokenize_line() instead security/ipe/policy.c:406: warning: Function parameter or member 'tokens' not described in 'parse_pass1' security/ipe/policy.c:449: warning: Function parameter or member 'pol' not described in 'parse_pass2' security/ipe/policy.c:449: warning: Excess function parameter 'p' description in 'parse_pass2' security/ipe/policy.c:736: warning: Function parameter or member 'p' not described in 'validate_policy' security/ipe/policy.c:736: warning: Excess function parameter 'policy' description in 'validate_policy' >> security/ipe/policy.c:866: warning: expecting prototype for ipe_free_policy(). Prototype was for ipe_put_policy() instead
vim +327 security/ipe/policy.c
313
314 /**
315 * ipe_tokenize_line: Parse a line of text into a list of token structures.
316 * @line: Supplies the line to parse.
317 *
318 * The final result can be NULL, which represents no tokens were parsed.
319 *
320 * Return:
321 * !0 - OK
322 * NULL - OK, no tokens were parsed.
323 * ERR_PTR(-EBADMSG) - Invalid policy syntax
324 * ERR_PTR(-ENOMEM) - No Memory
325 */
326 static struct ipe_policy_line *tokenize_line(char *line)
> 327 { 328 int rc = 0;
329 size_t i = 0;
330 size_t len = 0;
331 char *tok = NULL;
332 char quote = '\0';
333 struct ipe_policy_line *p = NULL;
334
335 /* nullterm guaranteed by strsep */
336 len = strlen(line);
337
338 for (i = 0; i < len; ++i) {
339 if (quote == '\0' && is_quote(line[i])) {
340 quote = line[i];
341 continue;
342 }
343
344 if (quote != '\0' && line[i] == quote) {
345 quote = '\0';
346 continue;
347 }
348
349 if (quote == '\0' && line[i] == START_COMMENT) {
350 tok = NULL;
351 break;
352 }
353
354 if (isgraph(line[i]) && !tok)
355 tok = &line[i];
356
357 if (quote == '\0' && isspace(line[i])) {
358 line[i] = '\0';
359
360 if (!tok)
361 continue;
362
363 rc = insert_token(tok, &p);
364 if (rc)
365 goto err;
366
367 tok = NULL;
368 }
369 }
370
371 if (quote != '\0') {
372 rc = -EBADMSG;
373 goto err;
374 }
375
376 if (tok) {
377 rc = insert_token(tok, &p);
378 if (rc)
379 goto err;
380 }
381
382 return p;
383
384 err:
385 free_parsed_line(p);
386 return ERR_PTR(rc);
387 }
388
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botRe: [RFC PATCH v7 03/16] ipe: add evaluation loop
In reply to [email protected][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]
Hi,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master jmorris-security/next-testing v5.15-rc7 next-20211026] [cannot apply to fscrypt/fsverity]
[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]
url: https://github.com/0day-ci/linux/commits/deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: openrisc-randconfig-r002-20211027 (attached as .config) compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/20039f58e001d8412eb85957b4fea1130a6f78d1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 git checkout 20039f58e001d8412eb85957b4fea1130a6f78d1
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash security/ipe/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> security/ipe/ctx.c:141: warning: expecting prototype for remove_policy(). Prototype was for ipe_remove_policy() instead
security/ipe/ctx.c:183: warning: expecting prototype for ipe_put_ns(). Prototype was for ipe_put_ctx() instead
vim +141 security/ipe/ctx.c
133
134 /**
135 * remove_policy: Remove a policy from its context
136 * @p: Supplies a pointer to a policy that will be removed from its context
137 *
138 * Decrements @p's reference by 1.
139 */
140 void ipe_remove_policy(struct ipe_policy *p)
> 141 { 142 struct ipe_context *ctx;
143
144 ctx = ipe_get_ctx_rcu(p->ctx);
145 if (!ctx)
146 return;
147
148 spin_lock(&ctx->lock);
149 list_del_init(&p->next);
150 rcu_assign_pointer(p->ctx, NULL);
151 spin_unlock(&ctx->lock);
152 synchronize_rcu();
153
154 ipe_put_ctx(ctx);
155 /* drop the reference representing the list */
156 ipe_put_policy(p);
157 }
158
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 29 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Tuesday, October 26, 2021 9:04 PMQuoted 26 lines · Roberto Sassu
Quoted 11 lines
From:[email protected] [mailto:[email protected]]
From: Deven Bowers<[email protected]>Overview:
---------IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing systems approach use labels or paths which control access to a resource, IPE controls access to a resource based on the system's trust of said resource.
To me, it does not give a particularly precise idea of what IPE is about.
It would have been more clear, assuming that I understood it correctly, if you have said:
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.
Quoted 8 lines
Quoted 6 lines
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.
You understood it perfectly, and managed to word in a much more clear way than I did. I'll apply these changes in the next posting! Thanks.
Welcome.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Trust requirements are established via IPE's policy, sourcing multiple different implementations within the kernel to build a cohesive trust model, based on how the system was built.
Trust, with respect to computing, is a concept that designates a set of entities who will endorse a set of resources as non-malicious. Traditionally, this is done via signatures, which is the act of endorsing a resource.
Integrity, on the other hand, is the concept of ensuring that a resource has not been modified since a point of time. This is typically done through cryptographic hashes or signatures.
Trust and integrity are very closely tied together concepts, as integrity is the way you can prove trust for a resource; otherwise it could have been modified by an entity who is untrusted.
IPE provides a way for a user to express trust requirements of resources, by using pre-existing systems which provide the integrity half of the equation.
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. Instead, IPE supports the PKI Trust Model, which generally designates a set of entities that provide a measure absolute trust.
Quoted 8 lines
Quoted 5 lines
It is true that packages are signed with PGP, which is decentralized, but there is a special case where Linux distribution vendors trust their own keys. This, at least, would allow to trust the software built by a particular vendor (I ported David Howells's work on PGP keys and signature to the current kernel).
Yes, that is true. I figured that this scenario was somewhat obvious, as it is, at a high level, similar to PKI but I can certainly add it explicitly.
Perfect.
Quoted 14 lines
Quoted 9 lines
Quoted 5 lines
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.
Yes, RPMs don't have per file signatures but have a signature of the list of file digests, which is equivalent. They could have also the fsverity digests (instead of the fsverity signatures) to reduce size overhead.
Quoted 5 lines
Given that the authenticity of RPMs headers can be verified, if the PGP key of the vendor is included in the primary keyring of the kernel, being able to protect file or fsverity digests against tampering by user space and being able to query them (e.g. with DIGLIM) extends the applicability of IPE to general purpose OSes.
Quoted 4 lines
Agreed. With these two functionalities, it does appear that IPE + DIGLIM can be used for general purpose RPM-based OSes. I'll add a reference to your recent posting (v3?) as a way to extend the functionality to general purposes OSes in the next revision.
Ok. Yes, v3 is the latest.
Quoted 184 lines
Quoted 14 lines
Quoted 14 lines
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 (NOT the policy syntax version). This is used to prevent roll-back of policy to potentially insecure previous versions of the policy.
Quoted 5 lines
Quoted 2 lines
The next portion of IPE policy, are rules. Rules are formed by key=value pairs, known as properties. IPE rules require two properties: "action",
Better:
IPE rules require two keys:
Ack.
Quoted 77 lines
Quoted 77 lines
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 will allow any execution. 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. Available properties for IPE described in the documentation patch of this series.
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. 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. User mode can interrogate the kernel to understand what properties and the associated versions through the securityfs node, $securityfs/ipe/config, which will return a string of form:
key1=version1 key2=version2 . . . keyN=versionNUser-mode should correlate these versions with the supported values identified in the documentation to determine whether a policy should be accepted by the system without actually trying to deploy 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, 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 userland 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=ALLOWAllow 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
Quoted 7 lines
Quoted 7 lines
Prohibit execution from a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec
Quoted 11 lines
Quoted 11 lines
146938 action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW op=EXECUTE dmverity_signature=TRUE action=ALLOWAllow only a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec
Quoted 54 lines
Quoted 47 lines
146938 action=ALLOW
Deploying Policies:
-------------------First sign a plain text policy, with a certificate that is present in the
SYSTEM_TRUSTED_KEYRINGof your test machine. Through openssl, the signing can be done via:openssl smime -sign -in "$MY_POLICY" -signer "$MY_CERTIFICATE" \ -inkey "$MY_PRIVATE_KEY" -binary -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_policyThe 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_versionattribute 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: The securityfs commands will require
CAP_MAC_ADMIN.Quoted 7 lines
Integrations:
-------------This patch series adds support for fsverity via digest and signature (
fsverity_signatureandfsverity_digest), dm-verity by digest and signature (dmverity_signatureanddmverity_roothash), and trust for the initramfs (boot_verified).Quoted 8 lines
Verifying the initial ram disk looks like a big problem. On general purpose OSes, having a reference value for it would be very hard.
Instead, we would still be able to use per file reference values. Executable and shared libraries in the initial ram disk are copied from the main OS. Without fsverity support in tmpfs, I wonder if it would be still possible to mark the file as immutable and do an on the fly calculation of the root digest.
Yes, verifying the initial ramdisk is very difficult. "
boot_verified", is largely an assumption of trust as all the warning shows in the documentation; it assumes the boot stack verified the initramfs somehow (i.e. u-boot verified boot with it in the fitImage), and 'pins' (similar to loadpin) the superblock to allow execution from that superblock.
Quoted 7 lines
Quoted 3 lines
As an alternative, the IMA approach of calculating the file digest could be used (or IPE could get the file digest as a property from the integrity subsystem).
In general, I would like to keep as much of the implementation of the integrity mechanisms out of IPE as much as possible - there are likely much better layers to implement new ways of providing integrity / authenticity claims than at the lsm layer within IPE.
That would be still the case. The integrity subsystem will be still responsible to calculate the file digest and maintain it in a per inode metadata. Then, IPE could evaluate the file digest as the same as for the fsverity digest:
op=EXECUTE integrity_digest=<hex> action=ALLOW
integrity_digest will be handled by a separate IPE module which communicates with the integrity subsystem.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 335 lines
Quoted 94 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 89 lines
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_SECURITY_IPE=y
CONFIG_SECURITY_IPE_KUNIT_TEST=y
CONFIG_IPE_PROP_BOOT_VERIFIED=y
CONFIG_IPE_PROP_DM_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_DM_VERITY_ROOTHASH=y
CONFIG_IPE_PROP_FS_VERITY_SIGNATURE=y
CONFIG_IPE_PROP_FS_VERITY_DIGEST=ySimply run:
make ARCH=um mrproper
./tools/testing/kunit/kunit.pyrun --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. This includes architectural block diagrams.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. However, there is a patchset that is looking to address this gap [1].
Appendix:
---------A. IPE Github Repository:https://github.com/microsoft/ipe B. IPE Users' Guide:
Documentation/admin-guide/LSM/ipe.rstReferences:
-----------[1]https://lore.kernel.org/all/[email protected]/
FAQ:
----Q: What's the difference between other LSMs which provide trust-based
access control, for instance, IMA?A: IMA is a fantastic option when needing measurement in addition to the
trust-based access model. All of IMA is centered around their measurement hashes, so you save time when doing both actions. IPE, on the other hand, is a highly performant system that does not rely (and explicitly prohibits), generating its own integrity mechanisms - separating measurement andaccess
Quoted 240 lines
Quoted 240 lines
control. Simply put, IPE provides only the enforcement of trust, while other subsystems provide the integrity guarantee that IPE needs to determine the trust of a resource. IMA provides both the integrity guarantee, the enforcement of trust, and a whole host of other features that may not be needed.
Changelog:
----------Changes since v1:
Split the second patch of the previous series into two. Minor corrections in the cover-letter and documentation comments regardingCAP_MAC_ADMINchecks in IPE.Changes since v2:
Address various comments by Jann Horn. Highlights:
Switch various audit allocators toGFP_KERNEL. Utilizercu_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.Changes since v3:
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.Changes since v4:
Correct some grammatical errors reported by Randy Dunlap. Fix some warnings reported by kernel test bot.
Change convention aroundsecurity_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.Changes since v5:
Change if statement condition insecurity_bdev_setsecurityto 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.Changes since v6:
* 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
* DroppedCONFIG_SECURITY_IPE_PERMISSIVE_SWITCH- functionality can easily come later with a small patch.
* Use partition0 forblock_devicefor dm-verity patchDeven Bowers (14):
security: add ipe lsm & initial context creation
ipe: add policy parser
ipe: add evaluation loop
ipe: add userspace interface
ipe: add LSM hooks on execution and kernel read uapi|audit: add trust audit message definitions
ipe: add auditing support
ipe: add permissive toggle
ipe: introduce 'boot_verified' as a trust provider fs|dm-verity: addblock_devLSM blob and submit dm-verity data
ipe: add support for dm-verity as a trust provider
scripts: add boot policy generation program
ipe: kunit tests
documentation: add ipe documentationFan Wu (2):
fsverity|security: add security hooks to fsverity digest and signature
ipe: enable support for fs-verity as a trust providerDocumentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 587 ++++++++++ .../admin-guide/kernel-parameters.txt | 12 + Documentation/security/index.rst | 1 + Documentation/security/ipe.rst | 339 ++++++ MAINTAINERS | 9 + block/bdev.c | 7 + drivers/md/dm-verity-target.c | 20 +- drivers/md/dm-verity-verify-sig.c | 16 +- drivers/md/dm-verity-verify-sig.h | 10 +- fs/verity/open.c | 12 + fs/verity/signature.c | 5 +- include/asm-generic/vmlinux.lds.h | 16 + include/linux/blk_types.h | 1 + include/linux/device-mapper.h | 3 + include/linux/fsverity.h | 3 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 12 + include/linux/security.h | 22 + include/uapi/linux/audit.h | 4 + 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/ipe/.gitignore | 1 + security/ipe/Kconfig | 100 ++ security/ipe/Makefile | 39 + security/ipe/audit.c | 304 +++++ security/ipe/audit.h | 41 + security/ipe/ctx.c | 381 ++++++ security/ipe/ctx.h | 43 + security/ipe/ctx_test.c | 732 ++++++++++++ security/ipe/eval.c | 237 ++++ security/ipe/eval.h | 57 + security/ipe/fs.c | 327 ++++++ security/ipe/fs.h | 13 + security/ipe/hooks.c | 328 ++++++ security/ipe/hooks.h | 56 + security/ipe/ipe.c | 143 +++ security/ipe/ipe.h | 27 + security/ipe/ipe_parser.h | 59 + security/ipe/modules.c | 134 +++ security/ipe/modules.h | 17 + security/ipe/modules/Kconfig | 66 ++ security/ipe/modules/Makefile | 12 + security/ipe/modules/boot_verified.c | 24 + security/ipe/modules/dmverity_roothash.c | 80 ++ security/ipe/modules/dmverity_signature.c | 25 + security/ipe/modules/fsverity_digest.c | 80 ++ security/ipe/modules/fsverity_signature.c | 33 + security/ipe/modules/ipe_module.h | 40 + security/ipe/parsers.c | 139 +++ security/ipe/parsers/Makefile | 12 + security/ipe/parsers/default.c | 106 ++ security/ipe/parsers/policy_header.c | 126 ++ security/ipe/policy.c | 1037 +++++++++++++++++ security/ipe/policy.h | 113 ++ security/ipe/policy_parser_tests.c | 299 +++++ security/ipe/policyfs.c | 528 +++++++++ security/security.c | 76 +- 63 files changed, 7069 insertions(+), 18 deletions(-)create mode 100644
Documentation/admin-guide/LSM/ipe.rstcreate mode 100644Documentation/security/ipe.rstcreate mode 100644scripts/ipe/Makefile
create mode 100644scripts/ipe/polgen/.gitignorecreate mode 100644scripts/ipe/polgen/Makefilecreate mode 100644scripts/ipe/polgen/polgen.ccreate mode 100644security/ipe/.gitignore
create mode 100644security/ipe/Kconfig
create mode 100644security/ipe/Makefile
create mode 100644security/ipe/audit.c
create mode 100644security/ipe/audit.h
create mode 100644security/ipe/ctx.c
create mode 100644security/ipe/ctx.h
create mode 100644security/ipe/ctx_test.c
create mode 100644security/ipe/eval.c
create mode 100644security/ipe/eval.h
create mode 100644security/ipe/fs.c
create mode 100644security/ipe/fs.h
create mode 100644security/ipe/hooks.c
create mode 100644security/ipe/hooks.h
create mode 100644security/ipe/ipe.c
create mode 100644security/ipe/ipe.h
create mode 100644security/ipe/ipe_parser.hcreate mode 100644security/ipe/modules.c
create mode 100644security/ipe/modules.h
create mode 100644security/ipe/modules/Kconfigcreate mode 100644security/ipe/modules/Makefilecreate mode 100644security/ipe/modules/boot_verified.ccreate mode 100644security/ipe/modules/dmverity_roothash.ccreate mode 100644security/ipe/modules/dmverity_signature.ccreate mode 100644security/ipe/modules/fsverity_digest.ccreate mode 100644security/ipe/modules/fsverity_signature.ccreate mode 100644security/ipe/modules/ipe_module.hcreate mode 100644security/ipe/parsers.c
create mode 100644security/ipe/parsers/Makefilecreate mode 100644security/ipe/parsers/default.ccreate mode 100644security/ipe/parsers/policy_header.ccreate mode 100644security/ipe/policy.c
create mode 100644security/ipe/policy.h
create mode 100644security/ipe/policy_parser_tests.ccreate mode 100644security/ipe/policyfs.c--
2.33.0
RE: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Deven BowersQuoted 97 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Tuesday, October 26, 2021 9:04 PMQuoted 13 lines · Roberto Sassu
Quoted 13 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, October 20, 2021 5:09 PMQuoted 11 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Friday, October 15, 2021 10:11 PMQuoted 2 lines · Deven Bowers
Quoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 5 lines · [email protected] wrote:
Quoted 5 lines
Quoted 5 lines
From: Fan Wu<[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
Also how does this differ from IMA? I know that IMA doesn't support fs-
verity
Quoted 1 line
Quoted 1 line
Quoted 1 line
file hashes, but that could be changed. Why not extend IMA to cover your
use
Quoted 36 lines
Quoted 19 lines
Quoted 11 lines
case(s)?
Quoted 9 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
Quoted 8 lines
Quoted 6 lines
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Quoted 8 lines
I was wondering if the following use case can be supported:
allow the execution of files protected with fsverity if the root digest is found among reference values (instead of providing them one by one in the policy).Something like:
op=EXECUTE fsverity_digest=diglim action=ALLOW
Looks like it works. I modified IPE to query the root digest of an fsverity-protected file in DIGLIM.
# cat ipe-policy policy_name="AllowFSVerityKmodules" policy_version=0.0.1 DEFAULT action=ALLOW DEFAULT op=KMODULE action=DENY op=KMODULE fsverity_digest=diglim action=ALLOWQuoted 8 lines
IPE setup:
# cat ipe-policy.p7s > /sys/kernel/security/ipe/new_policy # echo -n 1 > /sys/kernel/security/ipe/policies/AllowFSVerityKmodules/active # echo 1 > /sys/kernel/security/ipe/enforceIPE denies loading of kernel modules not protected by fsverity:
# insmod /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko insmod: ERROR: could not insert module /lib/modules/5.15.0-
rc1+/kernel/fs/fat/fat.ko: Permission deniedQuoted 6 lines
Protect fat.ko with fsverity:
# cp /lib/modules/5.15.0-rc1+/kernel/fs/fat/fat.ko /fsverity # fsverity enable /fsverity/fat.ko # fsverity measure /fsverity/fat.kosha256:079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe154 7803 /fsverity/fat.ko
Quoted 7 lines
IPE still denies the loading of fat.ko (root digest not uploaded to the kernel):
# insmod /fsverity/fat.ko insmod: ERROR: could not insert module /fsverity/fat.ko: Permission deniedGenerate a digest list with the root digest above and upload it to the kernel:
# ./compact_gen -i
079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803-a sha256 -d test -s -t file -fQuoted 1 line
# echo $PWD/test/0-file_list-compact-
079be6d88638e58141ee24bba89813917c44faa55ada4bf5d80335efe1547803>/sys/kernel/security/integrity/diglim/digest_list_addQuoted 5 lines
IPE allows the loading of fat.ko:
# insmod /fsverity/fat.ko #
Quoted 6 lines
Quoted 3 lines
Regarding authenticity, not shown in this demo, IPE will also ensure that the root digest is signed (
diglim_digest_get_info()reports this information).I apologize for the delay in responses, but it looks like you've figured it out.
No problem.
Quoted 10 lines
This kind of thing is exactly what IPE's design is supposed to solve, you have some other system which provides the integrity mechanism and (optionally) determine if it is trusted or not, and IPE can provide the policy aspect very easily to make a set of system-wide requirements around your mechanism.
I'm very supportive of adding the functionality, but I wonder if it makes more sense to have digilm's extension be a separate key instead of tied to the
fsverity_digestkey - something like
Quoted 5 lines
op=EXECUTE diglim_fsverity=TRUE action=DENY
that way the condition that enables this property can depend on digilm in the build, and it separates the two systems' integrations in a slightly more clean way.
Yes, I agree. It is much more clean.
Quoted 1 line
As an aside, did you find it difficult to extend?
No, it was very straightforward.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 28 lines
Quoted 28 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 23 lines
DIGLIM is a component I'm working on that generically stores digests. The current use case is to store file digests from
RPMTAG_FILEDIGESTSand use them with IMA, but the fsverity use case could be easily supported (if the root digest is stored in the RPM header).DIGLIM also tells whether or not the signature of the source containing file digests (or fsverity digests) is valid (the signature of the RPM header is taken from
RPMTAG_RSAHEADER).The memory occupation is relatively small for executables and shared libraries. I published a demo for Fedora and openSUSE some time ago:
https://lore.kernel.org/linux-
integrity/[email protected]/Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
RE: [RFC PATCH v7 05/16] ipe: add LSM hooks on execution and kernel read
In reply to Deven BowersQuoted 165 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Tuesday, October 26, 2021 9:04 PMQuoted 19 lines · Roberto Sassu
Quoted 19 lines
From:[email protected] [mailto:[email protected]]
From: 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 execve, mprotect, mmap,
kernel_load_dataandkernel_read_data.Signed-off-by Deven Bowers<[email protected]>---
Relevant changes since v6:
* 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] (this patch)Quoted 2 lines
Quoted 2 lines
--- security/ipe/hooks.c | 149++++++++++++++++++++++++++++++++++++++++++
Quoted 44 lines
Quoted 44 lines
security/ipe/hooks.h | 23 ++++++- security/ipe/ipe.c | 5 ++ security/ipe/policy.c | 23 +++++++ security/ipe/policy.h | 12 +++- 5 files changed, 209 insertions(+), 3 deletions(-)security/ipe/hooks.c +18
-0@@ -6,11 +6,15 @@#include "ipe.h" #include "ctx.h" #include "hooks.h" +#include "eval.h" +#include <linux/fs.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/binfmts.h> +#include <linux/mman.h> /** * ipe_task_alloc: Assign a new context for an associated task structure. @@ -56,3 +60,148 @@ void ipe_task_free(struct task_struct *task)ipe_put_ctx (ctx);rcu_read_unlock (); } + +/** +* ipe_on_exec: LSM hook called when a process is loaded through the exec +* family of system calls. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_exec (struct linux_binprm *bprm) +{ + return ipe_process_event(bprm->file, ipe_operation_exec,Quoted 8 lines
security/ipe/hooks.c void ipe_task_free(struct task_struct *task)
Quoted 8 lines
ipe_hook_exec);security/ipe/hooks.c +7
-0+} + +/** +* ipe_on_mmap: LSM hook called when a file is loaded through the mmap +* family of system calls. +* @f: File being mmap'd. Can be NULL in the case of anonymous memory. +* @reqprot: The requested protection on the mmap, passed from usermode.
Quoted 16 lines
Quoted 16 lines
+ * @prot: The effective protection on the mmap, resolved from reqprot and
+ * system configuration.
+ * @flags: Unused.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +5
-0+int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags) +{ +if (prot &PROT_EXEC || reqprot &PROT_EXEC ) + return ipe_process_event(f, ipe_operation_exec,
ipe_hook_mmap);security/ipe/hooks.c +2
-0+ +return 0 ;Quoted 8 lines
Quoted 8 lines
security/ipe/hooks.c +4
-0+} + +/** +* ipe_on_mprotect: LSM hook called when a mmap'd region of memory is changing
+ * its protections via mprotect.
+ * @vma: Existing virtual memory area created by mmap or similar
+ * @reqprot: The requested protection on the mmap, passed fromusermode.
Quoted 62 lines
Quoted 48 lines
+ * @prot: The effective protection on the mmap, resolved from reqprot and
+ * system configuration.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +41
-0+int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot) +{ +/* Already Executable */ +if (vma->vm_flags &VM_EXEC ) +return 0 ; + +if (((prot &PROT_EXEC ) || reqprot &PROT_EXEC )) +return ipe_process_event (vma->vm_file, ipe_operation_exec, + ipe_hook_mprotect); + +return 0 ; +} + +/** +* ipe_on_kernel_read: LSM hook called when a file is being read in from +* disk. +* @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. +* +* Return: +* 0 - OK +* !0 - Error +*/ +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents) +{ +enum ipe_operation op; + +switch (id) { +case READING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case READING_MODULE : + op = ipe_operation_kernel_module; +break ; +case READING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case READING_KEXEC_IMAGE :security/ipe/hooks.c void ipe_task_free(struct task_struct *task) · line 163
Quoted 10 lines
security/ipe/hooks.c +10
-0+ op = ipe_operation_kexec_image; +break ; +case READING_POLICY : + op = ipe_operation_ima_policy; +break ; +case READING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max;Possible problem here. If someone (like me) adds a new file type and forgets to add a case, there will be an out of bound access in
evaluate():
Quoted 7 lines
Quoted 4 lines
rules = &pol->parsed->rules[ctx->op];due to the static definition of the rules array in the
ipe_parsed_policystructure (array length:ipe_operation_max).Yeah, that's a problem. I can fix this down in the eval loop by matching the global default and emitting a WARN here.
Ok, will do a test with your new version of the patch set.
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 194 lines
Quoted 90 lines
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 85 lines
security/ipe/hooks.c +7
-0+ } + +return ipe_process_event (file, op, ipe_hook_kernel_read); +} + +/** +* ipe_on_kernel_load_data: LSM hook called when a buffer is being read in from
+ * disk.
+ * @id: Supplies the enumeration identifying the purpose of the read.
+ * @contents: Unused.
+ *
+ * Return:
+ * 0 - OK
+ * !0 - Error
+ */security/ipe/hooks.c +29
-0+int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents) +{ +enum ipe_operation op; + +switch (id) { +case LOADING_FIRMWARE : + op = ipe_operation_firmware; +break ; +case LOADING_MODULE : + op = ipe_operation_kernel_module; +break ; +case LOADING_KEXEC_INITRAMFS : + op = ipe_operation_kexec_initramfs; +break ; +case LOADING_KEXEC_IMAGE : + op = ipe_operation_kexec_image; +break ; +case LOADING_POLICY : + op = ipe_operation_ima_policy; +break ; +case LOADING_X509_CERTIFICATE : + op = ipe_operation_ima_x509; +break ; +default : + op = ipe_operation_max; + } + +return ipe_process_event (NULL , op, ipe_hook_kernel_load); +}security/ipe/hooks.h +20
-1@@ -5,11 +5,19 @@#ifndef IPE_HOOKS_H #define IPE_HOOKS_H +#include <linux/fs.h> #include <linux/types.h> #include <linux/sched.h> +#include <linux/binfmts.h> +#include <linux/security.h> enum ipe_hook { - ipe_hook_max =0 + ipe_hook_exec =0 , + ipe_hook_mmap, + ipe_hook_mprotect, + ipe_hook_kernel_read, + ipe_hook_kernel_load, + ipe_hook_max }; int ipe_task_alloc(struct task_struct *task,@@ -17,4 +25,17 @@ int ipe_task_alloc(struct task_struct *task,void ipe_task_free (struct task_struct *task); +int ipe_on_exec (struct linux_binprm *bprm); + +int ipe_on_mmap (struct file *f,unsigned long reqprot,unsigned long prot, +unsigned long flags); + +int ipe_on_mprotect (struct vm_area_struct *vma,unsigned long reqprot, +unsigned long prot); + +int ipe_on_kernel_read (struct file *file,enum kernel_read_file_id id, +bool contents); +Quoted 8 lines
security/ipe/ipe.c struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init =
Quoted 8 lines
security/ipe/hooks.h +2
-0+int ipe_on_kernel_load_data (enum kernel_load_data_id id,bool contents); +#endif /* IPE_HOOKS_H */ security/ipe/ipe.c +0
-0@@ -25,6 +25,11 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init ={
Quoted 10 lines
Quoted 10 lines
security/ipe/ipe.c +5
-0static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free), +LSM_HOOK_INIT (bprm_check_security, ipe_on_exec), +LSM_HOOK_INIT (mmap_file, ipe_on_mmap), +LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect), +LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read), +LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data), };Quoted 6 lines
security/ipe/policy.c int ipe_parse_op(const struct ipe_policy_token
Quoted 6 lines
security/ipe/ipe.c +0
-0/** security/ipe/policy.c +0
-0@@ -483,6 +483,14 @@ int ipe_parse_op(const struct ipe_policy_token*tok,
Quoted 78 lines
Quoted 78 lines
security/ipe/policy.c +23
-0{substring_t match[MAX_OPT_ARGS ] = {0 };const match_table_t ops = { + { ipe_operation_exec,"EXECUTE" }, + { ipe_operation_firmware,"FIRMWARE" }, + { ipe_operation_kernel_module,"KMODULE" }, + { ipe_operation_kexec_image,"KEXEC_IMAGE" }, + { ipe_operation_kexec_initramfs,"KEXEC_INITRAMFS" }, + { ipe_operation_ima_policy,"IMA_POLICY" }, + { ipe_operation_ima_x509,"IMA_X509_CERT" }, + { ipe_op_alias_kernel_read,"KERNEL_READ" }, { ipe_op_alias_max,NULL }, };@@ -838,6 +846,15 @@ static int parse_policy(struct ipe_policy *p)return rc; } +static const enum ipe_operation alias_kread[] = { + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, +}; +/** * ipe_is_op_alias: Determine if @op is an alias for one or more operations * @op: Supplies the operation to check. Should be either ipe_operation or @@ -852,9 +869,15 @@ static int parse_policy(struct ipe_policy *p)bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size) {switch (op) { +case ipe_op_alias_kernel_read: + *map = alias_kread; + *size =ARRAY_SIZE (alias_kread); +break ;default :return false; } + +return true; }/** security/ipe/policy.h +10
-3@@ -26,7 +26,14 @@ struct ipe_policy_line {struct ipe_module ;enum ipe_operation { - ipe_operation_max =0 , + ipe_operation_exec =0 , + ipe_operation_firmware, + ipe_operation_kernel_module, + ipe_operation_kexec_image, + ipe_operation_kexec_initramfs, + ipe_operation_ima_policy, + ipe_operation_ima_x509, + ipe_operation_max };/* @@ -34,7 +41,8 @@ enum ipe_operation {* that are just one or more operations under the hood */ enum ipe_op_alias { - ipe_op_alias_max = ipe_operation_max, + ipe_op_alias_kernel_read = ipe_operation_max, + ipe_op_alias_max, };enum ipe_action { --2.33.0
RE: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Deven BowersQuoted 96 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Tuesday, October 26, 2021 9:04 PMQuoted 3 lines · Eric Biggers
Quoted 2 lines · Deven Bowers
Quoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -
Quoted 11 lines · 0700,[email protected] wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
From: Fan Wu<[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
I’ve heard a lot of people use these terms in overloaded ways.
If we’re working with the definition of authenticity being “the property that a resource was _actually_ sent/created by a party”, and integrity being “the property that a resource was not modified from a point of time”, then yes. Though the statement isn’t false, though, because you’d need to prove integrity in the process of proving authenticity.
If not, could you clarify what you mean by authenticity and integrity, so that we can use consistent definitions?
Quoted 3 lines
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
We looked at extending IMA to cover our requirements extensively the past year
based on feedback the last time I posted these patches. We implemented a prototype that had half of our requirements, but found it resulted in a large change list that would result in a large amount of pain in respect to maintenance, in addition to other more architectural concerns about the implementation. We weren’t convinced it was the correct direction, for our needs.There was a presentation done at LSS 2021 around this prototype done by my colleague, Fan, who authored this patch and implemented the aforementioned prototype.
In general, IMA provides a whole suite of amazing functionality when it comes to everything integrity, as the fs-verity documentation states itself:
IMA specifies a system-wide policy that specifies which files are hashed and what to do with those hashes, such as log them, authenticate them, or add them to a measurement list.
Instead, IPE provides a fine-tuned way to _only_ enforce an access control policy to these files based on the defined trust requirements in the policy, under various contexts, (you might have different requirements for what executes in a general purpose, versus loadable kernel modules, for example). It will never provide bother to log, measure, or revalidate these hashes because
that’s not its purpose. This is why it belongs at the LSM layer instead of the
integrity subsystem layer, as it is providing access control based on a policy,
versus providing deep integrations with the actual integrity claim.IPE is trying to be agnostic to how precisely “trust” is provided, as opposed to be deeply integrated into the mechanism that provides “trust”.
Quoted 9 lines
Quoted 9 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
Quoted 8 lines
Quoted 6 lines
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
Do you have a better example? This one is pretty useless since one can get around it just by executing a file that doesn't have fs-verity enabled.
Here’s a more complete example:
policy_name=”fs-exec-only” policy_version=0.0.1 DEFAULT action=ALLOW
DEFAULT op=EXECUTE action=DENY op=EXECUTE fsverity_digest=<Digest> action=DENY op=EXECUTE fsverity_signature=TRUE action=ALLOW
Quoted 6 lines
Execution is prohibited unless it is a signed fs-verity file; However, after one of those executables was signed and published, an exploitable vulnerability in said executable was found, a new version was published without that vulnerability. We need to revoke trust for that executable since it could be used to exploit the system, so the first rule prevents it from matching the second.
With DIGLIM, revocation will be completely transparent since digests of files in the packages being removed will be also removed from the kernel. The next time IPE will evaluate an old version of the file (assuming that there was a copy somewhere) it will realize that the digest is not known anymore and will deny access.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 115 lines
Quoted 9 lines
Quoted 6 lines
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case.
No, it's not.
Digests are meaningless without knowing what algorithm they were created
with.
Quoted 6 lines
If your security policy is something like "Trust the file with digest $foo" and multiple hash algorithms are possible, then the alorithm intended to be used needs to be explicitly specified. Otherwise any algorithm with the same length digest will be accepted. That's a fatal flaw if any of these algorithms is cryptographically broken or was never intended to be a cryptographic
algorithm
Quoted 3 lines
in the first place (e.g., a non-cryptographic checksum).
Cryptosystems always need to specify the crypto algorithm(s) used; the
adversary
Quoted 1 line
must not be allowed to choose the algorithms.
Oof. You’re completely right. The part I was missing is that as time goes on,
the secure status of these cryptographic algorithms will change, and then we’ll
need a way to migrate between algorithms. Additionally, tooling and the like will
likely need a way to identify this from the policy text without consulting anything
else. This is a major oversight for general use, the system that this was originally
designed for only had support for a subset of the sha2-family (all separate lengths)
so I hadn’t even considered it.It's trivial to correct in a minimal amount of code, making the policy express the
digest like so:fsverity_digest=<algo>:<digest>
and change the argument passed to the LSM hook to accept a structure containing these
two fields.Quoted 1 line
I'm not sure how these patches can be taken seriously when they're getting
this
Quoted 1 line
sort of thing wrong.
That said, I, personally, hope that an honest mistake, in a series submitted as
an RFC submitted in good faith, is not a reason to discount an entire patch series.I hope you continue to provide feedback, as it is invaluable to making this system better, and making me, personally, a better developer.
Quoted 21 lines
Quoted 13 lines
Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 8 lines
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Quoted 5 lines
Most users of fs-verity built-in signatures have actually been enforcing their security policy in userspace, by checking whether specific files have the fs-verity bit set or not. Such users could just store and verify signatures in userspace instead, without any kernel involvement. So that's what I've been recommending (with limited success, unfortunately).
I believe the difference in security models comes from this line (emphasis, mine):
Quoted 1 line
by checking whether
_specificfiles_have the fs-verity bit set or not.IPE policy is written by a system author who owns the system, but may not have 100% control over all of the application code running on the system. In the case of applications which are not aware of IPE, the policy can still enforce that all of the code running on the system is trusted.
An example attack of what we're trying to mitigate: A hostile actor could downloads a binary off the internet with all required dependencies into tmpfs and runs their malicious executable.
With us validating this information in the kernel, even if the attacker downloaded their malicious executable to /tmp and executed it, it would still fail to pass policy and be denied, as the kernel is the common entrypoint across all executables.
Operationally, this _could_ be done by digest, but the policies would quickly become gigantic on a cartoonish proportion, as you'll have to authorize every single executable and dependency by digest - and there would be a complicated update story as the policy would have to be updated to onboard new digests.
By using signatures, we can prevent the policy update, and keep the policy size small.
Quoted 5 lines
If you really do need in-kernel signature verification, then that may be a legitimate use case for the fs-verity built-in signatures, although I do wonder why you aren't using IMA and its signature mechanism instead.
- Eric
kernel test robot
build botRe: [RFC PATCH v7 13/16] ipe: enable support for fs-verity as a trust provider
In reply to [email protected][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]
Hi,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master v5.15-rc7]
[cannot apply to jmorris-security/next-testing fscrypt/fsverity next-20211026] [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]
url: https://github.com/0day-ci/linux/commits/deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: openrisc-randconfig-r002-20211027 (attached as .config) compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1be21ee80ce58e3625217cc59f559c3bf56b8ed0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review deven-desai-linux-microsoft-com/Integrity-Policy-Enforcement-IPE/20211014-030810 git checkout 1be21ee80ce58e3625217cc59f559c3bf56b8ed0
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash security/ipe/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
security/ipe/hooks.c:220: warning: expecting prototype for ipe_bdev_free_security(). Prototype was for ipe_sb_free_security() instead
>> security/ipe/hooks.c:323: warning: expecting prototype for ipe_node_free_security(). Prototype was for ipe_inode_free_security() instead
vim +323 security/ipe/hooks.c
209
210 /**
211 * ipe_bdev_free_security: free nested structures within IPE's LSM blob
212 * in super_blocks
213 * @mnt_sb: Supplies a pointer to a super_block that contains the structure
214 * to free.
215 *
216 * IPE does not have any structures with mnt_sb, but uses this hook to
217 * invalidate a pinned super_block.
218 */
219 void ipe_sb_free_security(struct super_block *mnt_sb)
> 220 {
221 ipe_invalidate_pinned_sb(mnt_sb);
222 }
223
224 /**
225 * ipe_bdev_free_security: free nested structures within IPE's LSM blob
226 * in block_devices
227 * @bdev: Supplies a pointer to a block_device that contains the structure
228 * to free.
229 */
230 void ipe_bdev_free_security(struct block_device *bdev)
231 {
232 struct ipe_bdev *blob = ipe_bdev(bdev);
233
234 kfree(blob->sigdata);
235 kfree(blob->hash);
236 }
237
238 /**
239 * ipe_bdev_setsecurity: associate some data from the block device layer
240 * with IPE's LSM blob.
241 * @bdev: Supplies a pointer to a block_device that contains the LSM blob.
242 * @key: Supplies the string key that uniquely identifies the value.
243 * @value: Supplies the value to store.
244 * @len: The length of @value.
245 */
246 int ipe_bdev_setsecurity(struct block_device *bdev, const char *key,
247 const void *value, size_t len)
248 {
249 struct ipe_bdev *blob = ipe_bdev(bdev);
250
251 if (!strcmp(key, DM_VERITY_SIGNATURE_SEC_NAME)) {
252 blob->siglen = len;
253 blob->sigdata = kmemdup(value, len, GFP_KERNEL);
254 if (!blob->sigdata)
255 return -ENOMEM;
256
257 return 0;
258 }
259
260 if (!strcmp(key, DM_VERITY_ROOTHASH_SEC_NAME)) {
261 blob->hashlen = len;
262 blob->hash = kmemdup(value, len, GFP_KERNEL);
263 if (!blob->hash)
264 return -ENOMEM;
265
266 return 0;
267 }
268
269 return -ENOSYS;
270 }
271
272 /**
273 * ipe_inode_setsecurity: Sets the a certain field of a inode security
274 * blob, based on @key.
275 * @inode: The inode to source the security blob from.
276 * @name: The name representing the information to be stored.
277 * @value: The value to be stored.
278 * @size: The size of @value.
279 * @flags: unused
280 *
281 * Saves fsverity signature & digest into inode security blob
282 *
283 * Return:
284 * 0 - OK
285 * !0 - Error
286 */
287 int ipe_inode_setsecurity(struct inode *inode, const char *name,
288 const void *value, size_t size,
289 int flags)
290 {
291 struct ipe_inode *inode_sec = ipe_inode(inode);
292
293 if (!strcmp(name, FS_VERITY_SIGNATURE_SEC_NAME)) {
294 inode_sec->siglen = size;
295 inode_sec->sigdata = kmemdup(value, size, GFP_KERNEL);
296 if (!inode_sec->sigdata)
297 return -ENOMEM;
298
299 return 0;
300 }
301
302 if (!strcmp(name, FS_VERITY_DIGEST_SEC_NAME)) {
303 inode_sec->hashlen = size;
304 inode_sec->hash = kmemdup(value, size, GFP_KERNEL);
305 if (!inode_sec->hash)
306 return -ENOMEM;
307
308 return 0;
309 }
310
311 return -EOPNOTSUPP;
312 }
313
314 /**
315 * ipe_node_free_security: Frees all fields of IPE's inode security blob.
316 * @inode: The inode structure to source the security blob from.
317 *
318 * The deallocation of the blob itself is performed later by the LSM
319 * infrastructure, (on behalf of all LSMs) in lsm_free_file.
320 *
321 */
322 void ipe_inode_free_security(struct inode *inode)
> 323 {---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Eric Biggers
maintainerRe: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Deven BowersQuoted 14 lines · Deven Bowers
Quoted 5 lines
Quoted 4 lines
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
I’ve heard a lot of people use these terms in overloaded ways.
If we’re working with the definition of authenticity being “the property that a resource was _actually_ sent/created by a party”, and integrity being “the property that a resource was not modified from a point of time”, then yes. Though the statement isn’t false, though, because you’d need to prove integrity in the process of proving authenticity.
Quoted 2 lines
If not, could you clarify what you mean by authenticity and integrity, so that we can use consistent definitions?
In cryptography, integrity normally means knowing whether data has been non-maliciously changed, while authenticity means knowing whether data is from a particular source, which implies knowing whether it has been changed at all (whether maliciously or not). Consider that there are "Message Authentication Codes" (MACs) and "Authenticated Encryption", not "Message Integrity Codes" and "Intact Encryption".
Unfortunately lots of people do overload "integrity" to mean authenticity, so you're not alone. But it's confusing, so if you're going to do that then please make sure to clearly explain what you mean.
Quoted 37 lines
Quoted 3 lines
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
We looked at extending IMA to cover our requirements extensively the past year
based on feedback the last time I posted these patches. We implemented a prototype that had half of our requirements, but found it resulted in a large change list that would result in a large amount of pain in respect to maintenance, in addition to other more architectural concerns about the implementation. We weren’t convinced it was the correct direction, for our needs.There was a presentation done at LSS 2021 around this prototype done by my colleague, Fan, who authored this patch and implemented the aforementioned prototype.
In general, IMA provides a whole suite of amazing functionality when it comes to everything integrity, as the fs-verity documentation states itself:
IMA specifies a system-wide policy that specifies which files are hashed and what to do with those hashes, such as log them, authenticate them, or add them to a measurement list.
Instead, IPE provides a fine-tuned way to _only_ enforce an access control policy to these files based on the defined trust requirements in the policy, under various contexts, (you might have different requirements for what executes in a general purpose, versus loadable kernel modules, for example). It will never provide bother to log, measure, or revalidate these hashes because
that’s not its purpose. This is why it belongs at the LSM layer instead of the
integrity subsystem layer, as it is providing access control based on a policy,
versus providing deep integrations with the actual integrity claim.
Quoted 3 lines
IPE is trying to be agnostic to how precisely “trust” is provided, as opposed to be deeply integrated into the mechanism that provides “trust”.
IMA doesn't require logging or "measuring" hashes, though. Those are just some of its supported features. And I thought the IMA developers were planning to add support for fs-verity hashes, and that it wouldn't require an entirely new architecture to do so.
Anyway, while it does sound to me like you're duplicating IMA, I don't really have a horse in this race, and I defer to the IMA developers on this. I trust that you've been engaging with them? This patchset isn't even Cc'ed to linux-integrity, so it's unclear that's been happening.
- Eric
Re: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
Quoted 73 lines · Eric Biggers
Quoted 14 lines · Deven Bowers
Quoted 5 lines
Quoted 4 lines
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I think you mean authenticity, not integrity?
I’ve heard a lot of people use these terms in overloaded ways.
If we’re working with the definition of authenticity being “the property that a resource was _actually_ sent/created by a party”, and integrity being “the property that a resource was not modified from a point of time”, then yes. Though the statement isn’t false, though, because you’d need to prove integrity in the process of proving authenticity.
Quoted 2 lines
If not, could you clarify what you mean by authenticity and integrity, so that we can use consistent definitions?
In cryptography, integrity normally means knowing whether data has been non-maliciously changed, while authenticity means knowing whether data is from a particular source, which implies knowing whether it has been changed at all (whether maliciously or not). Consider that there are "Message Authentication Codes" (MACs) and "Authenticated Encryption", not "Message Integrity Codes" and "Intact Encryption".
Unfortunately lots of people do overload "integrity" to mean authenticity, so you're not alone. But it's confusing, so if you're going to do that then please make sure to clearly explain what you mean.
Quoted 37 lines
Quoted 3 lines
Also how does this differ from IMA? I know that IMA doesn't support fs-verity file hashes, but that could be changed. Why not extend IMA to cover your use case(s)?
We looked at extending IMA to cover our requirements extensively the past year
based on feedback the last time I posted these patches. We implemented a prototype that had half of our requirements, but found it resulted in a large change list that would result in a large amount of pain in respect to maintenance, in addition to other more architectural concerns about the implementation. We weren’t convinced it was the correct direction, for our needs.There was a presentation done at LSS 2021 around this prototype done by my colleague, Fan, who authored this patch and implemented the aforementioned prototype.
In general, IMA provides a whole suite of amazing functionality when it comes to everything integrity, as the fs-verity documentation states itself:
IMA specifies a system-wide policy that specifies which files are hashed and what to do with those hashes, such as log them, authenticate them, or add them to a measurement list.
Instead, IPE provides a fine-tuned way to _only_ enforce an access control policy to these files based on the defined trust requirements in the policy, under various contexts, (you might have different requirements for what executes in a general purpose, versus loadable kernel modules, for example). It will never provide bother to log, measure, or revalidate these hashes because
that’s not its purpose. This is why it belongs at the LSM layer instead of the
integrity subsystem layer, as it is providing access control based on a policy,
versus providing deep integrations with the actual integrity claim.Quoted 3 lines
IPE is trying to be agnostic to how precisely “trust” is provided, as opposed to be deeply integrated into the mechanism that provides “trust”.
IMA doesn't require logging or "measuring" hashes, though. Those are just some of its supported features. And I thought the IMA developers were planning to add support for fs-verity hashes, and that it wouldn't require an entirely new architecture to do so.
Quoted 4 lines
Anyway, while it does sound to me like you're duplicating IMA, I don't really have a horse in this race, and I defer to the IMA developers on this. I trust that you've been engaging with them? This patchset isn't even Cc'ed to linux-integrity, so it's unclear that's been happening.
That was entirely my mistake. Mimi and the linux-integrity list was CC'd on previous versions (Roberto actually added the list to his responses) - when I was reconstructing the To: line with get-maintainers.pl, the list didn't pop up and I did not remember to add it manually. I've corrected my mailing script to re-add them again.
Quoted 301 lines · Roberto Sassu
Quoted 29 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Tuesday, October 26, 2021 9:04 PMQuoted 26 lines · Roberto Sassu
Quoted 11 lines
From:[email protected] [mailto:[email protected]]
From: Deven Bowers<[email protected]>Overview:
---------IPE is a Linux Security Module which takes a complimentary approach to access control. Whereas existing systems approach use labels or paths which control access to a resource, IPE controls access to a resource based on the system's trust of said resource.
To me, it does not give a particularly precise idea of what IPE is about.
It would have been more clear, assuming that I understood it correctly, if you have said:
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.
Quoted 8 lines
Quoted 6 lines
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.
You understood it perfectly, and managed to word in a much more clear way than I did. I'll apply these changes in the next posting! Thanks.
Welcome.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Trust requirements are established via IPE's policy, sourcing multiple different implementations within the kernel to build a cohesive trust model, based on how the system was built.
Trust, with respect to computing, is a concept that designates a set of entities who will endorse a set of resources as non-malicious. Traditionally, this is done via signatures, which is the act of endorsing a resource.
Integrity, on the other hand, is the concept of ensuring that a resource has not been modified since a point of time. This is typically done through cryptographic hashes or signatures.
Trust and integrity are very closely tied together concepts, as integrity is the way you can prove trust for a resource; otherwise it could have been modified by an entity who is untrusted.
IPE provides a way for a user to express trust requirements of resources, by using pre-existing systems which provide the integrity half of the equation.
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. Instead, IPE supports the PKI Trust Model, which generally designates a set of entities that provide a measure absolute trust.Quoted 8 lines
Quoted 5 lines
It is true that packages are signed with PGP, which is decentralized, but there is a special case where Linux distribution vendors trust their own keys. This, at least, would allow to trust the software built by a particular vendor (I ported David Howells's work on PGP keys and signature to the current kernel).
Yes, that is true. I figured that this scenario was somewhat obvious, as it is, at a high level, similar to PKI but I can certainly add it explicitly.
Perfect.
Quoted 14 lines
Quoted 9 lines
Quoted 5 lines
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.
Yes, RPMs don't have per file signatures but have a signature of the list of file digests, which is equivalent. They could have also the fsverity digests (instead of the fsverity signatures) to reduce size overhead.
Quoted 5 lines
Given that the authenticity of RPMs headers can be verified, if the PGP key of the vendor is included in the primary keyring of the kernel, being able to protect file or fsverity digests against tampering by user space and being able to query them (e.g. with DIGLIM) extends the applicability of IPE to general purpose OSes.
Quoted 4 lines
Agreed. With these two functionalities, it does appear that IPE + DIGLIM can be used for general purpose RPM-based OSes. I'll add a reference to your recent posting (v3?) as a way to extend the functionality to general purposes OSes in the next revision.
Ok. Yes, v3 is the latest.
Quoted 184 lines
Quoted 14 lines
Quoted 14 lines
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 (NOT the policy syntax version). This is used to prevent roll-back of policy to potentially insecure previous versions of the policy.
Quoted 5 lines
Quoted 2 lines
The next portion of IPE policy, are rules. Rules are formed by key=value pairs, known as properties. IPE rules require two properties: "action",
Better:
IPE rules require two keys:
Ack.
Quoted 77 lines
Quoted 77 lines
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 will allow any execution. 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. Available properties for IPE described in the documentation patch of this series.
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. 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. User mode can interrogate the kernel to understand what properties and the associated versions through the securityfs node, $securityfs/ipe/config, which will return a string of form:
key1=version1 key2=version2 . . . keyN=versionNUser-mode should correlate these versions with the supported values identified in the documentation to determine whether a policy should be accepted by the system without actually trying to deploy 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, 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 userland 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=ALLOWAllow 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
Quoted 7 lines
Quoted 7 lines
Prohibit execution from a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec
Quoted 11 lines
Quoted 11 lines
146938 action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW op=EXECUTE dmverity_signature=TRUE action=ALLOWAllow only a specific dm-verity volume:
policy_name="AllowSignedAndInitial" policy_version=0.0.0 DEFAULT action=DENY
op=EXECUTE
dmverity_roothash=401fcec5944823ae12f62726e8184407a5fa9599783f030dec
Quoted 54 lines
Quoted 47 lines
146938 action=ALLOW
Deploying Policies:
-------------------First sign a plain text policy, with a certificate that is present in the
SYSTEM_TRUSTED_KEYRINGof your test machine. Through openssl, the signing can be done via:openssl smime -sign -in "$MY_POLICY" -signer "$MY_CERTIFICATE" \ -inkey "$MY_PRIVATE_KEY" -binary -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_policyThe 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_versionattribute 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: The securityfs commands will require
CAP_MAC_ADMIN.Quoted 7 lines
Integrations:
-------------This patch series adds support for fsverity via digest and signature (
fsverity_signatureandfsverity_digest), dm-verity by digest and signature (dmverity_signatureanddmverity_roothash), and trust for the initramfs (boot_verified).Quoted 8 lines
Verifying the initial ram disk looks like a big problem. On general purpose OSes, having a reference value for it would be very hard.
Instead, we would still be able to use per file reference values. Executable and shared libraries in the initial ram disk are copied from the main OS. Without fsverity support in tmpfs, I wonder if it would be still possible to mark the file as immutable and do an on the fly calculation of the root digest.
Yes, verifying the initial ramdisk is very difficult. "
boot_verified", is largely an assumption of trust as all the warning shows in the documentation; it assumes the boot stack verified the initramfs somehow (i.e. u-boot verified boot with it in the fitImage), and 'pins' (similar to loadpin) the superblock to allow execution from that superblock.Quoted 7 lines
Quoted 3 lines
As an alternative, the IMA approach of calculating the file digest could be used (or IPE could get the file digest as a property from the integrity subsystem).
In general, I would like to keep as much of the implementation of the integrity mechanisms out of IPE as much as possible - there are likely much better layers to implement new ways of providing integrity / authenticity claims than at the lsm layer within IPE.
That would be still the case. The integrity subsystem will be still responsible to calculate the file digest and maintain it in a per inode metadata. Then, IPE could evaluate the file digest as the same as for the fsverity digest:
Quoted 4 lines
op=EXECUTE integrity_digest=<hex> action=ALLOW
integrity_digestwill be handled by a separate IPE module which communicates with the integrity subsystem.
Sure, I'm happy with this. My comment was originally to the first half of your response ("the IMA approach of calculating the file digest could be used"); I don't see that as part of IPE's purpose.
I wanted to draw as rough boundary between what I find acceptable as an IPE extension and what isn't.
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Deven BowersHello,
Quoted 9 lines · EDT Deven Bowers
Quoted 8 lines · Steve Grubb
Quoted 4 lines · On Wednesday, October 13, 2021 3:06:26 PM EDT [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 systens with respect to IPE itself.
Quoted 7 lines
Quoted 3 lines
Would you mind sending examples of audit events so that we can see what the end result is? Some people add them to the commit text. But we still need to see what they look like.
Sure, sorry. I’ll add them to the commit description (and the documentation patch at the end) for v8 – In the interest of asynchronous feedback, I’ve copied the relevant examples:
Thanks for sending these. This helps.
Quoted 3 lines
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT op=EXECUTE action=DENY"
Question...why do all of these have a ctx_ prefix? Is it possible to trigger an audit context so that the audit machinery collects all of this stuff in it's own way? Which means you could drop everything execept op, hook, enforce, rule, and action.
We also have a field dictionary here:
https://github.com/linux-audit/audit-documentation/blob/main/specs/fields/
field-dictionary.csv
which names the known fields and how they should be formatted. If there is a collision where they are something else and cannot be in the same format, then we make a new name and hopefully update the dictionary. For example, if you are collecting a process id, use pid and not ctx_pid so that it matches a known definition.
Also, I don't thnk these events can stand on their own. Who did this action? You have the pid, but no uid, auid, or session_id.
Hope this helps...
-Steve
Quoted 36 lines
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT action=DENY"
AUDIT1420 IPE ctx_pid=253 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=1 ctx_comm="anon" rule="DEFAULT op=EXECUTE action=DENY"
These three audit records represent various types of results after evaluating
the trust of a resource. The first two differ in the rule that was matched in
IPE's policy, the first being an operation-specific default, the second being
a global default. The third is an example of what is audited when anonymous memory is blocked (as there is no way to verify the trust of an anonymous page).The remaining three events,
AUDIT_TRUST_POLICY_LOAD(1421),AUDIT_TRUST_POLICY_ACTIVATE(1422), andAUDIT_TRUST_STATUS(1423) have this form:AUDIT1421 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash>
AUDIT1422 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash>
AUDIT1423 IPE enforce=1The 1421 (
AUDIT_TRUST_POLICY_LOAD) event represents a new policy was loaded into the kernel, but not is not marked as the policy to enforce. TheThe 1422 (
AUDIT_TRUST_POLICY_ACTIVATE) event represents a policy that was already loaded was made the enforcing policy.The 1423 (
AUDIT_TRUST_STATUS) event represents a switch between permissive and
enforce, it is added in 08/16 (the following patch)
RE: [RFC PATCH v7 04/16] ipe: add userspace interface
In reply to [email protected]Quoted 376 lines
From: [email protected] [mailto:[email protected]]
From: 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.rstSigned-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* Refactor series to:
1. Support a context structure, enabling easier testing
* Split up patch 03/12 into two parts:
1. parser [02/16]
2. userspace interface [04/16] (this patch)
* 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.--- security/ipe/Makefile | 2 + security/ipe/ctx.c | 121 +++++++++ security/ipe/ctx.h | 6 + security/ipe/fs.c | 170 +++++++++++++ security/ipe/fs.h | 13 + security/ipe/policy.c | 41 ++++ security/ipe/policy.h | 4 + security/ipe/policyfs.c | 528 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 885 insertions(+) create mode 100644 security/ipe/fs.c create mode 100644 security/ipe/fs.h create mode 100644 security/ipe/policyfs.csecurity/ipe/Makefile +2
-0@@ -10,9 +10,11 @@ ccflags-y := -I$(srctree)/security/ipe/modules obj-$(CONFIG_SECURITY_IPE) += \ ctx.o \ eval.o \ + fs.o \ hooks.o \ ipe.o \ modules.o \ parsers/ \ parsers.o \ policy.o \ + policyfs.o \security/ipe/ctx.c +121
-0@@ -13,6 +13,29 @@#include <linux/refcount.h> #include <linux/spinlock.h> +/** +* ver_to_u64: convert an internal ipe_policy_version to a u64 +* @p: Policy to extract the version from +* +* Bits (LSB is index 0): +* [48,32] -> Major +* [32,16] -> Minor +* [16, 0] -> Revision +* +* Return: +* u64 version of the embedded version structure. +*/ +static inline u64 ver_to_u64 (const struct ipe_policy *const p) +{ +u64 r =0 ; + + r = (((u64 )p->parsed->version.major) <<32 ) + | (((u64 )p->parsed->version.minor) <<16 ) + | ((u64)(p->parsed->version.rev)); + +return r; +} +/** * ipe_current_ctx: Helper to retrieve the ipe_context for the current task. * @@ -96,6 +119,7 @@ static void free_ctx_work(struct work_struct *const work)list_for_each_entry (p, &ctx->policies, next)ipe_put_policy (p); +securityfs_remove (ctx->policy_root);kfree (ctx); }@@ -160,6 +184,9 @@ void ipe_remove_policy(struct ipe_policy *p)* ipe_add_policy: Associate @p with @ctx * @ctx: Supplies a pointer to the ipe_context structure to associate @p with. * @p: Supplies a pointer to the ipe_policy structure to associate. +* +* This will increase @p's reference count by one. +* */ void ipe_add_policy (struct ipe_context *ctx,struct ipe_policy *p) {@@ -168,7 +195,101 @@ void ipe_add_policy(struct ipe_context *ctx, struct ipe_policy *p) list_add_tail(&p->next, &ctx->policies);refcount_inc (&p->refcount);spin_unlock (&ctx->lock); +} + +/** +* ipe_replace_policy: Replace @old with @new in the list of policies in @ctx +* @ctx: Supplies the context object to manipulate. +* @old: Supplies a pointer to the ipe_policy to replace with @new +* @new: Supplies a pointer to the ipe_policy structure to replace @old with +*/ +int ipe_replace_policy (struct ipe_policy *old,struct ipe_policy *new) +{ +int rc = -EINVAL ; +struct ipe_context *ctx; +struct ipe_policy *cursor; +struct ipe_policy *p =NULL ; + + ctx =ipe_get_ctx_rcu (old->ctx); +if (!ctx) +return -ENOENT ; + +spin_lock (&ctx->lock); +list_for_each_entry (cursor, &ctx->policies, next) { +if (!strcmp (old->parsed->name, cursor->parsed->name)) { +if (ipe_is_policy_active (old)) { +if (ver_to_u64 (old) >ver_to_u64 (new)) +break ; +rcu_assign_pointer (ctx->active_policy, new); + } +list_replace_init (&cursor->next, &new->next); +refcount_inc (&new->refcount); +rcu_assign_pointer (new->ctx, old->ctx); + p = cursor; + rc =0 ; +break ; + } + } +spin_unlock (&ctx->lock); +synchronize_rcu (); + +ipe_put_policy (p); +ipe_put_ctx (ctx); +return rc; +} + +/** +* ipe_set_active_pol: Make @p the active policy. +* @p: Supplies a pointer to the policy to make active. +*/ +int ipe_set_active_pol (const struct ipe_policy *p) +{ +int rc =0 ; +struct ipe_policy *ap =NULL ; +struct ipe_context *ctx =NULL ; + + ctx =ipe_get_ctx_rcu (p->ctx); +if (!ctx) { + rc = -ENOENT ; + goto out; + } + + ap =ipe_get_policy_rcu (ctx->active_policy); +if (ap &&ver_to_u64 (ap) >ver_to_u64 (p)) { + rc = -EINVAL ; + goto out; + } + +spin_lock (&ctx->lock); +rcu_assign_pointer (ctx->active_policy, p); +spin_unlock (&ctx->lock);synchronize_rcu (); + +out: +ipe_put_policy (ap); +ipe_put_ctx (ctx); +return rc; +} + +/** +* ipe_is_policy_active: Determine wehther @p is the active policy +* @p: Supplies a pointer to the policy to check. +* +* Return: +* true - @p is the active policy of @ctx +* false - @p is not the active policy of @ctx +*/ +bool ipe_is_policy_active (const struct ipe_policy *p) +{ +bool rv; +struct ipe_context *ctx; + +rcu_read_lock (); + ctx =rcu_dereference (p->ctx); + rv = !IS_ERR_OR_NULL (ctx) &&rcu_access_pointer (ctx->active_policy) == p; +rcu_read_unlock (); + +return rv; }/**
security/ipe/ctx.h +6
-0@@ -7,6 +7,7 @@#include <linux/sched.h> #include <linux/types.h> +#include <linux/dcache.h> #include <linux/refcount.h> #include <linux/spinlock.h> #include <linux/workqueue.h> @@ -20,6 +21,8 @@ struct ipe_context {struct list_head policies;/* type: ipe_policy */ +struct dentry *policy_root; +struct work_struct free_work; };@@ -30,5 +33,8 @@ struct ipe_context *ipe_get_ctx_rcu(struct ipe_context __rcu *ctx);void ipe_put_ctx (struct ipe_context *ctx);void ipe_add_policy (struct ipe_context *ctx,struct ipe_policy *p);void ipe_remove_policy (struct ipe_policy *p); +int ipe_replace_policy (struct ipe_policy *old,struct ipe_policy *new); +int ipe_set_active_pol (const struct ipe_policy *p); +bool ipe_is_policy_active (const struct ipe_policy *p);#endif /*
IPE_CONTEXT_H*/security/ipe/fs.c new file +85
-0@@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#include "ipe.h" +#include "fs.h" +#include "policy.h" + +#include <linux/dcache.h> +#include <linux/security.h> + +static struct dentry *np__ro_after_init ; +static struct dentry *root__ro_after_init ; +static struct dentry *config__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 ; +struct ipe_context *ctx =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + ctx =ipe_current_ctx (); + + copy =memdup_user_nul (data, len); +if (IS_ERR (copy)) { + rc =PTR_ERR (copy); + goto err; + } + + p =ipe_new_policy (NULL ,0 , copy, len); +if (IS_ERR (p)) { + rc =PTR_ERR (p); + goto err; + } + + rc =ipe_new_policyfs_node (ctx, p); +if (rc) + goto err; + +ipe_add_policy (ctx, p); +err: +ipe_put_policy (p); +ipe_put_ctx (ctx); +return (rc <0 ) ? rc : len; +} + +/** +* get_config: Read handler for the securityfs node, "ipe/config" +* @f: Supplies a file structure representing the securityfs node. +* @data: Supplies a buffer passed to the read syscall +* @len: Supplies the length of @data +* @offset: unused. +* +* Return: +* >0 - Success, Length of buffer written +* <0 - Error +*/ +static ssize_t get_config (struct file *f,char __user *data,size_t len, +loff_t *offset) +{ +int rc =0 ; +char *buf =NULL ; +size_t buflen =0 ; +char tmp[30 ] = {0 }; +struct ipe_parser *p =NULL ; +struct ipe_module *m =NULL ; + +for (p = __start_ipe_parsers; p < __end_ipe_parsers; ++p) + buflen += snprintf(NULL, 0, "%s=%d\n", p->first_token, p-Quoted 1 line
version);
security/ipe/fs.c new file +13
-0+for (m = __start_ipe_modules; m < __end_ipe_modules; ++m) + buflen +=snprintf (NULL ,0 ,"%s=%d\n" , m->name, m->version); + + ++buflen; + buf =kzalloc (buflen,GFP_KERNEL ); +if (!buf) { + rc = -ENOMEM ; + goto out; + } + +for (p = __start_ipe_parsers; p < __end_ipe_parsers; ++p) { +memset (tmp,0x0 ,ARRAY_SIZE (tmp)); + scnprintf(tmp, ARRAY_SIZE(tmp), "%s=%d\n", p->first_token, p-Quoted 1 line
version);
security/ipe/fs.c new file +6
-0+strcat (buf, tmp); + } + +for (m = __start_ipe_modules; m < __end_ipe_modules; ++m) { +memset (tmp,0x0 ,ARRAY_SIZE (tmp)); + scnprintf(tmp, ARRAY_SIZE(tmp), "%s=%d\n", m->name, m-Quoted 1 line
version);
security/ipe/fs.c new file +20
-0+strcat (buf, tmp); + } + + rc =simple_read_from_buffer (data, len, offset, buf, buflen); +out: +kfree (buf); +return rc; +} + +static const struct file_operations cfg_fops = { + .read = get_config, +}; + +static const struct file_operations np_fops = { + .write = new_policy, +}; + +/** +* ipe_init_securityfs: Initialize IPE's securityfs tree at fsinit +*
security/ipe/fs.c line 134
Quoted 10 lines
security/ipe/fs.c new file +10
-0+* Return: +* !0 - Error +* 0 - OK +*/ +static int __init ipe_init_securityfs (void ) +{ +int rc =0 ; +struct ipe_context *ctx =NULL ; + + ctx =ipe_current_ctx ();
Hi Deven
the instruction above should be executed only if IPE LSM is enabled. Otherwise, the kernel panics due to the illegal access to the security blob of the task.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 680 lines
security/ipe/fs.c new file +36
-0+ + root =securityfs_create_dir ("ipe" ,NULL ); +if (IS_ERR (root)) { + rc =PTR_ERR (root); + goto err; + } + + np =securityfs_create_file ("new_policy" ,0200 , root,NULL , &np_fops); +if (IS_ERR (np)) { + rc =PTR_ERR (np); + goto err; + } + + config =securityfs_create_file ("config" ,0400 , root,NULL , + &cfg_fops); +if (IS_ERR (config)) { + rc =PTR_ERR (config); + goto err; + } + + ctx->policy_root =securityfs_create_dir ("policies" , root); +if (IS_ERR (ctx->policy_root)) { + rc =PTR_ERR (ctx->policy_root); + goto err; + } + +return 0 ; +err: +securityfs_remove (np); +securityfs_remove (root); +securityfs_remove (config); +securityfs_remove (ctx->policy_root); +return rc; +} + +fs_initcall (ipe_init_securityfs);security/ipe/fs.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef IPE_FS_H +#define IPE_FS_H + +void ipe_soft_del_policyfs (struct ipe_policy *p); +int ipe_new_policyfs_node (struct ipe_context *ctx,struct ipe_policy *p); +void ipe_del_policyfs_node (struct ipe_policy *p); + +#endif /* IPE_FS_H */ security/ipe/policy.c +41
-0@@ -4,6 +4,7 @@*/ #include "ipe.h" +#include "fs.h" #include "policy.h" #include "ipe_parser.h" #include "modules.h" @@ -867,6 +868,8 @@ void ipe_put_policy(struct ipe_policy *p)if (IS_ERR_OR_NULL (p) || !refcount_dec_and_test (&p->refcount))return ; +ipe_del_policyfs_node (p); +securityfs_remove (p->policyfs);free_parsed_policy (p->parsed);if (!p->pkcs7)kfree (p->text);@@ -911,6 +914,44 @@ 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. +* @old: Supplies a pointer to the policy to replace +* @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. +* +* Return: +* !IS_ERR - OK +*/ +struct ipe_policy *ipe_update_policy (struct ipe_policy *old, +const char *text,size_t textlen, +const char *pkcs7,size_t pkcs7len) +{ +int rc =0 ; +struct ipe_policy *new; + + new =ipe_new_policy (text, textlen, pkcs7, pkcs7len); +if (IS_ERR (new)) { + rc =PTR_ERR (new); + goto err; + } + +if (strcmp (new->parsed->name, old->parsed->name)) { + rc = -EINVAL ; + goto err; + } + + rc =ipe_replace_policy (old, new); +err: +ipe_put_policy (new); +return (rc <0 ) ?ERR_PTR (rc) : new; +} +/** * ipe_new_policy: allocate and parse an ipe_policy structure. *
security/ipe/policy.h +4
-0@@ -88,12 +88,16 @@ struct ipe_policy {refcount_t refcount; +struct dentry *policyfs;struct list_head next;/* type: ipe_policy */ struct ipe_context __rcu *ctx; };struct ipe_policy *ipe_new_policy (const char *text,size_t textlen,const char *pkcs7,size_t pkcs7len); +struct ipe_policy *ipe_update_policy (struct ipe_policy *old,const char *text, +size_t textlen,const char *pkcs7, +size_t pkcs7len);void ipe_put_policy (struct ipe_policy *pol);bool ipe_is_op_alias (int op,const enum ipe_operation **map,size_t *size);struct ipe_policy *ipe_get_policy_rcu (struct ipe_policy __rcu *p);security/ipe/policyfs.c new file +516
-0@@ -0,0 +1,528 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#include "ipe.h" +#include "policy.h" +#include "fs.h" + +#include <linux/fs.h> +#include <linux/namei.h> +#include <linux/types.h> +#include <linux/dcache.h> +#include <linux/security.h> + +#define MAX_VERSION_SIZE ARRAY_SIZE("65535.65535.65535") + +/** +* find_policy: Follow the i_private field of a dentry, returning the address +* of the resulting policy structure. +* @f: Securityfs object that contains a link to the dentry containing the +* policy structure. +* +* Return: +* Always-Valid Address Pointer +*/ +static inline struct ipe_policy __rcu **find_policy (struct file *f) +{ +struct dentry *link; + + link =d_inode (f->f_path.dentry)->i_private; + +return (struct ipe_policy __rcu **)&(d_inode (link)->i_private); +} + +/** +* 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 the securityfs node, +* "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 ipe_policy *p =NULL ; + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) +return -ENOENT ; + +if (!p->pkcs7) { + rc = -ENOENT ; + goto out; + } + + rc =simple_read_from_buffer (data, len, offset, p->pkcs7, p->pkcs7len); + +out: +ipe_put_policy (p); +return rc; +} + +/** +* read_policy: Read handler for the securityfs node, +* "ipe/policies/$name/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. +* +* @data will be populated with the plain-text version of the policy +* on success. +* +* Return: +* >0 - Success, Length of buffer written +* <0 - Error +*/ +static ssize_t read_policy (struct file *f,char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +struct ipe_policy *p =NULL ; + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) +return -ENOENT ; + + rc =simple_read_from_buffer (data, len, offset, p->text, p->textlen); + +ipe_put_policy (p); +return rc; +} + +/** +* read_name: Read handler for the securityfs node, +* "ipe/policies/$name/name" +* @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 policy_name attribute on success +* +* Return: +* >0 - Success, Length of buffer written +* <0 - Error +*/ +static ssize_t read_name (struct file *f,char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +struct ipe_policy *p =NULL ; + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) +return -ENOENT ; + + rc =simple_read_from_buffer (data, len, offset, p->parsed->name, +strlen (p->parsed->name)); + +ipe_put_policy (p); +return rc; +} + +/** +* read_version: Read handler for the securityfs node, +* "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 ipe_policy *p =NULL ; +char buffer[MAX_VERSION_SIZE ] = {0 }; + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) +return -ENOENT ; + + bufsize =scnprintf (buffer,ARRAY_SIZE (buffer),"%hu.%hu.%hu" , + p->parsed->version.major, p->parsed->version.minor, + p->parsed->version.rev); + + rc =simple_read_from_buffer (data, len, offset, buffer, bufsize); + +ipe_put_policy (p); +return rc; +} + +/** +* setactive: Write handler for the securityfs node, +* "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 ipe_policy *p =NULL ; +struct ipe_context *ctx =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + rc =kstrtobool_from_user (data, len, &value); +if (rc) + goto out; + +if (!value) { + rc = -EINVAL ; + goto out; + } + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) { + rc = -ENOENT ; + goto out; + } + + ctx =ipe_get_ctx_rcu (p->ctx); +if (!ctx) { + rc = -ENOENT ; + goto out; + } + + rc =ipe_set_active_pol (p); + +out: +ipe_put_ctx (ctx); +ipe_put_policy (p); +return (rc <0 ) ? rc : len; +} + +/** +* getactive: Read handler for the securityfs node, +* "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 ipe_policy *p =NULL ; + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) { + rc = -ENOENT ; + goto out; + } + + str =ipe_is_policy_active (p) ?"1" :"0" ; + rc =simple_read_from_buffer (data, len, offset, str,2 ); + +out: +ipe_put_policy (p); +return rc; +} + +/** +* update_policy: Write handler for the securityfs node, +* "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. +* +* 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) +{ +int rc =0 ; +char *copy =NULL ; +struct ipe_policy *new =NULL ; +struct ipe_policy *old =NULL ; +struct ipe_context *ctx =NULL ; +struct ipe_policy __rcu **addr =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + ctx =ipe_current_ctx (); +if (!ctx) +return -ENOENT ; + + addr =find_policy (f); + old =ipe_get_policy_rcu (*addr); +if (!old) { + rc = -ENOENT ; + goto err; + } + + copy =memdup_user (data, len); +if (IS_ERR (copy)) { + rc =PTR_ERR (copy); + goto err; + } + + new =ipe_update_policy (old,NULL ,0 , copy, len); +if (IS_ERR (new)) { + rc =PTR_ERR (new); + goto err; + } + +spin_lock (&ctx->lock); +rcu_assign_pointer (*addr, new); +spin_unlock (&ctx->lock); +synchronize_rcu (); + +swap (new->policyfs, old->policyfs); + +kfree (copy); +ipe_put_ctx (ctx); +ipe_put_policy (old); +return len; +err: +kfree (copy); +ipe_put_ctx (ctx); +ipe_put_policy (new); +ipe_put_policy (old); +return rc; +} + +/** +* delete_policy: write handler for securityfs dir, "ipe/policies/$name/delete" +* @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 deletes the policy represented by $name. +* +* Return: +* >0 - Success, Length of buffer written +* <0 - Error +*/ +static ssize_t delete_policy (struct file *f,const char __user *data, +size_t len,loff_t *offset) +{ +int rc =0 ; +bool value = false; +struct ipe_policy *p =NULL ; +struct ipe_context *ctx =NULL ; + +if (!file_ns_capable (f, &init_user_ns,CAP_MAC_ADMIN )) +return -EPERM ; + + rc =kstrtobool_from_user (data, len, &value); +if (rc) + goto out; + +if (!value) { + rc = -EINVAL ; + goto out; + } + + p =ipe_get_policy_rcu (*find_policy (f)); +if (!p) { + rc = -ENOENT ; + goto out; + } + +if (ipe_is_policy_active (p)) { + rc = -EPERM ; + goto out; + } + + ctx =ipe_get_ctx_rcu (p->ctx); +if (!ctx) { + rc = -ENOENT ; + goto out; + } + +ipe_remove_policy (p); +out: +ipe_put_ctx (ctx); +ipe_put_policy (p); +return (rc <0 ) ? rc : len; +} + +static const struct file_operations content_fops = { + .read = read_policy, +}; + +static const struct file_operations pkcs7_fops = { + .read = read_pkcs7, +}; + +static const struct file_operations name_fops = { + .read = read_name, +}; + +static const struct file_operations ver_fops = { + .read = read_version, +}; + +static const struct file_operations active_fops = { + .write = setactive, + .read = getactive, +}; + +static const struct file_operations update_fops = { + .write = update_policy, +}; + +static const struct file_operations delete_fops = { + .write = delete_policy, +}; + +/** +* policy_subdir: files under a policy subdirectory +*/ +static const struct ipefs_file policy_subdir[] = { + {"pkcs7" ,0444 , &pkcs7_fops }, + {"policy" ,0444 , &content_fops }, + {"name" ,0444 , &name_fops }, + {"version" ,0444 , &ver_fops }, + {"active" ,0600 , &active_fops }, + {"update" ,0200 , &update_fops }, + {"delete" ,0200 , &delete_fops }, +}; + +/** +* soft_del_policyfs - soft delete the policyfs tree, preventing new +* accesses to the interfaces for this policy. +* @p - Policy to soft delete the tree for. +*/ +static void soft_del_policyfs (struct ipe_policy *p) +{ +struct inode *ino =NULL ; +struct ipe_policy __rcu **addr =NULL ; + + ino =d_inode (p->policyfs); + addr = (struct ipe_policy __rcu **)&ino->i_private; + +inode_lock (ino); +rcu_assign_pointer (*addr,NULL ); +inode_unlock (ino); +synchronize_rcu (); +} + +/** +* ipe_del_policyfs_node: Delete a securityfs entry for @p +* @p: Supplies a pointer to the policy to delete a securityfs entry for. +*/ +void ipe_del_policyfs_node (struct ipe_policy *p) +{ +size_t i =0 ; +struct dentry *d =NULL ; +const struct ipefs_file *f =NULL ; + +if (IS_ERR_OR_NULL (p->policyfs)) +return ; + +soft_del_policyfs (p); + +for (i =0 ; i <ARRAY_SIZE (policy_subdir); ++i) { + f = &policy_subdir[i]; + + d =lookup_positive_unlocked (f->name, p->policyfs, +strlen (f->name)); +if (IS_ERR (d)) +continue ; + +securityfs_remove (d); +dput (d); + } + +securityfs_remove (p->policyfs); +} + +/** +* ipe_new_policyfs_node: Create a securityfs entry for @p +* @ctx: Supplies a pointer to a context structure that contains the root of +* the policy tree. +* @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_context *ctx,struct ipe_policy *p) +{ +int rc =0 ; +size_t i =0 ; +struct dentry *d =NULL ; +struct ipe_policy **addr =NULL ; +const struct ipefs_file *f =NULL ; + + p->policyfs =securityfs_create_dir (p->parsed->name, ctx->policy_root); +if (IS_ERR (p->policyfs)) { + rc =PTR_ERR (p->policyfs); + goto err; + } + + addr = (struct ipe_policy **)&(d_inode (p->policyfs)->i_private); + *addr = p; + +for (i =0 ; i <ARRAY_SIZE (policy_subdir); ++i) { + f = &policy_subdir[i]; + + d = securityfs_create_file(f->name, f->access, p->policyfs, p-Quoted 1 line
policyfs,
security/ipe/policyfs.c new file +12
-1+ f->fops); +if (IS_ERR (d)) { + rc =PTR_ERR (d); + goto err; + } + } + +return 0 ; +err: +ipe_del_policyfs_node (p); +return rc; +} --2.33.0
RE: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Deven BowersQuoted 10 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Friday, October 15, 2021 9:26 PMQuoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 5 lines · [email protected] wrote:
Quoted 5 lines
From: Fan Wu <[email protected]>
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.
Quoted 6 lines
Quoted 1 line
Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I wanted to go back on this question.
It seems, at least for fsverity, that you could obtain the root digest at run-time, without storing it in a security blob.
I thought I should use fsverity_get_info() but the fsverity_info structure is not exported (it is defined in fs/verity/fsverity_private.h).
Then, I defined a new function, fsverity_get_file_digest() to copy the file_digest member of fsverity_info to a buffer and to pass the associated hash algorithm.
With that, the code of evaluate() for DIGLIM becomes:
info = fsverity_get_info(file_inode(ctx->file));
if (info)
ret = fsverity_get_file_digest(info, buffer, sizeof(buffer), &algo);
if (!strcmp(expect->data, "diglim") && ret > 0) {
ret = diglim_digest_get_info(buffer, algo, COMPACT_FILE, &modifiers, &actions);
if (!ret)
return true;
}Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 111 lines
IPE needs the digest information to be able to compare a digest provided by the policy author, against the digest calculated by fsverity to make a decision on whether that specific file, represented by the digest is authorized for the actions specified in the policy.
A more concrete example, if an IPE policy author writes:
op=EXECUTE fsverity_digest=<HexDigest > action=DENY
IPE takes the digest provided by this security hook, stores it in IPE's security blob on the inode. If this file is later executed, IPE compares the digest stored in the LSM blob, provided by this hook, against <HexDigest> in the policy, if it matches, it denies the access, performing a revocation of that file.
This brings me to your next comment:
Quoted 1 line
The digest isn't meaningful without knowing the hash algorithm it uses.
It's available here, but you aren't passing it to this function.
The digest is meaningful without the algorithm in this case. IPE does not want to recalculate a digest, that’s expensive and doesn’t provide any value. IPE, in this case, treats this as a buffer to compare the policy-provided one above to make a policy decision about access to the resource.
Quoted 4 lines
Quoted 2 lines
Also changes the implementaion inside the hook function to let multiple LSMs can add hooks.
Please split
fs/verity/changes andsecurity/changes into separate patches, if possible.Sorry, will do, not a problem.
Quoted 1 line
Review struct fsverity_info *fsverity_create_info(const
Quoted 1 line
(quoted diff) +0
-0@@ -177,6 +178,17 @@ struct fsverity_info *fsverity_create_info(conststruct inode *inode,
Quoted 8 lines
fs/verity/open.c struct fsverity_info *fsverity_create_info(const struct inode *inode, · line 182
Quoted 5 lines
fs/verity/open.c +2
-0fsverity_err (inode,"Error %d computing file digest" , err); goto out; } + + err = security_inode_setsecurity((struct inode *)inode,If a non-const inode is needed, please propagate that into the callers rather than randomly casting away the const.
Quoted 6 lines
fs/verity/open.c struct fsverity_info *fsverity_create_info(const struct inode *inode,
Quoted 3 lines
fs/verity/open.c +3
-0+FS_VERITY_DIGEST_SEC_NAME , + vi->file_digest, + vi->tree_params.hash_alg-
digest_size,fs/verity/open.c int fsverity_verify_signature(const struct fsverity_info
Quoted 2 lines
fs/verity/open.c +1
-0+ 0);@@ -84,7 +85,9 @@ int fsverity_verify_signature(const struct fsverity_info*vi,
Quoted 7 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 92
Quoted 6 lines
fs/verity/signature.c +1
-1pr_debug ("Valid signature for file digest %s:%*phN\n" , hash_alg->name, hash_alg->digest_size, vi->file_digest); -return 0 ; + return security_inode_setsecurity((struct inode *)inode,Likewise, please don't cast away const.
Sorry, I should've caught these myself. I'll change
fsverity_create_infoto accept the non-const inode, and changefsverity_verify_signatureto accept an additional inode struct as the first arg instead of changing thefsverity_infostructure to have a non-const inode field.Quoted 4 lines
fs/verity/signature.c int fsverity_verify_signature(const struct fsverity_info *vi, · line 90
Quoted 2 lines
fs/verity/signature.c +2
-0+FS_VERITY_SIGNATURE_SEC_NAME , + signature, sig_size, 0);This is only for fs-verity built-in signatures which aren't the only way to do signatures with fs-verity. Are you sure this is what you're looking for?
Could you elaborate on the other signature types that can be used with fs-verity? I’m 99% sure this is what I’m looking for as this is a signature validated in the kernel against the fs-verity keyring as part of the “fsverity enable” utility.
It's important that the signature is validated in the kernel, as userspace is considered untrusted until the signature is validated for this case.
Quoted 1 line
Can you elaborate on your use case for fs-verity built-in signatures,
Sure, signatures, like digests, also provide a way to prove integrity, and the trust component comes from the validation against the keyring, as opposed to a fixed value in IPE’s policy. The use case for fs-verity built-in signatures is that we have a rw ext4 filesystem that has some executable files, and we want to have a execution policy (through IPE) that only _trusted_ executables can run. Perf is important here, hence fs-verity.
Quoted 1 line
and what the LSM hook will do with them?
At the moment, this will just signal to IPE that these fs-verity files were enabled with a built-in signature as opposed to enabled without a signature. In v7, it copies the signature data into IPE's LSM blob attached to the inode.
In v8+, I'm changing this to store “true” in IPE's LSM blob instead, as copying
the signature data is an unnecessary waste of space and point of failure. This
has a _slightly_ different functionality then fs.verity.require_signatures, because even if someone were to disable the require signatures option, IPE would still know if these files were signed or not and be able to make the access control decision based IPE's policy.Very concretely, this powers this kind of rule in IPE:
op=EXECUTE fsverity_signature=TRUE action=ALLOW
if that
fsverity_signaturevalue in IPE’s LSM blob attached to the inode is true, thenfsverity_signaturein IPE’s policy will evaluate to true and match
this rule. The inverse is also applicable.
RE: [RFC PATCH v7 14/16] scripts: add boot policy generation program
In reply to [email protected]Quoted 315 lines
From: [email protected] [mailto:[email protected]]
From: 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_POLICYinto a c-string literal that is parsed at kernel startup as an unsigned policy.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* Move patch 01/12 to [14/16] of the series--- 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 | 13 +++ security/ipe/ctx.c | 18 +++++ 10 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/.gitignoreMAINTAINERS +1
-0@@ -9283,6 +9283,7 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> M: Fan Wu <[email protected]> S: Supported +F: scripts/ipe/ F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVERscripts/Makefile +1
-0@@ -41,6 +41,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 modscripts/ipe/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +subdir-y := polgenscripts/ipe/polgen/.gitignore new file +1
-0@@ -0,0 +1 @@ +polgenscripts/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@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <stdlib.h> +#include <stddef.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> + +static void usage (const char *const name) +{ +printf ("Usage: %s OutputFile (PolicyFile)\n" , name); +exit (EINVAL ); +} + +static int policy_to_buffer (const char *pathname,char **buffer,size_t *size) +{ +int rc =0 ; +FILE *fd; +char *lbuf; +size_t fsize; +size_t read; + + fd =fopen (pathname,"r" ); +if (!fd) { + rc = errno; + goto out; + } + +fseek (fd,0 ,SEEK_END ); + fsize =ftell (fd); +rewind (fd); + + lbuf =malloc (fsize); +if (!lbuf) { + rc =ENOMEM ; + goto out_close; + } + + read =fread ((void *)lbuf,sizeof (*lbuf), fsize, fd); +if (read != fsize) { + rc =-1 ; + goto out_free; + } + + *buffer = lbuf; + *size = fsize; +fclose (fd); + +return rc; + +out_free: +free (lbuf); +out_close: +fclose (fd); +out: +return rc; +} + +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 <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 '"' : +fprintf (fd,"\\\"" ); +break ; +case '\'' : +fprintf (fd,"'" ); +break ; +case '\n' : +fprintf (fd,"\\n\"\n\t\"" ); +break ; +case '\\' : +fprintf (fd,"\\\\" ); +break ; +case '\t' : +fprintf (fd,"\\t" ); +break ; +case '\?' : +fprintf (fd,"\\?" ); +break ; +default : +fprintf (fd,"%c" , buf[i]); + } + } +fprintf (fd,"\";\n" ); +fclose (fd); + +return 0 ; + +err: +if (fd) +fclose (fd); +return rc; +} + +int main (int argc,const char *const argv[]) +{ +int rc =0 ; +size_t len =0 ; +char *policy =NULL ; + +if (argc <2 ) +usage (argv[0 ]); + +if (argc >2 ) { + rc =policy_to_buffer (argv[2 ], &policy, &len); +if (rc !=0 ) + goto cleanup; + } + + rc =write_boot_policy (argv[1 ], policy, len); +cleanup: +if (policy) +free (policy); +if (rc !=0 ) +perror ("An error occurred during policy conversion: " ); +return rc; +}security/ipe/.gitignore new file +1
-0@@ -0,0 +1 @@ +boot-policy.csecurity/ipe/Kconfig +10
-0@@ -20,6 +20,16 @@ menuconfig SECURITY_IPE 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. + choice prompt "Hash algorithm used in auditing policies" default IPE_AUDIT_HASH_SHA1security/ipe/Makefile +8
-0@@ -7,7 +7,18 @@ ccflags-y := -I$(srctree)/security/ipe/modules +quiet_cmd_polgen = IPE_POL $(2) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/boot-policy.c $(2) + +$(eval $(call config_filename,IPE_BOOT_POLICY)) + +targets += boot-policy.c + +$(obj)/boot-policy.c: scripts/ipe/polgen/polgen$(IPE_BOOT_POLICY_FILENAME) FORCE
security/ipe/Makefile +5
-0+ $(call if_changed,polgen,$(IPE_BOOT_POLICY_FILENAME)) + obj-$(CONFIG_SECURITY_IPE) += \ + boot-policy.o \ ctx.o \ eval.o \ fs.o \@@ -21,3 +32,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ policyfs.o \ obj-$(CONFIG_AUDIT) += audit.o + +clean-files := boot-policy.c \security/ipe/ctx.c +2
-0@@ -15,6 +15,7 @@#include <linux/spinlock.h> #include <linux/moduleparam.h> +extern const char *const ipe_boot_policy;static bool success_audit;static bool enforce = true;@@ -329,6 +330,7 @@ void ipe_put_ctx(struct ipe_context *ctx)int __init ipe_init_ctx (void ) {int rc =0 ; +struct ipe_policy *p =NULL ;struct ipe_context *lns =NULL ; lns =create_ctx ();
security/ipe/ctx.c int __init ipe_init_ctx(void) · line 351
Quoted 8 lines
security/ipe/ctx.c +5
-0@@ -342,10 +344,26 @@ int __init ipe_init_ctx(void)WRITE_ONCE (lns->enforce, enforce);spin_unlock (&lns->lock); +if (ipe_boot_policy) { + p =ipe_new_policy (ipe_boot_policy,strlen (ipe_boot_policy), +NULL ,0 ); +if (IS_ERR (p)) { + rc =PTR_ERR (lns);
This should be:
rc = PTR_ERR(p);
security/ipe/ctx.c int __init ipe_init_ctx(void) · line 357
Quoted 6 lines
security/ipe/ctx.c +6
-0+ goto err; + } + +ipe_add_policy (lns, p); + rc =ipe_set_active_pol (p); +if (!rc)
Here you need to set a non-zero value, so that ipe_init() does not enable the LSM.
I would set to 1 a new global variable, like ipe_lsm_enabled, in ipe_init() just before security_add_hooks().
Then, I would add a check of this variable in ipe_init_securityfs() to avoid the kernel panic.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 14 lines
security/ipe/ctx.c +5
-1+ goto err; + } +rcu_assign_pointer (*ipe_tsk_ctx (current), lns); +ipe_put_policy (p);return 0 ; err: +ipe_put_policy (p);ipe_put_ctx (lns);return rc; } --2.33.0
RE: [RFC PATCH v7 14/16] scripts: add boot policy generation program
Quoted 331 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, November 3, 2021 5:43 PMQuoted 142 lines
From: [email protected] [mailto:[email protected]]
From: 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_POLICYinto a c-string literal that is parsed at kernel startup as an unsigned policy.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* Move patch 01/12 to [14/16] of the series--- 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 | 13 +++ security/ipe/ctx.c | 18 +++++ 10 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/.gitignoreMAINTAINERS +1
-0@@ -9283,6 +9283,7 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> M: Fan Wu <[email protected]> S: Supported +F: scripts/ipe/ F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVERscripts/Makefile +1
-0@@ -41,6 +41,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 modscripts/ipe/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +subdir-y := polgenscripts/ipe/polgen/.gitignore new file +1
-0@@ -0,0 +1 @@ +polgenscripts/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 +52
-0@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <stdlib.h> +#include <stddef.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> + +static void usage (const char *const name) +{ +printf ("Usage: %s OutputFile (PolicyFile)\n" , name); +exit (EINVAL ); +} + +static int policy_to_buffer (const char *pathname,char **buffer,size_t *size) +{ +int rc =0 ; +FILE *fd; +char *lbuf; +size_t fsize; +size_t read; + + fd =fopen (pathname,"r" ); +if (!fd) { + rc = errno; + goto out; + } + +fseek (fd,0 ,SEEK_END ); + fsize =ftell (fd); +rewind (fd); + + lbuf =malloc (fsize); +if (!lbuf) { + rc =ENOMEM ; + goto out_close; + } + + read =fread ((void *)lbuf,sizeof (*lbuf), fsize, fd); +if (read != fsize) { + rc =-1 ; + goto out_free; + } + + *buffer = lbuf; + *size = fsize; +fclose (fd); + +return rc;scripts/ipe/polgen/polgen.c line 62
Quoted 10 lines
scripts/ipe/polgen/polgen.c new file +10
-0+ +out_free: +free (lbuf); +out_close: +fclose (fd); +out: +return rc; +} + +static int write_boot_policy(const char *pathname, const char *buf, size_tsize)
Quoted 163 lines
scripts/ipe/polgen/polgen.c new file +83
-0+{ +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 <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 '"' : +fprintf (fd,"\\\"" ); +break ; +case '\'' : +fprintf (fd,"'" ); +break ; +case '\n' : +fprintf (fd,"\\n\"\n\t\"" ); +break ; +case '\\' : +fprintf (fd,"\\\\" ); +break ; +case '\t' : +fprintf (fd,"\\t" ); +break ; +case '\?' : +fprintf (fd,"\\?" ); +break ; +default : +fprintf (fd,"%c" , buf[i]); + } + } +fprintf (fd,"\";\n" ); +fclose (fd); + +return 0 ; + +err: +if (fd) +fclose (fd); +return rc; +} + +int main (int argc,const char *const argv[]) +{ +int rc =0 ; +size_t len =0 ; +char *policy =NULL ; + +if (argc <2 ) +usage (argv[0 ]); + +if (argc >2 ) { + rc =policy_to_buffer (argv[2 ], &policy, &len); +if (rc !=0 ) + goto cleanup; + } + + rc =write_boot_policy (argv[1 ], policy, len); +cleanup: +if (policy) +free (policy); +if (rc !=0 ) +perror ("An error occurred during policy conversion: " ); +return rc; +}security/ipe/.gitignore new file +1
-0@@ -0,0 +1 @@ +boot-policy.csecurity/ipe/Kconfig +10
-0@@ -20,6 +20,16 @@ menuconfig SECURITY_IPE 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. + choice prompt "Hash algorithm used in auditing policies" default IPE_AUDIT_HASH_SHA1security/ipe/Makefile +8
-0@@ -7,7 +7,18 @@ ccflags-y := -I$(srctree)/security/ipe/modules +quiet_cmd_polgen = IPE_POL $(2) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/boot-policy.c $(2) + +$(eval $(call config_filename,IPE_BOOT_POLICY)) + +targets += boot-policy.c + +$(obj)/boot-policy.c: scripts/ipe/polgen/polgen$(IPE_BOOT_POLICY_FILENAME) FORCE
security/ipe/Makefile +5
-0+ $(call if_changed,polgen,$(IPE_BOOT_POLICY_FILENAME)) + obj-$(CONFIG_SECURITY_IPE) += \ + boot-policy.o \ ctx.o \ eval.o \ fs.o \@@ -21,3 +32,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ policyfs.o \ obj-$(CONFIG_AUDIT) += audit.o + +clean-files := boot-policy.c \security/ipe/ctx.c +2
-0@@ -15,6 +15,7 @@#include <linux/spinlock.h> #include <linux/moduleparam.h> +extern const char *const ipe_boot_policy;static bool success_audit;static bool enforce = true;@@ -329,6 +330,7 @@ void ipe_put_ctx(struct ipe_context *ctx)int __init ipe_init_ctx (void ) {int rc =0 ; +struct ipe_policy *p =NULL ;struct ipe_context *lns =NULL ; lns =create_ctx ();security/ipe/ctx.c int __init ipe_init_ctx(void) · line 351
Quoted 8 lines
security/ipe/ctx.c +5
-0@@ -342,10 +344,26 @@ int __init ipe_init_ctx(void)WRITE_ONCE (lns->enforce, enforce);spin_unlock (&lns->lock); +if (ipe_boot_policy) { + p =ipe_new_policy (ipe_boot_policy,strlen (ipe_boot_policy), +NULL ,0 ); +if (IS_ERR (p)) { + rc =PTR_ERR (lns);This should be:
rc = PTR_ERR(p);
Quoted 9 lines
security/ipe/ctx.c int __init ipe_init_ctx(void) · line 357
Quoted 6 lines
security/ipe/ctx.c +6
-0+ goto err; + } + +ipe_add_policy (lns, p); + rc =ipe_set_active_pol (p); +if (!rc)Here you need to set a non-zero value, so that
ipe_init()does not enable the LSM.
Actually you probably should just check that rc is not zero and goto err.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 25 lines
I would set to 1 a new global variable, like
ipe_lsm_enabled, inipe_init()just beforesecurity_add_hooks().Then, I would add a check of this variable in
ipe_init_securityfs()to avoid the kernel panic.Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 14 lines
security/ipe/ctx.c +5
-1+ goto err; + } +rcu_assign_pointer (*ipe_tsk_ctx (current), lns); +ipe_put_policy (p);return 0 ; err: +ipe_put_policy (p);ipe_put_ctx (lns);return rc; } --2.33.0
Re: [RFC PATCH v7 04/16] ipe: add userspace interface
In reply to Roberto SassuQuoted 17 lines · Roberto Sassu
Quoted 5 lines
security/ipe/fs.c new file +4
-0+ +/** +* ipe_init_securityfs: Initialize IPE's securityfs tree at fsinit +* security/ipe/fs.c line 134
Quoted 10 lines
security/ipe/fs.c new file +10
-0+* Return: +* !0 - Error +* 0 - OK +*/ +static int __init ipe_init_securityfs (void ) +{ +int rc =0 ; +struct ipe_context *ctx =NULL ; + + ctx =ipe_current_ctx ();Hi Deven
Quoted 3 lines
the instruction above should be executed only if IPE LSM is enabled. Otherwise, the kernel panics due to the illegal access to the security blob of the task.
I see. I mistakenly assumed that failure in the LSM init would cause a kernel panic (as the system is now booting without a potentially required security component) as opposed to just disabling the LSM and emitting a warning.
Easy fix for v8.
Thanks for pointing it out.
Re: [RFC PATCH v7 14/16] scripts: add boot policy generation program
In reply to Roberto SassuQuoted 338 lines · Roberto Sassu
Quoted 330 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, November 3, 2021 5:43 PMQuoted 142 lines
From: [email protected] [mailto:[email protected]]
From: 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_POLICYinto a c-string literal that is parsed at kernel startup as an unsigned policy.Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* Move patch 01/12 to [14/16] of the series--- 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 | 13 +++ security/ipe/ctx.c | 18 +++++ 10 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/.gitignoreMAINTAINERS +1
-0@@ -9283,6 +9283,7 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> M: Fan Wu <[email protected]> S: Supported +F: scripts/ipe/ F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVERscripts/Makefile +1
-0@@ -41,6 +41,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 modscripts/ipe/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +subdir-y := polgenscripts/ipe/polgen/.gitignore new file +1
-0@@ -0,0 +1 @@ +polgenscripts/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 +52
-0@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <stdlib.h> +#include <stddef.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> + +static void usage (const char *const name) +{ +printf ("Usage: %s OutputFile (PolicyFile)\n" , name); +exit (EINVAL ); +} + +static int policy_to_buffer (const char *pathname,char **buffer,size_t *size) +{ +int rc =0 ; +FILE *fd; +char *lbuf; +size_t fsize; +size_t read; + + fd =fopen (pathname,"r" ); +if (!fd) { + rc = errno; + goto out; + } + +fseek (fd,0 ,SEEK_END ); + fsize =ftell (fd); +rewind (fd); + + lbuf =malloc (fsize); +if (!lbuf) { + rc =ENOMEM ; + goto out_close; + } + + read =fread ((void *)lbuf,sizeof (*lbuf), fsize, fd); +if (read != fsize) { + rc =-1 ; + goto out_free; + } + + *buffer = lbuf; + *size = fsize; +fclose (fd); + +return rc;scripts/ipe/polgen/polgen.c line 62
Quoted 10 lines
scripts/ipe/polgen/polgen.c new file +10
-0+ +out_free: +free (lbuf); +out_close: +fclose (fd); +out: +return rc; +} + +static int write_boot_policy(const char *pathname, const char *buf, size_tsize)
Quoted 163 lines
scripts/ipe/polgen/polgen.c new file +83
-0+{ +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 <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 '"' : +fprintf (fd,"\\\"" ); +break ; +case '\'' : +fprintf (fd,"'" ); +break ; +case '\n' : +fprintf (fd,"\\n\"\n\t\"" ); +break ; +case '\\' : +fprintf (fd,"\\\\" ); +break ; +case '\t' : +fprintf (fd,"\\t" ); +break ; +case '\?' : +fprintf (fd,"\\?" ); +break ; +default : +fprintf (fd,"%c" , buf[i]); + } + } +fprintf (fd,"\";\n" ); +fclose (fd); + +return 0 ; + +err: +if (fd) +fclose (fd); +return rc; +} + +int main (int argc,const char *const argv[]) +{ +int rc =0 ; +size_t len =0 ; +char *policy =NULL ; + +if (argc <2 ) +usage (argv[0 ]); + +if (argc >2 ) { + rc =policy_to_buffer (argv[2 ], &policy, &len); +if (rc !=0 ) + goto cleanup; + } + + rc =write_boot_policy (argv[1 ], policy, len); +cleanup: +if (policy) +free (policy); +if (rc !=0 ) +perror ("An error occurred during policy conversion: " ); +return rc; +}security/ipe/.gitignore new file +1
-0@@ -0,0 +1 @@ +boot-policy.csecurity/ipe/Kconfig +10
-0@@ -20,6 +20,16 @@ menuconfig SECURITY_IPE 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. + choice prompt "Hash algorithm used in auditing policies" default IPE_AUDIT_HASH_SHA1security/ipe/Makefile +8
-0@@ -7,7 +7,18 @@ ccflags-y := -I$(srctree)/security/ipe/modules +quiet_cmd_polgen = IPE_POL $(2) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/boot-policy.c $(2) + +$(eval $(call config_filename,IPE_BOOT_POLICY)) + +targets += boot-policy.c + +$(obj)/boot-policy.c: scripts/ipe/polgen/polgen$(IPE_BOOT_POLICY_FILENAME) FORCE
security/ipe/Makefile +5
-0+ $(call if_changed,polgen,$(IPE_BOOT_POLICY_FILENAME)) + obj-$(CONFIG_SECURITY_IPE) += \ + boot-policy.o \ ctx.o \ eval.o \ fs.o \@@ -21,3 +32,5 @@ obj-$(CONFIG_SECURITY_IPE) += \ policyfs.o \ obj-$(CONFIG_AUDIT) += audit.o + +clean-files := boot-policy.c \security/ipe/ctx.c +2
-0@@ -15,6 +15,7 @@#include <linux/spinlock.h> #include <linux/moduleparam.h> +extern const char *const ipe_boot_policy;static bool success_audit;static bool enforce = true;@@ -329,6 +330,7 @@ void ipe_put_ctx(struct ipe_context *ctx)int __init ipe_init_ctx (void ) {int rc =0 ; +struct ipe_policy *p =NULL ;struct ipe_context *lns =NULL ; lns =create_ctx ();security/ipe/ctx.c int __init ipe_init_ctx(void) · line 351
Quoted 8 lines
security/ipe/ctx.c +5
-0@@ -342,10 +344,26 @@ int __init ipe_init_ctx(void)WRITE_ONCE (lns->enforce, enforce);spin_unlock (&lns->lock); +if (ipe_boot_policy) { + p =ipe_new_policy (ipe_boot_policy,strlen (ipe_boot_policy), +NULL ,0 ); +if (IS_ERR (p)) { + rc =PTR_ERR (lns);This should be:
rc = PTR_ERR(p);Quoted 8 lines
security/ipe/ctx.c int __init ipe_init_ctx(void) · line 357
Quoted 6 lines
security/ipe/ctx.c +6
-0+ goto err; + } + +ipe_add_policy (lns, p); + rc =ipe_set_active_pol (p); +if (!rc)Here you need to set a non-zero value, so that
ipe_init()does not enable the LSM.
Quoted 5 lines
Actually you probably should just check that rc is not zero and goto err.
Roberto
Yeah, I actually noticed these two mistakes myself fairly recently.
Changes will be applied in v8.
Quoted 6 lines
Quoted 6 lines
I would set to 1 a new global variable, like
ipe_lsm_enabled, inipe_init()just beforesecurity_add_hooks().Then, I would add a check of this variable in
ipe_init_securityfs()to avoid the kernel panic.
That's my plan.
-Deven
Re: [RFC PATCH v7 07/16] ipe: add auditing support
In reply to Steve GrubbQuoted 16 lines · Steve Grubb
Hello,
Quoted 7 lines · EDT Deven Bowers
Quoted 6 lines · Steve Grubb
Quoted 4 lines · On Wednesday, October 13, 2021 3:06:26 PM EDT [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 systens with respect to IPE itself.
Quoted 6 lines
Quoted 3 lines
Would you mind sending examples of audit events so that we can see what the end result is? Some people add them to the commit text. But we still need to see what they look like.
Sure, sorry. I’ll add them to the commit description (and the documentation patch at the end) for v8 – In the interest of asynchronous feedback, I’ve copied the relevant examples:
Quoted 7 lines
Thanks for sending these. This helps.
Quoted 3 lines
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT op=EXECUTE action=DENY"
Question...why do all of these have a
ctx_prefix?
Ah, the ctx_ was because these fields are all grouped in ipe in a context (ctx) structure. An private version (pre-v1) had these grouped like:
ctx={ pid=229 comm="grep" op=EXECUTE ... }
But during an internal review, it was brought up that the grouping is likely non-standard and to cause more issues than its worth instead of just prefixing the field with ctx_. Now that I think about it a bit more, the context is implicit, so the prefix and grouping doesn't make sense.
Quoted 3 lines
Is it possible to trigger an audit context so that the audit machinery collects all of this stuff in it's own way? Which means you could drop everything execept op, hook, enforce, rule, and action.
I could do something internal in IPE that will create the context in the right way. As far as inside the audit stack it looks like the closest analogue would be common_lsm_audit - which fixes the type to be AVC. I don't think adding another form of AVC is appropriate?
I could also either extend common_lsm_audit to accept a type parameter, or make a more generalized function as part of the audit framework. Do you have a preference? Paul, do you have a preference?
Quoted 9 lines
We also have a field dictionary here:
https://github.com/linux-audit/audit-documentation/blob/main/specs/fields/
field-dictionary.csvwhich names the known fields and how they should be formatted. If there is a collision where they are something else and cannot be in the same format, then we make a new name and hopefully update the dictionary. For example, if you are collecting a process id, use pid and not
ctx_pidso that it matches a known definition.
Wow. I didn't know about this - it should be pretty easy to change the fields to follow this mapping. Almost everything has a correlation already. It looks like there would be only one collision with hook being currently defined with netfilter. Everything else would be new (e.g. rule), or could map an existingfield.
Quoted 2 lines
Also, I don't thnk these events can stand on their own. Who did this action? You have the pid, but no uid, auid, or
session_id.
It makes sense to add these fields; and it'd be taken care of with your suggestion above to make the audit context just gathers this information in its own, consistent way.
Quoted 41 lines
Hope this helps...
-Steve
Quoted 36 lines
AUDIT1420 IPE ctx_pid=229 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=0 ctx_comm="grep" ctx_pathname="/usr/lib/libc-2.23.so" ctx_ino=532 ctx_dev=vda rule="DEFAULT action=DENY"
AUDIT1420 IPE ctx_pid=253 ctx_op=EXECUTE ctx_hook=MMAP ctx_enforce=1 ctx_comm="anon" rule="DEFAULT op=EXECUTE action=DENY"
These three audit records represent various types of results after evaluating
the trust of a resource. The first two differ in the rule that was matched in
IPE's policy, the first being an operation-specific default, the second being
a global default. The third is an example of what is audited when anonymous memory is blocked (as there is no way to verify the trust of an anonymous page).The remaining three events,
AUDIT_TRUST_POLICY_LOAD(1421),AUDIT_TRUST_POLICY_ACTIVATE(1422), andAUDIT_TRUST_STATUS(1423) have this form:AUDIT1421 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash>
AUDIT1422 IPE policy_name="my-policy" policy_version=0.0.0 <hash_alg_name>=<hash>
AUDIT1423 IPE enforce=1The 1421 (
AUDIT_TRUST_POLICY_LOAD) event represents a new policy was loaded into the kernel, but not is not marked as the policy to enforce. TheThe 1422 (
AUDIT_TRUST_POLICY_ACTIVATE) event represents a policy that was already loaded was made the enforcing policy.The 1423 (
AUDIT_TRUST_STATUS) event represents a switch between permissive and
enforce, it is added in 08/16 (the following patch)
Re: [RFC PATCH v7 12/16] fsverity|security: add security hooks to fsverity digest and signature
In reply to Roberto SassuQuoted 29 lines · Roberto Sassu
Quoted 7 lines
From: Deven Bowers [mailto:[email protected]]
Sent: Friday, October 15, 2021 9:26 PMQuoted 1 line · Eric Biggers
On Wed, Oct 13, 2021 at 12:06:31PM -0700,
Quoted 2 lines · [email protected] wrote:
Quoted 2 lines
From: Fan Wu <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Add
security_inode_setsecurityto fsverity signature verification. This can let LSMs save the signature data and digest hashes provided by fsverity.Can you elaborate on why LSMs need this information?
The proposed LSM (IPE) of this series will be the only one to need this information at the moment. IPE’s goal is to have provide trust-based access control. Trust and Integrity are tied together, as you cannot prove trust without proving integrity.
I wanted to go back on this question.
It seems, at least for fsverity, that you could obtain the root digest at run-time, without storing it in a security blob.
I thought I should use
fsverity_get_info()but thefsverity_infostructure is not exported (it is defined infs/verity/fsverity_private.h).Then, I defined a new function,
fsverity_get_file_digest()to copy thefile_digestmember offsverity_infoto a buffer and to pass the associated hash algorithm.With that, the code of
evaluate()for DIGLIM becomes:
Quoted 9 lines
info = fsverity_get_info(file_inode(ctx->file));
if (info)
ret = fsverity_get_file_digest(info, buffer, sizeof(buffer), &algo);
if (!strcmp(expect->data, "diglim") && ret > 0) {
ret = diglim_digest_get_info(buffer, algo, COMPACT_FILE, &modifiers, &actions);
if (!ret)
return true;
}This would work with the digest with a bit more code in fs-verity. It also has benefits if there are other callers who want this information.
I was planning on grouping the digest and signature into apublic_key_signature structure in v8 to pass the digest, digest algorithm,digest size, signature and signature size (as opposed to defining a new structfor this purpose), reducing the number of LSM hook calls down to one functionin fsverity.
I think both approaches have merit. fsverity_get_file_digest is more useful if there are callers outside of LSMs that want this information. The LSM hook is cleaner if only LSMs want this information.
At least, at the moment, it seems like it's only IPE who wants this information, and it's not like it won't be able to change later if the need arises, as this is all implementation details that wouldn't effect the end-user.
I'll defer to Eric - his opinion holds the most weight, as fsverity would be the main code affected in either case.
RE: [RFC PATCH v7 11/16] ipe: add support for dm-verity as a trust provider
In reply to [email protected]Quoted 323 lines
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, October 13, 2021 9:07 PM
From: 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".Signed-off-by Deven Bowers <[email protected]>---
Relevant changes since v6:
* Squash patch 08/12, 10/12 to [11/16]--- security/ipe/eval.c | 5 ++ security/ipe/eval.h | 10 +++ security/ipe/hooks.c | 48 ++++++++++++++ security/ipe/hooks.h | 6 ++ security/ipe/ipe.c | 9 +++ security/ipe/ipe.h | 3 + security/ipe/modules/Kconfig | 23 +++++++ security/ipe/modules/Makefile | 2 + security/ipe/modules/dmverity_roothash.c | 80 +++++++++++++++++++++++ security/ipe/modules/dmverity_signature.c | 25 +++++++ 10 files changed, 211 insertions(+) create mode 100644 security/ipe/modules/dmverity_roothash.c create mode 100644 security/ipe/modules/dmverity_signature.csecurity/ipe/eval.c +5
-0@@ -23,6 +23,7 @@ static struct super_block *pinned_sb;static DEFINE_SPINLOCK (pin_lock);#define FILE_SUPERBLOCK (f) ((f)->f_path.mnt->mnt_sb) +#define FILE_BLOCK_DEV (f) (FILE_SUPERBLOCK(f)->s_bdev)/** * pin_sb: pin the underlying superblock of @f, marking it as trusted @@ -95,6 +96,10 @@ static struct ipe_eval_ctx *build_ctx(const struct file *file, ctx->hook = hook; ctx->ci_ctx =ipe_current_ctx (); ctx->from_init_sb =from_pinned (file); +if (file) { +if (FILE_BLOCK_DEV (file)) + ctx->ipe_bdev =ipe_bdev (FILE_BLOCK_DEV (file)); + }return ctx; }security/ipe/eval.h +10
-0@@ -13,6 +13,14 @@#include "hooks.h" #include "policy.h" +struct ipe_bdev { +const u8 *sigdata; +size_t siglen; + +const u8 *hash; +size_t hashlen; +}; +struct ipe_eval_ctx {enum ipe_hook hook;enum ipe_operation op;@@ -20,6 +28,8 @@ struct ipe_eval_ctx {const struct file *file;struct ipe_context *ci_ctx; +const struct ipe_bdev *ipe_bdev; +bool from_init_sb; };security/ipe/hooks.c +48
-0@@ -13,6 +13,7 @@#include <linux/types.h> #include <linux/refcount.h> #include <linux/rcupdate.h> +#include <linux/blk_types.h> #include <linux/binfmts.h> #include <linux/mman.h> @@ -219,3 +220,50 @@ void ipe_sb_free_security(struct super_block *mnt_sb) {ipe_invalidate_pinned_sb (mnt_sb); } + +/** +* ipe_bdev_free_security: free nested structures within IPE's LSM blob +* in 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->sigdata); +} + +/** +* ipe_bdev_setsecurity: associate some data from the block device layer +* with 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_SIGNATURE_SEC_NAME )) { + blob->siglen = len; + blob->sigdata =kmemdup (value, len,GFP_KERNEL ); +if (!blob->sigdata) +return -ENOMEM ; + +return 0 ; + } + +if (!strcmp (key,DM_VERITY_ROOTHASH_SEC_NAME )) { + blob->hashlen = len; + blob->hash =kmemdup (value, len,GFP_KERNEL ); +if (!blob->hash) +return -ENOMEM ; + +return 0 ; + } + +return -ENOSYS ; +}security/ipe/hooks.h +6
-0@@ -10,6 +10,7 @@#include <linux/sched.h> #include <linux/binfmts.h> #include <linux/security.h> +#include <linux/device-mapper.h> enum ipe_hook { ipe_hook_exec =0 ,@@ -40,4 +41,9 @@ int ipe_on_kernel_load_data(enum kernel_load_data_id id, bool contents);void ipe_sb_free_security (struct super_block *mnt_sb); +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 /*
IPE_HOOKS_H*/security/ipe/ipe.c +9
-0@@ -9,6 +9,7 @@#include "ipe_parser.h" #include "modules/ipe_module.h" #include "modules.h" +#include "eval.h" #include <linux/fs.h> #include <linux/sched.h> @@ -20,8 +21,14 @@ struct lsm_blob_sizes ipe_blobs __lsm_ro_after_init = { .lbs_task =sizeof (struct ipe_context __rcu *), + .lbs_bdev =sizeof (struct ipe_bdev ), }; +struct ipe_bdev *ipe_bdev (struct block_device *b) +{ +return b->security + ipe_blobs.lbs_bdev; +} + static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_alloc, ipe_task_alloc),LSM_HOOK_INIT (task_free, ipe_task_free),@@ -31,6 +38,8 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (kernel_read_file, ipe_on_kernel_read),LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data),LSM_HOOK_INIT (sb_free_security, ipe_sb_free_security), +LSM_HOOK_INIT (bdev_free_security, ipe_bdev_free_security), + LSM_HOOK_INIT(bdev_setsecurity, ipe_bdev_setsecurity), };/**
security/ipe/ipe.h +3
-0@@ -14,10 +14,13 @@#include <linux/types.h> #include <linux/sched.h> +#include <linux/blk_types.h> #include <linux/lsm_hooks.h> extern struct lsm_blob_sizes ipe_blobs;extern struct ipe_parser __start_ipe_parsers[], __end_ipe_parsers[];extern struct ipe_module __start_ipe_modules[], __end_ipe_modules[]; +struct ipe_bdev *ipe_bdev (struct block_device *b); +#endif /* IPE_H */ security/ipe/modules/Kconfig +23
-0@@ -16,5 +16,28 @@ config IPE_PROP_BOOT_VERIFIED If unsure, answer N. +config IPE_PROP_DM_VERITY_SIGNATURE + bool "Enable support for signed dm-verity volumes" + depends on DM_VERITY_VERIFY_ROOTHASH_SIG + default Y + help + This option enables the property 'dmverity_signature' in + IPE policy. This property evaluates to TRUE when a file + is evaluated against a dm-verity volume that was mounted + with a signed root-hash. + + If unsure, answer Y. + +config IPE_PROP_DM_VERITY_ROOTHASH + bool "Enable support for dm-verity volumes" + depends on DM_VERITY + default Y + help + This option enables the property 'dmverity_roothash' in + IPE policy. This property evaluates to TRUE when a file + is evaluated against a dm-verity volume whose root hash + matches the supplied value. + + If unsure, answer Y. endmenusecurity/ipe/modules/Makefile +2
-0@@ -6,3 +6,5 @@ # obj-$(CONFIG_IPE_PROP_BOOT_VERIFIED) += boot_verified.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_SIGNATURE) += dmverity_signature.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_ROOTHASH) += dmverity_roothash.osecurity/ipe/modules/dmverity_roothash.c new file +51
-0@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +struct counted_array { +size_t len; +u8 *data; +}; + +static int dvrh_parse (const char *valstr,void **value) +{ +int rv =0 ; +struct counted_array *arr; + + arr =kzalloc (sizeof (*arr),GFP_KERNEL ); +if (!arr) { + rv = -ENOMEM ; + goto err; + } + + arr->len = (strlen (valstr) /2 ); + + arr->data =kzalloc (arr->len,GFP_KERNEL ); +if (!arr->data) { + rv = -ENOMEM ; + goto err; + } + + rv =hex2bin (arr->data, valstr, arr->len); +if (rv !=0 ) + goto err2; + + *value = arr; +return rv; +err2: +kfree (arr->data); +err: +kfree (arr); +return rv; +} + +static bool dvrh_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +const u8 *src; +struct counted_array *expect = (struct counted_array *)val;
security/ipe/modules/dmverity_roothash.c line 61
Quoted 10 lines
security/ipe/modules/dmverity_roothash.c new file +10
-0+ +if (!ctx->ipe_bdev) +return false; + +if (ctx->ipe_bdev->hashlen != expect->len) +return false; + + src = ctx->ipe_bdev->hash; + +return !memcmp (expect->data, src, expect->len);
Hi Deven
I was curious to see if determining the property at run-time could apply also to dm-verity. It seems it could be done (I omit some checks, I also keep the expected value in hex format):
---
md = dm_get_md(file_inode(ctx->file)->i_sb->s_dev);
table = dm_get_live_table(md, &srcu_idx);
num_targets = dm_table_get_num_targets(table);
for (i = 0; i < num_targets; i++) {
struct dm_target *ti = dm_table_get_target(table, i);
if (strcmp(ti->type->name, "verity"))
continue;
ti->type->status(ti, STATUSTYPE_IMA, 0, result, sizeof(result));
}
dm_put_live_table(md, srcu_idx);
dm_put(md);
root_digest_ptr = strstr(result, "root_digest=");
return !strncmp(expect->data, root_digest_ptr + 12, expect->len);---
Only dm_table_get_target() is not exported yet, but I guess it could be. dm_table_get_num_targets() is exported.
With this code, you would not have to manage security blobs outside IPE. Maybe you could add a blob for the super block, so that you verify the dm-verity property just once per filesystem.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 53 lines
security/ipe/modules/dmverity_roothash.c new file +19
-0+} + +static int dvrh_free (void **val) +{ +struct counted_array *expect = (struct counted_array *)val; + +kfree (expect->data); +kfree (expect); + +return 0 ; +} + +IPE_MODULE (dvrh) = { + .name ="dmverity_roothash" , + .version =1 , + .parse = dvrh_parse, + .free = dvrh_free, + .eval = dvrh_eval, +};security/ipe/modules/dmverity_signature.c new file +25
-1@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +static bool dvv_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +bool expect = (bool )val; +bool eval = ctx->ipe_bdev && (!!ctx->ipe_bdev->sigdata); + +return expect == eval; +} + +IPE_MODULE (dvv) = { + .name ="dmverity_signature" , + .version =1 , + .parse = ipe_bool_parse, + .free =NULL , + .eval = dvv_eval, +}; --2.33.0
Re: [RFC PATCH v7 11/16] ipe: add support for dm-verity as a trust provider
Quoted 4 lines · Roberto Sassu
Quoted 4 lines
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, October 13, 2021 9:07 PM
From: Deven Bowers <[email protected]>
..snip
Quoted 104 lines
Quoted 68 lines
security/ipe/modules/Makefile +2
-0@@ -6,3 +6,5 @@ # obj-$(CONFIG_IPE_PROP_BOOT_VERIFIED) += boot_verified.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_SIGNATURE) += dmverity_signature.o +obj-$(CONFIG_IPE_PROP_DM_VERITY_ROOTHASH) += dmverity_roothash.osecurity/ipe/modules/dmverity_roothash.c new file +51
-0@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +struct counted_array { +size_t len; +u8 *data; +}; + +static int dvrh_parse (const char *valstr,void **value) +{ +int rv =0 ; +struct counted_array *arr; + + arr =kzalloc (sizeof (*arr),GFP_KERNEL ); +if (!arr) { + rv = -ENOMEM ; + goto err; + } + + arr->len = (strlen (valstr) /2 ); + + arr->data =kzalloc (arr->len,GFP_KERNEL ); +if (!arr->data) { + rv = -ENOMEM ; + goto err; + } + + rv =hex2bin (arr->data, valstr, arr->len); +if (rv !=0 ) + goto err2; + + *value = arr; +return rv; +err2: +kfree (arr->data); +err: +kfree (arr); +return rv; +} + +static bool dvrh_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +const u8 *src; +struct counted_array *expect = (struct counted_array *)val;security/ipe/modules/dmverity_roothash.c line 61
Quoted 10 lines
security/ipe/modules/dmverity_roothash.c new file +10
-0+ +if (!ctx->ipe_bdev) +return false; + +if (ctx->ipe_bdev->hashlen != expect->len) +return false; + + src = ctx->ipe_bdev->hash; + +return !memcmp (expect->data, src, expect->len);Hi Deven
I was curious to see if determining the property at run-time could apply also to dm-verity. It seems it could be done (I omit some checks, I also keep the expected value in hex format):
---
md = dm_get_md(file_inode(ctx->file)->i_sb->s_dev); table = dm_get_live_table(md, &srcu_idx); num_targets = dm_table_get_num_targets(table); for (i = 0; i < num_targets; i++) { struct dm_target *ti = dm_table_get_target(table, i); if (strcmp(ti->type->name, "verity")) continue; ti->type->status(ti, STATUSTYPE_IMA, 0, result, sizeof(result)); } dm_put_live_table(md, srcu_idx); dm_put(md); root_digest_ptr = strstr(result, "root_digest="); return !strncmp(expect->data, root_digest_ptr + 12, expect->len);
Quoted 4 lines
---
Only
dm_table_get_target()is not exported yet, but I guess it could be.dm_table_get_num_targets()is exported.
I had tried something similar in a very early draft of IPE. The issue that comes with this is that when you compile device-mapper as a module (CONFIG_BLK_DEV_DM=m) you start to get linking errors with this approach.
Obviously, we can fix this in the IPE's module Kconfig by setting the dependency to be =y, but it's something to highlight. My general preference is to support the =m configuration by using these blobs.
The runtime approach does work with fs-verity, because fs-verity is a file-system level feature that cannot be compiled as a module.
Quoted 62 lines
With this code, you would not have to manage security blobs outside IPE. Maybe you could add a blob for the super block, so that you verify the dm-verity property just once per filesystem.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 53 lines
security/ipe/modules/dmverity_roothash.c new file +19
-0+} + +static int dvrh_free (void **val) +{ +struct counted_array *expect = (struct counted_array *)val; + +kfree (expect->data); +kfree (expect); + +return 0 ; +} + +IPE_MODULE (dvrh) = { + .name ="dmverity_roothash" , + .version =1 , + .parse = dvrh_parse, + .free = dvrh_free, + .eval = dvrh_eval, +};security/ipe/modules/dmverity_signature.c new file +25
-1@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe_module.h" + +#include <linux/fs.h> +#include <linux/types.h> + +static bool dvv_eval (const struct ipe_eval_ctx *ctx,const void *val) +{ +bool expect = (bool )val; +bool eval = ctx->ipe_bdev && (!!ctx->ipe_bdev->sigdata); + +return expect == eval; +} + +IPE_MODULE (dvv) = { + .name ="dmverity_signature" , + .version =1 , + .parse = ipe_bool_parse, + .free =NULL , + .eval = dvv_eval, +}; --2.33.0
RFC PATCH 1/1 device mapper: Add builtin function dm_get_status()
Users of the device mapper driver might want to obtain a device status, with status types defined in the status_type_t enumerator.
If a function to get the status is exported by the device mapper, when compiled as a module, it is not suitable to use by callers compiled builtin in the kernel.
Introduce the real function to get the status, _dm_get_status(), in the device mapper module, and add the stub dm_get_status() in dm-builtin.c, so that it can be invoked by builtin callers.
The stub calls the real function if the device mapper is compiled builtin or the module has been loaded. Calls to the real function are safely disabled if the module is unloaded. The race condition is avoided by incrementing the reference count of the module.
_dm_get_status() invokes the status() method for each device mapper table, which writes a string to the supplied buffer as output. The buffer might contain multiple strings concatenated together. If there is not enough space available, the string is truncated and a termination character is put at the end.
--- drivers/md/dm-builtin.c | 13 +++++++ drivers/md/dm-core.h | 5 +++ drivers/md/dm.c | 71 +++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 3 ++ 4 files changed, 92 insertions(+)
drivers/md/dm-builtin.c +13 -0
@@ -47,3 +47,16 @@ void dm_kobject_release(struct kobject *kobj) }EXPORT_SYMBOL (dm_kobject_release); + +dm_get_status_fn status_fn; +EXPORT_SYMBOL (status_fn); + +ssize_t dm_get_status (dev_t dev,status_type_t type,const char *target_name, +u8 *buf,size_t buf_len) +{ +if (status_fn) +return status_fn (dev, type, target_name, buf, buf_len); + +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL (dm_get_status);
drivers/md/dm-core.h +5 -0
@@ -259,4 +259,9 @@ extern atomic_t dm_global_event_nr;extern wait_queue_head_t dm_global_eventq;void dm_issue_global_event (void ); +typedef ssize_t (*dm_get_status_fn )(dev_t dev,status_type_t type, +const char *target_name,u8 *buf, +size_t buf_len); + +extern dm_get_status_fn status_fn;#endif
drivers/md/dm.c +71 -0
89 lines not on this page · raw message
include/linux/device-mapper.h +3 -0
@@ -487,6 +487,9 @@ int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, struct dm_report_zones_args *args, unsigned int nr_zones);#endif /* CONFIG_BLK_DEV_ZONED */ +ssize_t dm_get_status (dev_t dev,status_type_t type,const char *target_name, +u8 *buf,size_t buf_len); +/* * Device mapper functions to parse and create devices specified by the * parameter "dm-mod.create="
Signature · 1 line
2.32.0
RE: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 125 lines
From: Roberto Sassu
Sent: Wednesday, December 1, 2021 5:37 PM
Users of the device mapper driver might want to obtain a device status, with status types defined in thestatus_type_tenumerator.If a function to get the status is exported by the device mapper, when compiled as a module, it is not suitable to use by callers compiled builtin in the kernel.
Introduce the real function to get the status,
_dm_get_status(), in the device mapper module, and add the stubdm_get_status()indm-builtin.c, so that it can be invoked by builtin callers.The stub calls the real function if the device mapper is compiled builtin or the module has been loaded. Calls to the real function are safely disabled if the module is unloaded. The race condition is avoided by incrementing the reference count of the module.
_dm_get_status()invokes thestatus()method for each device mapper table, which writes a string to the supplied buffer as output. The buffer might contain multiple strings concatenated together. If there is not enough space available, the string is truncated and a termination character is put at the end.Signed-off-by Roberto Sassu <[email protected]>--- drivers/md/dm-builtin.c | 13 +++++++ drivers/md/dm-core.h | 5 +++ drivers/md/dm.c | 71 +++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 3 ++ 4 files changed, 92 insertions(+)drivers/md/dm-builtin.c +5
-0@@ -47,3 +47,16 @@ void dm_kobject_release(struct kobject *kobj) }EXPORT_SYMBOL (dm_kobject_release); + +dm_get_status_fn status_fn; +EXPORT_SYMBOL (status_fn); + +ssize_t dm_get_status(dev_t dev, status_type_t type, const char
*target_name,drivers/md/dm-builtin.c +8
-0+ u8 *buf, size_t buf_len) +{ + if (status_fn) + return status_fn(dev, type, target_name, buf, buf_len); + +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL (dm_get_status);drivers/md/dm-core.h +5
-0@@ -259,4 +259,9 @@ extern atomic_t dm_global_event_nr;extern wait_queue_head_t dm_global_eventq;void dm_issue_global_event (void ); +typedef ssize_t (*dm_get_status_fn )(dev_t dev,status_type_t type, +const char *target_name,u8 *buf, +size_t buf_len); + +extern dm_get_status_fn status_fn;#endif drivers/md/dm.c +48
-0@@ -192,6 +192,74 @@ static unsigned dm_get_numa_node(void)DM_NUMA_NODE , num_online_nodes() - 1); } +static ssize_t _dm_get_status (dev_t dev,status_type_t type, +const char *target_name,u8 *buf,size_t buf_len) +{ +struct mapped_device *md; +struct dm_table *table; +u8 *buf_ptr = buf; +ssize_t len, res =0 ; +int srcu_idx, num_targets, i; + +if (buf_len >INT_MAX ) +return -EINVAL ; + +if (!buf_len) +return buf_len; + +if (!try_module_get (THIS_MODULE )) +return -EBUSY ; + + md =dm_get_md (dev); +if (!md) { + res = -ENOENT ; + goto out_module; + } + + table =dm_get_live_table (md, &srcu_idx); +if (!table) { + res = -ENOENT ; + goto out_md; + } + +memset (buf,0 , buf_len); + + num_targets =dm_table_get_num_targets (table); + +for (i =0 ; i < num_targets; i++) { +struct dm_target *ti =dm_table_get_target (table, i); + +if (!ti) +continue ; + +if (target_name &&strcmp (ti->type->name, target_name)) +continue ; + +if (!ti->type->status) +continue ; + + ti->type->status (ti, type,0 , buf_ptr, buf + buf_len - buf_ptr); +
drivers/md/dm.c static unsigned dm_get_numa_node(void) · line 253
Quoted 10 lines
drivers/md/dm.c +10
-0+if (!*buf_ptr) +continue ; + + len =strlen (buf_ptr); + buf_ptr += len +1 ; + +if (buf_ptr == buf + buf_len) +break ; + + res += len +1 ;
The line above before the check.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 48 lines
drivers/md/dm.c +10
-0+ } + +dm_put_live_table (md, srcu_idx); +out_md: +dm_put (md); +out_module: +module_put (THIS_MODULE ); +return res; +} +static int __init local_init (void ) {drivers/md/dm.c +3
-0int r;@@ -275,6 +343,7 @@ static int __init dm_init(void) goto bad; } + status_fn = _dm_get_status;return 0 ; bad:while (i--)@@ -287,6 +356,8 @@ static void __exit dm_exit(void) {int i =ARRAY_SIZE (_exits); + status_fn =NULL ; +while (i--) _exits[i]();include/linux/device-mapper.h +3
-0@@ -487,6 +487,9 @@ int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, struct dm_report_zones_args *args, unsigned int nr_zones);#endif /* CONFIG_BLK_DEV_ZONED */ +ssize_t dm_get_status (dev_t dev,status_type_t type,const char *target_name, +u8 *buf,size_t buf_len); +/* * Device mapper functions to parse and create devices specified by the
* parameter "dm-mod.create="
--
2.32.0
Re: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
In reply to Roberto SassuQuoted 2 lines · Roberto Sassu
Users of the device mapper driver might want to obtain a device status, with status types defined in the
status_type_tenumerator.
The patch looks really odd. And without the corresponding user of your new functionality it is entirely unreviewable anyway.
RE: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 8 lines
From: Christoph Hellwig [mailto:[email protected]]
Sent: Thursday, December 2, 2021 8:21 AMQuoted 2 lines · Roberto Sassu
Users of the device mapper driver might want to obtain a device status, with status types defined in the
status_type_tenumerator.The patch looks really odd. And without the corresponding user of your new functionality it is entirely unreviewable anyway.
Hi Christoph
ok, I will send it together with a patch for a not yet accepted software, Integrity Policy Enforcement (IPE), that will be the primary user of the introduced functionality.
Regarding the patch itself, could you please provide a more detailed explanation?
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Re: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 6 lines · Roberto Sassu
ok, I will send it together with a patch for a not yet accepted software, Integrity Policy Enforcement (IPE), that will be the primary user of the introduced functionality.
Regarding the patch itself, could you please provide a more detailed explanation?
We don't build things into the kernel just as hooks. So in doubt you need to restructured the code. And that a security module pokes into a random block driver is a big hint that whatever you're trying to do is completely broken.
RE: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 7 lines
From: Christoph Hellwig [mailto:[email protected]]
Sent: Thursday, December 2, 2021 9:44 AMQuoted 4 lines · Roberto Sassu
ok, I will send it together with a patch for a not yet accepted software, Integrity Policy Enforcement (IPE), that will be the primary user of the introduced functionality.
Quoted 7 lines
Quoted 2 lines
Regarding the patch itself, could you please provide a more detailed explanation?
We don't build things into the kernel just as hooks. So in doubt you need to restructured the code. And that a security module pokes into a random block driver is a big hint that whatever you're trying to do is completely broken.
I will add more context to the discussion.
The problem being solved is how to grant access to files which satisfy a property defined in the policy.
For example, a policy enforced by IPE could be:
policy_name="AllowDMVerityKmodules" policy_version=0.0.1
DEFAULT action=ALLOW
DEFAULT op=KMODULE action=DENY
op=KMODULE dmverity_roothash=3c64aae64ae5e8ca781df4d1fbff7c02cb78c4f18a79198263db192cc7f7ba11 action=ALLOW
This would require IPE to obtain somehow this property.
So far, there are two different approaches. The first one, proposed by the IPE authors was to define a new LSM hook for block devices, to append a security blob for those devices, and to store the dm-verity root digest as soon as this information can be determined. IPE will then access the security blob at run-time and will match the blob content with the property value in the policy.
The second one I'm proposing is to directly retrieve the information at run-time, when files are accessed, and to possibly cache the result of the evaluation per filesystem. This would avoid to the introduction of a new LSM hook and to append a security blob for the purpose of passing information from the device mapper driver to IPE.
Security blobs are usually used to store LSM-specific information such as a label (or a reference of it). Sometimes, when the label must be stored persistently, the subsystem responsible for this task, such as the VFS, uses subsystem-defined methods to retrieve the label from the storage and copy it to the security blob.
In this case, it is not an LSM-specific information but rather an existing property of another subsystem IPE is interested in. Since LSMs need anyway to inspect the object before making the security decision, they could directly retrieve the information that is already available, instead of making it redundant.
Even if I would prefer the second option, it would be fine for me if the first is adopted.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Re: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 2 lines · Roberto Sassu
The problem being solved is how to grant access to files which satisfy a property defined in the policy.
If you have want to enforce access to files in the block layer using a specific stacking block driver you don't just have one layering violation but a bunch of them. Please go back to the drawing board.
RE: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 9 lines
From: Christoph Hellwig [mailto:[email protected]]
Sent: Friday, December 3, 2021 7:52 AMQuoted 2 lines · Roberto Sassu
The problem being solved is how to grant access to files which satisfy a property defined in the policy.
If you have want to enforce access to files in the block layer using a specific stacking block driver you don't just have one layering violation but a bunch of them. Please go back to the drawing board.
Ok. I write my thoughts here, so that it is easier to align.
dm-verity provides block-level integrity, which means that the block layer itself is responsible to not pass data to the upper layer, the filesystem, if a block is found corrupted.
The dm-verity root digest represents the immutable state of the block device. dm-verity is still responsible to enforce accesses to the block device according to the root digest passed at device setup time. Nothing changes, the block layer still detects data corruption against the passed reference value.
The task of the security layer is to decide whether or not the root digest passed at device setup time is acceptable, e.g. it represents a device containing genuine files coming from a software vendor.
The mandatory policy can be enforced at different layers, depending on whether the security controls are placed. A possibility would be to deny mounting block devices that don't satisfy the mandatory policy.
However, if the mandatory policy wants only to restrict execution of approved files and allowing the rest, making the decision at the block layer is too coarse and restrictive. It would force the user to mount only approved block devices. The security layer must operate on files to enforce this policy.
Now probably there is the part where there is no agreement.
The integrity property of a block device applies also to the files on the filesystem mounted from that device. User space programs cannot access files in that filesystem coming from a device with a different dm-verity root digest, or files stored in a corrupted block device.
If what I wrote is correct, that the integrity property is preserved across the layers, this would give enough flexibility to enforce policies at a higher layer, although that property is guaranteed by a lower layer.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
RE: [RFC][PATCH] device mapper: Add builtin function dm_get_status()
Quoted 50 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Friday, December 3, 2021 11:20 AMQuoted 9 lines
From: Christoph Hellwig [mailto:[email protected]]
Sent: Friday, December 3, 2021 7:52 AMQuoted 2 lines · Roberto Sassu
The problem being solved is how to grant access to files which satisfy a property defined in the policy.
If you have want to enforce access to files in the block layer using a specific stacking block driver you don't just have one layering violation but a bunch of them. Please go back to the drawing board.
Ok. I write my thoughts here, so that it is easier to align.
dm-verity provides block-level integrity, which means that the block layer itself is responsible to not pass data to the upper layer, the filesystem, if a block is found corrupted.
The dm-verity root digest represents the immutable state of the block device. dm-verity is still responsible to enforce accesses to the block device according to the root digest passed at device setup time. Nothing changes, the block layer still detects data corruption against the passed reference value.
The task of the security layer is to decide whether or not the root digest passed at device setup time is acceptable, e.g. it represents a device containing genuine files coming from a software vendor.
The mandatory policy can be enforced at different layers, depending on whether the security controls are placed. A possibility would be to deny mounting block devices that don't satisfy the mandatory policy.
However, if the mandatory policy wants only to restrict execution of approved files and allowing the rest, making the decision at the block layer is too coarse and restrictive. It would force the user to mount only approved block devices. The security layer must operate on files to enforce this policy.
Now probably there is the part where there is no agreement.
The integrity property of a block device applies also to the files on the filesystem mounted from that device. User space programs cannot access files in that filesystem coming from a device with a different dm-verity root digest, or files stored in a corrupted block device.
Quoted 4 lines
If what I wrote is correct, that the integrity property is preserved across the layers, this would give enough flexibility to enforce policies at a higher layer, although that property is guaranteed by a lower layer.
Hi Christoph
did I address your concerns? If yes, I could send the new patch set, including the patch that uses the new functionality.
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua