Integrity Policy Enforcement LSM (IPE)
Subsystems (9)
v4 cover Integrity Policy Enforcement LSM (IPE)
Overview:
------------------------------------
IPE is a Linux Security Module which allows for a configurable policy to enforce integrity requirements on the whole system. It attempts to solve the issue of Code Integrity: that any code being executed (or files being read), are identical to the version that was built by a trusted source.
The type of system for which IPE is designed for use is an embedded device with a specific purpose (e.g. network firewall device in a data center), where all software and configuration is built and provisioned by the owner.
Specifically, a system which leverages IPE is not intended for general purpose computing and does not utilize any software or configuration built by a third party. An ideal system to leverage IPE has both mutable and immutable components, however, all binary executable code is immutable.
The scope of IPE is constrained to the OS. It is assumed that platform firmware verifies the the kernel and optionally the root filesystem (e.g. via U-Boot verified boot). IPE then utilizes LSM hooks to enforce a flexible, kernel-resident integrity verification policy.
IPE differs from other LSMs which provide integrity checking (for instance, IMA), as it has no dependency on the filesystem metadata itself. The attributes that IPE checks are deterministic properties that exist solely in the kernel. Additionally, IPE provides no additional mechanisms of verifying these files (e.g. IMA Signatures) - all of the attributes of verifying files are existing features within the kernel, such as dm-verity or fsverity.
IPE provides a policy that allows owners of the system to easily specify integrity requirements and uses dm-verity signatures to simplify the authentication of allowed objects like authorized code and data.
IPE supports two modes, permissive (similar to SELinux's permissive mode) and enforce. Permissive mode performs the same checks, and logs policy violations as enforce mode, but will not enforce the policy. This allows users to test policies before enforcing them.
The default mode is enforce, and can be changed via the kernel commandline parameter ipe.enforce=(0|1), or the securityfs node /sys/kernel/security/ipe/enforce. The ability to switch modes can be compiled out of the LSM via setting the config CONFIG_SECURITY_IPE_PERMISSIVE_SWITCH to N.
IPE additionally supports success auditing. When enabled, all events that pass IPE policy and are not blocked will emit an audit event. This is disabled by default, and can be enabled via the kernel commandline ipe.success_audit=(0|1) or the securityfs node /sys/kernel/security/ipe/success_audit.
Policies can be staged at runtime through securityfs and activated through sysfs. Please see the Deploying Policies section of this cover letter for more information.
The IPE LSM is compiled under CONFIG_SECURITY_IPE.
Policy:
------------------------------------
IPE policy is designed to be both forward compatible and backwards compatible. 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 properties section of this cover-letter, the repository available in Appendix A, and the kernel documentation page.
Order does not matter for the rule's properties - they can be listed in any order, however it is encouraged to have the "op" property be first, and the "action" property be last, for readability.
Additionally, 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/property_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.
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, please see Appendix A or 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:
-------------------
Deploying policies is simple. 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 sysctl "ipe.active_policy":
echo -n 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. At any point the policy can be updated on the provision that the policy version to be deployed is greater than or equal to the running version (to prevent roll-back attacks). This update can be done by redirecting the file into the policy's "raw" node, under the policies subdirectory:
cat "$MY_UPDATED_POLICY.p7s" > \
"/sys/kernel/security/ipe/policies/$MY_POLICY_NAME/raw"Additionally, policies can be deleted via the "del_policy" securityfs node. Simply write the name of the policy to be deleted to that node:
echo -n 1 >
"/sys/kernel/security/ipe/policies/$MY_POLICY_NAME/delete"
There are two requirements to delete policies:
1. The policy being deleted must not be the active policy.
2. The policy being deleted must not be the boot policy.
It's important to know above that the "echo" command will add a newline to the end of the input, and this will be considered as part of the filename. You can remove the newline via the -n parameter.
NOTE: If a MAC LSM is enabled, the securityfs commands will require CAP_MAC_ADMIN. This is due to sysfs supporting fine-grained MAC attributes, while securityfs at the current moment does not.
Properties:
------------------------------------
This initial patchset introducing IPE adds three properties:
'boot_verified', 'dmverity_signature' and 'dmverity_roothash'.
boot_verified (CONFIG_IPE_BOOT_PROP):
This property can be utilized for authorization of the first super-block that is mounted on the system, where IPE attempts to evaluate a file. Typically this is used for systems with an initramfs or other initial disk, where this is unmounted before the system becomes available, and is not covered by any other property. The format of this property is:
boot_verified=(TRUE|FALSE)
WARNING: This property will trust any disk where the first IPE evaluation occurs. If you do not have a startup disk that is unpacked and unmounted (like initramfs), then it will automatically trust the root filesystem and potentially overauthorize the entire disk.
dmverity_roothash (CONFIG_IPE_DM_VERITY_ROOTHASH):
This property can be utilized for authorization or revocation of specific dmverity volumes, identified via root hash. It has a dependency on the DM_VERITY module. The format of this property is:
dmverity_roothash=<HashHexDigest>
dmverity_signature (CONFIG_IPE_DM_VERITY_SIGNATURE):
This property can be utilized for authorization of all dm-verity volumes that have a signed roothash that chains to the system trusted keyring. It has a dependency on the DM_VERITY_VERIFY_ROOTHASH_SIG config. The format of this property is:
dmverity_signature=(TRUE|FALSE)
Testing:
------------------------------------
A test suite is available (Appendix B) for ease of use. For manual instructions:
Enable IPE through the following Kconfigs:
CONFIG_SECURITY_IPE=y CONFIG_SECURITY_IPE_BOOT_POLICY="../AllowAllInitialSB.pol" CONFIG_SECURITY_IPE_PERMISSIVE_SWITCH=y CONFIG_IPE_BOOT_PROP=y CONFIG_IPE_DM_VERITY_ROOTHASH=y CONFIG_IPE_DM_VERITY_SIGNATURE=y CONFIG_DM_VERITY=y CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y CONFIG_SYSTEM_TRUSTED_KEYRING=y CONFIG_SYSTEM_TRUSTED_KEYS="/path/to/my/cert/list.pem"
Start a test system, that boots directly from the filesystem, without an initrd. I recommend testing in permissive mode until all tests pass, then switch to enforce to ensure behavior remains identical.
boot_verified:
If booted correctly, the filesystem mounted on / should be marked as boot_verified. Verify by turning on success auditing (sysctl ipe.success_audit=1), and run a binary. In the audit output, prop_boot_verified should be TRUE.
To test denials, mount a temporary filesystem (mount -t tmpfs -o size=4M tmp tmp), and copy a binary (e.g. ls) to this new filesystem. Disable success auditing and attempt to run the file. The file should have an audit event, but be allowed to execute in permissive mode, and prop_boot_verified should be FALSE.
dmverity_roothash:
First, you must create a dm-verity volume. This can be done through squashfs-tools and veritysetup (provided by cryptsetup).
Creating a squashfs volume:
mksquashfs /path/to/directory/with/executable /path/to/output.squashfs
Format the volume for use with dm-verity & save the root hash:
output_rh=$(veritysetup format output.squashfs output.hashtree | \
tee verity_out.txt | awk "/Root hash/" | \
sed -E "s/Root hash:\s+//g")
echo -n $output_rh > output.roothashCreate a two policies, filling in the appropriate fields below:
Policy 1:
policy_name="roothash-denial" policy_version=0.0.0 DEFAULT action=ALLOW
op=EXECUTE dmverity_roothash=$output_rh action=DENY
Policy 2:
policy_name="roothash-allow" policy_version=0.0.0 DEFAULT action=ALLOW
DEFAULT op=EXECUTE action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW op=EXECUTE dmverity_roothash=$output_rh action=ALLOW
Deploy each policy, then mark the first, "roothash-denial" as active, per the "Deploying Policies" section of this cover letter. Mount the dm-verity volume:
veritysetup open output.squashfs output.hashtree unverified \
cat output.roothash
mount /dev/mapper/unverified /my/mount/point
Attempt to execute a binary in the mount point, and it should emit an audit event for a match against the rule:
op=EXECUTE dmverity_roothash=$output_rh action=DENY
To test the second policy, perform the same steps, but this time, enable success auditing before running the executable. The success audit event should be a match against this rule:
op=EXECUTE dmverity_roothash=$output_rh action=ALLOW
dmverity_signature:
Follow the setup steps for dmverity_roothash. Sign the roothash via:
openssl smime -sign -in "output.roothash" -signer "$MY_CERTIFICATE" \
-inkey "$MY_PRIVATE_KEY" -binary -outform der -noattr \
-out "output.p7s"
Create a policy:
policy_name="verified" policy_version=0.0.0
DEFAULT action=DENY
op=EXECUTE boot_verified=TRUE action=ALLOW
op=EXECUTE dmverity_verified=TRUE action=ALLOWDeploy the policy, and mark as active, per the "Deploying Policies" section of this cover letter. Mount the dm-verity volume with verification:
veritysetup open output.squashfs output.hashtree unverified \
`cat output.roothash` --root-hash-signature=output.p7s
mount /dev/mapper/unverified /my/mount/pointNOTE: The --root-hash-signature option was introduced in veritysetup 2.3.0
Turn on success auditing and attempt to execute a binary in the mount point, and it should emit an audit event for a match against the rule:
op=EXECUTE dmverity_verified=TRUE action=ALLOW
To test denials, mount the dm-verity volume the same way as the "dmverity_roothash" section, and attempt to execute a binary. Failure should occur.
Documentation:
------------------------------------
Full documentation is available on github in IPE's master repository (Appendix A). This is intended to be an exhaustive source of documentation around IPE.
Additionally, there is higher level documentation in the admin-guide.
Technical diagrams are available here:
http://microsoft.github.io/ipe/technical/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, or JIT'd code. Unfortunately, as this is dynamically generated code, there is no way for IPE to detect that this code has not been tampered with in transition from where it was built, to where it is running. As a result, IPE is incapable of tackling this problem for dynamically generated code. However, there is a patch series being prepared that addresses this problem for libffi and gcc closures by implemeting a safer kernel trampoline API.
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. This specific gap is planned on being addressed within IPE. For more information on how we plan to address this gap, please see the Future Development section, below.
Future Development:
------------------------------------
Support for filtering signatures by specific certificates. In this case, our "dmverity_signature" (or a separate property) can be set to a specific certificate declared in IPE's policy, allowing for more controlled use-cases determine by a user's PKI structure.
Support for integrity verification for general file reads. This addresses the script interpreter issue indicated in the "Known Gaps" section, as these script files are typically opened with O_RDONLY. We are evaluating whether to do this by comparing the original userland filepath passed into the open syscall, thereby allowing existing callers to take advantage without any code changes; the alternate design is to extend the new openat2(2) syscall, with an new flag, tentatively called "O_VERIFY". While the second option requires a code change for all the interpreters, frameworks and languages that wish to leverage it, it is a wholly cleaner implementation in the kernel. For interpreters specifically, the O_MAYEXEC patch series published by Mickaël Salaün[1] is a similar implementation to the O_VERIFY idea described above.
Onboarding IPE's test suite to KernelCI. Currently we are developing a test suite in the same vein as SELinux's test suite. Once development of the test suite is complete, and provided IPE is accepted, we intend to onboard this test suite onto KernelCI.
Hardened resistance against roll-back attacks. Currently there exists a window of opportunity between user-mode setup and the user-policy being deployed, where a prior user-policy can be loaded, that is potentially insecure. However, with a kernel update, you can revise the boot policy's version to be the same version as the latest policy, closing this window. In the future, I would like to close this window of opportunity without a kernel update, using some persistent storage mechanism.
Open Issues:
------------
For linux-audit/integrity folks:
1. Introduction of new audit definitions in the kernel integrity range - is this preferred, as opposed to reusing definitions with existing IMA definitions?
TODOs:
------
linux-audit changes to support the new audit events.
Appendix:
------------------------------------
A. IPE Github Repository: https://github.com/microsoft/ipe
Hosted Documentation: https://microsoft.github.io/ipe
B. IPE Users' Guide: Documentation/admin-guide/LSM/ipe.rst C. IPE Test Suite: *TBA* (under development)
References:
------------------------------------
1. https://lore.kernel.org/linux-integrity/[email protected]/
Changelog:
------------------------------------
v1: Introduced
v2:
Split the second patch of the previous series into two. Minor corrections in the cover-letter and documentation comments regarding CAP_MAC_ADMIN checks in IPE.
v3:
Address various comments by Jann Horn. Highlights:
Switch various audit allocators to GFP_KERNEL. Utilize rcu_access_pointer() in various locations. Strip out the caching system for properties
Strip comments from headers
Move functions around in patches
Remove kernel command line parameters
Reconcile the race condition on the delete node for policy by
expanding the policy critical section.
Address a few comments by Jonathan Corbet around the documentation
pages for IPE.
Fix an issue with the initialization of IPE policy with a "-0"
version, caused by not initializing the hlist entries before freeing.
v4:
Address a concern around IPE's behavior with unknown syntax.
Specifically, make any unknown syntax a fatal error instead of a warning, as suggested by Mickaël Salaün.
Introduce a new securityfs node, $securityfs/ipe/property_config,
which provides a listing of what properties are enabled by the kernel and their versions. This allows usermode to predict what policies should be allowed.
Strip some comments from c files that I missed.
Clarify some documentation comments around 'boot_verified'.
While this currently does not functionally change the property itself, the distinction is important when IPE can enforce verified reads. Additionally, 'KERNEL_READ' was omitted from the documentation. This has been corrected.
Change SecurityFS and SHA1 to a reverse dependency.
Update the cover-letter with the updated behavior of unknown syntax. Remove all sysctls, making an equivalent function in securityfs. Rework the active/delete mechanism to be a node under the policy in
$securityfs/ipe/policies.
The kernel command line parameters ipe.enforce and ipe.success_audit
have returned as this functionality is no longer exposed through sysfs.
Deven Bowers (12):
scripts: add ipe tooling to generate boot policy
security: add ipe lsm evaluation loop and audit system
security: add ipe lsm policy parser and policy loading
ipe: add property for trust of boot volume
fs: add security blob and hooks for block_device
dm-verity: move signature check after tree validation
dm-verity: add bdev_setsecurity hook for dm-verity signature
ipe: add property for signed dmverity volumes
dm-verity: add bdev_setsecurity hook for root-hash
ipe: add property for dmverity roothash
documentation: add ipe documentation
cleanup: uapi/linux/audit.h
Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 472 +++++++ MAINTAINERS | 8 + drivers/md/dm-verity-target.c | 50 +- drivers/md/dm-verity-verify-sig.c | 147 +- drivers/md/dm-verity-verify-sig.h | 20 +- drivers/md/dm-verity.h | 2 +- fs/block_dev.c | 8 + include/linux/device-mapper.h | 3 + include/linux/fs.h | 1 + include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 11 + include/linux/security.h | 22 + include/uapi/linux/audit.h | 36 +- scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 7 + scripts/ipe/polgen/polgen.c | 136 ++ security/Kconfig | 12 +- security/Makefile | 2 + security/ipe/.gitignore | 2 + security/ipe/Kconfig | 47 + security/ipe/Makefile | 33 + security/ipe/ipe-audit.c | 316 +++++ security/ipe/ipe-audit.h | 26 + security/ipe/ipe-blobs.c | 91 ++ security/ipe/ipe-blobs.h | 18 + security/ipe/ipe-engine.c | 221 +++ security/ipe/ipe-engine.h | 49 + security/ipe/ipe-hooks.c | 169 +++ security/ipe/ipe-hooks.h | 70 + security/ipe/ipe-parse.c | 890 ++++++++++++ security/ipe/ipe-parse.h | 17 + security/ipe/ipe-pin.c | 93 ++ security/ipe/ipe-pin.h | 36 + security/ipe/ipe-policy.c | 148 ++ security/ipe/ipe-policy.h | 69 + security/ipe/ipe-prop-internal.h | 49 + security/ipe/ipe-property.c | 142 ++ security/ipe/ipe-property.h | 100 ++ security/ipe/ipe-secfs.c | 1316 ++++++++++++++++++ security/ipe/ipe-secfs.h | 16 + security/ipe/ipe.c | 116 ++ security/ipe/ipe.h | 22 + security/ipe/properties/Kconfig | 36 + security/ipe/properties/Makefile | 13 + security/ipe/properties/boot-verified.c | 82 ++ security/ipe/properties/dmverity-roothash.c | 153 ++ security/ipe/properties/dmverity-signature.c | 82 ++ security/ipe/properties/prop-entry.h | 38 + security/ipe/utility.h | 32 + security/security.c | 61 + 53 files changed, 5406 insertions(+), 94 deletions(-) create mode 100644 Documentation/admin-guide/LSM/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/ipe-audit.c create mode 100644 security/ipe/ipe-audit.h create mode 100644 security/ipe/ipe-blobs.c create mode 100644 security/ipe/ipe-blobs.h create mode 100644 security/ipe/ipe-engine.c create mode 100644 security/ipe/ipe-engine.h create mode 100644 security/ipe/ipe-hooks.c create mode 100644 security/ipe/ipe-hooks.h create mode 100644 security/ipe/ipe-parse.c create mode 100644 security/ipe/ipe-parse.h create mode 100644 security/ipe/ipe-pin.c create mode 100644 security/ipe/ipe-pin.h create mode 100644 security/ipe/ipe-policy.c create mode 100644 security/ipe/ipe-policy.h create mode 100644 security/ipe/ipe-prop-internal.h create mode 100644 security/ipe/ipe-property.c create mode 100644 security/ipe/ipe-property.h create mode 100644 security/ipe/ipe-secfs.c create mode 100644 security/ipe/ipe-secfs.h create mode 100644 security/ipe/ipe.c create mode 100644 security/ipe/ipe.h create mode 100644 security/ipe/properties/Kconfig create mode 100644 security/ipe/properties/Makefile create mode 100644 security/ipe/properties/boot-verified.c create mode 100644 security/ipe/properties/dmverity-roothash.c create mode 100644 security/ipe/properties/dmverity-signature.c create mode 100644 security/ipe/properties/prop-entry.h create mode 100644 security/ipe/utility.h
Signature · 1 line
2.27.0
RFC PATCH v4 1/12 scripts: add ipe tooling to generate boot policy
Add a tool for the generation of an IPE policy to be compiled into the kernel. This policy will be enforced until userland deploys and activates a new policy.
--- MAINTAINERS | 6 ++ scripts/Makefile | 1 + scripts/ipe/Makefile | 2 + scripts/ipe/polgen/.gitignore | 1 + scripts/ipe/polgen/Makefile | 7 ++ scripts/ipe/polgen/polgen.c | 136 ++++++++++++++++++++++++++++++++++ 6 files changed, 153 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
MAINTAINERS +6 -0
@@ -8580,6 +8580,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]> +L: [email protected] +S: Supported +F: scripts/ipe/ + INTEL 810/815 FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]> L: [email protected]
scripts/Makefile +1 -0
@@ -34,6 +34,7 @@ hostprogs += unifdef 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 +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +hostprogs-y := polgen +HOST_EXTRACFLAGS += \ + -I$(srctree)/include \ + -I$(srctree)/include/uapi \ + +always := $(hostprogs-y)
scripts/ipe/polgen/polgen.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.27.0
RFC PATCH v4 2/12 security: add ipe lsm evaluation loop and audit system
In reply to Deven BowersAdd the core logic of the IPE LSM, the evaluation loop (engine), a portion of the audit system, and the skeleton of the policy structure.
--- MAINTAINERS | 1 + include/uapi/linux/audit.h | 4 + security/Kconfig | 12 +- security/Makefile | 2 + security/ipe/.gitignore | 2 + security/ipe/Kconfig | 43 ++++++ security/ipe/Makefile | 26 ++++ security/ipe/ipe-audit.c | 231 +++++++++++++++++++++++++++++++ security/ipe/ipe-audit.h | 18 +++ security/ipe/ipe-engine.c | 213 ++++++++++++++++++++++++++++ security/ipe/ipe-engine.h | 37 +++++ security/ipe/ipe-hooks.c | 149 ++++++++++++++++++++ security/ipe/ipe-hooks.h | 61 ++++++++ security/ipe/ipe-policy.h | 62 +++++++++ security/ipe/ipe-prop-internal.h | 37 +++++ security/ipe/ipe-property.c | 142 +++++++++++++++++++ security/ipe/ipe-property.h | 99 +++++++++++++ security/ipe/ipe.c | 70 ++++++++++ security/ipe/ipe.h | 20 +++ 19 files changed, 1223 insertions(+), 6 deletions(-) create mode 100644 security/ipe/.gitignore create mode 100644 security/ipe/Kconfig create mode 100644 security/ipe/Makefile create mode 100644 security/ipe/ipe-audit.c create mode 100644 security/ipe/ipe-audit.h create mode 100644 security/ipe/ipe-engine.c create mode 100644 security/ipe/ipe-engine.h create mode 100644 security/ipe/ipe-hooks.c create mode 100644 security/ipe/ipe-hooks.h create mode 100644 security/ipe/ipe-policy.h create mode 100644 security/ipe/ipe-prop-internal.h create mode 100644 security/ipe/ipe-property.c create mode 100644 security/ipe/ipe-property.h create mode 100644 security/ipe/ipe.c create mode 100644 security/ipe/ipe.h
MAINTAINERS +1 -0
@@ -8585,6 +8585,7 @@ M: Deven Bowers <[email protected]> L: [email protected] S: Supported F: scripts/ipe/ +F: security/ipe/ INTEL 810/815 FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]>
include/uapi/linux/audit.h +4 -0
@@ -154,6 +154,10 @@#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ #define AUDIT_INTEGRITY_EVM_XATTR 1806/* New EVM-covered xattr */ #define AUDIT_INTEGRITY_POLICY_RULE 1807/* IMA policy rules */ +#define AUDIT_INTEGRITY_POLICY_LOAD 1808/* IPE Policy Load */ +#define AUDIT_INTEGRITY_POLICY_ACTIVATE 1809/* IPE Policy Activation */ +#define AUDIT_INTEGRITY_EVENT 1810/* IPE Evaluation Event */ +#define AUDIT_INTEGRITY_MODE 1811/* IPE Mode Switch */ #define AUDIT_KERNEL 2000/* Asynchronous audit record. NOT A REQUEST. */
security/Kconfig +6 -6
@@ -238,6 +238,7 @@ source "security/loadpin/Kconfig" source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" +source "security/ipe/Kconfig" source "security/integrity/Kconfig"
@@ -277,11 +278,11 @@ endchoice config LSM string "Ordered list of enabled LSMs" - default "lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC - default "lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" + default "lockdown,yama,loadpin,ipe,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK + default "lockdown,yama,loadpin,ipe,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR + default "lockdown,yama,loadpin,ipe,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO + default "lockdown,yama,loadpin,ipe,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC + default "lockdown,yama,loadpin,ipe,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" help A comma-separated list of LSMs, in initialization order. Any LSMs left off this list will be ignored. This can be
@@ -292,4 +293,3 @@ config LSM source "security/Kconfig.hardening" endmenu -
security/Makefile +2 -0
@@ -13,6 +13,7 @@ subdir-$(CONFIG_SECURITY_LOADPIN) += loadpin subdir-$(CONFIG_SECURITY_SAFESETID) += safesetid subdir-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown subdir-$(CONFIG_BPF_LSM) += bpf +subdir-$(CONFIG_SECURITY_IPE) += ipe # always enable default capabilities obj-y += commoncap.o
@@ -32,6 +33,7 @@ obj-$(CONFIG_SECURITY_SAFESETID) += safesetid/ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ obj-$(CONFIG_CGROUPS) += device_cgroup.o obj-$(CONFIG_BPF_LSM) += bpf/ +obj-$(CONFIG_SECURITY_IPE) += ipe/ # Object integrity file lists subdir-$(CONFIG_INTEGRITY) += integrity
security/ipe/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# Generated Boot Policy +ipe-bp.c
security/ipe/Kconfig new file +43 -0
43 lines not on this page · raw message
security/ipe/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +# 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. +# + +quiet_cmd_polgen = IPE_POL $(patsubst "%",%,$(2)) + cmd_polgen = scripts/ipe/polgen/polgen security/ipe/ipe-bp.c $(2) + +$(eval $(call config_filename,SECURITY_IPE_BOOT_POLICY)) + +targets += ipe-bp.c +$(obj)/ipe-bp.c: scripts/ipe/polgen/polgen $(SECURITY_IPE_BOOT_POLICY_FILENAME) FORCE + $(call if_changed,polgen,$(SECURITY_IPE_BOOT_POLICY_FILENAME)) + +obj-$(CONFIG_SECURITY_IPE) += \ + ipe.o \ + ipe-audit.o \ + ipe-bp.o \ + ipe-engine.o \ + ipe-property.o \ + ipe-hooks.o \ + ipe-secfs.o \ + +clean-files := ipe-bp.c
security/ipe/ipe-audit.c new file +231 -0
231 lines not on this page · raw message
security/ipe/ipe-audit.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe-engine.h" +#include "ipe-policy.h" + +#ifndef IPE_AUDIT_H +#define IPE_AUDIT_H + +void ipe_audit_mode (void ); + +void ipe_audit_match (const struct ipe_engine_ctx *ctx, +enum ipe_match match_type,enum ipe_action action, +const struct ipe_rule *rule); + +#endif /* IPE_AUDIT_H */
security/ipe/ipe-engine.c new file +213 -0
213 lines not on this page · raw message
security/ipe/ipe-engine.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe-hooks.h" + +#include <linux/types.h> +#include <linux/rbtree.h> +#include <linux/fs.h> + +#ifndef IPE_ENGINE_H +#define IPE_ENGINE_H + +struct ipe_engine_ctx { +enum ipe_op op; +enum ipe_hook hook; +const struct file *file; +const char *audit_pathname; +}; + +struct ipe_prop_cache { +struct rb_node node; +void *storage; +const struct ipe_property *prop; +}; + +enum ipe_match { + ipe_match_rule =0 , + ipe_match_table, + ipe_match_global +}; + +int ipe_process_event (const struct file *file,enum ipe_op op, +enum ipe_hook hook); + +#endif /* IPE_ENGINE_H */
security/ipe/ipe-hooks.c new file +149 -0
149 lines not on this page · raw message
security/ipe/ipe-hooks.h new file +61 -0
61 lines not on this page · raw message
security/ipe/ipe-policy.h new file +62 -0
62 lines not on this page · raw message
security/ipe/ipe-prop-internal.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe-property.h" + +#include <linux/types.h> + +#ifndef IPE_PROPERTY_INTERNAL_H +#define IPE_PROPERTY_INTERNAL_H + +#define IPE_PROPERTY_OPERATION "op" +#define IPE_PROPERTY_DEFAULT "DEFAULT" +#define IPE_PROPERTY_ACTION "action" + +#define IPE_OP_EXECUTE "EXECUTE" +#define IPE_OP_FIRMWARE "FIRMWARE" +#define IPE_OP_KEXEC_IMAGE "KEXEC_IMAGE" +#define IPE_OP_KEXEC_INITRAMFS "KEXEC_INITRAMFS" +#define IPE_OP_X509_CERTIFICATE "X509_CERT" +#define IPE_OP_POLICY "POLICY" +#define IPE_OP_KMODULE "KMODULE" +#define IPE_OP_KERNEL_READ "KERNEL_READ" + +struct ipe_prop_reg { +struct rb_node node; +const struct ipe_property *prop; +}; + +int ipe_for_each_prop (int (*view)(const struct ipe_property *prop, +void *ctx), +void *ctx); + +const struct ipe_property *ipe_lookup_prop (const char *key); + +#endif /* IPE_PROPERTY_INTERNAL_H */
security/ipe/ipe-property.c new file +142 -0
142 lines not on this page · raw message
security/ipe/ipe-property.h new file +99 -0
99 lines not on this page · raw message
security/ipe/ipe.c new file +70 -0
70 lines not on this page · raw message
security/ipe/ipe.h new file +20 -0
@@ -0,0 +1,20 @@ +/* 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 <linux/types.h> +#include <linux/fs.h> + +#define IPE_MODE_ENFORCE "enforce" +#define IPE_MODE_PERMISSIVE "permissive" + +extern bool ipe_enforce; +extern bool ipe_success_audit; + +#endif /* IPE_H */
Signature · 1 line
2.27.0
Randy Dunlap
reviewerRe: [RFC PATCH v4 02/12] security: add ipe lsm evaluation loop and audit system
security/ipe/Kconfig line 37
Quoted 7 lines · Deven Bowers
security/ipe/Kconfig new file +7
-0+config SECURITY_IPE_PERMISSIVE_SWITCH + bool "Enable the ability to switch IPE to permissive mode" + default y + help + This option enables two ways of switching IPE to permissive mode, + a sysctl (if enabled), `ipe.enforce`, or a kernel command line + parameter, `ipe.enforce`. If either of these are set to 0, files
is set
Quoted 4 lines
security/ipe/Kconfig new file +4
-0+ will be subject to IPE's policy, audit messages will be logged, but + the policy will not be enforced. + + If unsure, answer Y.
Signature · 1 line
~Randy
Re: [RFC PATCH v4 02/12] security: add ipe lsm evaluation loop and audit system
Quoted 10 lines · Randy Dunlap
security/ipe/Kconfig line 37
Quoted 7 lines · Deven Bowers
security/ipe/Kconfig new file +7
-0+config SECURITY_IPE_PERMISSIVE_SWITCH + bool "Enable the ability to switch IPE to permissive mode" + default y + help + This option enables two ways of switching IPE to permissive mode, + a sysctl (if enabled), `ipe.enforce`, or a kernel command line + parameter, `ipe.enforce`. If either of these are set to 0, filesis set
Thanks, I'll change it in the next iteration.
Quoted 7 lines
Quoted 5 lines
security/ipe/Kconfig new file +4
-0+ will be subject to IPE's policy, audit messages will be logged, but + the policy will not be enforced. + + If unsure, answer Y.
kernel test robot
build botRe: [RFC PATCH v4 02/12] security: add ipe lsm evaluation loop and audit system
In reply to Deven Bowers[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5 next-20200717] [cannot apply to security/next-testing]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from arch/m68k/include/asm/io_mm.h:25,
from arch/m68k/include/asm/io.h:8,
from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:11,
from include/linux/skbuff.h:31,
from include/linux/lsm_audit.h:24,
from security/ipe/ipe-property.h:9,
from security/ipe/ipe-engine.c:7:
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsb':
arch/m68k/include/asm/raw_io.h:83:7: warning: variable '__w' set but not used [-Wunused-but-set-variable]
83 | ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:430:3: note: in expansion of macro 'rom_out_8'
430 | rom_out_8(port, *buf++);
| ^~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw':
arch/m68k/include/asm/raw_io.h:86:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
86 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:448:3: note: in expansion of macro 'rom_out_be16'
448 | rom_out_be16(port, *buf++);
| ^~~~~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw_swapw':
arch/m68k/include/asm/raw_io.h:90:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
90 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:466:3: note: in expansion of macro 'rom_out_le16'
466 | rom_out_le16(port, *buf++);
| ^~~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/ipe.h:12,
from security/ipe/ipe-engine.c:6:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
In file included from arch/m68k/include/asm/bug.h:32,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/preempt.h:5,
from ./arch/m68k/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/ipe.h:12,
from security/ipe/ipe-engine.c:6:
include/linux/dma-mapping.h: In function 'dma_map_resource':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/asm-generic/bug.h:144:27: note: in definition of macro 'WARN_ON_ONCE'
144 | int __ret_warn_once = !!(condition); \
| ^~~~~~~~~
arch/m68k/include/asm/page_mm.h:170:25: note: in expansion of macro 'virt_addr_valid'
170 | #define pfn_valid(pfn) virt_addr_valid(pfn_to_virt(pfn))
| ^~~~~~~~~~~~~~~
include/linux/dma-mapping.h:352:19: note: in expansion of macro 'pfn_valid'
352 | if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
| ^~~~~~~~~
security/ipe/ipe-engine.c: In function 'get_audit_pathname':
>> security/ipe/ipe-engine.c:39:22: warning: variable 'sb' set but not used [-Wunused-but-set-variable]
39 | struct super_block *sb;
| ^~vim +/sb +39 security/ipe/ipe-engine.c
21
22 /**
23 * get_audit_pathname: Return the absolute path of the file struct passed in
24 * @file: file to derive an absolute path from.
25 *
26 * This function walks past chroots and mount points.
27 *
28 * Return:
29 * !NULL - OK
30 * ERR_PTR(-ENOENT) - No File
31 * ERR_PTR(-ENOMEM) - No Memory
32 * ERR_PTR(-ENAMETOOLONG) - Path Exceeds PATH_MAX
33 */
34 static char *get_audit_pathname(const struct file *file)
35 {
36 int rc = 0;
37 char *pos = NULL;
38 char *pathbuf = NULL;
> 39 struct super_block *sb;
40 char *temp_path = NULL;
41
42 /* No File to get Path From */
43 if (!file)
44 return ERR_PTR(-ENOENT);
45
46 sb = file->f_path.dentry->d_sb;
47
48 pathbuf = __getname();
49 if (!pathbuf)
50 return ERR_PTR(-ENOMEM);
51
52 pos = d_absolute_path(&file->f_path, pathbuf, PATH_MAX);
53 if (IS_ERR(pos)) {
54 rc = PTR_ERR(pos);
55 goto err;
56 }
57
58 temp_path = __getname();
59 if (!temp_path) {
60 rc = -ENOMEM;
61 goto err;
62 }
63
64 strlcpy(temp_path, pos, PATH_MAX);
65
66 __putname(pathbuf);
67
68 return temp_path;
69
70 err:
71 __putname(pathbuf);
72 return ERR_PTR(rc);
73 }
74 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v4 3/12 security: add ipe lsm policy parser and policy loading
In reply to Deven BowersAdds the policy parser and the policy loading to IPE, along with the related sysfs, securityfs entries, and audit events.
--- security/ipe/Kconfig | 2 + security/ipe/Makefile | 2 + security/ipe/ipe-audit.c | 87 +- security/ipe/ipe-audit.h | 8 + security/ipe/ipe-parse.c | 890 ++++++++++++++++++++ security/ipe/ipe-parse.h | 17 + security/ipe/ipe-policy.c | 148 ++++ security/ipe/ipe-policy.h | 13 +- security/ipe/ipe-prop-internal.h | 12 + security/ipe/ipe-property.h | 1 + security/ipe/ipe-secfs.c | 1308 ++++++++++++++++++++++++++++++ security/ipe/ipe-secfs.h | 16 + 12 files changed, 2500 insertions(+), 4 deletions(-) create mode 100644 security/ipe/ipe-parse.c create mode 100644 security/ipe/ipe-parse.h create mode 100644 security/ipe/ipe-policy.c create mode 100644 security/ipe/ipe-secfs.c create mode 100644 security/ipe/ipe-secfs.h
security/ipe/Kconfig +2 -0
@@ -7,6 +7,8 @@ menuconfig SECURITY_IPE bool "Integrity Policy Enforcement (IPE)" depends on SECURITY && AUDIT select SYSTEM_DATA_VERIFICATION + select SECURITYFS + select CRYPTO_SHA1 help This option enables the Integrity Policy Enforcement subsystem allowing systems to enforce integrity having no dependencies
security/ipe/Makefile +2 -0
@@ -19,6 +19,8 @@ obj-$(CONFIG_SECURITY_IPE) += \ ipe-audit.o \ ipe-bp.o \ ipe-engine.o \ + ipe-parse.o \ + ipe-policy.o \ ipe-property.o \ ipe-hooks.o \ ipe-secfs.o \
security/ipe/ipe-audit.c +86 -1
96 lines not on this page · raw message
security/ipe/ipe-audit.h +8 -0
@@ -3,6 +3,7 @@* Copyright (C) Microsoft Corporation. All rights reserved. */ +#include "ipe-prop-internal.h" #include "ipe-engine.h" #include "ipe-policy.h"
@@ -15,4 +16,11 @@ void ipe_audit_match(const struct ipe_engine_ctx *ctx, enum ipe_match match_type, enum ipe_action action, const struct ipe_rule *rule); +void ipe_audit_policy_load (const struct ipe_policy *pol,const uint8_t *raw, +size_t raw_size,struct crypto_shash *tfm); + +void ipe_audit_policy_activation (const struct ipe_policy *pol); + +void ipe_audit_unset_remap (enum ipe_op op); +#endif /* IPE_AUDIT_H */
security/ipe/ipe-parse.c new file +890 -0
890 lines not on this page · raw message
security/ipe/ipe-parse.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include "ipe-policy.h" + +#include <linux/types.h> + +#ifndef IPE_PARSE_H +#define IPE_PARSE_H + +struct ipe_policy *ipe_parse_policy (char *policy); + +void ipe_free_policy (struct ipe_policy *pol); + +#endif /* IPE_AUDIT_H */
security/ipe/ipe-policy.c new file +148 -0
148 lines not on this page · raw message
security/ipe/ipe-policy.h +10 -3
@@ -14,9 +14,6 @@#ifndef IPE_POLICY_H #define IPE_POLICY_H -#define IPE_HEADER_POLICY_NAME "policy_name" -#define IPE_HEADER_POLICY_VERSION "policy_version" -extern const char *const ipe_boot_policy;extern const struct ipe_policy *ipe_active_policy;
@@ -59,4 +56,14 @@ struct ipe_policy { struct ipe_rule_table ops[ipe_op_max - 1]; }; +bool ipe_is_valid_policy (const struct ipe_policy *old, +const struct ipe_policy *new); + +bool ipe_is_active_policy (const struct ipe_policy *policy); + +int ipe_update_active_policy (const struct ipe_policy *old, +const struct ipe_policy *new); + +int ipe_activate_policy (const struct ipe_policy *policy); +#endif /* IPE_POLICY_H */
security/ipe/ipe-prop-internal.h +12 -0
@@ -10,10 +10,20 @@#ifndef IPE_PROPERTY_INTERNAL_H #define IPE_PROPERTY_INTERNAL_H +/* built-in tokens */ +#define IPE_HEADER_POLICY_NAME "policy_name" +#define IPE_HEADER_POLICY_VERSION "policy_version"#define IPE_PROPERTY_OPERATION "op"#define IPE_PROPERTY_DEFAULT "DEFAULT"#define IPE_PROPERTY_ACTION "action" +/* Version strings for built-in tokens */ +#define IPE_PROPERTY_OPERATION_VER IPE_PROPERTY_OPERATION "=1" +#define IPE_PROPERTY_ACTION_VER IPE_PROPERTY_ACTION "=1" +#define IPE_PROPERTY_DEFAULT_VER IPE_PROPERTY_DEFAULT "=1" +#define IPE_HEADER_POLICY_NAME_VER IPE_HEADER_POLICY_NAME "=1" +#define IPE_HEADER_POLICY_VERSION_VER IPE_HEADER_POLICY_VERSION "=1" +#define IPE_OP_EXECUTE "EXECUTE"#define IPE_OP_FIRMWARE "FIRMWARE"#define IPE_OP_KEXEC_IMAGE "KEXEC_IMAGE"
@@ -23,6 +33,8 @@#define IPE_OP_KMODULE "KMODULE"#define IPE_OP_KERNEL_READ "KERNEL_READ" +#define IPE_UNKNOWN "UNKNOWN" +struct ipe_prop_reg {struct rb_node node;const struct ipe_property *prop;
security/ipe/ipe-property.h +1 -0
@@ -86,6 +86,7 @@ typedef void (*ipe_free_value)(void **value);struct ipe_property {const char *const property_name; +u16 version;ipe_property_evaluator eval;ipe_property_audit rule_audit;ipe_ctx_audit ctx_audit;
security/ipe/ipe-secfs.c new file +1308 -0
1,308 lines not on this page · raw message
security/ipe/ipe-secfs.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#include <linux/types.h> + +#include "ipe-policy.h" + +#ifndef IPE_SECFS_H +#define IPE_SECFS_H + +extern struct mutex ipe_policy_lock; + +int ipe_set_active_policy (const char *id,size_t id_len); + +#endif /* IPE_SECFS_H */
Signature · 1 line
2.27.0
kernel test robot
build botRe: [RFC PATCH v4 03/12] security: add ipe lsm policy parser and policy loading
[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5 next-20200717] [cannot apply to security/next-testing]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from arch/m68k/include/asm/io_mm.h:25,
from arch/m68k/include/asm/io.h:8,
from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:11,
from include/linux/skbuff.h:31,
from include/linux/lsm_audit.h:24,
from security/ipe/ipe-property.h:9,
from security/ipe/ipe-policy.h:7,
from security/ipe/ipe-parse.h:6,
from security/ipe/ipe-secfs.c:7:
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsb':
arch/m68k/include/asm/raw_io.h:83:7: warning: variable '__w' set but not used [-Wunused-but-set-variable]
83 | ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:430:3: note: in expansion of macro 'rom_out_8'
430 | rom_out_8(port, *buf++);
| ^~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw':
arch/m68k/include/asm/raw_io.h:86:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
86 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:448:3: note: in expansion of macro 'rom_out_be16'
448 | rom_out_be16(port, *buf++);
| ^~~~~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw_swapw':
arch/m68k/include/asm/raw_io.h:90:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
90 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:466:3: note: in expansion of macro 'rom_out_le16'
466 | rom_out_le16(port, *buf++);
| ^~~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/ipe.h:12,
from security/ipe/ipe-secfs.c:6:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
In file included from arch/m68k/include/asm/bug.h:32,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/preempt.h:5,
from ./arch/m68k/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/ipe.h:12,
from security/ipe/ipe-secfs.c:6:
include/linux/dma-mapping.h: In function 'dma_map_resource':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/asm-generic/bug.h:144:27: note: in definition of macro 'WARN_ON_ONCE'
144 | int __ret_warn_once = !!(condition); \
| ^~~~~~~~~
arch/m68k/include/asm/page_mm.h:170:25: note: in expansion of macro 'virt_addr_valid'
170 | #define pfn_valid(pfn) virt_addr_valid(pfn_to_virt(pfn))
| ^~~~~~~~~~~~~~~
include/linux/dma-mapping.h:352:19: note: in expansion of macro 'pfn_valid'
352 | if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
| ^~~~~~~~~
security/ipe/ipe-secfs.c: At top level:
>> security/ipe/ipe-secfs.c:1021:5: warning: no previous prototype for 'ipe_build_policy_secfs_node' [-Wmissing-prototypes]
1021 | int ipe_build_policy_secfs_node(const u8 *data, size_t len)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> security/ipe/ipe-secfs.c:1116:12: warning: no previous prototype for 'ipe_build_secfs_root' [-Wmissing-prototypes]
1116 | int __init ipe_build_secfs_root(void)
| ^~~~~~~~~~~~~~~~~~~~
>> security/ipe/ipe-secfs.c:1290:12: warning: no previous prototype for 'ipe_securityfs_init' [-Wmissing-prototypes]
1290 | int __init ipe_securityfs_init(void)
| ^~~~~~~~~~~~~~~~~~~vim +/ipe_build_policy_secfs_node +1021 security/ipe/ipe-secfs.c
1009
1010 /**
1011 * ipe_build_policy_secfs_node: Build a new securityfs node for IPE policies.
1012 * @data: Raw enveloped PKCS#7 data that represents the policy.
1013 * @len: Length of @data.
1014 *
1015 * Return:
1016 * 0 - OK
1017 * -EEXIST - Policy already exists
1018 * -EBADMSG - Invalid policy syntax
1019 * -ENOMEM - Out of memory
1020 */
> 1021 int ipe_build_policy_secfs_node(const u8 *data, size_t len)
1022 {
1023 int rc = 0;
1024 struct dentry *root = NULL;
1025 struct inode *root_i = NULL;
1026 struct crypto_shash *tfm = NULL;
1027 struct ipe_policy_node *node = NULL;
1028
1029 tfm = crypto_alloc_shash("sha1", 0, 0);
1030 if (IS_ERR(tfm)) {
1031 rc = PTR_ERR(tfm);
1032 goto out;
1033 }
1034
1035 node = ipe_alloc_policy_node(data, len);
1036 if (IS_ERR(node)) {
1037 rc = PTR_ERR(node);
1038 goto free_hash;
1039 }
1040
1041 root = securityfs_create_dir(node->parsed->policy_name,
1042 policies_root);
1043 if (IS_ERR(root)) {
1044 rc = PTR_ERR(root);
1045 goto free_private;
1046 }
1047
1048 root_i = d_inode(root);
1049
1050 inode_lock(root_i);
1051 root_i->i_private = node;
1052 ipe_audit_policy_load(node->parsed, node->data, node->data_len, tfm);
1053 inode_unlock(root_i);
1054
1055 rc = ipe_alloc_policy_tree(root);
1056 if (rc)
1057 goto free_secfs;
1058
1059 crypto_free_shash(tfm);
1060 return rc;
1061
1062 free_secfs:
1063 securityfs_remove(root);
1064 free_private:
1065 ipe_free_policy_node(node);
1066 free_hash:
1067 crypto_free_shash(tfm);
1068 out:
1069 return rc;
1070 }
1071
1072 /**
1073 * ipe_new_policy: Entry point of the securityfs node, "ipe/new_policy".
1074 * @f: File representing the securityfs entry.
1075 * @data: Raw enveloped PKCS#7 data that represents the policy.
1076 * @len: Length of @data.
1077 * @offset: Offset for @data.
1078 *
1079 * Return:
1080 * > 0 - OK
1081 * -EEXIST - Policy already exists
1082 * -EBADMSG - Invalid policy syntax
1083 * -ENOMEM - Out of memory
1084 * -EPERM - if a MAC subsystem is enabled, missing CAP_MAC_ADMIN
1085 */
1086 static ssize_t ipe_new_policy(struct file *f, const char __user *data,
1087 size_t len, loff_t *offset)
1088 {
1089 ssize_t rc = 0;
1090 u8 *cpy = NULL;
1091
1092 if (!file_ns_capable(f, &init_user_ns, CAP_MAC_ADMIN))
1093 return -EPERM;
1094
1095 cpy = memdup_user(data, len);
1096 if (IS_ERR(cpy))
1097 return PTR_ERR(cpy);
1098
1099 rc = ipe_build_policy_secfs_node(cpy, len);
1100
1101 kfree(cpy);
1102 return rc < 0 ? rc : len;
1103 }
1104
1105 static const struct file_operations new_policy_ops = {
1106 .write = ipe_new_policy
1107 };
1108
1109 /**
1110 * ipe_build_secfs_root: Build the root of securityfs for IPE.
1111 *
1112 * Return:
1113 * 0 - OK
1114 * !0 - See securityfs_create_dir and securityfs_create_file
1115 */
> 1116 int __init ipe_build_secfs_root(void) 1117 {
1118 int rc = 0;
1119 struct dentry *new = NULL;
1120 struct dentry *cfg = NULL;
1121 struct dentry *root = NULL;
1122 struct dentry *audit = NULL;
1123 struct dentry *enforce = NULL;
1124 struct dentry *policies = NULL;
1125
1126 root = securityfs_create_dir(IPE_ROOT, NULL);
1127 if (IS_ERR(root)) {
1128 rc = PTR_ERR(root);
1129 goto out;
1130 }
1131
1132 new = securityfs_create_file(NEW_POLICY, 0644, root, NULL,
1133 &new_policy_ops);
1134 if (IS_ERR(new)) {
1135 rc = PTR_ERR(new);
1136 goto out_free_root;
1137 }
1138
1139 policies = securityfs_create_dir(IPE_POLICIES, root);
1140 if (IS_ERR(policies)) {
1141 rc = PTR_ERR(policies);
1142 goto out_free_new;
1143 }
1144
1145 cfg = securityfs_create_file(IPE_PROPERTY_CFG, 0444, root, NULL,
1146 &prop_cfg_ops);
1147 if (IS_ERR(cfg)) {
1148 rc = PTR_ERR(cfg);
1149 goto out_free_policies;
1150 }
1151
1152 audit = securityfs_create_file(IPE_SUCCESS_AUDIT, 0644, root, NULL,
1153 &audit_ops);
1154 if (IS_ERR(cfg)) {
1155 rc = PTR_ERR(audit);
1156 goto out_free_cfg;
1157 }
1158
1159 enforce = ipe_init_enforce_node(root);
1160 if (IS_ERR(enforce)) {
1161 rc = PTR_ERR(audit);
1162 goto out_free_audit;
1163 }
1164
1165 securityfs_root = root;
1166 new_policy_node = new;
1167 policies_root = policies;
1168 property_cfg_node = cfg;
1169 success_audit_node = audit;
1170 enforce_node = enforce;
1171
1172 return rc;
1173
1174 out_free_audit:
1175 securityfs_remove(audit);
1176 out_free_cfg:
1177 securityfs_remove(cfg);
1178 out_free_policies:
1179 securityfs_remove(policies);
1180 out_free_new:
1181 securityfs_remove(new);
1182 out_free_root:
1183 securityfs_remove(root);
1184 out:
1185 return rc;
1186 }
1187
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v4 4/12 ipe: add property for trust of boot volume
In reply to Deven BowersAdd a property for IPE policy to express trust of the first superblock where a file would be evaluated to determine trust.
--- security/ipe/Kconfig | 2 + security/ipe/Makefile | 4 ++ security/ipe/ipe-engine.c | 4 ++ security/ipe/ipe-hooks.c | 19 +++++ security/ipe/ipe-hooks.h | 2 + security/ipe/ipe-pin.c | 93 +++++++++++++++++++++++++ security/ipe/ipe-pin.h | 36 ++++++++++ security/ipe/ipe.c | 24 +++++++ security/ipe/properties/Kconfig | 15 ++++ security/ipe/properties/Makefile | 11 +++ security/ipe/properties/boot-verified.c | 82 ++++++++++++++++++++++ security/ipe/properties/prop-entry.h | 20 ++++++ security/ipe/utility.h | 22 ++++++ 13 files changed, 334 insertions(+) create mode 100644 security/ipe/ipe-pin.c create mode 100644 security/ipe/ipe-pin.h create mode 100644 security/ipe/properties/Kconfig create mode 100644 security/ipe/properties/Makefile create mode 100644 security/ipe/properties/boot-verified.c create mode 100644 security/ipe/properties/prop-entry.h create mode 100644 security/ipe/utility.h
security/ipe/Kconfig +2 -0
@@ -42,4 +42,6 @@ config SECURITY_IPE_PERMISSIVE_SWITCH If unsure, answer Y. +source "security/ipe/properties/Kconfig" + endif
security/ipe/Makefile +4 -0
@@ -26,3 +26,7 @@ obj-$(CONFIG_SECURITY_IPE) += \ ipe-secfs.o \ clean-files := ipe-bp.c + +obj-$(CONFIG_IPE_BOOT_PROP) += ipe-pin.o + +obj-$(CONFIG_SECURITY_IPE) += properties/
security/ipe/ipe-engine.c +4 -0
@@ -9,6 +9,8 @@#include "ipe-policy.h" #include "ipe-engine.h" #include "ipe-audit.h" +#include "ipe-pin.h" +#include "utility.h" #include <linux/types.h> #include <linux/fs.h>
@@ -205,6 +207,8 @@ int ipe_process_event(const struct file *file, enum ipe_op op,if (IS_ERR (ctx)) goto cleanup; +ipe_pin_superblock (ctx->file); + rc =evaluate (ctx); cleanup:
security/ipe/ipe-hooks.c +19 -0
@@ -6,6 +6,7 @@#include "ipe.h" #include "ipe-hooks.h" #include "ipe-engine.h" +#include "ipe-pin.h" #include <linux/types.h> #include <linux/fs.h>
@@ -147,3 +148,21 @@ int ipe_on_kernel_load_data(enum kernel_load_data_id id) ipe_hook_kernel_load); } } + +/** +* ipe_sb_free_security: LSM hook called on sb_free_security. +* @mnt_sb: Super block that is being freed. +* +* IPE does not currently utilize the super block security hook, +* it utilizes this hook to invalidate the saved super block for +* the boot_verified property. +* +* For more information, see the LSM hook, sb_free_security. +* +* Return: +* 0 - OK +*/ +void ipe_sb_free_security (struct super_block *mnt_sb) +{ +ipe_invalidate_pinned_sb (mnt_sb); +}
security/ipe/ipe-hooks.h +2 -0
@@ -58,4 +58,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); +void ipe_sb_free_security (struct super_block *mnt_sb); +#endif /* IPE_HOOK_H */
security/ipe/ipe-pin.c new file +93 -0
93 lines not on this page · raw message
security/ipe/ipe-pin.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#ifndef IPE_PIN_H +#define IPE_PIN_H + +#include <linux/types.h> +#include <linux/fs.h> + +#ifdef CONFIG_IPE_BOOT_PROP + +bool ipe_is_from_pinned_sb (const struct file *file); + +void ipe_pin_superblock (const struct file *file); + +void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb); + +#else /* CONFIG_IPE_BOOT_PROP */ + +static inline bool ipe_is_from_pinned_sb (const struct file *file) +{ +return false; +} + +static inline void ipe_pin_superblock (const struct file *file) +{ +} + +static inline void ipe_invalidate_pinned_sb (const struct super_block *mnt_sb) +{ +} + +#endif /* !CONFIG_IPE_BOOT_PROP */ + +#endif /* IPE_PIN_H */
security/ipe/ipe.c +24 -0
@@ -7,6 +7,7 @@#include "ipe-policy.h" #include "ipe-hooks.h" #include "ipe-secfs.h" +#include "properties/prop-entry.h" #include <linux/module.h> #include <linux/lsm_hooks.h>
@@ -22,8 +23,27 @@ 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 (file_mprotect, ipe_on_mprotect), + LSM_HOOK_INIT(sb_free_security, ipe_sb_free_security), }; +/** +* ipe_load_properties: Call the property entry points for all the IPE modules +* that were selected at kernel build-time. +* +* Return: +* 0 - OK +*/ +static int __init ipe_load_properties (void ) +{ +int rc =0 ; + + rc =ipe_init_bootv (); +if (rc !=0 ) +return rc; + +return rc; +} +/** * ipe_init: Entry point of IPE. *
@@ -41,6 +61,10 @@ static int __init ipe_init(void) {int rc; + rc =ipe_load_properties (); +if (rc !=0 ) +panic ("IPE: properties failed to load" ); +pr_info ("mode=%s" , (ipe_enforce ==1 ) ?IPE_MODE_ENFORCE :IPE_MODE_PERMISSIVE );
security/ipe/properties/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Integrity Policy Enforcement (IPE) configuration +# + +config IPE_BOOT_PROP + bool "Enable trust for boot volume" + 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 the initial + superblock. + + if unsure, answer N.
security/ipe/properties/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 properties that IPE uses +# as part of the kernel tree. +# + +obj-$(CONFIG_SECURITY_IPE) += properties.o + +properties-$(CONFIG_IPE_BOOT_PROP) += boot-verified.o
security/ipe/properties/boot-verified.c new file +82 -0
82 lines not on this page · raw message
security/ipe/properties/prop-entry.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#include <linux/types.h> + +#ifndef IPE_PROP_ENTRY_H +#define IPE_PROP_ENTRY_H + +#ifndef CONFIG_IPE_BOOT_PROP +static inline int __init ipe_init_bootv (void ) +{ +return 0 ; +} +#else +int __init ipe_init_bootv (void ); +#endif /* CONFIG_IPE_BOOT_PROP */ + +#endif /* IPE_PROP_ENTRY_H */
security/ipe/utility.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ + +#ifndef IPE_UTILITY_H +#define IPE_UTILITY_H + +#include <linux/types.h> +#include <linux/fs.h> + +static inline bool has_mount (const struct file *file) +{ +return file && file->f_path.mnt; +} + +static inline bool has_sb (const struct file *file) +{ +return has_mount (file) && file->f_path.mnt->mnt_sb; +} + +#endif /* IPE_UTILITY_H */
Signature · 1 line
2.27.0
kernel test robot
build botRe: [RFC PATCH v4 04/12] ipe: add property for trust of boot volume
[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5 next-20200717] [cannot apply to security/next-testing]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> security/ipe/ipe-pin.c:34:6: warning: no previous prototype for 'ipe_is_from_pinned_sb' [-Wmissing-prototypes]
34 | bool ipe_is_from_pinned_sb(const struct file *file)
| ^~~~~~~~~~~~~~~~~~~~~
>> security/ipe/ipe-pin.c:62:6: warning: no previous prototype for 'ipe_pin_superblock' [-Wmissing-prototypes]
62 | void ipe_pin_superblock(const struct file *file)
| ^~~~~~~~~~~~~~~~~~
>> security/ipe/ipe-pin.c:81:6: warning: no previous prototype for 'ipe_invalidate_pinned_sb' [-Wmissing-prototypes] 81 | void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)
| ^~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from arch/m68k/include/asm/io_mm.h:25,
from arch/m68k/include/asm/io.h:8,
from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:11,
from include/linux/skbuff.h:31,
from include/linux/lsm_audit.h:24,
from security/ipe/properties/../ipe-property.h:9,
from security/ipe/properties/boot-verified.c:8:
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsb':
arch/m68k/include/asm/raw_io.h:83:7: warning: variable '__w' set but not used [-Wunused-but-set-variable]
83 | ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:430:3: note: in expansion of macro 'rom_out_8'
430 | rom_out_8(port, *buf++);
| ^~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw':
arch/m68k/include/asm/raw_io.h:86:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
86 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:448:3: note: in expansion of macro 'rom_out_be16'
448 | rom_out_be16(port, *buf++);
| ^~~~~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw_swapw':
arch/m68k/include/asm/raw_io.h:90:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
90 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:466:3: note: in expansion of macro 'rom_out_le16'
466 | rom_out_le16(port, *buf++);
| ^~~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/properties/../ipe.h:12,
from security/ipe/properties/boot-verified.c:6:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
In file included from arch/m68k/include/asm/bug.h:32,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/preempt.h:5,
from ./arch/m68k/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/properties/../ipe.h:12,
from security/ipe/properties/boot-verified.c:6:
include/linux/dma-mapping.h: In function 'dma_map_resource':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/asm-generic/bug.h:144:27: note: in definition of macro 'WARN_ON_ONCE'
144 | int __ret_warn_once = !!(condition); \
| ^~~~~~~~~
arch/m68k/include/asm/page_mm.h:170:25: note: in expansion of macro 'virt_addr_valid'
170 | #define pfn_valid(pfn) virt_addr_valid(pfn_to_virt(pfn))
| ^~~~~~~~~~~~~~~
include/linux/dma-mapping.h:352:19: note: in expansion of macro 'pfn_valid'
352 | if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
| ^~~~~~~~~
security/ipe/properties/boot-verified.c: At top level:
>> security/ipe/properties/boot-verified.c:79:5: warning: no previous prototype for 'ipe_init_bootv' [-Wmissing-prototypes] 79 | int ipe_init_bootv(void)
| ^~~~~~~~~~~~~~
vim +/ipe_is_from_pinned_sb +34 security/ipe/ipe-pin.c
24
25 /**
26 * ipe_is_from_pinned_sb: Determine if @file originates from the initial
27 * super block that a file was executed from.
28 * @file: File to check if it originates from the super block.
29 *
30 * Return:
31 * true - File originates from the initial super block
32 * false - File does not originate from the initial super block
33 */
> 34 bool ipe_is_from_pinned_sb(const struct file *file)
35 {
36 bool rv = false;
37
38 spin_lock(&pinned_sb_spinlock);
39
40 /*
41 * Check if pinned_sb is set:
42 * NULL == not set -> exit
43 * ERR == was once set (and has been unmounted) -> exit
44 * AND check that the pinned sb is the same as the file's.
45 */
46 if (!IS_ERR_OR_NULL(pinned_sb) &&
47 file->f_path.mnt->mnt_sb == pinned_sb) {
48 rv = true;
49 goto cleanup;
50 }
51
52 cleanup:
53 spin_unlock(&pinned_sb_spinlock);
54 return rv;
55 }
56
57 /**
58 * ipe_pin_superblock: Attempt to save a file's super block address to later
59 * determine if a file originates from a super block.
60 * @file: File to source the super block from.
61 */
> 62 void ipe_pin_superblock(const struct file *file)
63 {
64 spin_lock(&pinned_sb_spinlock);
65
66 /* if set, return */
67 if (pinned_sb || !file)
68 goto cleanup;
69
70 pinned_sb = file->f_path.mnt->mnt_sb;
71 cleanup:
72 spin_unlock(&pinned_sb_spinlock);
73 }
74
75 /**
76 * ipe_invalidate_pinned_sb: Invalidate the saved super block.
77 * @mnt_sb: Super block to compare against the saved super block.
78 *
79 * This avoids authorizing a file when the super block does not exist anymore.
80 */
> 81 void ipe_invalidate_pinned_sb(const struct super_block *mnt_sb)---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v4 5/12 fs: add security blob and hooks for block_device
In reply to Deven BowersAdd a security blob and associated allocation, deallocation and set hooks for a block_device structure.
--- fs/block_dev.c | 8 +++++ include/linux/fs.h | 1 + include/linux/lsm_hook_defs.h | 5 +++ include/linux/lsm_hooks.h | 11 +++++++ include/linux/security.h | 22 +++++++++++++ security/security.c | 61 +++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+)
fs/block_dev.c +8 -0
@@ -34,6 +34,7 @@#include <linux/falloc.h> #include <linux/uaccess.h> #include <linux/suspend.h> +#include <linux/security.h> #include "internal.h" struct bdev_inode {
@@ -768,11 +769,18 @@ static struct inode *bdev_alloc_inode(struct super_block *sb)struct bdev_inode *ei =kmem_cache_alloc (bdev_cachep,GFP_KERNEL );if (!ei)return NULL ; + +if (unlikely (security_bdev_alloc (&ei->bdev))) { +kmem_cache_free (bdev_cachep, ei); +return NULL ; + } +return &ei->vfs_inode; }static void bdev_free_inode (struct inode *inode) { +security_bdev_free (&BDEV_I (inode)->bdev);kmem_cache_free (bdev_cachep,BDEV_I (inode)); }
include/linux/fs.h +1 -0
@@ -509,6 +509,7 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; +void *security; } __randomize_layout;/* XArray tags, for tagging dirty and writeback pages in the pagecache. */
include/linux/lsm_hook_defs.h +5 -0
@@ -391,3 +391,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 +11 -0
@@ -1507,6 +1507,16 @@* * @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 the security property associated with @name for @bdev with +* value @value. @size indicates the size of the @value in bytes. +* * Security hooks for perf events * * @perf_event_open:
@@ -1553,6 +1563,7 @@ struct lsm_blob_sizes {int lbs_ipc;int lbs_msg_msg;int lbs_task; +int lbs_bdev; };/*
include/linux/security.h +22 -0
@@ -451,6 +451,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)
@@ -1291,6 +1296,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 +61 -0
91 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC PATCH v4 05/12] fs: add security blob and hooks for block_device
Quoted 223 lines · Deven Bowers
Add a security blob and associated allocation, deallocation and set hooks for a
block_devicestructure.Signed-off-by Deven Bowers <[email protected]>--- fs/block_dev.c | 8 +++++ include/linux/fs.h | 1 + include/linux/lsm_hook_defs.h | 5 +++ include/linux/lsm_hooks.h | 11 +++++++ include/linux/security.h | 22 +++++++++++++ security/security.c | 61 +++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+)fs/block_dev.c +8
-0@@ -34,6 +34,7 @@#include <linux/falloc.h> #include <linux/uaccess.h> #include <linux/suspend.h> +#include <linux/security.h> #include "internal.h" struct bdev_inode {@@ -768,11 +769,18 @@ static struct inode *bdev_alloc_inode(struct super_block *sb)struct bdev_inode *ei =kmem_cache_alloc (bdev_cachep,GFP_KERNEL );if (!ei)return NULL ; + +if (unlikely (security_bdev_alloc (&ei->bdev))) { +kmem_cache_free (bdev_cachep, ei); +return NULL ; + } +return &ei->vfs_inode; }static void bdev_free_inode (struct inode *inode) { +security_bdev_free (&BDEV_I (inode)->bdev);kmem_cache_free (bdev_cachep,BDEV_I (inode)); }include/linux/fs.h +1
-0@@ -509,6 +509,7 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; +void *security; } __randomize_layout;/* XArray tags, for tagging dirty and writeback pages in the pagecache. */ include/linux/lsm_hook_defs.h +5
-0@@ -391,3 +391,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 +11
-0@@ -1507,6 +1507,16 @@* * @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 the security property associated with @name for @bdev with +* value @value. @size indicates the size of the @value in bytes. +* * Security hooks for perf events * * @perf_event_open: @@ -1553,6 +1563,7 @@ struct lsm_blob_sizes {int lbs_ipc;int lbs_msg_msg;int lbs_task; +int lbs_bdev; };/* include/linux/security.h +22
-0@@ -451,6 +451,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)@@ -1291,6 +1296,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 +49
-0@@ -28,6 +28,7 @@#include <linux/string.h> #include <linux/msg.h> #include <net/flow.h> +#include <linux/fs.h> #define MAX_LSM_EVM_XATTR 2@@ -202,6 +203,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)lsm_set_blob_size (&needed->lbs_ipc, &blob_sizes.lbs_ipc);lsm_set_blob_size (&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);lsm_set_blob_size (&needed->lbs_task, &blob_sizes.lbs_task); +lsm_set_blob_size (&needed->lbs_bdev, &blob_sizes.lbs_bdev); }/* Prepare LSM for initialization. */ @@ -337,6 +339,7 @@ static void __init ordered_lsm_init(void)init_debug ("ipc blob size = %d\n" , blob_sizes.lbs_ipc);init_debug ("msg_msg blob size = %d\n" , blob_sizes.lbs_msg_msg);init_debug ("task blob size = %d\n" , blob_sizes.lbs_task); +init_debug ("bdev blob size = %d\n" , blob_sizes.lbs_bdev);/* * Create any kmem_caches needed for blobs @@ -654,6 +657,28 @@ static int lsm_msg_msg_alloc(struct msg_msg *mp)return 0 ; } +/** +* lsm_bdev_alloc - allocate a composite block_device blob +* @bdev: the block_device that needs a blob +* +* Allocate the block_device blob for all the modules +* +* Returns 0, or -ENOMEM if memory can't be allocated. +*/ +static int lsm_bdev_alloc (struct block_device *bdev) +{ +if (blob_sizes.lbs_bdev ==0 ) { + bdev->security =NULL ; +return 0 ; + } + + bdev->security =kzalloc (blob_sizes.lbs_bdev,GFP_KERNEL ); +if (!bdev->security) +return -ENOMEM ; + +return 0 ; +} +/** * lsm_early_task - during initialization allocate a composite task blob * @task: the task that needs a blob @@ -2516,6 +2541,42 @@ int security_locked_down(enum lockdown_reason what) }EXPORT_SYMBOL (security_locked_down); +int security_bdev_alloc (struct block_device *bdev) +{ +int rc =0 ; + + rc =lsm_bdev_alloc (bdev); +if (unlikely (rc)) +return rc; + + rc =call_int_hook (bdev_alloc_security,0 , bdev); +if (unlikely (rc)) +security_bdev_free (bdev); + +return 0 ; +} +EXPORT_SYMBOL (security_bdev_alloc); + +void security_bdev_free (struct block_device *bdev) +{ +if (!bdev->security) +return ; + +call_void_hook (bdev_free_security, bdev); + +kfree (bdev->security);
security/security.c int security_locked_down(enum lockdown_reason what) · line 2577
Quoted 10 lines
security/security.c +10
-0+ bdev->security =NULL ; +} +EXPORT_SYMBOL (security_bdev_free); + +int security_bdev_setsecurity (struct block_device *bdev, +const char *name,const void *value, +size_t size) +{ +return call_int_hook (bdev_setsecurity,0 , bdev, name, value, size); +}
What is your expectation regarding multiple security modules using the same @name? What do you expect a security module to do if it does not support a particular @name? You may have a case where SELinux supports a @name that AppArmor (or KSRI) doesn't. -ENOSYS may be you friend here.
Quoted 5 lines
security/security.c +2
-0+EXPORT_SYMBOL (security_bdev_setsecurity); +#ifdef CONFIG_PERF_EVENTS int security_perf_event_open (struct perf_event_attr *attr,int type) {
Re: [RFC PATCH v4 05/12] fs: add security blob and hooks for block_device
On 7/17/2020 5:14 PM, Casey Schaufler wrote:
[...snip]
Quoted 5 lines
Quoted 5 lines
security/security.c +5
-0+EXPORT_SYMBOL (security_bdev_free); + +int security_bdev_setsecurity (struct block_device *bdev, +const char *name,const void *value, +size_t size)
Quoted 9 lines
security/security.c int security_locked_down(enum lockdown_reason what) · line 2577
Quoted 3 lines
security/security.c +3
-0+{ +return call_int_hook (bdev_setsecurity,0 , bdev, name, value, size); +}What is your expectation regarding multiple security modules using the same @name? What do you expect a security module to do if it does not support a particular @name? You may have a case where SELinux supports a @name that AppArmor (or KSRI) doesn't.
-ENOSYSmay be you friend here.
I expect that some security modules may want to use the same @name / use the data contained with @name. I cannot speak to the future cases of other LSMs, but I expect if they want the raw @value, they'll copy it into their security blob, or interpret @value to a field defined by their security blob.
Originally, I expected a security module that does not implement a
particular @name no-op with return 0, not -ENOSYS, but I recognize that
error codes are valuable, and it's a trivial change - I'll switch the security hook to call the hooks while allowing -ENOSYS or 0 in the next iteration.
Quoted 5 lines
Quoted 5 lines
security/security.c +2
-0+EXPORT_SYMBOL (security_bdev_setsecurity); +#ifdef CONFIG_PERF_EVENTS int security_perf_event_open (struct perf_event_attr *attr,int type) {
RFC PATCH v4 6/12 dm-verity: move signature check after tree validation
In reply to Deven BowersThe CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG introduced by Jaskaran was intended to be used to allow an LSM to enforce verifications for all dm-verity volumes.
However, with it's current implementation, this signature verification occurs after the merkel-tree is validated, as a result the signature can pass initial verification by passing a matching root-hash and signature. This results in an unreadable block_device, but that has passed signature validation (and subsequently, would be marked as verified).
This change moves the signature verification to after the merkel-tree has finished validation.
--- drivers/md/dm-verity-target.c | 42 ++++----- drivers/md/dm-verity-verify-sig.c | 140 ++++++++++++++++++++++-------- drivers/md/dm-verity-verify-sig.h | 20 ++--- drivers/md/dm-verity.h | 2 +- 4 files changed, 132 insertions(+), 72 deletions(-)
drivers/md/dm-verity-target.c +18 -24
@@ -471,9 +471,9 @@ static int verity_verify_io(struct dm_verity_io *io)struct bvec_iter start;unsigned b;struct crypto_wait wait; +int r;for (b =0 ; b < io->n_blocks; b++) { -int r;sector_t cur_block = io->block + b;struct ahash_request *req =verity_io_hash_req (v, io);
@@ -530,6 +530,16 @@ static int verity_verify_io(struct dm_verity_io *io)return -EIO ; } +/* +* At this point, the merkel tree has finished validating. +* if signature was specified, validate the signature here. +*/ + r =verity_verify_root_hash (v); +if (r <0 ) { +DMERR_LIMIT ("signature mismatch" ); +return r; + } +return 0 ; }
@@ -728,7 +738,7 @@ static void verity_status(struct dm_target *ti, status_type_t type, args++;if (v->validated_blocks) args++; -if (v->signature_key_desc) +if (v->sig) args +=DM_VERITY_ROOT_HASH_VERIFICATION_OPTS ;if (!args)return ;
@@ -751,9 +761,9 @@ static void verity_status(struct dm_target *ti, status_type_t type,if (v->validated_blocks)DMEMIT (" " DM_VERITY_OPT_AT_MOST_ONCE ); sz =verity_fec_status_table (v, sz, result, maxlen); -if (v->signature_key_desc) +if (v->sig)DMEMIT (" " DM_VERITY_ROOT_HASH_VERIFICATION_OPT_SIG_KEY -" %s" , v->signature_key_desc); +" %s" , v->sig->signature_key_desc);break ; } }
@@ -819,7 +829,7 @@ static void verity_dtr(struct dm_target *ti)verity_fec_dtr (v); -kfree (v->signature_key_desc); +verity_verify_dtr (v);kfree (v); }
@@ -876,8 +886,7 @@ static int verity_alloc_zero_digest(struct dm_verity *v)return r; } -static int verity_parse_opt_args (struct dm_arg_set *as,struct dm_verity *v, -struct dm_verity_sig_opts *verify_args) +static int verity_parse_opt_args (struct dm_arg_set *as,struct dm_verity *v) {int r;unsigned argc;
@@ -927,9 +936,7 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,return r;continue ; }else if (verity_verify_is_sig_opt_arg (arg_name)) { - r =verity_verify_sig_parse_opt_args (as, v, - verify_args, - &argc, arg_name); + r =verity_verify_sig_parse_opt_args (as, v, &argc);if (r)return r;continue ;
@@ -960,7 +967,6 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,static int verity_ctr (struct dm_target *ti,unsigned argc,char **argv) {struct dm_verity *v; -struct dm_verity_sig_opts verify_args = {0 };struct dm_arg_set as;unsigned int num;unsigned long long num_ll;
@@ -1128,20 +1134,11 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) as.argc = argc; as.argv = argv; - r =verity_parse_opt_args (&as, v, &verify_args); + r =verity_parse_opt_args (&as, v);if (r <0 ) goto bad; } -/* Root hash signature is a optional parameter*/ - r =verity_verify_root_hash (root_hash_digest_to_validate, -strlen (root_hash_digest_to_validate), - verify_args.sig, - verify_args.sig_size); -if (r <0 ) { - ti->error ="Root hash verification failed" ; - goto bad; - } v->hash_per_block_bits =__fls ((1 << v->hash_dev_block_bits) / v->digest_size);
@@ -1207,13 +1204,10 @@ 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 )); -verity_verify_sig_opts_cleanup (&verify_args); -return 0 ; bad: -verity_verify_sig_opts_cleanup (&verify_args);verity_dtr (ti);return r;
drivers/md/dm-verity-verify-sig.c +104 -36
201 lines not on this page · raw message
drivers/md/dm-verity-verify-sig.h +9 -11
@@ -11,31 +11,30 @@#define DM_VERITY_ROOT_HASH_VERIFICATION "DM Verity Sig Verification"#define DM_VERITY_ROOT_HASH_VERIFICATION_OPT_SIG_KEY "root_hash_sig_key_desc" -struct dm_verity_sig_opts { +struct dm_verity_sig { +char *signature_key_desc;unsigned int sig_size;u8 *sig; +bool passed; };#ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG #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 (const struct dm_verity *v);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, -struct dm_verity_sig_opts *sig_opts, -unsigned int *argc,const char *arg_name); +unsigned int *argc); -void verity_verify_sig_opts_cleanup (struct dm_verity_sig_opts *sig_opts); +void verity_verify_dtr (struct dm_verity *v);#else #define DM_VERITY_ROOT_HASH_VERIFICATION_OPTS 0 -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 (const struct dm_verity *v) {return 0 ; }
@@ -46,13 +45,12 @@ 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, -struct dm_verity_sig_opts *sig_opts, -unsigned int *argc,const char *arg_name) +unsigned int *argc) {return -EINVAL ; } -void verity_verify_sig_opts_cleanup (struct dm_verity_sig_opts *sig_opts) +void verity_verify_dtr (struct dm_verity *v) { }
drivers/md/dm-verity.h +1 -1
@@ -64,7 +64,7 @@ struct dm_verity {struct dm_verity_fec *fec;/* forward error correction */ unsigned long *validated_blocks;/* bitset blocks validated */ -char *signature_key_desc;/* signature keyring reference */ +struct dm_verity_sig *sig;/* signature verification */ };struct dm_verity_io {
Signature · 1 line
2.27.0
kernel test robot
build botRe: [RFC PATCH v4 06/12] dm-verity: move signature check after tree validation
[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5] [cannot apply to security/next-testing next-20200717]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: i386-debian-10.3 (attached as .config) compiler: gcc-9 (Debian 9.3.0-14) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from drivers/md/dm-verity-target.c:18:
drivers/md/dm-verity-verify-sig.h:37:5: warning: no previous prototype for 'verity_verify_root_hash' [-Wmissing-prototypes]
37 | int verity_verify_root_hash(const struct dm_verity *v)
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/md/dm-verity-verify-sig.h:42:6: warning: no previous prototype for 'verity_verify_is_sig_opt_arg' [-Wmissing-prototypes]
42 | bool verity_verify_is_sig_opt_arg(const char *arg_name)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/md/dm-verity-verify-sig.h:47:5: warning: no previous prototype for 'verity_verify_sig_parse_opt_args' [-Wmissing-prototypes]
47 | int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/md/dm-verity-verify-sig.h:53:6: warning: no previous prototype for 'verity_verify_dtr' [-Wmissing-prototypes]
53 | void verity_verify_dtr(struct dm_verity *v)
| ^~~~~~~~~~~~~~~~~
drivers/md/dm-verity-target.c: In function 'verity_ctr':
drivers/md/dm-verity-target.c:988:8: warning: variable 'root_hash_digest_to_validate' set but not used [-Wunused-but-set-variable]
988 | char *root_hash_digest_to_validate;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/verity_verify_dtr +53 drivers/md/dm-verity-verify-sig.h
52
> 53 void verity_verify_dtr(struct dm_verity *v)
54 {
55 }
56 ---
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 v4 06/12] dm-verity: move signature check after tree validation
In reply to Deven Bowers[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5] [cannot apply to security/next-testing next-20200717]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: s390-randconfig-r015-20200717 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)
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
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
^
In file included from drivers/md/dm-verity-target.c:16:
In file included from drivers/md/dm-verity.h:14:
In file included from include/linux/dm-bufio.h:12:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
^
In file included from drivers/md/dm-verity-target.c:16:
In file included from drivers/md/dm-verity.h:14:
In file included from include/linux/dm-bufio.h:12:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
__fswab32(x))
^
In file included from drivers/md/dm-verity-target.c:16:
In file included from drivers/md/dm-verity.h:14:
In file included from include/linux/dm-bufio.h:12:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
In file included from drivers/md/dm-verity-target.c:18:
drivers/md/dm-verity-verify-sig.h:37:5: warning: no previous prototype for function 'verity_verify_root_hash' [-Wmissing-prototypes]
int verity_verify_root_hash(const struct dm_verity *v)
^
drivers/md/dm-verity-verify-sig.h:37:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int verity_verify_root_hash(const struct dm_verity *v)
^
static
drivers/md/dm-verity-verify-sig.h:42:6: warning: no previous prototype for function 'verity_verify_is_sig_opt_arg' [-Wmissing-prototypes]
bool verity_verify_is_sig_opt_arg(const char *arg_name)
^
drivers/md/dm-verity-verify-sig.h:42:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
bool verity_verify_is_sig_opt_arg(const char *arg_name)
^
static
drivers/md/dm-verity-verify-sig.h:47:5: warning: no previous prototype for function 'verity_verify_sig_parse_opt_args' [-Wmissing-prototypes]
int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
^
drivers/md/dm-verity-verify-sig.h:47:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
^
static
>> drivers/md/dm-verity-verify-sig.h:53:6: warning: no previous prototype for function 'verity_verify_dtr' [-Wmissing-prototypes]
void verity_verify_dtr(struct dm_verity *v)
^ drivers/md/dm-verity-verify-sig.h:53:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void verity_verify_dtr(struct dm_verity *v)
^
static
24 warnings generated.
vim +/verity_verify_dtr +53 drivers/md/dm-verity-verify-sig.h
46
> 47 int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
48 unsigned int *argc)
49 {
50 return -EINVAL;
51 }
52
> 53 void verity_verify_dtr(struct dm_verity *v)
54 {
55 }
56 ---
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 v4 06/12] dm-verity: move signature check after tree validation
In reply to Deven Bowers[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5] [cannot apply to security/next-testing next-20200717]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from arch/m68k/include/asm/io_mm.h:25,
from arch/m68k/include/asm/io.h:8,
from include/linux/io.h:13,
from include/linux/irq.h:20,
from include/asm-generic/hardirq.h:13,
from ./arch/m68k/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:10,
from include/linux/highmem.h:10,
from include/linux/pagemap.h:11,
from include/linux/blkdev.h:16,
from include/linux/dm-bufio.h:12,
from drivers/md/dm-verity.h:14,
from drivers/md/dm-verity-target.c:16:
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsb':
arch/m68k/include/asm/raw_io.h:83:7: warning: variable '__w' set but not used [-Wunused-but-set-variable]
83 | ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:430:3: note: in expansion of macro 'rom_out_8'
430 | rom_out_8(port, *buf++);
| ^~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw':
arch/m68k/include/asm/raw_io.h:86:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
86 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:448:3: note: in expansion of macro 'rom_out_be16'
448 | rom_out_be16(port, *buf++);
| ^~~~~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw_swapw':
arch/m68k/include/asm/raw_io.h:90:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
90 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:466:3: note: in expansion of macro 'rom_out_le16'
466 | rom_out_le16(port, *buf++);
| ^~~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/rculist.h:10,
from include/linux/pid.h:5,
from include/linux/sched.h:14,
from include/linux/blkdev.h:5,
from include/linux/dm-bufio.h:12,
from drivers/md/dm-verity.h:14,
from drivers/md/dm-verity-target.c:16:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/md/dm-verity-target.c: In function 'verity_ctr':
>> drivers/md/dm-verity-target.c:988:8: warning: variable 'root_hash_digest_to_validate' set but not used [-Wunused-but-set-variable]
988 | char *root_hash_digest_to_validate;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/root_hash_digest_to_validate +988 drivers/md/dm-verity-target.c
753c1fd02807cb drivers/md/dm-verity.c Sami Tolvanen 2015-11-05 963
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 964 /*
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 965 * Target parameters:
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 966 * <version> The current format is version 1.
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 967 * Vsn 0 is compatible with original Chromium OS releases.
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 968 * <data device>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 969 * <hash device>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 970 * <data block size>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 971 * <hash block size>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 972 * <the number of data blocks>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 973 * <hash start block>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 974 * <algorithm>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 975 * <digest>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 976 * <salt> Hex string or "-" if no salt.
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 977 */
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 978 static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 979 {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 980 struct dm_verity *v;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 981 struct dm_arg_set as;
753c1fd02807cb drivers/md/dm-verity.c Sami Tolvanen 2015-11-05 982 unsigned int num;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 983 unsigned long long num_ll;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 984 int r;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 985 int i;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 986 sector_t hash_position;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 987 char dummy;
88cd3e6cfac915 drivers/md/dm-verity-target.c Jaskaran Khurana 2019-07-17 @988 char *root_hash_digest_to_validate;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 989
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 990 v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 991 if (!v) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 992 ti->error = "Cannot allocate verity structure";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 993 return -ENOMEM;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 994 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 995 ti->private = v;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 996 v->ti = ti;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 997
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 998 r = verity_fec_ctr_alloc(v);
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 999 if (r)
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1000 goto bad;
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1001
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1002 if ((dm_table_get_mode(ti->table) & ~FMODE_READ)) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1003 ti->error = "Device must be readonly";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1004 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1005 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1006 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1007
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1008 if (argc < 10) {
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1009 ti->error = "Not enough arguments";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1010 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1011 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1012 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1013
5d8be84397618a drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1014 if (sscanf(argv[0], "%u%c", &num, &dummy) != 1 ||
5d8be84397618a drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1015 num > 1) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1016 ti->error = "Invalid version";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1017 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1018 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1019 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1020 v->version = num;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1021
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1022 r = dm_get_device(ti, argv[1], FMODE_READ, &v->data_dev);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1023 if (r) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1024 ti->error = "Data device lookup failed";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1025 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1026 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1027
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1028 r = dm_get_device(ti, argv[2], FMODE_READ, &v->hash_dev);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1029 if (r) {
21ffe552e9cd9f drivers/md/dm-verity-target.c Eric Biggers 2016-09-08 1030 ti->error = "Hash device lookup failed";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1031 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1032 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1033
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1034 if (sscanf(argv[3], "%u%c", &num, &dummy) != 1 ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1035 !num || (num & (num - 1)) ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1036 num < bdev_logical_block_size(v->data_dev->bdev) ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1037 num > PAGE_SIZE) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1038 ti->error = "Invalid data device block size";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1039 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1040 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1041 }
553d8fe029a561 drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1042 v->data_dev_block_bits = __ffs(num);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1043
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1044 if (sscanf(argv[4], "%u%c", &num, &dummy) != 1 ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1045 !num || (num & (num - 1)) ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1046 num < bdev_logical_block_size(v->hash_dev->bdev) ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1047 num > INT_MAX) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1048 ti->error = "Invalid hash device block size";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1049 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1050 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1051 }
553d8fe029a561 drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1052 v->hash_dev_block_bits = __ffs(num);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1053
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1054 if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 ||
1d55f6bcc0331d drivers/md/dm-verity.c Mikulas Patocka 2012-09-26 1055 (sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT))
1d55f6bcc0331d drivers/md/dm-verity.c Mikulas Patocka 2012-09-26 1056 >> (v->data_dev_block_bits - SECTOR_SHIFT) != num_ll) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1057 ti->error = "Invalid data blocks";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1058 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1059 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1060 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1061 v->data_blocks = num_ll;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1062
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1063 if (ti->len > (v->data_blocks << (v->data_dev_block_bits - SECTOR_SHIFT))) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1064 ti->error = "Data device is too small";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1065 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1066 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1067 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1068
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1069 if (sscanf(argv[6], "%llu%c", &num_ll, &dummy) != 1 ||
1d55f6bcc0331d drivers/md/dm-verity.c Mikulas Patocka 2012-09-26 1070 (sector_t)(num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT))
1d55f6bcc0331d drivers/md/dm-verity.c Mikulas Patocka 2012-09-26 1071 >> (v->hash_dev_block_bits - SECTOR_SHIFT) != num_ll) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1072 ti->error = "Invalid hash start";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1073 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1074 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1075 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1076 v->hash_start = num_ll;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1077
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1078 v->alg_name = kstrdup(argv[7], GFP_KERNEL);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1079 if (!v->alg_name) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1080 ti->error = "Cannot allocate algorithm name";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1081 r = -ENOMEM;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1082 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1083 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1084
d1ac3ff008fb9a drivers/md/dm-verity-target.c Gilad Ben-Yossef 2017-02-19 1085 v->tfm = crypto_alloc_ahash(v->alg_name, 0, 0);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1086 if (IS_ERR(v->tfm)) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1087 ti->error = "Cannot initialize hash function";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1088 r = PTR_ERR(v->tfm);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1089 v->tfm = NULL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1090 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1091 }
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1092
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1093 /*
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1094 * dm-verity performance can vary greatly depending on which hash
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1095 * algorithm implementation is used. Help people debug performance
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1096 * problems by logging the ->cra_driver_name.
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1097 */
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1098 DMINFO("%s using implementation \"%s\"", v->alg_name,
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1099 crypto_hash_alg_common(v->tfm)->base.cra_driver_name);
bbf6a566920e1b drivers/md/dm-verity-target.c Eric Biggers 2018-12-05 1100
d1ac3ff008fb9a drivers/md/dm-verity-target.c Gilad Ben-Yossef 2017-02-19 1101 v->digest_size = crypto_ahash_digestsize(v->tfm);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1102 if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1103 ti->error = "Digest size too big";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1104 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1105 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1106 }
d1ac3ff008fb9a drivers/md/dm-verity-target.c Gilad Ben-Yossef 2017-02-19 1107 v->ahash_reqsize = sizeof(struct ahash_request) +
d1ac3ff008fb9a drivers/md/dm-verity-target.c Gilad Ben-Yossef 2017-02-19 1108 crypto_ahash_reqsize(v->tfm);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1109
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1110 v->root_digest = kmalloc(v->digest_size, GFP_KERNEL);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1111 if (!v->root_digest) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1112 ti->error = "Cannot allocate root digest";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1113 r = -ENOMEM;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1114 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1115 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1116 if (strlen(argv[8]) != v->digest_size * 2 ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1117 hex2bin(v->root_digest, argv[8], v->digest_size)) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1118 ti->error = "Invalid root digest";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1119 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1120 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1121 }
88cd3e6cfac915 drivers/md/dm-verity-target.c Jaskaran Khurana 2019-07-17 1122 root_hash_digest_to_validate = argv[8];
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1123
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1124 if (strcmp(argv[9], "-")) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1125 v->salt_size = strlen(argv[9]) / 2;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1126 v->salt = kmalloc(v->salt_size, GFP_KERNEL);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1127 if (!v->salt) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1128 ti->error = "Cannot allocate salt";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1129 r = -ENOMEM;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1130 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1131 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1132 if (strlen(argv[9]) != v->salt_size * 2 ||
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1133 hex2bin(v->salt, argv[9], v->salt_size)) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1134 ti->error = "Invalid salt";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1135 r = -EINVAL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1136 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1137 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1138 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1139
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1140 argv += 10;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1141 argc -= 10;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1142
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1143 /* Optional parameters */
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1144 if (argc) {
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1145 as.argc = argc;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1146 as.argv = argv;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1147
03b608829d1182 drivers/md/dm-verity-target.c Deven Bowers 2020-07-17 1148 r = verity_parse_opt_args(&as, v);
753c1fd02807cb drivers/md/dm-verity.c Sami Tolvanen 2015-11-05 1149 if (r < 0)
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1150 goto bad;
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1151 }
65ff5b7ddf0541 drivers/md/dm-verity.c Sami Tolvanen 2015-03-18 1152
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1153 v->hash_per_block_bits =
553d8fe029a561 drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1154 __fls((1 << v->hash_dev_block_bits) / v->digest_size);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1155
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1156 v->levels = 0;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1157 if (v->data_blocks)
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1158 while (v->hash_per_block_bits * v->levels < 64 &&
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1159 (unsigned long long)(v->data_blocks - 1) >>
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1160 (v->hash_per_block_bits * v->levels))
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1161 v->levels++;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1162
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1163 if (v->levels > DM_VERITY_MAX_LEVELS) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1164 ti->error = "Too many tree levels";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1165 r = -E2BIG;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1166 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1167 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1168
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1169 hash_position = v->hash_start;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1170 for (i = v->levels - 1; i >= 0; i--) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1171 sector_t s;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1172 v->hash_level_block[i] = hash_position;
b1bf2de0727193 drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1173 s = (v->data_blocks + ((sector_t)1 << ((i + 1) * v->hash_per_block_bits)) - 1)
b1bf2de0727193 drivers/md/dm-verity.c Mikulas Patocka 2013-07-10 1174 >> ((i + 1) * v->hash_per_block_bits);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1175 if (hash_position + s < hash_position) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1176 ti->error = "Hash device offset overflow";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1177 r = -E2BIG;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1178 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1179 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1180 hash_position += s;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1181 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1182 v->hash_blocks = hash_position;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1183
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1184 v->bufio = dm_bufio_client_create(v->hash_dev->bdev,
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1185 1 << v->hash_dev_block_bits, 1, sizeof(struct buffer_aux),
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1186 dm_bufio_alloc_callback, NULL);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1187 if (IS_ERR(v->bufio)) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1188 ti->error = "Cannot initialize dm-bufio";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1189 r = PTR_ERR(v->bufio);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1190 v->bufio = NULL;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1191 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1192 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1193
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1194 if (dm_bufio_get_device_size(v->bufio) < v->hash_blocks) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1195 ti->error = "Hash device is too small";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1196 r = -E2BIG;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1197 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1198 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1199
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1200 /* WQ_UNBOUND greatly improves performance when running on ramdisk */
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1201 v->verify_wq = alloc_workqueue("kverityd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND, num_online_cpus());
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1202 if (!v->verify_wq) {
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1203 ti->error = "Cannot allocate workqueue";
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1204 r = -ENOMEM;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1205 goto bad;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1206 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1207
30187e1d48a258 drivers/md/dm-verity-target.c Mike Snitzer 2016-01-31 1208 ti->per_io_data_size = sizeof(struct dm_verity_io) +
d1ac3ff008fb9a drivers/md/dm-verity-target.c Gilad Ben-Yossef 2017-02-19 1209 v->ahash_reqsize + v->digest_size * 2;
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1210
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1211 r = verity_fec_ctr(v);
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1212 if (r)
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1213 goto bad;
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1214
30187e1d48a258 drivers/md/dm-verity-target.c Mike Snitzer 2016-01-31 1215 ti->per_io_data_size = roundup(ti->per_io_data_size,
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1216 __alignof__(struct dm_verity_io));
a739ff3f543afb drivers/md/dm-verity-target.c Sami Tolvanen 2015-12-03 1217
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1218 return 0;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1219
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1220 bad:
88cd3e6cfac915 drivers/md/dm-verity-target.c Jaskaran Khurana 2019-07-17 1221
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1222 verity_dtr(ti);
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1223
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1224 return r;
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1225 }
a4ffc152198efb drivers/md/dm-verity.c Mikulas Patocka 2012-03-28 1226 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v4 7/12 dm-verity: add bdev_setsecurity hook for dm-verity signature
In reply to Deven BowersAdd a security hook call to set a security property of a block_device in dm-verity with the results of a verified, signed root-hash.
--- drivers/md/dm-verity-verify-sig.c | 7 +++++++ include/linux/device-mapper.h | 2 ++ 2 files changed, 9 insertions(+)
drivers/md/dm-verity-verify-sig.c +7 -0
@@ -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"
@@ -182,6 +185,10 @@ int verity_verify_root_hash(const struct dm_verity *v) goto cleanup; sig_target->passed = true; + + ret =security_bdev_setsecurity (dm_table_get_md (v->ti->table)->bdev, +DM_VERITY_SIGNATURE_SEC_NAME , + v->sig->sig, v->sig->sig_size); cleanup:kfree (root_hash);return ret;
include/linux/device-mapper.h +2 -0
@@ -624,4 +624,6 @@ static inline unsigned long to_bytes(sector_t n) return (n << SECTOR_SHIFT); } +#define DM_VERITY_SIGNATURE_SEC_NAME DM_NAME ".verity-sig" +#endif /* _LINUX_DEVICE_MAPPER_H */
Signature · 1 line
2.27.0
RFC PATCH v4 8/12 ipe: add property for signed dmverity volumes
In reply to Deven BowersAllow IPE to leverage the stacked security blob infrastructure, and enlighten IPE to the block_device security blob.
This allows IPE to have a property to express rules around a device-mapper verity volume whose root-hash has been signed, and the signature has been verified against the system keyring. This is property is also added in this patch.
--- security/ipe/Kconfig | 2 +- security/ipe/Makefile | 1 + security/ipe/ipe-blobs.c | 82 ++++++++++++++++++++ security/ipe/ipe-blobs.h | 18 +++++ security/ipe/ipe-engine.c | 4 + security/ipe/ipe-engine.h | 9 +++ security/ipe/ipe-hooks.c | 1 + security/ipe/ipe-hooks.h | 7 ++ security/ipe/ipe.c | 18 +++++ security/ipe/ipe.h | 2 + security/ipe/properties/Kconfig | 10 +++ security/ipe/properties/Makefile | 1 + security/ipe/properties/dmverity-signature.c | 82 ++++++++++++++++++++ security/ipe/properties/prop-entry.h | 9 +++ security/ipe/utility.h | 10 +++ 15 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 security/ipe/ipe-blobs.c create mode 100644 security/ipe/ipe-blobs.h create mode 100644 security/ipe/properties/dmverity-signature.c
security/ipe/Kconfig +1 -1
@@ -5,7 +5,7 @@ menuconfig SECURITY_IPE bool "Integrity Policy Enforcement (IPE)" - depends on SECURITY && AUDIT + depends on SECURITY && AUDIT && BLOCK select SYSTEM_DATA_VERIFICATION select SECURITYFS select CRYPTO_SHA1
security/ipe/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_SECURITY_IPE) += \ ipe-property.o \ ipe-hooks.o \ ipe-secfs.o \ + ipe-blobs.o \ clean-files := ipe-bp.c
security/ipe/ipe-blobs.c new file +82 -0
82 lines not on this page · raw message
security/ipe/ipe-blobs.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) Microsoft Corporation. All rights reserved. +*/ +#include <linux/types.h> +#include <linux/fs.h> + +#include "ipe.h" + +#ifndef IPE_BLOB_H +#define IPE_BLOB_H + +static inline struct ipe_bdev_blob *ipe_bdev (struct block_device *bdev) +{ +return bdev->security + ipe_blobs.lbs_bdev; +} + +#endif /* IPE_BLOB_H */
security/ipe/ipe-engine.c +4 -0
@@ -10,6 +10,7 @@#include "ipe-engine.h" #include "ipe-audit.h" #include "ipe-pin.h" +#include "ipe-blobs.h" #include "utility.h" #include <linux/types.h>
@@ -116,6 +117,9 @@ static struct ipe_engine_ctx *build_ctx(const struct file *file, local->op = op; local->hook = hook; +if (has_bdev (file)) + local->sec_bdev =ipe_bdev (bdev (file)); +return local; }
security/ipe/ipe-engine.h +9 -0
@@ -3,20 +3,29 @@* Copyright (C) Microsoft Corporation. All rights reserved. */ +#include "ipe.h" #include "ipe-hooks.h" #include <linux/types.h> #include <linux/rbtree.h> #include <linux/fs.h> +#include <crypto/pkcs7.h> +#ifndef IPE_ENGINE_H #define IPE_ENGINE_H +struct ipe_bdev_blob { +u8 *dmverity_rh_sig; +size_t dmv_rh_sig_len; +}; +struct ipe_engine_ctx {enum ipe_op op;enum ipe_hook hook;const struct file *file;const char *audit_pathname; +const struct ipe_bdev_blob *sec_bdev; }; struct ipe_prop_cache {
security/ipe/ipe-hooks.c +1 -0
@@ -15,6 +15,7 @@#include <linux/mman.h> #include <linux/mm.h> #include <linux/security.h> +#include <linux/device-mapper.h> /** * ipe_on_exec: LSM hook called on the exec family of system calls.
security/ipe/ipe-hooks.h +7 -0
@@ -60,4 +60,11 @@ int ipe_on_kernel_load_data(enum kernel_load_data_id id);void ipe_sb_free_security (struct super_block *mnt_sb); +int ipe_bdev_alloc_security (struct block_device *bdev); + +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_HOOK_H */
security/ipe/ipe.c +18 -0
@@ -24,6 +24,9 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (kernel_load_data, ipe_on_kernel_load_data),LSM_HOOK_INIT (file_mprotect, ipe_on_mprotect),LSM_HOOK_INIT (sb_free_security, ipe_sb_free_security), +LSM_HOOK_INIT (bdev_alloc_security, ipe_bdev_alloc_security), +LSM_HOOK_INIT (bdev_free_security, ipe_bdev_free_security), + LSM_HOOK_INIT(bdev_setsecurity, ipe_bdev_setsecurity), };/**
@@ -41,6 +44,10 @@ static int __init ipe_load_properties(void)if (rc !=0 )return rc; + rc =ipe_init_dm_verity_signature (); +if (rc !=0 ) +return rc; +return rc; }
@@ -73,9 +80,20 @@ static int __init ipe_init(void)return rc; } +struct lsm_blob_sizes ipe_blobs = { + .lbs_cred =0 , + .lbs_file =0 , + .lbs_inode =0 , + .lbs_ipc =0 , + .lbs_msg_msg =0 , + .lbs_task =0 , + .lbs_bdev =sizeof (struct ipe_bdev_blob ), +}; +DEFINE_LSM (ipe) = { .name ="ipe" , .init = ipe_init, + .blobs = &ipe_blobs, };bool ipe_enforce = true;
security/ipe/ipe.h +2 -0
@@ -10,11 +10,13 @@#include <linux/types.h> #include <linux/fs.h> +#include <linux/lsm_hooks.h> #define IPE_MODE_ENFORCE "enforce"#define IPE_MODE_PERMISSIVE "permissive"extern bool ipe_enforce;extern bool ipe_success_audit; +extern struct lsm_blob_sizes ipe_blobs;#endif /* IPE_H */
security/ipe/properties/Kconfig +10 -0
@@ -13,3 +13,13 @@ config IPE_BOOT_PROP superblock. if unsure, answer N. + +config IPE_DM_VERITY_SIGNATURE + bool "Enable property for signature verified dm-verity volumes" + depends on DM_VERITY_VERIFY_ROOTHASH_SIG + help + This option enables IPE's integration with Device-Mapper Verity's + signed root-hashes. This enables the usage of the property, + "dmverity_signature" in IPE's policy. + + if unsure, answer Y.
security/ipe/properties/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_SECURITY_IPE) += properties.o properties-$(CONFIG_IPE_BOOT_PROP) += boot-verified.o +properties-$(CONFIG_IPE_DM_VERITY_SIGNATURE) += dmverity-signature.o
security/ipe/properties/dmverity-signature.c new file +82 -0
82 lines not on this page · raw message
security/ipe/properties/prop-entry.h +9 -0
@@ -17,4 +17,13 @@ static inline int __init ipe_init_bootv(void)int __init ipe_init_bootv (void );#endif /* CONFIG_IPE_BOOT_PROP */ +#ifndef CONFIG_IPE_DM_VERITY_SIGNATURE +static inline int __init ipe_init_dm_verity_signature (void ) +{ +return 0 ; +} +#else +int __init ipe_init_dm_verity_signature (void ); +#endif /* CONFIG_IPE_DM_VERITY_SIGNATURE */ +#endif /* IPE_PROP_ENTRY_H */
security/ipe/utility.h +10 -0
@@ -19,4 +19,14 @@ static inline bool has_sb(const struct file *file) return has_mount(file) && file->f_path.mnt->mnt_sb; } +static inline bool has_bdev (const struct file *file) +{ +return has_sb (file) && file->f_path.mnt->mnt_sb->s_bdev; +} + +static inline struct block_device *bdev (const struct file *file) +{ +return file->f_path.mnt->mnt_sb->s_bdev; +} +#endif /* IPE_UTILITY_H */
Signature · 1 line
2.27.0
kernel test robot
build botRe: [RFC PATCH v4 08/12] ipe: add property for signed dmverity volumes
[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 Deven,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on dm/for-next]
[also build test WARNING on pcmoore-selinux/next linus/master v5.8-rc5] [cannot apply to security/next-testing next-20200717]
[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-Bowers/Integrity-Policy-Enforcement-LSM-IPE/20200718-071232 base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from arch/m68k/include/asm/io_mm.h:25,
from arch/m68k/include/asm/io.h:8,
from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:11,
from include/linux/skbuff.h:31,
from include/linux/lsm_audit.h:24,
from security/ipe/properties/../ipe-property.h:9,
from security/ipe/properties/dmverity-signature.c:8:
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsb':
arch/m68k/include/asm/raw_io.h:83:7: warning: variable '__w' set but not used [-Wunused-but-set-variable]
83 | ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:430:3: note: in expansion of macro 'rom_out_8'
430 | rom_out_8(port, *buf++);
| ^~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw':
arch/m68k/include/asm/raw_io.h:86:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
86 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:448:3: note: in expansion of macro 'rom_out_be16'
448 | rom_out_be16(port, *buf++);
| ^~~~~~~~~~~~
arch/m68k/include/asm/raw_io.h: In function 'raw_rom_outsw_swapw':
arch/m68k/include/asm/raw_io.h:90:8: warning: variable '__w' set but not used [-Wunused-but-set-variable]
90 | ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
| ^~~
arch/m68k/include/asm/raw_io.h:466:3: note: in expansion of macro 'rom_out_le16'
466 | rom_out_le16(port, *buf++);
| ^~~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/properties/../ipe.h:12,
from security/ipe/properties/dmverity-signature.c:6:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
In file included from arch/m68k/include/asm/bug.h:32,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/preempt.h:5,
from ./arch/m68k/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from security/ipe/properties/../ipe.h:12,
from security/ipe/properties/dmverity-signature.c:6:
include/linux/dma-mapping.h: In function 'dma_map_resource':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/asm-generic/bug.h:144:27: note: in definition of macro 'WARN_ON_ONCE'
144 | int __ret_warn_once = !!(condition); \
| ^~~~~~~~~
arch/m68k/include/asm/page_mm.h:170:25: note: in expansion of macro 'virt_addr_valid'
170 | #define pfn_valid(pfn) virt_addr_valid(pfn_to_virt(pfn))
| ^~~~~~~~~~~~~~~
include/linux/dma-mapping.h:352:19: note: in expansion of macro 'pfn_valid'
352 | if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
| ^~~~~~~~~
security/ipe/properties/dmverity-signature.c: At top level:
>> security/ipe/properties/dmverity-signature.c:79:5: warning: no previous prototype for 'ipe_init_dm_verity_signature' [-Wmissing-prototypes] 79 | int ipe_init_dm_verity_signature(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/ipe_init_dm_verity_signature +79 security/ipe/properties/dmverity-signature.c
78 > 79 int ipe_init_dm_verity_signature(void)
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v4 9/12 dm-verity: add bdev_setsecurity hook for root-hash
In reply to Deven BowersAdd a security hook call to set a security property of a block_device in dm-verity with the root-hash that was verified to match the merkel-tree.
--- drivers/md/dm-verity-target.c | 8 ++++++++ include/linux/device-mapper.h | 1 + 2 files changed, 9 insertions(+)
drivers/md/dm-verity-target.c +8 -0
@@ -16,8 +16,10 @@#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"
@@ -530,6 +532,12 @@ static int verity_verify_io(struct dm_verity_io *io)return -EIO ; } + r =security_bdev_setsecurity (dm_table_get_md (v->ti->table)->bdev, +DM_VERITY_ROOTHASH_SEC_NAME , + v->root_digest, v->digest_size); +if (unlikely (r <0 )) +return r; +/* * At this point, the merkel tree has finished validating. * if signature was specified, validate the signature here.
include/linux/device-mapper.h +1 -0
@@ -625,5 +625,6 @@ static inline unsigned long to_bytes(sector_t n) }#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 */
Signature · 1 line
2.27.0
RFC PATCH v4 10/12 ipe: add property for dmverity roothash
In reply to Deven BowersAdd a property to allow IPE policy to express rules around a specific root-hash of a dm-verity volume.
This can be used for revocation, (when combined with the previous dm-verity property) or the authorization of a single dm-verity volume.
--- security/ipe/ipe-blobs.c | 9 ++ security/ipe/ipe-engine.h | 3 + security/ipe/ipe.c | 4 + security/ipe/properties/Kconfig | 13 +- security/ipe/properties/Makefile | 1 + security/ipe/properties/dmverity-roothash.c | 153 ++++++++++++++++++++ security/ipe/properties/prop-entry.h | 9 ++ 7 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 security/ipe/properties/dmverity-roothash.c
security/ipe/ipe-blobs.c +9 -0
@@ -46,6 +46,7 @@ void ipe_bdev_free_security(struct block_device *bdev)struct ipe_bdev_blob *bdev_sec =ipe_bdev (bdev);kfree (bdev_sec->dmverity_rh_sig); +kfree (bdev_sec->dmverity_rh);memset (bdev_sec,0x0 ,sizeof (*bdev_sec)); }
@@ -78,5 +79,13 @@ int ipe_bdev_setsecurity(struct block_device *bdev, const char *key, bdev_sec->dmv_rh_sig_len = len; } +if (!strcmp (key,DM_VERITY_ROOTHASH_SEC_NAME )) { + bdev_sec->dmverity_rh =kmemdup (value, len,GFP_KERNEL ); +if (!bdev_sec->dmverity_rh) +return -ENOMEM ; + + bdev_sec->rh_size = len; + } +return 0 ; }
security/ipe/ipe-engine.h +3 -0
@@ -18,6 +18,9 @@struct ipe_bdev_blob {u8 *dmverity_rh_sig;size_t dmv_rh_sig_len; + +u8 *dmverity_rh; +size_t rh_size; };struct ipe_engine_ctx {
security/ipe/ipe.c +4 -0
@@ -48,6 +48,10 @@ static int __init ipe_load_properties(void)if (rc !=0 )return rc; + rc =ipe_init_dm_verity_rh (); +if (rc !=0 ) +return rc; +return rc; }
security/ipe/properties/Kconfig +12 -1
@@ -14,8 +14,19 @@ config IPE_BOOT_PROP if unsure, answer N. +config IPE_DM_VERITY_ROOTHASH + bool "Enable property for authorizing dm-verity volumes via root-hash" + depends on DM_VERITY + help + This option enables IPE's integration with Device-Mapper Verity. + This enables the usage of the property "dmverity_roothash" in IPE's + policy. This property allows authorization or revocation via a + a hex-string representing the roothash of a dmverity volume. + + if unsure, answer Y. + config IPE_DM_VERITY_SIGNATURE - bool "Enable property for signature verified dm-verity volumes" + bool "Enable property for verified dm-verity volumes" depends on DM_VERITY_VERIFY_ROOTHASH_SIG help This option enables IPE's integration with Device-Mapper Verity's
security/ipe/properties/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_SECURITY_IPE) += properties.o properties-$(CONFIG_IPE_BOOT_PROP) += boot-verified.o properties-$(CONFIG_IPE_DM_VERITY_SIGNATURE) += dmverity-signature.o +properties-$(CONFIG_IPE_DM_VERITY_ROOTHASH) += dmverity-roothash.o
security/ipe/properties/dmverity-roothash.c new file +153 -0
153 lines not on this page · raw message
security/ipe/properties/prop-entry.h +9 -0
@@ -26,4 +26,13 @@ static inline int __init ipe_init_dm_verity_signature(void)int __init ipe_init_dm_verity_signature (void );#endif /* CONFIG_IPE_DM_VERITY_SIGNATURE */ +#ifndef CONFIG_IPE_DM_VERITY_ROOTHASH +static inline int __init ipe_init_dm_verity_rh (void ) +{ +return 0 ; +} +#else +int __init ipe_init_dm_verity_rh (void ); +#endif /* CONFIG_IPE_DM_VERITY_ROOTHASH */ +#endif /* IPE_PROP_ENTRY_H */
Signature · 1 line
2.27.0
RFC PATCH v4 11/12 documentation: add ipe documentation
In reply to Deven BowersAdd IPE's documentation to the kernel tree.
--- Documentation/admin-guide/LSM/index.rst | 1 + Documentation/admin-guide/LSM/ipe.rst | 508 ++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 510 insertions(+) create mode 100644 Documentation/admin-guide/LSM/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 +508 -0
508 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -8584,6 +8584,7 @@ INTEGRITY POLICY ENFORCEMENT (IPE) M: Deven Bowers <[email protected]> L: [email protected] S: Supported +F: Documentation/admin-guide/LSM/ipe.rst F: scripts/ipe/ F: security/ipe/
Signature · 1 line
2.27.0
RFC PATCH v4 12/12 cleanup: uapi/linux/audit.h
In reply to Deven BowersRemove trailing whitespaces and align the integrity #defines in linux/uapi/audit.h
--- include/uapi/linux/audit.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
include/uapi/linux/audit.h +16 -16
@@ -48,7 +48,7 @@* 2500 - 2999 future user space (maybe integrity labels and related events) * * Messages from 1000-1199 are bi-directional. 1200-1299 & 2100 - 2999 are -* exclusively user space. 1300-2099 is kernel --> user space +* exclusively user space. 1300-2099 is kernel --> user space * communication. */ #define AUDIT_GET 1000/* Get status */
@@ -78,7 +78,7 @@#define AUDIT_LAST_USER_MSG 1199#define AUDIT_FIRST_USER_MSG2 2100/* More user space messages */ #define AUDIT_LAST_USER_MSG2 2999 - +#define AUDIT_DAEMON_START 1200/* Daemon startup record */ #define AUDIT_DAEMON_END 1201/* Daemon normal stop record */ #define AUDIT_DAEMON_ABORT 1202/* Daemon error stop record */
@@ -140,20 +140,20 @@#define AUDIT_MAC_CALIPSO_ADD 1418/* NetLabel: add CALIPSO DOI entry */ #define AUDIT_MAC_CALIPSO_DEL 1419/* NetLabel: del CALIPSO DOI entry */ -#define AUDIT_FIRST_KERN_ANOM_MSG 1700 -#define AUDIT_LAST_KERN_ANOM_MSG 1799 -#define AUDIT_ANOM_PROMISCUOUS 1700/* Device changed promiscuous mode */ -#define AUDIT_ANOM_ABEND 1701/* Process ended abnormally */ -#define AUDIT_ANOM_LINK 1702/* Suspicious use of file links */ -#define AUDIT_ANOM_CREAT 1703/* Suspicious file creation */ -#define AUDIT_INTEGRITY_DATA 1800/* Data integrity verification */ -#define AUDIT_INTEGRITY_METADATA 1801/* Metadata integrity verification */ -#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ -#define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ -#define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ -#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ -#define AUDIT_INTEGRITY_EVM_XATTR 1806/* New EVM-covered xattr */ -#define AUDIT_INTEGRITY_POLICY_RULE 1807/* IMA policy rules */ +#define AUDIT_FIRST_KERN_ANOM_MSG 1700 +#define AUDIT_LAST_KERN_ANOM_MSG 1799 +#define AUDIT_ANOM_PROMISCUOUS 1700/* Device changed promiscuous mode */ +#define AUDIT_ANOM_ABEND 1701/* Process ended abnormally */ +#define AUDIT_ANOM_LINK 1702/* Suspicious use of file links */ +#define AUDIT_ANOM_CREAT 1703/* Suspicious file creation */ +#define AUDIT_INTEGRITY_DATA 1800/* Data integrity verification */ +#define AUDIT_INTEGRITY_METADATA 1801/* Metadata integrity verification */ +#define AUDIT_INTEGRITY_STATUS 1802/* Integrity enable status */ +#define AUDIT_INTEGRITY_HASH 1803/* Integrity HASH type */ +#define AUDIT_INTEGRITY_PCR 1804/* PCR invalidation msgs */ +#define AUDIT_INTEGRITY_RULE 1805/* policy rule */ +#define AUDIT_INTEGRITY_EVM_XATTR 1806/* New EVM-covered xattr */ +#define AUDIT_INTEGRITY_POLICY_RULE 1807/* IMA policy rules */ #define AUDIT_INTEGRITY_POLICY_LOAD 1808/* IPE Policy Load */ #define AUDIT_INTEGRITY_POLICY_ACTIVATE 1809/* IPE Policy Activation */ #define AUDIT_INTEGRITY_EVENT 1810/* IPE Evaluation Event */
Signature · 1 line
2.27.0