Skip to contentSkip to conversation

Integrity Policy Enforcement LSM (IPE)

RFC PATCH Superseded Deven Bowers 10 participants 61 messages Jul 28, 2020 – Aug 14, 2020

Subsystems (9)
Documentation VFS Block layer Kbuild +5 more subsystems

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 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.roothash

Create 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=ALLOW

Deploy 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/point

NOTE: 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.

v5:
Correct some grammatical errors reported by Randy Dunlap.
Fix some warnings reported by kernel test bot.
Change convention around security_bdev_setsecurity. -ENOSYS
is now expected if an LSM does not implement a particular @name,
as suggested by Casey Schaufler.
Minor string corrections related to the move from sysfs to securityfs
Correct a spelling of an #ifdef for the permissive argument.
Add the kernel parameters re-added to the documentation.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.roothash

Create 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=ALLOW

Deploy 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/point

NOTE: 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.

v5:
Correct some grammatical errors reported by Randy Dunlap. Fix some warnings reported by kernel test bot.
Change convention around security_bdev_setsecurity. -ENOSYS
is now expected if an LSM does not implement a particular @name, as suggested by Casey Schaufler.
Minor string corrections related to the move from sysfs to securityfs Correct a spelling of an #ifdef for the permissive argument. Add the kernel parameters re-added to the documentation. Fix a minor bug where the mode being audited on permissive switch
was the original mode, not the mode being swapped to.
Cleanup doc comments, fix some whitespace alignment issues.

Deven Bowers (11):
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
documentation: add ipe documentation
cleanup: uapi/linux/audit.h

 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/ipe.rst         |  508 +++++++
 .../admin-guide/kernel-parameters.txt         |   12 +
 MAINTAINERS                                   |    8 +
 drivers/md/dm-verity-target.c                 |   52 +-
 drivers/md/dm-verity-verify-sig.c             |  147 +-
 drivers/md/dm-verity-verify-sig.h             |   24 +-
 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                     |   12 +
 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                          |   48 +
 security/ipe/Makefile                         |   33 +
 security/ipe/ipe-audit.c                      |  303 ++++
 security/ipe/ipe-audit.h                      |   24 +
 security/ipe/ipe-blobs.c                      |   95 ++
 security/ipe/ipe-blobs.h                      |   18 +
 security/ipe/ipe-engine.c                     |  213 +++
 security/ipe/ipe-engine.h                     |   49 +
 security/ipe/ipe-hooks.c                      |  169 +++
 security/ipe/ipe-hooks.h                      |   70 +
 security/ipe/ipe-parse.c                      |  889 +++++++++++
 security/ipe/ipe-parse.h                      |   17 +
 security/ipe/ipe-pin.c                        |   93 ++
 security/ipe/ipe-pin.h                        |   36 +
 security/ipe/ipe-policy.c                     |  149 ++
 security/ipe/ipe-policy.h                     |   69 +
 security/ipe/ipe-prop-internal.h              |   49 +
 security/ipe/ipe-property.c                   |  143 ++
 security/ipe/ipe-property.h                   |  100 ++
 security/ipe/ipe-secfs.c                      | 1309 +++++++++++++++++
 security/ipe/ipe-secfs.h                      |   14 +
 security/ipe/ipe.c                            |  115 ++
 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                           |   74 +
 54 files changed, 5443 insertions(+), 98 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 · 7 lines
2.27.0


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

RFC PATCH v5 1/11 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
index d53db30d1365..86450be5437b 100644
@@ -8579,6 +8579,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
index 95ecf970c74c..b3c1882fd6dd 100644
@@ -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
new file mode 100644
index 000000000000..e87553fbb8d6
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+subdir-y := polgen
scripts/ipe/polgen/.gitignore new file +1 -0
new file mode 100644
index 000000000000..80f32f25d200
@@ -0,0 +1 @@
+polgen
scripts/ipe/polgen/Makefile new file +7 -0
new file mode 100644
index 000000000000..a519b594e13c
@@ -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
#2 lore raw

RFC PATCH v5 2/11 security: add ipe lsm evaluation loop and audit system

In reply to Deven Bowers

Add 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             |  44 ++++++
 security/ipe/Makefile            |  25 ++++
 security/ipe/ipe-audit.c         | 231 +++++++++++++++++++++++++++++++
 security/ipe/ipe-audit.h         |  18 +++
 security/ipe/ipe-engine.c        | 205 +++++++++++++++++++++++++++
 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               |  67 +++++++++
 security/ipe/ipe.h               |  20 +++
 19 files changed, 1212 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
index 86450be5437b..bed30cc1cfd7 100644
@@ -8584,6 +8584,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
index 9b6a973f4cc3..5a634cca1d42 100644
@@ -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
index cd3cc7da3a55..94924556b637 100644
@@ -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
index 3baf435de541..48bd063d66e1 100644
@@ -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
new file mode 100644
index 000000000000..bbf824e665d7
@@ -0,0 +1,2 @@
+# Generated Boot Policy
+ipe-bp.c
security/ipe/Kconfig new file +44 -0

44 lines not on this page · raw message

security/ipe/Makefile new file +25 -0
new file mode 100644
index 000000000000..40565b73fac2
@@ -0,0 +1,25 @@
+# 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 \
+
+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
new file mode 100644
index 000000000000..e00f415bed2c
@@ -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(bool enforcing);
+
+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 +205 -0

205 lines not on this page · raw message

security/ipe/ipe-engine.h new file +37 -0
new file mode 100644
index 000000000000..d9a95674e70d
@@ -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
new file mode 100644
index 000000000000..95a2081e77ee
@@ -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 +67 -0

67 lines not on this page · raw message

security/ipe/ipe.h new file +20 -0
new file mode 100644
index 000000000000..af72bb574f73
@@ -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
#3 lore raw

RFC PATCH v5 3/11 security: add ipe lsm policy parser and policy loading

In reply to Deven Bowers

Adds the policy parser and the policy loading to IPE, along with the related securityfs entries and audit events.

---
 security/ipe/Kconfig             |    2 +
 security/ipe/Makefile            |    3 +
 security/ipe/ipe-audit.c         |   74 +-
 security/ipe/ipe-audit.h         |    6 +
 security/ipe/ipe-parse.c         |  889 ++++++++++++++++++++
 security/ipe/ipe-parse.h         |   17 +
 security/ipe/ipe-policy.c        |  149 ++++
 security/ipe/ipe-policy.h        |   13 +-
 security/ipe/ipe-prop-internal.h |   18 +-
 security/ipe/ipe-property.c      |    9 +-
 security/ipe/ipe-property.h      |    1 +
 security/ipe/ipe-secfs.c         | 1309 ++++++++++++++++++++++++++++++
 security/ipe/ipe-secfs.h         |   14 +
 13 files changed, 2493 insertions(+), 11 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
index 7615109a19ca..665524fc3ca4 100644
@@ -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 +3 -0
index 40565b73fac2..7d6da33dd0c4 100644
@@ -19,7 +19,10 @@ 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 \
 
 clean-files := ipe-bp.c
security/ipe/ipe-audit.c +73 -1

83 lines not on this page · raw message

security/ipe/ipe-audit.h +6 -0
index e00f415bed2c..350818d5c47f 100644
@@ -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,9 @@ 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);
+
 #endif /* IPE_AUDIT_H */
security/ipe/ipe-parse.c new file +889 -0

889 lines not on this page · raw message

security/ipe/ipe-parse.h new file +17 -0
new file mode 100644
index 000000000000..b1a9bbd97534
@@ -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 +149 -0

149 lines not on this page · raw message

security/ipe/ipe-policy.h +10 -3
index c0c9f2962c92..b3ef3d3d2e7f 100644
@@ -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 +15 -3
index 95a2081e77ee..7c14b204be13 100644
@@ -10,9 +10,19 @@
 #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"
+/* 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"
@@ -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.c +5 -4
index d4b0283f86bd..262da9f622d6 100644
@@ -12,7 +12,7 @@
 #include <linux/slab.h>
 
 /* global root containing all registered properties */
-struct rb_root ipe_registry_root = RB_ROOT;
+static struct rb_root ipe_registry_root = RB_ROOT;
 
 /**
  * reg_lookup: Attempt to find a `prop_reg` structure with property_name @key.
@@ -70,7 +70,8 @@ const struct ipe_property *ipe_lookup_prop(const char *key)
  * the system, after calling ipe_register_property.
  *
  * All necessary properties need to be loaded via this method before
- * loading a policy, otherwise the properties will be ignored as unknown.
+ * loading a policy, otherwise the marked as unknown, and cause parsing to
+ * fail.
  *
  * Return:
  * 0 - OK
@@ -113,9 +114,9 @@ int ipe_register_property(const struct ipe_property *prop)
 
 /**
  * ipe_for_each_prop: Iterate over all currently-registered properties
- *	calling @fn on the values, and providing @view @ctx.
+ *		      calling @fn on the values, and providing @view @ctx.
  * @view: The function to call for each property. This is given the property
- *	structure as the first argument, and @ctx as the second.
+ *	  structure as the first argument, and @ctx as the second.
  * @ctx: caller-specified context that is passed to the function. Can be NULL.
  *
  * Return:
security/ipe/ipe-property.h +1 -0
index cf570d52d0d2..8bb2e2c1619c 100644
@@ -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 +1309 -0

1,309 lines not on this page · raw message

security/ipe/ipe-secfs.h new file +14 -0
new file mode 100644
index 000000000000..7732a8dcf11f
@@ -0,0 +1,14 @@
+/* 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;
+
+#endif /* IPE_SECFS_H */
Signature · 1 line
2.27.0
#4 lore raw

RFC PATCH v5 4/11 ipe: add property for trust of boot volume

In reply to Deven Bowers

Add 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                      | 28 +++++++-
 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, 337 insertions(+), 1 deletion(-)
 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
index 665524fc3ca4..469ef78c2f4f 100644
@@ -43,4 +43,6 @@ config SECURITY_IPE_PERMISSIVE_SWITCH
 
 	  If unsure, answer Y.
 
+source "security/ipe/properties/Kconfig"
+
 endif
security/ipe/Makefile +4 -0
index 7d6da33dd0c4..7e98982c5035 100644
@@ -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
index ac526d4ea5e6..0291ced99d64 100644
@@ -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>
@@ -197,6 +199,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
index 071c4af23a3d..45efe022be04 100644
@@ -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
index 806659b7cdbe..5e46726f2562 100644
@@ -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
new file mode 100644
index 000000000000..b707e6253c33
@@ -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 +27 -1
index 6e3b9a10813c..706ff38083c6 100644
@@ -6,6 +6,7 @@
 #include "ipe.h"
 #include "ipe-policy.h"
 #include "ipe-hooks.h"
+#include "properties/prop-entry.h"
 
 #include <linux/module.h>
 #include <linux/lsm_hooks.h>
@@ -21,8 +22,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.
  *
@@ -38,12 +58,18 @@ static struct security_hook_list ipe_hooks[] __lsm_ro_after_init = {
  */
 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_add_hooks(ipe_hooks, ARRAY_SIZE(ipe_hooks), "IPE");
 
-	return 0;
+	return rc;
 }
 
 DEFINE_LSM(ipe) = {
security/ipe/properties/Kconfig new file +15 -0
new file mode 100644
index 000000000000..75c6c6ff6cd8
@@ -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
new file mode 100644
index 000000000000..e3e7fe17cf58
@@ -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
new file mode 100644
index 000000000000..f598dd9608b9
@@ -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
new file mode 100644
index 000000000000..a13089bb0d8f
@@ -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
#5 lore raw

RFC PATCH v5 5/11 fs: add security blob and hooks for block_device

In reply to Deven Bowers

Add 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     | 12 ++++++
 include/linux/security.h      | 22 +++++++++++
 security/security.c           | 74 +++++++++++++++++++++++++++++++++++
 6 files changed, 122 insertions(+)
fs/block_dev.c +8 -0
index 0ae656e022fd..8602dd62c3e2 100644
@@ -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
index f5abba86107d..42d7e3ce7712 100644
@@ -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
index af998f93d256..f3c0da0db4e8 100644
@@ -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 +12 -0
index 95b7c1d32062..8670c19a8cef 100644
@@ -1507,6 +1507,17 @@
  *
  *     @what: kernel feature being accessed
  *
+ * @bdev_alloc_security:
+ *	Initialize the security field inside a block_device structure.
+ *
+ * @bdev_free_security:
+ *	Cleanup the security information stored inside a block_device structure.
+ *
+ * @bdev_setsecurity:
+ *	Set a security property associated with @name for @bdev with
+ *	value @value. @size indicates the size of @value in bytes.
+ *	If a @name is not implemented, return -ENOSYS.
+ *
  * Security hooks for perf events
  *
  * @perf_event_open:
@@ -1553,6 +1564,7 @@ struct lsm_blob_sizes {
 	int	lbs_ipc;
 	int	lbs_msg_msg;
 	int	lbs_task;
+	int	lbs_bdev;
 };
 
 /*
include/linux/security.h +22 -0
index 0a0a03b36a3b..8f83fdc6c65d 100644
@@ -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 +74 -0

104 lines not on this page · raw message

Signature · 1 line
2.27.0
#9 lore raw

RFC PATCH v5 6/11 dm-verity: move signature check after tree validation

In reply to Deven Bowers

The 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     |  44 ++++------
 drivers/md/dm-verity-verify-sig.c | 140 ++++++++++++++++++++++--------
 drivers/md/dm-verity-verify-sig.h |  24 +++--
 drivers/md/dm-verity.h            |   2 +-
 4 files changed, 134 insertions(+), 76 deletions(-)
drivers/md/dm-verity-target.c +18 -26
index eec9f252e935..fabc173aa7b3 100644
@@ -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;
@@ -968,7 +974,6 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	int i;
 	sector_t hash_position;
 	char dummy;
-	char *root_hash_digest_to_validate;
 
 	v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL);
 	if (!v) {
@@ -1102,7 +1107,6 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 		r = -EINVAL;
 		goto bad;
 	}
-	root_hash_digest_to_validate = argv[8];
 
 	if (strcmp(argv[9], "-")) {
 		v->salt_size = strlen(argv[9]) / 2;
@@ -1128,20 +1132,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 +1202,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 +11 -13
index 19b1547aa741..7de8409fa9fa 100644
@@ -11,48 +11,46 @@
 #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)
+inline int verity_verify_root_hash(const struct dm_verity *v)
 {
 	return 0;
 }
 
-bool verity_verify_is_sig_opt_arg(const char *arg_name)
+inline bool verity_verify_is_sig_opt_arg(const char *arg_name)
 {
 	return false;
 }
 
-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)
+inline int verity_verify_sig_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
+					    unsigned int *argc)
 {
 	return -EINVAL;
 }
 
-void verity_verify_sig_opts_cleanup(struct dm_verity_sig_opts *sig_opts)
+inline void verity_verify_dtr(struct dm_verity *v)
 {
 }
 
drivers/md/dm-verity.h +1 -1
index 641b9e3a399b..995c495decad 100644
@@ -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
#12 lore raw

RFC PATCH v5 7/11 dm-verity: add bdev_setsecurity hook for dm-verity signature

In reply to Deven Bowers

Add 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
index 27dac8aa2e5a..242e2421d3c8 100644
@@ -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
index 8750f2dc5613..02be0be21d38 100644
@@ -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
#13 lore raw

RFC PATCH v5 8/11 ipe: add property for signed dmverity volumes

In reply to Deven Bowers

Allow 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                     | 84 ++++++++++++++++++++
 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, 257 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
index 469ef78c2f4f..11b50ef9abca 100644
@@ -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
index 7e98982c5035..98a2245b6956 100644
@@ -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 +84 -0

84 lines not on this page · raw message

security/ipe/ipe-blobs.h new file +18 -0
new file mode 100644
index 000000000000..7561f4cef558
@@ -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
index 0291ced99d64..043faf64ceef 100644
@@ -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>
@@ -112,6 +113,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
index d9a95674e70d..038c39a8973e 100644
@@ -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
index 45efe022be04..18ab2dcd74d1 100644
@@ -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
index 5e46726f2562..b2417831cfc1 100644
@@ -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
index 706ff38083c6..8a612eb62879 100644
@@ -23,6 +23,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),
 };
 
 /**
@@ -40,6 +43,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;
 }
 
@@ -72,9 +79,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
index af72bb574f73..a59cae2deec6 100644
@@ -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
index 75c6c6ff6cd8..4046f7e5eaef 100644
@@ -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
index e3e7fe17cf58..6b67cbe36e31 100644
@@ -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
index f598dd9608b9..85366366ff0d 100644
@@ -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
index a13089bb0d8f..7580f17274a3 100644
@@ -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
#14 lore raw

RFC PATCH v5 9/11 dm-verity: add bdev_setsecurity hook for root-hash

In reply to Deven Bowers

Add 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 +
 security/ipe/ipe-blobs.c                    |  11 ++
 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 ++
 9 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 security/ipe/properties/dmverity-roothash.c
drivers/md/dm-verity-target.c +8 -0
index fabc173aa7b3..7f609906af16 100644
@@ -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
index 02be0be21d38..b82e8223d52a 100644
@@ -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 */
security/ipe/ipe-blobs.c +11 -0
index 041d7d47b723..6a09d5c6dea8 100644
@@ -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));
 }
@@ -80,5 +81,15 @@ int ipe_bdev_setsecurity(struct block_device *bdev, const char *key,
 		return 0;
 	}
 
+	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;
+	}
+
 	return -ENOSYS;
 }
security/ipe/ipe-engine.h +3 -0
index 038c39a8973e..696baaa423ff 100644
@@ -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
index 8a612eb62879..8f4dfb8c547f 100644
@@ -47,6 +47,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
index 4046f7e5eaef..4f09092522d9 100644
@@ -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
index 6b67cbe36e31..d9a3807797f4 100644
@@ -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
index 85366366ff0d..86a360570f3b 100644
@@ -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
#15 lore raw

RFC PATCH v5 10/11 documentation: add ipe documentation

In reply to Deven Bowers

Add IPE's documentation to the kernel tree.

---
 Documentation/admin-guide/LSM/index.rst       |   1 +
 Documentation/admin-guide/LSM/ipe.rst         | 508 ++++++++++++++++++
 .../admin-guide/kernel-parameters.txt         |  12 +
 MAINTAINERS                                   |   1 +
 4 files changed, 522 insertions(+)
 create mode 100644 Documentation/admin-guide/LSM/ipe.rst
Documentation/admin-guide/LSM/index.rst +1 -0
index a6ba95fbaa9f..ce63be6d64ad 100644
@@ -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

Documentation/admin-guide/kernel-parameters.txt +12 -0
index fb95fad81c79..5309813f25f7 100644
@@ -1953,6 +1953,18 @@
 	ipcmni_extend	[KNL] Extend the maximum number of unique System V
 			IPC identifiers from 32,768 to 16,777,216.
 
+	ipe.enforce=	[IPE]
+			Format: <bool>
+			Determine whether IPE starts in permissive (0) or
+			enforce (1) mode. The default is enforce.
+
+	ipe.success_audit=
+			[IPE]
+			Format: <bool>
+			Start IPE with success auditing enabled, emitting
+			an audit event when a binary is allowed. The default
+			is 0.
+
 	irqaffinity=	[SMP] Set the default irq affinity mask
 			The argument is a cpu list, as described above.
 
MAINTAINERS +1 -0
index bed30cc1cfd7..a5ab3ee733b6 100644
@@ -8583,6 +8583,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
#16 lore raw

RFC PATCH v5 10/12 ipe: add property for dmverity roothash

In reply to Deven Bowers

Add 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                    |  11 ++
 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, 193 insertions(+), 1 deletion(-)
 create mode 100644 security/ipe/properties/dmverity-roothash.c
security/ipe/ipe-blobs.c +11 -0
index 9d67b63497fc..18d5bf689c54 100644
@@ -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));
 }
@@ -80,5 +81,15 @@ int ipe_bdev_setsecurity(struct block_device *bdev, const char *key,
 		return 0;
 	}
 
+	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;
+	}
+
 	return -EOPNOTSUPP;
 }
security/ipe/ipe-engine.h +3 -0
index 038c39a8973e..696baaa423ff 100644
@@ -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
index ad25ac3f2a4f..5d2535503c20 100644
@@ -47,6 +47,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
index 4046f7e5eaef..4f09092522d9 100644
@@ -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
index 6b67cbe36e31..d9a3807797f4 100644
@@ -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
index 85366366ff0d..86a360570f3b 100644
@@ -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
#17 lore raw

RFC PATCH v5 11/11 cleanup: uapi/linux/audit.h

In reply to Deven Bowers

Remove 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
index 5a634cca1d42..609b4a5e8a80 100644
@@ -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
#18 lore raw

RFC PATCH v5 11/12 documentation: add ipe documentation

In reply to Deven Bowers

Add 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
index a6ba95fbaa9f..ce63be6d64ad 100644
@@ -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
index 2876c69435d5..492de7bda6b9 100644
@@ -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
#19 lore raw

RFC PATCH v5 12/12 cleanup: uapi/linux/audit.h

In reply to Deven Bowers

Remove 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
index 5a634cca1d42..609b4a5e8a80 100644
@@ -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
#10 lore raw

Re: [RFC PATCH v5 06/11] dm-verity: move signature check after tree validation

In reply to Deven Bowers
Quoted 42 lines · Deven Bowers

The 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     |  44 ++++------
 drivers/md/dm-verity-verify-sig.c | 140 ++++++++++++++++++++++--------
 drivers/md/dm-verity-verify-sig.h |  24 +++--
 drivers/md/dm-verity.h            |   2 +-
 4 files changed, 134 insertions(+), 76 deletions(-)
drivers/md/dm-verity-target.c +3 -1
index eec9f252e935..fabc173aa7b3 100644
@@ -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.

drivers/md/dm-verity-target.c static int verity_verify_io(struct dm_verity_io *io) · line 544

Quoted 10 lines
drivers/md/dm-verity-target.c +8 -0
+	 * 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;
 }

This doesn't make any sense.

This just moves the signature verification to some random I/O.

The whole point of dm-verity is that data is verified on demand. You can't know whether any particular data or hash block is consistent with the root hash or not until it is read and verified.

When the first I/O completes it might have just checked one block of a billion.

Not to mention that you didn't consider locking at all.

- Eric

#6 lore raw

Re: [RFC PATCH v5 05/11] fs: add security blob and hooks for block_device

In reply to Deven Bowers
Quoted 232 lines · Deven Bowers

Add 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     | 12 ++++++
 include/linux/security.h      | 22 +++++++++++
 security/security.c           | 74 +++++++++++++++++++++++++++++++++++
 6 files changed, 122 insertions(+)
fs/block_dev.c +8 -0
index 0ae656e022fd..8602dd62c3e2 100644
@@ -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
index f5abba86107d..42d7e3ce7712 100644
@@ -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
index af998f93d256..f3c0da0db4e8 100644
@@ -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 +12 -0
index 95b7c1d32062..8670c19a8cef 100644
@@ -1507,6 +1507,17 @@
  *
  *     @what: kernel feature being accessed
  *
+ * @bdev_alloc_security:
+ *	Initialize the security field inside a block_device structure.
+ *
+ * @bdev_free_security:
+ *	Cleanup the security information stored inside a block_device structure.
+ *
+ * @bdev_setsecurity:
+ *	Set a security property associated with @name for @bdev with
+ *	value @value. @size indicates the size of @value in bytes.
+ *	If a @name is not implemented, return -ENOSYS.
+ *
  * Security hooks for perf events
  *
  * @perf_event_open:
@@ -1553,6 +1564,7 @@ struct lsm_blob_sizes {
 	int	lbs_ipc;
 	int	lbs_msg_msg;
 	int	lbs_task;
+	int	lbs_bdev;
 };
 
 /*
include/linux/security.h +22 -0
index 0a0a03b36a3b..8f83fdc6c65d 100644
@@ -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 +57 -0
index 70a7ad357bc6..fff445eba400 100644
@@ -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,55 @@ 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);
+	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)
+{

security/security.c int security_locked_down(enum lockdown_reason what) · line 2585

Quoted 10 lines
security/security.c +10 -0
+	int rc = 0;
+	struct security_hook_list *p;
+
+	hlist_for_each_entry(p, &security_hook_heads.bdev_setsecurity, list) {
+		rc = p->hook.bdev_setsecurity(bdev, name, value, size);
+
+		if (rc == -ENOSYS)
+			rc = 0;
+
+		if (rc != 0)

Perhaps:

		else if (rc != 0)
Quoted 10 lines
security/security.c +7 -0
+			break;
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL(security_bdev_setsecurity);
+
 #ifdef CONFIG_PERF_EVENTS
 int security_perf_event_open(struct perf_event_attr *attr, int type)
 {
maintainer
#7 lore raw

Re: [RFC PATCH v5 05/11] fs: add security blob and hooks for block_device

Quoted 9 lines · Casey Schaufler

security/security.c int security_locked_down(enum lockdown_reason what) · line 2585

Quoted 7 lines
security/security.c +7 -0
+	hlist_for_each_entry(p, &security_hook_heads.bdev_setsecurity, list) {
+		rc = p->hook.bdev_setsecurity(bdev, name, value, size);
+
+		if (rc == -ENOSYS)
+			rc = 0;
+
+		if (rc != 0)

Perhaps:

Quoted 6 lines
		else if (rc != 0)

security/security.c int security_locked_down(enum lockdown_reason what) · line 2589

Quoted 4 lines
security/security.c +4 -0
+			break;
+	}
+
+	return rc;
	hlist_for_each_entry(p, &security_hook_heads.bdev_setsecurity, list) {
		rc = p->hook.bdev_setsecurity(bdev, name, value, size);
		if (rc && rc != -ENOSYS)
			return rc;
	}
	return 0;

Easier to reason about that way...

#11 lore raw

Re: [RFC PATCH v5 06/11] dm-verity: move signature check after tree validation

In reply to Eric Biggers
Quoted 62 lines · Eric Biggers
Quoted 42 lines · Deven Bowers

The 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     |  44 ++++------
  drivers/md/dm-verity-verify-sig.c | 140 ++++++++++++++++++++++--------
  drivers/md/dm-verity-verify-sig.h |  24 +++--
  drivers/md/dm-verity.h            |   2 +-
  4 files changed, 134 insertions(+), 76 deletions(-)
drivers/md/dm-verity-target.c +3 -1
index eec9f252e935..fabc173aa7b3 100644
@@ -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.

drivers/md/dm-verity-target.c static int verity_verify_io(struct dm_verity_io *io) · line 544

Quoted 10 lines
drivers/md/dm-verity-target.c +8 -0
+	 * 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;
  }

This doesn't make any sense.

This just moves the signature verification to some random I/O.

The whole point of dm-verity is that data is verified on demand. You can't know whether any particular data or hash block is consistent with the root hash or not until it is read and verified.

Quoted 6 lines

When the first I/O completes it might have just checked one block of a billion.

Not to mention that you didn't consider locking at all.

- Eric

I appear to have dangerously misunderstood how dm-verity works under the covers. What I thought was happening here was that *this* would be where the first I/O that completes validation and has been verified - the root hash signature could then be checked against the root hash, and then no-op for remaining blocks, provided the signature validates.

The reason why I was proposing moving the signature check, is that I was afraid of the block_device being created in dm-verity with a root-hash that belongs to a different device + a signature that verifies that root-hash, would get past verity_ctr, as despite the root hash not
matching the hash tree, the signature and the root hash will be verified. At this point, a block_device structure would be resident in
the kernel with the security attributes I propose in the next patch in the series. This device would never be read successfully, but the
structure with the attribute would exist.

This felt odd because there would be a structure in the kernel with an attribute that says it passed a security check, but the block_device is effectively invalid.

I realize now that that's a pretty ridiculous situation because the theoretical attack with access to manipulate the kernel memory in such a way to make it viable could just override whatever is needed to make the exploit work, and isn't unique to dm-verity.

I'm going to drop this patch in the next iteration of this series.

#8 lore raw

Re: [RFC PATCH v5 05/11] fs: add security blob and hooks for block_device

In reply to Al Viro
Quoted 25 lines · Al Viro
Quoted 9 lines · Casey Schaufler

security/security.c int security_locked_down(enum lockdown_reason what) · line 2585

Quoted 7 lines
security/security.c +7 -0
+	hlist_for_each_entry(p, &security_hook_heads.bdev_setsecurity, list) {
+		rc = p->hook.bdev_setsecurity(bdev, name, value, size);
+
+		if (rc == -ENOSYS)
+			rc = 0;
+
+		if (rc != 0)

Perhaps:

Quoted 6 lines
		else if (rc != 0)

security/security.c int security_locked_down(enum lockdown_reason what) · line 2589

Quoted 4 lines
security/security.c +4 -0
+			break;
+	}
+
+	return rc;
	hlist_for_each_entry(p, &security_hook_heads.bdev_setsecurity, list) {
		rc = p->hook.bdev_setsecurity(bdev, name, value, size);
		if (rc && rc != -ENOSYS)
			return rc;
	}
	return 0;
Quoted 2 lines

Easier to reason about that way...

Yeah, this is cleaner. I'll make the change for v6.

#20 lore raw
In reply to Deven Bowers

Hi!

Quoted 5 lines

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.

How is that different from security/integrity/ima?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#21 lore raw
Quoted 9 lines · Pavel Machek

Hi!

Quoted 5 lines

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.

How is that different from security/integrity/ima?

Maybe if you would have read the cover letter all the way down to the 5th paragraph which explains how IPE is different from IMA we could avoided this mail exchange...

Signature · 2 lines
Thanks,
Sasha
#22 lore raw
Quoted 9 lines · Sasha Levin
Quoted 8 lines · Pavel Machek

Hi!

Quoted 5 lines

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.

Quoted 5 lines
Quoted 1 line

How is that different from security/integrity/ima?

Maybe if you would have read the cover letter all the way down to the 5th paragraph which explains how IPE is different from IMA we could avoided this mail exchange...

"
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.
"

That is not really helpful.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
maintainer
#23 lore raw
Quoted 30 lines · Pavel Machek
Quoted 9 lines · Sasha Levin
Quoted 8 lines · Pavel Machek

Hi!

Quoted 5 lines

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.

Quoted 5 lines
Quoted 1 line

How is that different from security/integrity/ima?

Maybe if you would have read the cover letter all the way down to the 5th paragraph which explains how IPE is different from IMA we could avoided this mail exchange...

"
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.
"

Quoted 1 line

That is not really helpful.

I think what the above is trying to to is to expose is an IMA limitation that the new LSM fixes. I think what it meant to say is that IMA uses xattrs to store the signature data which is the "metadata dependency". However, it overlooks the fact that IMA can use appended signatures as well, which have no metadata dependency, so I'm not sure I've helped you understand why this is different from IMA.

Perhaps a more convincing argument is that IMA hooks into various filesystem "gates" to perform integrity checks (file read and file execute being the most obvious). This LSM wants additional gates within device mapper itself that IMA currently doesn't hook into.

Perhaps the big question is: If we used the existing IMA appended signature for detached signatures (effectively becoming the "properties" referred to in the cover letter) and hooked IMA into device mapper using additional policy terms, would that satisfy all the requirements this new LSM has?

James

#24 lore raw
Quoted 31 lines · James Bottomley
Quoted 30 lines · Pavel Machek
Quoted 9 lines · Sasha Levin
Quoted 8 lines · Pavel Machek

Hi!

Quoted 5 lines

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.

Quoted 5 lines
Quoted 1 line

How is that different from security/integrity/ima?

Maybe if you would have read the cover letter all the way down to the 5th paragraph which explains how IPE is different from IMA we could avoided this mail exchange...

"
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.
"

Quoted 1 line
Quoted 1 line

That is not really helpful.

Perhaps I can explain (and re-word this paragraph) a bit better.

As James indicates, IPE does try to close the gap of the IMA limitation with xattr. I honestly wasn’t familiar with the appended signatures, which seems fine.

Regardless, this isn’t the larger benefit that IPE provides. The larger benefit of this is how IPE separates _mechanisms_ (properties) to enforce integrity requirements, from _policy_. The LSM provides policy, while things like dm-verity provide mechanism.

So to speak, IPE acts as the glue for other mechanisms to leverage a customizable, system-wide policy to enforce. While this initial patchset only onboards dm-verity, there’s also potential for MAC labels, fs-verity, authenticated BTRFS, dm-integrity, etc. IPE leverages existing systems in the kernel, while IMA uses its own.

Another difference is the general coverage. IMA has some difficulties in covering mprotect[1], IPE doesn’t (the MAP_ANONYMOUS indicated by Jann in that thread would be denied as the file struct would be null, with IPE’s current set of supported mechanisms. mprotect would continue to function as expected if you change to PROT_EXEC).

Quoted 5 lines

Perhaps the big question is: If we used the existing IMA appended signature for detached signatures (effectively becoming the "properties" referred to in the cover letter) and hooked IMA into device mapper using additional policy terms, would that satisfy all the requirements this new LSM has?

Well, Mimi, what do you think? Should we integrate all the features of IPE into IMA, or do you think they are sufficiently different in architecture that it would be worth it to keep the code base in separate LSMs?

[1] https://lore.kernel.org/linux-integrity/[email protected]/

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

maintainer
#25 lore raw
Quoted 35 lines · Deven Bowers
Quoted 30 lines · James Bottomley
Quoted 29 lines · Pavel Machek
Quoted 10 lines · Sasha Levin
Quoted 9 lines · Pavel Machek

Hi!

Quoted 6 lines

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.

Quoted 5 lines
Quoted 1 line

How is that different from security/integrity/ima?

Maybe if you would have read the cover letter all the way down to the 5th paragraph which explains how IPE is different from IMA we could avoided this mail exchange...

"
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.
"

Quoted 1 line
Quoted 1 line

That is not really helpful.

Perhaps I can explain (and re-word this paragraph) a bit better.

Quoted 8 lines

As James indicates, IPE does try to close the gap of the IMA limitation with xattr. I honestly wasn’t familiar with the appended signatures, which seems fine.

Regardless, this isn’t the larger benefit that IPE provides. The larger benefit of this is how IPE separates _mechanisms_ (properties) to enforce integrity requirements, from _policy_. The LSM provides policy, while things like dm-verity provide mechanism.

Colour me confused here, but I thought that's exactly what IMA does. The mechanism is the gates and the policy is simply a list of rules which are applied when a gate is triggered. The policy necessarily has to be tailored to the information available at the gate (so the bprm exec gate knows filesystem things like the inode for instance) but the whole thing looks very extensible.

Quoted 5 lines

So to speak, IPE acts as the glue for other mechanisms to leverage a customizable, system-wide policy to enforce. While this initial patchset only onboards dm-verity, there’s also potential for MAC labels, fs-verity, authenticated BTRFS, dm-integrity, etc. IPE leverages existing systems in the kernel, while IMA uses its own.

Is this about who does the measurement? I think there's no reason at all why IMA can't leverage existing measurements, it's just nothing to leverage existed when it was created.

Quoted 5 lines

Another difference is the general coverage. IMA has some difficulties in covering mprotect[1], IPE doesn’t (the MAP_ANONYMOUS indicated by Jann in that thread would be denied as the file struct would be null, with IPE’s current set of supported mechanisms. mprotect would continue to function as expected if you change to PROT_EXEC).

I don't really think a debate over who does what and why is productive at this stage. I just note that IMA policy could be updated to deny MAP_ANONYMOUS, but no-one's asked for that (probably because of the huge application breakage that would ensue). The policy is a product of the use case and the current use case for IMA is working with existing filesystem semantics.

Quoted 10 lines
Quoted 5 lines

Perhaps the big question is: If we used the existing IMA appended signature for detached signatures (effectively becoming the "properties" referred to in the cover letter) and hooked IMA into device mapper using additional policy terms, would that satisfy all the requirements this new LSM has?

Well, Mimi, what do you think? Should we integrate all the features of IPE into IMA, or do you think they are sufficiently different in architecture that it would be worth it to keep the code base in separate LSMs?

I'll leave Mimi to answer, but really this is exactly the question that should have been asked before writing IPE. However, since we have the cart before the horse, let me break the above down into two specific questions.

1. Could we implement IPE in IMA (as in would extensions to IMA cover everything). I think the answers above indicate this is a "yes".
2. Should we extend IMA to implement it? This is really whether from a usability standpoint two seperate LSMs would make sense to cover the different use cases. I've got to say the least attractive thing about separation is the fact that you now both have a policy parser. You've tried to differentiate yours by making it more Kconfig based, but policy has a way of becoming user space supplied because the distros hate config options, so I think you're going to end up with a policy parser very like IMAs.

James

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

maintainer
#26 lore raw
Quoted 4 lines · James Bottomley

I'll leave Mimi to answer, but really this is exactly the question that should have been asked before writing IPE. However, since we have the cart before the horse, let me break the above down into two specific questions.

The question is valid and it was asked. We decided to first prototype what we needed and then evaluate if it should be integrated with IMA. We discussed this plan in person with Mimi (at LSS-NA in 2019), and presented a more mature version of IPE to LSS-NA in 2020, with the expectation that such a discussion may come up (it did not).

These patches are still part of this process and 'RFC' status.

Quoted 2 lines

1. Could we implement IPE in IMA (as in would extensions to IMA cover everything). I think the answers above indicate this is a "yes".

It could be done, if needed.

Quoted 3 lines

2. Should we extend IMA to implement it? This is really whether from a usability standpoint two seperate LSMs would make sense to cover the different use cases.

One issue here is that IMA is fundamentally a measurement & appraisal scheme which has been extended to include integrity enforcement. IPE was designed from scratch to only perform integrity enforcement. As such, it is a cleaner design -- "do one thing and do it well" is a good design pattern.

In our use-case, we utilize _both_ IMA and IPE, for attestation and code integrity respectively. It is useful to be able to separate these concepts. They really are different:

- Code integrity enforcement ensures that code running locally is of known provenance and has not been modified prior to execution.

- Attestation is about measuring the health of a system and having that measurement validated by a remote system. (Local attestation is useless).

I'm not sure there is value in continuing to shoe-horn both of these into IMA.

Quoted 6 lines

I've got to say the least attractive thing
about separation is the fact that you now both have a policy parser.
You've tried to differentiate yours by making it more Kconfig
based, but policy has a way of becoming user space supplied because the distros hate config options, so I think you're going to end up with a policy parser very like IMAs.

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#27 lore raw
Quoted 7 lines · James Morris
Quoted 4 lines · James Bottomley

I'll leave Mimi to answer, but really this is exactly the question that should have been asked before writing IPE. However, since we have the cart before the horse, let me break the above down into two specific questions.

Quoted 5 lines

The question is valid and it was asked. We decided to first prototype what we needed and then evaluate if it should be integrated with IMA. We discussed this plan in person with Mimi (at LSS-NA in 2019), and presented a more mature version of IPE to LSS-NA in 2020, with the expectation that such a discussion may come up (it did not).

When we first spoke the concepts weren't fully formulated, at least to me.

Quoted 22 lines

These patches are still part of this process and 'RFC' status.

Quoted 2 lines

1. Could we implement IPE in IMA (as in would extensions to IMA cover everything). I think the answers above indicate this is a "yes".

It could be done, if needed.

Quoted 3 lines

2. Should we extend IMA to implement it? This is really whether from a usability standpoint two seperate LSMs would make sense to cover the different use cases.

One issue here is that IMA is fundamentally a measurement & appraisal scheme which has been extended to include integrity enforcement. IPE was designed from scratch to only perform integrity enforcement. As such, it is a cleaner design -- "do one thing and do it well" is a good design pattern.

In our use-case, we utilize _both_ IMA and IPE, for attestation and code integrity respectively. It is useful to be able to separate these concepts. They really are different:

Quoted 8 lines

- Code integrity enforcement ensures that code running locally is of known provenance and has not been modified prior to execution.

- Attestation is about measuring the health of a system and having that measurement validated by a remote system. (Local attestation is useless).

I'm not sure there is value in continuing to shoe-horn both of these into IMA.

True, IMA was originally limited to measurement and attestation, but most of the original EVM concepts were subsequently included in IMA. (Remember, Reiner Sailer wrote the original IMA, which I inherited. I was originially working on EVM code integrity.) From a naming perspective including EVM code integrity in IMA was a mistake. My thinking at the time was that as IMA was already calculating the file hash, instead of re-calculating the file hash for integrity, calculate the file hash once and re-use it for multiple things - measurement,
integrity, and audit. At the same time define a single system wide
policy.

When we first started working on IMA, EVM, trusted, and encrypted keys, the general kernel community didn't see a need for any of it. Thus, a lot of what was accomplished has been accomplished without the backing of the real core filesystem people.

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

Mimi

Quoted 7 lines
Quoted 7 lines

I've got to say the least attractive thing
about separation is the fact that you now both have a policy parser.
You've tried to differentiate yours by making it more Kconfig
based, but policy has a way of becoming user space supplied because the distros hate config options, so I think you're going to end up with a policy parser very like IMAs.

maintainer
#28 lore raw
Quoted 10 lines · Mimi Zohar

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

What are your thoughts on IPE being a standalone LSM? Would you prefer to see its functionality integrated into IMA?

maintainer
#29 lore raw
Quoted 9 lines · James Morris
Quoted 7 lines · Mimi Zohar

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Quoted 6 lines
Quoted 3 lines

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

What are your thoughts on IPE being a standalone LSM? Would you prefer to see its functionality integrated into IMA?

Improving the integrity subsystem would be preferred.

Mimi

maintainer
#30 lore raw
Quoted 10 lines · Mimi Zohar
Quoted 9 lines · James Morris
Quoted 7 lines · Mimi Zohar

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

What are your thoughts on IPE being a standalone LSM? Would you prefer to see its functionality integrated into IMA?

Improving the integrity subsystem would be preferred.

Are you planning to attend Plumbers? Perhaps we could propose a BoF session on this topic.

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#31 lore raw
Quoted 16 lines · James Morris
Quoted 14 lines · Mimi Zohar
Quoted 13 lines · James Morris
Quoted 10 lines · Mimi Zohar

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What are your thoughts on IPE being a standalone LSM? Would you prefer to see its functionality integrated into IMA?

Improving the integrity subsystem would be preferred.

Are you planning to attend Plumbers? Perhaps we could propose a BoF session on this topic.

That sounds like a good idea.

Mimi

maintainer
#32 lore raw
Quoted 20 lines · Mimi Zohar
Quoted 19 lines · James Morris
Quoted 17 lines · Mimi Zohar
Quoted 15 lines · James Morris
Quoted 10 lines · Mimi Zohar

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

What are your thoughts on IPE being a standalone LSM? Would you prefer to see its functionality integrated into IMA?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Improving the integrity subsystem would be preferred.

Are you planning to attend Plumbers? Perhaps we could propose a BoF session on this topic.

That sounds like a good idea.

Other than it is already sold out.

Mimi

#34 lore raw
In reply to Mimi Zohar
Quoted 12 lines · Mimi Zohar
Quoted 7 lines · James Morris
Quoted 4 lines · James Bottomley

I'll leave Mimi to answer, but really this is exactly the question that should have been asked before writing IPE. However, since we have the cart before the horse, let me break the above down into two specific questions.

Quoted 32 lines
Quoted 5 lines

The question is valid and it was asked. We decided to first prototype what we needed and then evaluate if it should be integrated with IMA. We discussed this plan in person with Mimi (at LSS-NA in 2019), and presented a more mature version of IPE to LSS-NA in 2020, with the expectation that such a discussion may come up (it did not).

When we first spoke the concepts weren't fully formulated, at least to me.

Quoted 24 lines

These patches are still part of this process and 'RFC' status.

Quoted 2 lines

1. Could we implement IPE in IMA (as in would extensions to IMA cover everything). I think the answers above indicate this is a "yes".

It could be done, if needed.

Quoted 3 lines

2. Should we extend IMA to implement it? This is really whether from a usability standpoint two seperate LSMs would make sense to cover the different use cases.

One issue here is that IMA is fundamentally a measurement & appraisal scheme which has been extended to include integrity enforcement. IPE was designed from scratch to only perform integrity enforcement. As such, it is a cleaner design -- "do one thing and do it well" is a good design pattern.

In our use-case, we utilize _both_ IMA and IPE, for attestation and code integrity respectively. It is useful to be able to separate these concepts. They really are different:

- Code integrity enforcement ensures that code running locally is of known provenance and has not been modified prior to execution.

My interest is in code integrity enforcement for executables stored in NFS files.

My struggle with IPE is that due to its dependence on dm-verity, it does not seem to able to protect content that is stored separately from its execution environment and accessed via a file access protocol (FUSE, SMB, NFS, etc).

Quoted 22 lines
Quoted 5 lines

- Attestation is about measuring the health of a system and having that measurement validated by a remote system. (Local attestation is useless).

I'm not sure there is value in continuing to shoe-horn both of these into IMA.

True, IMA was originally limited to measurement and attestation, but most of the original EVM concepts were subsequently included in IMA. (Remember, Reiner Sailer wrote the original IMA, which I inherited. I was originially working on EVM code integrity.) From a naming perspective including EVM code integrity in IMA was a mistake. My thinking at the time was that as IMA was already calculating the file hash, instead of re-calculating the file hash for integrity, calculate the file hash once and re-use it for multiple things - measurement,
integrity, and audit. At the same time define a single system wide
policy.

When we first started working on IMA, EVM, trusted, and encrypted keys, the general kernel community didn't see a need for any of it. Thus, a lot of what was accomplished has been accomplished without the backing of the real core filesystem people.

Quoted 6 lines

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Mimi, when you and I discussed this during LSS NA 2019, I didn't fully understand that you expected me to implement signed Merkle trees for all filesystems. At the time, it sounded to me like you wanted signed Merkle trees only for NFS files. Is that still the case?

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

IMO we need agreement from everyone (integrity developers, FS implementers, and Linux distributors) that a signed Merkle tree IMA metadata format, stored in either an xattr or appended to an executable file, will be the way forward for IMA in all filesystems.

Quoted 13 lines

Going forward I see a lot of what we've accomplished being incorporated into the filesystems. When IMA will be limited to defining a system wide policy, I'll have completed my job.

Mimi

Quoted 7 lines
Quoted 7 lines

I've got to say the least attractive thing
about separation is the fact that you now both have a policy parser.
You've tried to differentiate yours by making it more Kconfig
based, but policy has a way of becoming user space supplied because the distros hate config options, so I think you're going to end up with a policy parser very like IMAs.

maintainer
#35 lore raw
Quoted 1 line · Chuck Lever
Quoted 1 line · Mimi Zohar

<snip>

Quoted 11 lines
Quoted 6 lines

If block layer integrity was enough, there wouldn't have been a need
for fs-verity. Even fs-verity is limited to read only filesystems,
which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Mimi, when you and I discussed this during LSS NA 2019, I didn't fully understand that you expected me to implement signed Merkle trees for all filesystems. At the time, it sounded to me like you wanted signed Merkle trees only for NFS files. Is that still the case?

I definitely do not expect you to support signed Merkle trees for all filesystems. My interested is from an IMA perspective of measuring and verifying the fs-verity Merkle tree root (and header info) signature. This is independent of which filesystems support it.

Quoted 4 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Up to now, verifying remote filesystem file integrity has been out of
scope for IMA. With fs-verity file signatures I can at least grasp
how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Mimi

Quoted 5 lines

IMO we need agreement from everyone (integrity developers, FS implementers, and Linux distributors) that a signed Merkle tree IMA metadata format, stored in either an xattr or appended to an executable file, will be the way forward for IMA in all filesystems.

maintainer
#36 lore raw
Quoted 31 lines · Mimi Zohar
Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 5, 2020, at 2:15 PM, Mimi Zohar <[email protected]> wrote:

<snip>

Quoted 8 lines
Quoted 7 lines

If block layer integrity was enough, there wouldn't have been a
need for fs-verity. Even fs-verity is limited to read only
filesystems, which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Quoted 5 lines

Mimi, when you and I discussed this during LSS NA 2019, I didn't fully understand that you expected me to implement signed Merkle trees for all filesystems. At the time, it sounded to me like you wanted signed Merkle trees only for NFS files. Is that still the case?

I definitely do not expect you to support signed Merkle trees for all filesystems. My interested is from an IMA perspective of measuring and verifying the fs-verity Merkle tree root (and header info) signature. This is independent of which filesystems support it.

Quoted 5 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Quoted 6 lines

Up to now, verifying remote filesystem file integrity has been out of
scope for IMA. With fs-verity file signatures I can at least grasp
how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do). The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block. Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

1. Ahead of time transfer: The merkle tree is transferred and verified at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the necessary components, so when presented with a unit, we check the log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the SCSI DIF/DIX), so to IMA all the pieces get presented instead of IMA having to manage the tree

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

James

maintainer
#37 lore raw
Quoted 38 lines · James Bottomley
Quoted 30 lines · Mimi Zohar
Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 5, 2020, at 2:15 PM, Mimi Zohar <[email protected]> wrote:

<snip>

Quoted 8 lines
Quoted 7 lines

If block layer integrity was enough, there wouldn't have been a
need for fs-verity. Even fs-verity is limited to read only
filesystems, which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Quoted 5 lines

Mimi, when you and I discussed this during LSS NA 2019, I didn't fully understand that you expected me to implement signed Merkle trees for all filesystems. At the time, it sounded to me like you wanted signed Merkle trees only for NFS files. Is that still the case?

I definitely do not expect you to support signed Merkle trees for all filesystems. My interested is from an IMA perspective of measuring and verifying the fs-verity Merkle tree root (and header info) signature. This is independent of which filesystems support it.

Quoted 4 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Quoted 6 lines

Up to now, verifying remote filesystem file integrity has been out of
scope for IMA. With fs-verity file signatures I can at least grasp
how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

I'm not opposed to doing that, but you're taking this discussion in a totally different direction. The current discussion is about NFSv4 supporting the existing IMA signatures, not only fs-verity signatures. I'd like to understand how that is possible and for the community to weigh in on whether it makes sense.

Quoted 19 lines

The
first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block. Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

1. Ahead of time transfer: The merkle tree is transferred and verified at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the necessary components, so when presented with a unit, we check the log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the SCSI DIF/DIX), so to IMA all the pieces get presented instead of IMA having to manage the tree

Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

I was under the impression that IMA support for fs-verity signatures would be limited to including the fs-verity signature in the
measurement list and verifying the fs-verity signature. As fs-verity
is limited to immutable files, this could be done on file open. fs- verity would be responsible for enforcing the block/page data
integrity. From a local filesystem perspective, I think that is all
that is necessary.

In terms of remote file systems, the main issue is transporting and storing the Merkle tree. As fs-verity is limited to immutable files, this could still be done on file open.

Mimi

maintainer
#38 lore raw
Quoted 1 line · Mimi Zohar

On Mon, 2020-08-10 at 08:35 -0700, James Bottomley wrote:

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Up to now, verifying remote filesystem file integrity has been
out of scope for IMA. With fs-verity file signatures I can at
least grasp how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 8 lines
Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

I'm not opposed to doing that, but you're taking this discussion in a totally different direction. The current discussion is about NFSv4 supporting the existing IMA signatures, not only fs-verity signatures. I'd like to understand how that is possible and for the community to weigh in on whether it makes sense.

Well, I see the NFS problem as being chunk at a time, right, which is merkle tree, or is there a different chunk at a time mechanism we want to use? IMA currently verifies signature on open/exec and then controls updates. Since for NFS we only control the client, we can't do that on an NFS server, so we really do need verification at read time ... unless we're threading IMA back to the NFS server?

Quoted 28 lines
Quoted 23 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block. Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

1. Ahead of time transfer: The merkle tree is transferred and
verified
at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer
the
necessary components, so when presented with a unit, we check
the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the
SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Quoted 7 lines

I was under the impression that IMA support for fs-verity signatures would be limited to including the fs-verity signature in the
measurement list and verifying the fs-verity signature. As fs-
verity is limited to immutable files, this could be done on file open. fs-verity would be responsible for enforcing the block/page
data integrity. From a local filesystem perspective, I think that
is all that is necessary.

The fs-verity use case is a bit of a crippled one because it's immutable. I think NFS represents more the general case where you can't rely on immutability and have to verify at chunk read time. If we get chunk at a time working for NFS, it should work also for fs- verity and we wouldn't need to have two special paths.

I think, even for NFS we would only really need to log the open, so same as you imagine for fs-verity. As long as the chunk read hashes match, we can be silent because everything is going OK, so we only need to determine what to do and log on mismatch (which isn't expected to happen for fs-verity).

Quoted 3 lines

In terms of remote file systems, the main issue is transporting and storing the Merkle tree. As fs-verity is limited to immutable files, this could still be done on file open.

Right, I mentioned that in my options ... we need some "supply integrity" hook ... or possibly multiple hooks for a variety of possible methods.

James

maintainer
#39 lore raw
Quoted 20 lines · James Bottomley
Quoted 1 line · Mimi Zohar

On Mon, 2020-08-10 at 08:35 -0700, James Bottomley wrote:

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Up to now, verifying remote filesystem file integrity has been
out of scope for IMA. With fs-verity file signatures I can at
least grasp how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 8 lines
Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

I'm not opposed to doing that, but you're taking this discussion in a totally different direction. The current discussion is about NFSv4 supporting the existing IMA signatures, not only fs-verity signatures. I'd like to understand how that is possible and for the community to weigh in on whether it makes sense.

Quoted 6 lines

Well, I see the NFS problem as being chunk at a time, right, which is merkle tree, or is there a different chunk at a time mechanism we want to use? IMA currently verifies signature on open/exec and then controls updates. Since for NFS we only control the client, we can't do that on an NFS server, so we really do need verification at read time ... unless we're threading IMA back to the NFS server?

Yes. I still don't see how we can support the existing IMA signatures, which is based on the file data hash, unless the "chunk at a time mechanism" is not a tree, but linear.

Mimi

Quoted 56 lines
Quoted 29 lines
Quoted 24 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block. Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

1. Ahead of time transfer: The merkle tree is transferred and
verified
at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer
the
necessary components, so when presented with a unit, we check
the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the
SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Quoted 7 lines

I was under the impression that IMA support for fs-verity signatures would be limited to including the fs-verity signature in the
measurement list and verifying the fs-verity signature. As fs-
verity is limited to immutable files, this could be done on file open. fs-verity would be responsible for enforcing the block/page
data integrity. From a local filesystem perspective, I think that
is all that is necessary.

The fs-verity use case is a bit of a crippled one because it's immutable. I think NFS represents more the general case where you can't rely on immutability and have to verify at chunk read time. If we get chunk at a time working for NFS, it should work also for fs- verity and we wouldn't need to have two special paths.

I think, even for NFS we would only really need to log the open, so same as you imagine for fs-verity. As long as the chunk read hashes match, we can be silent because everything is going OK, so we only need to determine what to do and log on mismatch (which isn't expected to happen for fs-verity).

Quoted 3 lines

In terms of remote file systems, the main issue is transporting and storing the Merkle tree. As fs-verity is limited to immutable files, this could still be done on file open.

Right, I mentioned that in my options ... we need some "supply integrity" hook ... or possibly multiple hooks for a variety of possible methods.

#40 lore raw
In reply to James Bottomley
Quoted 43 lines · James Bottomley
Quoted 31 lines · Mimi Zohar
Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 5, 2020, at 2:15 PM, Mimi Zohar <[email protected]> wrote:

<snip>

Quoted 8 lines
Quoted 7 lines

If block layer integrity was enough, there wouldn't have been a
need for fs-verity. Even fs-verity is limited to read only
filesystems, which makes validating file integrity so much easier. From the beginning, we've said that fs-verity signatures should be included in the measurement list. (I thought someone signed on to add that support to IMA, but have not yet seen anything.)

Quoted 5 lines

Mimi, when you and I discussed this during LSS NA 2019, I didn't fully understand that you expected me to implement signed Merkle trees for all filesystems. At the time, it sounded to me like you wanted signed Merkle trees only for NFS files. Is that still the case?

I definitely do not expect you to support signed Merkle trees for all filesystems. My interested is from an IMA perspective of measuring and verifying the fs-verity Merkle tree root (and header info) signature. This is independent of which filesystems support it.

Quoted 5 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Quoted 6 lines

Up to now, verifying remote filesystem file integrity has been out of
scope for IMA. With fs-verity file signatures I can at least grasp
how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

Thanks for the help! I just want to emphasize that documentation (eg, a specification) will be critical for remote filesystems.

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

Quoted 4 lines

The
first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block.

Remote filesystems will need to agree that the size of that unit is the same everywhere, or the unit size could be stored in the per-file metadata.

Quoted 5 lines

Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

Quoted 9 lines

1. Ahead of time transfer: The merkle tree is transferred and verified at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the necessary components, so when presented with a unit, we check the log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the SCSI DIF/DIX), so to IMA all the pieces get presented instead of IMA having to manage the tree

A Merkle tree is potentially large enough that it cannot be stored in an extended attribute. In addition, an extended attribute is not a byte stream that you can seek into or read small parts of, it is retrieved in a single shot.

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Also, changes to a file's content and its tree signature are not atomic. If a file is mutable, then there is the period between when the file content has changed and when the signature is updated. Some discussion of how a client is to behave in those situations will be necessary.

--
Chuck Lever
[email protected]

maintainer
#41 lore raw
Quoted 4 lines · Chuck Lever
Quoted 4 lines

On Aug 10, 2020, at 11:35 AM, James Bottomley
<[email protected]> wrote:

Quoted 1 line · Mimi Zohar

On Sat, 2020-08-08 at 13:47 -0400, Chuck Lever wrote:

[...]

Quoted 16 lines
Quoted 13 lines
Quoted 5 lines
Quoted 4 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Quoted 7 lines

Up to now, verifying remote filesystem file integrity has been
out of scope for IMA. With fs-verity file signatures I can at
least grasp how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

Quoted 8 lines

Thanks for the help! I just want to emphasize that documentation (eg, a specification) will be critical for remote filesystems.

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

I don't understand what you mean by GPL encumbered formats. The GPL is a code licence not a data or document licence. The way the spec process works in Linux is that we implement or evolve a data format under a GPL implementaiton, but that implementation doesn't implicate the later standardisation of the data format and people are free to reimplement under any licence they choose.

Quoted 29 lines
Quoted 4 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block.

Remote filesystems will need to agree that the size of that unit is the same everywhere, or the unit size could be stored in the per-file metadata.

Quoted 5 lines

Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

Quoted 13 lines

1. Ahead of time transfer: The merkle tree is transferred and
verified
at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the necessary components, so when presented with a unit, we check
the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the
SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 4 lines

A Merkle tree is potentially large enough that it cannot be stored in an extended attribute. In addition, an extended attribute is not a byte stream that you can seek into or read small parts of, it is retrieved in a single shot.

Well you wouldn't store the tree would you, just the head hash. The rest of the tree can be derived from the data. You need to distinguish between what you *must* have to verify integrity (the head hash, possibly signed) and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Quoted 9 lines
Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Also, changes to a file's content and its tree signature are not atomic. If a file is mutable, then there is the period between when the file content has changed and when the signature is updated. Some discussion of how a client is to behave in those situations will be necessary.

For IMA, if you write to a checked file, it gets rechecked the next time the gate (open/exec/mmap) is triggered. This means you must complete the update and have the new integrity data in-place before triggering the check. I think this could apply equally to a merkel tree based system. It's a sort of Doctor, Doctor it hurts when I do this situation.

James

#42 lore raw
Quoted 29 lines · James Bottomley
Quoted 4 lines · Chuck Lever
Quoted 4 lines

On Aug 10, 2020, at 11:35 AM, James Bottomley
<[email protected]> wrote:

Quoted 1 line · Mimi Zohar

On Sat, 2020-08-08 at 13:47 -0400, Chuck Lever wrote:

[...]

Quoted 19 lines
Quoted 13 lines
Quoted 5 lines
Quoted 4 lines

The first priority (for me, anyway) therefore is getting the ability to move IMA metadata between NFS clients and servers shoveled into the NFS protocol, but that's been blocked for various legal reasons.

Quoted 7 lines

Up to now, verifying remote filesystem file integrity has been
out of scope for IMA. With fs-verity file signatures I can at
least grasp how remote file integrity could possibly work. I don't understand how remote file integrity with existing IMA formats could be supported. You might want to consider writing a whitepaper, which could later be used as the basis for a patch set cover letter.

Quoted 2 lines

I think, before this, we can help with the basics (and perhaps we should sort them out before we start documenting what we'll do).

Thanks for the help! I just want to emphasize that documentation (eg, a specification) will be critical for remote filesystems.

Quoted 8 lines
Quoted 5 lines

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

I don't understand what you mean by GPL encumbered formats. The GPL is a code licence not a data or document licence.

IETF contributions occur under a BSD-style license incompatible with the GPL.

https://trustee.ietf.org/trust-legal-provisions.html

Non-Linux implementers (of OEM storage devices) rely on such standards processes to indemnify them against licensing claims.

Today, there is no specification for existing IMA metadata formats, there is only code. My lawyer tells me that because the code that implements these formats is under GPL, the formats themselves cannot be contributed to, say, the IETF without express permission from the authors of that code. There are a lot of authors of the Linux IMA code, so this is proving to be an impediment to contribution. That blocks the ability to provide a fully-specified NFS protocol extension to support IMA metadata formats.

Quoted 5 lines

The way the spec
process works in Linux is that we implement or evolve a data format under a GPL implementaiton, but that implementation doesn't implicate the later standardisation of the data format and people are free to reimplement under any licence they choose.

That technology transfer can happen only if all the authors of that prototype agree to contribute to a standard. That's much easier if that agreement comes before an implementation is done. The current IMA code base is more than a decade old, and there are more than a hundred authors who have contributed to that base.

Thus IMO we want an unencumbered description of any IMA metadata format that is to be contributed to an open standards body (as it would have to be to extend, say, the NFS protocol).

I'm happy to write that specification, as long as any contributions here are unencumbered and acknowledged. In fact, I have been working on a (so far, flawed) NFS extension:

https://datatracker.ietf.org/doc/draft-ietf-nfsv4-integrity-measurement/

Now, for example, the components of a putative Merkle-based IMA metadata format are all already open:

- The unit size is just an integer

- A certificate fingerprint is a de facto standard, and the fingerprint digest algorithms are all standardized

- Merkle trees are public domain, I believe, and we're not adding any special sauce here

- Digital signing algorithms are all standardized

Wondering if we want to hash and save the file's mtime and size too.

Quoted 34 lines
Quoted 29 lines
Quoted 4 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block.

Remote filesystems will need to agree that the size of that unit is the same everywhere, or the unit size could be stored in the per-file metadata.

Quoted 5 lines

Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

Quoted 13 lines

1. Ahead of time transfer: The merkle tree is transferred and
verified
at some time before the accesses begin, so we already have a verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the necessary components, so when presented with a unit, we check
the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the
SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 4 lines

A Merkle tree is potentially large enough that it cannot be stored in an extended attribute. In addition, an extended attribute is not a byte stream that you can seek into or read small parts of, it is retrieved in a single shot.

Quoted 4 lines

Well you wouldn't store the tree would you, just the head hash. The rest of the tree can be derived from the data. You need to distinguish between what you *must* have to verify integrity (the head hash, possibly signed)

We're dealing with an untrusted storage device, and for a remote filesystem, an untrusted network.

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Therefore, tree root digests must be cryptographically signed to be properly protected in these environments. Verifying that signature should be done infrequently relative to reading a file's content.

Quoted 4 lines

and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

We assume that storage targets (for block or file) are not trusted. Therefore storage clients cannot rely on intermediate results (eg, middle nodes in a Merkle tree) unless those results are generated within the client's trust envelope.

So: if the storage target is considered inside the client's trust envelope, it can cache or store durably any intermediate parts of the verification process. If not, the network and file storage is considered untrusted, and the client has to rely on nothing but the signed digest of the tree root.

We could build a scheme around, say, fscache, that might save the intermediate results durably and locally.

Quoted 15 lines
Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 7 lines
Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Also, changes to a file's content and its tree signature are not atomic. If a file is mutable, then there is the period between when the file content has changed and when the signature is updated. Some discussion of how a client is to behave in those situations will be necessary.

Quoted 6 lines

For IMA, if you write to a checked file, it gets rechecked the next time the gate (open/exec/mmap) is triggered. This means you must complete the update and have the new integrity data in-place before triggering the check. I think this could apply equally to a merkel tree based system. It's a sort of Doctor, Doctor it hurts when I do this situation.

I imagine it's a common situation where a "yum update" process is modifying executables while clients are running them. To prevent a read from pulling refreshed content before the new tree root is available, it would have to block temporarily until the verification process succeeds with the updated tree root.

--
Chuck Lever
[email protected]

maintainer
#43 lore raw
Quoted 3 lines · Chuck Lever
Quoted 3 lines

On Aug 11, 2020, at 1:43 AM, James Bottomley <[email protected]> wrote:
On Mon, 2020-08-10 at 19:36 -0400, Chuck Lever wrote:

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

Thanks for the help! I just want to emphasize that documentation (eg, a specification) will be critical for remote filesystems.

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

I don't understand what you mean by GPL encumbered formats. The GPL is a code licence not a data or document licence.

Quoted 7 lines

IETF contributions occur under a BSD-style license incompatible with the GPL.

https://trustee.ietf.org/trust-legal-provisions.html

Non-Linux implementers (of OEM storage devices) rely on such standards processes to indemnify them against licensing claims.

Well, that simply means we won't be contributing the Linux implementation, right? However, IETF doesn't require BSD for all implementations, so that's OK.

Quoted 8 lines

Today, there is no specification for existing IMA metadata formats, there is only code. My lawyer tells me that because the code that implements these formats is under GPL, the formats themselves cannot be contributed to, say, the IETF without express permission from the authors of that code. There are a lot of authors of the Linux IMA code, so this is proving to be an impediment to contribution. That blocks the ability to provide a fully-specified NFS protocol extension to support IMA metadata formats.

Well, let me put the counterpoint: I can write a book about how linux device drivers work (which includes describing the data formats), for instance, without having to get permission from all the authors ... or is your lawyer taking the view we should be suing Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman for licence infringement? In fact do they think we now have a huge class action possibility against O'Reilly and a host of other publishers ...

Quoted 12 lines
Quoted 5 lines

The way the spec process works in Linux is that we implement or evolve a data format under a GPL implementaiton, but that implementation doesn't implicate the later standardisation of the data format and people are free to reimplement under any licence they choose.

That technology transfer can happen only if all the authors of that prototype agree to contribute to a standard. That's much easier if that agreement comes before an implementation is done. The current IMA code base is more than a decade old, and there are more than a hundred authors who have contributed to that base.

Quoted 3 lines

Thus IMO we want an unencumbered description of any IMA metadata format that is to be contributed to an open standards body (as it would have to be to extend, say, the NFS protocol).

Fine, good grief, people who take a sensible view of this can write the data format down and publish it under any licence you like then you can pick it up again safely. Would CC0 be OK? ... neither GPL nor BSD are document licences and we shouldn't perpetuate bad practice by licensing documentation under them.

James

maintainer
#46 lore raw
In reply to Chuck Lever
Quoted 6 lines · Chuck Lever
Quoted 6 lines

On Aug 11, 2020, at 1:43 AM, James Bottomley <James.Bottomley@Hanse nPartnership.com> wrote:

Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 10, 2020, at 11:35 AM, James Bottomley
<[email protected]> wrote:

[...]

Quoted 44 lines
Quoted 36 lines
Quoted 31 lines
Quoted 4 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block.

Remote filesystems will need to agree that the size of that unit is the same everywhere, or the unit size could be stored in the per-filemetadata.

Quoted 5 lines

Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

Quoted 15 lines

1. Ahead of time transfer: The merkle tree is transferred and
verified
at some time before the accesses begin, so we already have
a
verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer
the
necessary components, so when presented with a unit, we
check the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like
the SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 4 lines

A Merkle tree is potentially large enough that it cannot be stored in an extended attribute. In addition, an extended attribute is not a byte stream that you can seek into or read small parts of, it is retrieved in a single shot.

Quoted 4 lines

Well you wouldn't store the tree would you, just the head hash. The rest of the tree can be derived from the data. You need to distinguish between what you *must* have to verify integrity (the head hash, possibly signed)

We're dealing with an untrusted storage device, and for a remote filesystem, an untrusted network.

Quoted 8 lines

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Therefore, tree root digests must be cryptographically signed to be properly protected in these environments. Verifying that signature should be done infrequently relative to reading a file's content.

I'm not disagreeing there has to be a way for the relying party to trust the root hash.

Quoted 10 lines
Quoted 5 lines

and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

We assume that storage targets (for block or file) are not trusted. Therefore storage clients cannot rely on intermediate results (eg, middle nodes in a Merkle tree) unless those results are generated within the client's trust envelope.

Yes, they can ... because supplied nodes can be verified. That's the whole point of a merkle tree. As long as I'm sure of the root hash I can verify all the rest even if supplied by an untrusted source. If you consider a simple merkle tree covering 4 blocks:

       R
     /   \
  H11     H12
  / \     / \
H21 H22 H23 H24
 |    |   |   |
B1   B2  B3  B4

Assume I have the verified root hash R. If you supply B3 you also supply H24 and H11 as proof. I verify by hashing B3 to produce H23 then hash H23 and H24 to produce H12 and if H12 and your supplied H11 hash to R the tree is correct and the B3 you supplied must likewise be correct.

Quoted 8 lines

So: if the storage target is considered inside the client's trust envelope, it can cache or store durably any intermediate parts of the verification process. If not, the network and file storage is considered untrusted, and the client has to rely on nothing but the signed digest of the tree root.

We could build a scheme around, say, fscache, that might save the intermediate results durably and locally.

I agree we want caching on the client, but we can always page in from the remote as long as we page enough to verify up to R, so we're always sure the remote supplied genuine information.

Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Quoted 7 lines
Quoted 3 lines

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

Quoted 17 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Also, changes to a file's content and its tree signature are not atomic. If a file is mutable, then there is the period between when the file content has changed and when the signature is updated. Some discussion of how a client is to behave in those situations will be necessary.

Quoted 6 lines

For IMA, if you write to a checked file, it gets rechecked the next time the gate (open/exec/mmap) is triggered. This means you must complete the update and have the new integrity data in-place before triggering the check. I think this could apply equally to a merkel tree based system. It's a sort of Doctor, Doctor it hurts when I do this situation.

Quoted 5 lines

I imagine it's a common situation where a "yum update" process is modifying executables while clients are running them. To prevent a read from pulling refreshed content before the new tree root is available, it would have to block temporarily until the verification process succeeds with the updated tree root.

No ... it's not. Yum specifically worries about that today because if you update running binaries, it causes a crash. Yum constructs the entire new file then atomically links it into place and deletes the old inode to prevent these crashes. It never allows you to get into the situation where you can execute something that will be modified. That's also why you have to restart stuff after a yum update because if you didn't it would still be attached to the deleted inode.

James

maintainer
#52 lore raw
In reply to Chuck Lever
Quoted 4 lines · Chuck Lever

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

I don't believe that is Mimi's point, because it's mostly not correct:
the xattr mechanism does provide this today. The point is the mechanism we use for storing IMA hashes and signatures today is xattrs because they have robust security properties for local filesystems that the kernel enforces. This use goes beyond IMA, selinux labels for instance use this property as well.

What I think you're saying is that NFS can't provide the robust security for xattrs we've been relying on, so you need some other mechanism for storing them.

I think Mimi's other point is actually that IMA uses a flat hash which we derive by reading the entire file and then watching for mutations. Since you cannot guarantee we get notice of mutation with NFS, the entire IMA mechanism can't really be applied in its current form and we have to resort to chunk at a time verifications that a Merkel tree would provide. Doesn't this make moot any thinking about standardisation in NFS for the current IMA flat hash mechanism because we simply can't use it ... If I were to construct a prototype I'd have to work out and securely cache the hash of ever chunk when verifying the flat hash so I could recheck on every chunk read. I think that's infeasible for large files.

James

#44 lore raw
In reply to James Bottomley

Hi!

Quoted 32 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

(eg, a specification) will be critical for remote filesystems.

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

I don't understand what you mean by GPL encumbered formats. The GPL is a code licence not a data or document licence.

Quoted 7 lines

IETF contributions occur under a BSD-style license incompatible with the GPL.

https://trustee.ietf.org/trust-legal-provisions.html

Non-Linux implementers (of OEM storage devices) rely on such standards processes to indemnify them against licensing claims.

Well, that simply means we won't be contributing the Linux implementation, right? However, IETF doesn't require BSD for all implementations, so that's OK.

Quoted 8 lines

Today, there is no specification for existing IMA metadata formats, there is only code. My lawyer tells me that because the code that implements these formats is under GPL, the formats themselves cannot be contributed to, say, the IETF without express permission from the authors of that code. There are a lot of authors of the Linux IMA code, so this is proving to be an impediment to contribution. That blocks the ability to provide a fully-specified NFS protocol extension to support IMA metadata formats.

Quoted 2 lines

Well, let me put the counterpoint: I can write a book about how linux

You should probably talk to your lawyer.

Quoted 6 lines

device drivers work (which includes describing the data formats), for instance, without having to get permission from all the authors ... or is your lawyer taking the view we should be suing Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman for licence infringement? In fact do they think we now have a huge class action possibility against O'Reilly and a host of other publishers ...

Because yes, you can reverse engineer for compatibility reasons -- doing clean room re-implementation (BIOS binary -> BIOS documentation -> BIOS sources under different license), but that was only tested in the US, is expensive, and I understand people might be uncomfortable doing that.

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
maintainer
#58 lore raw
In reply to Chuck Lever
Quoted 7 lines · Chuck Lever

My interest is in code integrity enforcement for executables stored in NFS files.

My struggle with IPE is that due to its dependence on dm-verity, it does not seem to able to protect content that is stored separately from its execution environment and accessed via a file access protocol (FUSE, SMB, NFS, etc).

It's not dependent on DM-Verity, that's just one possible integrity verification mechanism, and one of two supported in this initial version. The other is 'boot_verified' for a verified or otherwise trusted rootfs. Future versions will support FS-Verity, at least.

IPE was designed to be extensible in this way, with a strong separation of mechanism and policy.

Whatever is implemented for NFS should be able to plug in to IPE pretty easily.

Signature · 2 lines
James Morris
<[email protected]>
#53 lore raw
In reply to James Bottomley
Quoted 10 lines · James Bottomley
Quoted 4 lines · Chuck Lever

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Quoted 6 lines

I don't believe that is Mimi's point, because it's mostly not correct:
the xattr mechanism does provide this today. The point is the mechanism we use for storing IMA hashes and signatures today is xattrs because they have robust security properties for local filesystems that the kernel enforces. This use goes beyond IMA, selinux labels for instance use this property as well.

I don't buy this for a second. If storing a security label in a local xattr is so secure, we wouldn't have any need for EVM.

Quoted 3 lines

What I think you're saying is that NFS can't provide the robust security for xattrs we've been relying on, so you need some other mechanism for storing them.

For NFS, there's a network traversal which is an attack surface.

A local xattr can be attacked as well: a device or bus malfunction can corrupt the content of an xattr, or a privileged user can modify it.

How does that metadata get from the software provider to the end user? It's got to go over a network, stored in various ways, some of which will not be trusted. To attain an unbroken chain of provenance, that metadata has to be signed.

I don't think the question is the storage mechanism, but rather the protection mechanism. Signing the metadata protects it in all of these cases.

Quoted 6 lines

I think Mimi's other point is actually that IMA uses a flat hash which we derive by reading the entire file and then watching for mutations. Since you cannot guarantee we get notice of mutation with NFS, the entire IMA mechanism can't really be applied in its current form and we have to resort to chunk at a time verifications that a Merkel tree would provide.

I'm not sure what you mean by this. An NFS client relies on notification of mutation to maintain the integrity of its cache of NFS file content, and it's done that since the 1980s.

In addition to examining a file's mtime and ctime as maintained by the NFS server, a client can rely on the file's NFSv4 change attribute or an NFSv4 delegation.

Quoted 9 lines

Doesn't this make moot any thinking about
standardisation in NFS for the current IMA flat hash mechanism because we simply can't use it ... If I were to construct a prototype I'd have to work out and securely cache the hash of ever chunk when verifying the flat hash so I could recheck on every chunk read. I think that's infeasible for large files.

James

--
Chuck Lever
[email protected]

#47 lore raw
In reply to James Bottomley
Quoted 92 lines · James Bottomley
Quoted 6 lines · Chuck Lever
Quoted 6 lines

On Aug 11, 2020, at 1:43 AM, James Bottomley <James.Bottomley@Hanse nPartnership.com> wrote:

Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 10, 2020, at 11:35 AM, James Bottomley
<[email protected]> wrote:

[...]

Quoted 44 lines
Quoted 36 lines
Quoted 31 lines
Quoted 4 lines

The first basic is that a merkle tree allows unit at a time verification. First of all we should agree on the unit. Since we always fault a page at a time, I think our merkle tree unit should be a page not a block.

Remote filesystems will need to agree that the size of that unit is the same everywhere, or the unit size could be stored in the per-filemetadata.

Quoted 5 lines

Next, we should agree where the check gates for the per page accesses should be ... definitely somewhere in readpage, I suspect and finally we should agree how the merkle tree is presented at the gate. I think there are three ways:

Quoted 15 lines

1. Ahead of time transfer: The merkle tree is transferred and verified
at some time before the accesses begin, so we already have
a
verified copy and can compare against the lower leaf.
2. Async transfer: We provide an async mechanism to transfer the
necessary components, so when presented with a unit, we
check the
log n components required to get to the root
3. The protocol actually provides the capability of 2 (like the SCSI
DIF/DIX), so to IMA all the pieces get presented instead of
IMA
having to manage the tree

Quoted 4 lines

A Merkle tree is potentially large enough that it cannot be stored in an extended attribute. In addition, an extended attribute is not a byte stream that you can seek into or read small parts of, it is retrieved in a single shot.

Quoted 4 lines

Well you wouldn't store the tree would you, just the head hash. The rest of the tree can be derived from the data. You need to distinguish between what you *must* have to verify integrity (the head hash, possibly signed)

We're dealing with an untrusted storage device, and for a remote filesystem, an untrusted network.

Quoted 8 lines

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Therefore, tree root digests must be cryptographically signed to be properly protected in these environments. Verifying that signature should be done infrequently relative to reading a file's content.

I'm not disagreeing there has to be a way for the relying party to trust the root hash.

Quoted 10 lines
Quoted 5 lines

and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

We assume that storage targets (for block or file) are not trusted. Therefore storage clients cannot rely on intermediate results (eg, middle nodes in a Merkle tree) unless those results are generated within the client's trust envelope.

Yes, they can ... because supplied nodes can be verified. That's the whole point of a merkle tree. As long as I'm sure of the root hash I can verify all the rest even if supplied by an untrusted source. If you consider a simple merkle tree covering 4 blocks:

      R
    /   \
 H11     H12
 / \     / \
H21 H22 H23 H24
|    |   |   |
B1   B2  B3  B4
Quoted 5 lines

Assume I have the verified root hash R. If you supply B3 you also supply H24 and H11 as proof. I verify by hashing B3 to produce H23 then hash H23 and H24 to produce H12 and if H12 and your supplied H11 hash to R the tree is correct and the B3 you supplied must likewise be correct.

I'm not sure what you are proving here. Obviously this has to work in order for a client to reconstruct the file's Merkle tree given only R and the file content.

It's the construction of the tree and verification of the hashes that are potentially expensive. The point of caching intermediate hashes is so that the client verifies them as few times as possible. I don't see value in caching those hashes on an untrusted server -- the client will have to reverify them anyway, and there will be no savings.

Cache once, as close as you can to where the data will be used.

Quoted 6 lines
Quoted 6 lines

So: if the storage target is considered inside the client's trust envelope, it can cache or store durably any intermediate parts of the verification process. If not, the network and file storage is considered untrusted, and the client has to rely on nothing but the signed digest of the tree root.

Quoted 6 lines
Quoted 2 lines

We could build a scheme around, say, fscache, that might save the intermediate results durably and locally.

I agree we want caching on the client, but we can always page in from the remote as long as we page enough to verify up to R, so we're always sure the remote supplied genuine information.

Agreed.

Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Quoted 7 lines
Quoted 3 lines

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Quoted 7 lines

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

My point is there is a difference between a trusted cache and an untrusted cache. I argue there is not much value in a cache where the hashes have to be verified again.

Quoted 23 lines
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

There are also a load of minor things like how we get the head hash, which must be presented and verified ahead of time for each of the above 3.

Also, changes to a file's content and its tree signature are not atomic. If a file is mutable, then there is the period between when the file content has changed and when the signature is updated. Some discussion of how a client is to behave in those situations will be necessary.

Quoted 6 lines

For IMA, if you write to a checked file, it gets rechecked the next time the gate (open/exec/mmap) is triggered. This means you must complete the update and have the new integrity data in-place before triggering the check. I think this could apply equally to a merkel tree based system. It's a sort of Doctor, Doctor it hurts when I do this situation.

Quoted 5 lines

I imagine it's a common situation where a "yum update" process is modifying executables while clients are running them. To prevent a read from pulling refreshed content before the new tree root is available, it would have to block temporarily until the verification process succeeds with the updated tree root.

Quoted 7 lines

No ... it's not. Yum specifically worries about that today because if you update running binaries, it causes a crash. Yum constructs the entire new file then atomically links it into place and deletes the old inode to prevent these crashes. It never allows you to get into the situation where you can execute something that will be modified. That's also why you have to restart stuff after a yum update because if you didn't it would still be attached to the deleted inode.

Fair enough.

--
Chuck Lever
[email protected]

#59 lore raw
In reply to James Morris
Quoted 14 lines · James Morris
Quoted 7 lines · Chuck Lever

My interest is in code integrity enforcement for executables stored in NFS files.

My struggle with IPE is that due to its dependence on dm-verity, it does not seem to able to protect content that is stored separately from its execution environment and accessed via a file access protocol (FUSE, SMB, NFS, etc).

Quoted 7 lines

It's not dependent on DM-Verity, that's just one possible integrity verification mechanism, and one of two supported in this initial version. The other is 'boot_verified' for a verified or otherwise trusted rootfs. Future versions will support FS-Verity, at least.

IPE was designed to be extensible in this way, with a strong separation of mechanism and policy.

I got that, but it looked to me like the whole system relied on having access to the block device under the filesystem. That's not possible for a remote filesystem like Ceph or NFS.

I'm happy to take a closer look if someone can point me the right way.

--
Chuck Lever
[email protected]

#45 lore raw
In reply to James Bottomley
Quoted 24 lines · James Bottomley
Quoted 3 lines · Chuck Lever
Quoted 3 lines

On Aug 11, 2020, at 1:43 AM, James Bottomley <[email protected]> wrote:
On Mon, 2020-08-10 at 19:36 -0400, Chuck Lever wrote:

[...]

Quoted 15 lines
Quoted 11 lines
Quoted 8 lines

Thanks for the help! I just want to emphasize that documentation (eg, a specification) will be critical for remote filesystems.

If any of this is to be supported by a remote filesystem, then we need an unencumbered description of the new metadata format rather than code. GPL-encumbered formats cannot be contributed to the NFS standard, and are probably difficult for other filesystems that are not Linux-native, like SMB, as well.

I don't understand what you mean by GPL encumbered formats. The GPL is a code licence not a data or document licence.

IETF contributions occur under a BSD-style license incompatible with the GPL.

Quoted 7 lines
Quoted 4 lines

https://trustee.ietf.org/trust-legal-provisions.html

Non-Linux implementers (of OEM storage devices) rely on such standards processes to indemnify them against licensing claims.

Well, that simply means we won't be contributing the Linux implementation, right?

At the present time, there is nothing but the Linux implementation. There's no English description, there's no specification of the formats, the format is described only by source code.

The only way to contribute current IMA metadata formats to an open standards body like the IETF is to look at encumbered code first. We would effectively be contributing an implementation in this case.

(I'm not saying the current formats should or should not be contributed; merely that there is a legal stumbling block to doing so that can be avoided for newly defined formats).

Quoted 2 lines

Well, let me put the counterpoint: I can write a book about how linux device drivers work (which includes describing the data formats)

Our position is that someone who reads that book and implements those formats under a non-GPL-compatible license would be in breach of the GPL.

The point of the standards process is to indemnify implementing and distributing under _any_ license what has been published by the standards body. That legally enables everyone to use the published protocol/format in their own code no matter how it happens to be licensed.

Quoted 3 lines

Fine, good grief, people who take a sensible view of this can write the data format down and publish it under any licence you like then you can pick it up again safely.

That's what I proposed. Write it down under the IETF Trust legal provisions license. And I volunteered to do that.

All I'm saying is that description needs to come before code.

--
Chuck Lever
[email protected]

maintainer
#54 lore raw
In reply to Chuck Lever
Quoted 16 lines · Chuck Lever
Quoted 9 lines

On Aug 11, 2020, at 2:28 PM, James Bottomley <James.Bottomley@Hanse nPartnership.com> wrote:

Quoted 4 lines · Chuck Lever

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Quoted 6 lines

I don't believe that is Mimi's point, because it's mostly not
correct: the xattr mechanism does provide this today. The point is the mechanism we use for storing IMA hashes and signatures today is xattrs because they have robust security properties for local filesystems that the kernel enforces. This use goes beyond IMA, selinux labels for instance use this property as well.

Quoted 2 lines

I don't buy this for a second. If storing a security label in a local xattr is so secure, we wouldn't have any need for EVM.

What don't you buy? Security xattrs can only be updated by local root.
If you trust local root, the xattr mechanism is fine ... it's the only
one a lot of LSMs use, for instance. If you don't trust local root or worry about offline backups, you use EVM. A thing isn't secure or insecure, it depends on the threat model. However, if you don't trust the NFS server it doesn't matter whether you do or don't trust local root, you can't believe the contents of the xattr.

Quoted 10 lines
Quoted 3 lines

What I think you're saying is that NFS can't provide the robust security for xattrs we've been relying on, so you need some other mechanism for storing them.

For NFS, there's a network traversal which is an attack surface.

A local xattr can be attacked as well: a device or bus malfunction can corrupt the content of an xattr, or a privileged user can modify it.

Quoted 8 lines

How does that metadata get from the software provider to the end user? It's got to go over a network, stored in various ways, some of which will not be trusted. To attain an unbroken chain of provenance, that metadata has to be signed.

I don't think the question is the storage mechanism, but rather the protection mechanism. Signing the metadata protects it in all of these cases.

I think we're saying about the same thing. For most people the security mechanism of local xattrs is sufficient. If you're paranoid, you don't believe it is and you use EVM.

Quoted 10 lines
Quoted 6 lines

I think Mimi's other point is actually that IMA uses a flat hash which we derive by reading the entire file and then watching for mutations. Since you cannot guarantee we get notice of mutation with NFS, the entire IMA mechanism can't really be applied in its current form and we have to resort to chunk at a time verifications that a Merkel tree would provide.

I'm not sure what you mean by this. An NFS client relies on notification of mutation to maintain the integrity of its cache of NFS file content, and it's done that since the 1980s.

Mutation detection is part of the current IMA security model. If IMA sees a file mutate it has to be rehashed the next time it passes the gate. If we can't trust the NFS server, we can't trust the NFS mutation notification and we have to have a different mechanism to check the file.

Quoted 3 lines

In addition to examining a file's mtime and ctime as maintained by the NFS server, a client can rely on the file's NFSv4 change attribute or an NFSv4 delegation.

And that's secure in the face of a malicious or compromised server?

The bottom line is still, I think we can't use linear hashes with an open/exec/mmap gate with NFS and we have to move to chunk at a time verification like that provided by a merkel tree.

James

maintainer
#48 lore raw
In reply to Chuck Lever
Quoted 4 lines · Chuck Lever
Quoted 4 lines

On Aug 11, 2020, at 11:53 AM, James Bottomley
<[email protected]> wrote:

On Tue, 2020-08-11 at 10:48 -0400, Chuck Lever wrote:

[...]

Quoted 32 lines
Quoted 24 lines
Quoted 11 lines
Quoted 6 lines

and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

We assume that storage targets (for block or file) are not trusted. Therefore storage clients cannot rely on intermediate results (eg, middle nodes in a Merkle tree) unless those results are generated within the client's trust envelope.

Yes, they can ... because supplied nodes can be verified. That's the whole point of a merkle tree. As long as I'm sure of the root hash I can verify all the rest even if supplied by an untrusted source. If you consider a simple merkle tree covering 4 blocks:

      R
    /   \

H11 H12
/ \ / \
H21 H22 H23 H24

Quoted 1 line
   |   |   |
Quoted 7 lines

B1 B2 B3 B4

Assume I have the verified root hash R. If you supply B3 you also supply H24 and H11 as proof. I verify by hashing B3 to produce H23 then hash H23 and H24 to produce H12 and if H12 and your supplied H11 hash to R the tree is correct and the B3 you supplied must likewise be correct.

Quoted 3 lines

I'm not sure what you are proving here. Obviously this has to work in order for a client to reconstruct the file's Merkle tree given only R and the file content.

You implied the server can't be trusted to generate the merkel tree. I'm showing above it can because of the tree path based verification.

Quoted 6 lines

It's the construction of the tree and verification of the hashes that are potentially expensive. The point of caching intermediate hashes is so that the client verifies them as few times as possible. I don't see value in caching those hashes on an untrusted server -- the client will have to reverify them anyway, and there will be no savings.

I'm not making any claim about server caching, I'm just saying the client can request pieces of the tree from the server without having to reconstruct the whole thing itself because it can verify their correctness.

Quoted 55 lines

Cache once, as close as you can to where the data will be used.

Quoted 6 lines
Quoted 6 lines

So: if the storage target is considered inside the client's trust envelope, it can cache or store durably any intermediate parts of the verification process. If not, the network and file storage is considered untrusted, and the client has to rely on nothing but the signed digest of the tree root.

Quoted 6 lines
Quoted 2 lines

We could build a scheme around, say, fscache, that might save the intermediate results durably and locally.

I agree we want caching on the client, but we can always page in from the remote as long as we page enough to verify up to R, so we're always sure the remote supplied genuine information.

Agreed.

Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Quoted 7 lines
Quoted 3 lines

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Quoted 8 lines

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

Quoted 3 lines

My point is there is a difference between a trusted cache and an untrusted cache. I argue there is not much value in a cache where the hashes have to be verified again.

And my point isn't about caching, it's about where the tree comes from.
I claim and you agree the client can get the tree from the server a
piece at a time (because it can path verify it) and doesn't have to generate it itself. How much of the tree the client has to store and whether the server caches, reads it in from somewhere or reconstructs it is an implementation detail.

James

#60 lore raw
In reply to Chuck Lever
Quoted 19 lines · Chuck Lever
Quoted 19 lines · James Morris
Quoted 7 lines · Chuck Lever

My interest is in code integrity enforcement for executables stored in NFS files.

My struggle with IPE is that due to its dependence on dm-verity, it does not seem to able to protect content that is stored separately from its execution environment and accessed via a file access protocol (FUSE, SMB, NFS, etc).

It's not dependent on DM-Verity, that's just one possible integrity verification mechanism, and one of two supported in this initial version. The other is 'boot_verified' for a verified or otherwise trusted rootfs. Future versions will support FS-Verity, at least.

Quoted 6 lines
Quoted 2 lines

IPE was designed to be extensible in this way, with a strong separation of mechanism and policy.

I got that, but it looked to me like the whole system relied on having access to the block device under the filesystem. That's not possible for a remote filesystem like Ceph or NFS.

Block device structure no, (though that's what the currently used, to be
fair). It really has a hard dependency on the file structure,
specifically the ability to determine whether that file structure can be used to navigate back to the integrity claim provided by the mechanism.

In the current world of IPE, the integrity claim is the root-hash or root-hash-signature on the block device, provided by dm-verity's setsecurity hooks (also introduced in this series).

Quoted 3 lines

I'm happy to take a closer look if someone can point me the right way.

Sure, if you look at the 2nd patch, you want to look at the file "security/ipe/ipe-property.h", it defines what methods are required to be implemented by a mechanism to work with IPE. It passes the engine
context which is defined as:

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;

};

Now, if the security blob existed for the block_device, it would be in sec_bdev, but that may be NULL, as well to be fair.

If you want a more worked example of how integration works, patches 8 and 10 introduce the dm-verity properties mentioned in this patch.

#55 lore raw
In reply to James Bottomley
Quoted 47 lines · James Bottomley
Quoted 16 lines · Chuck Lever
Quoted 9 lines

On Aug 11, 2020, at 2:28 PM, James Bottomley <James.Bottomley@Hanse nPartnership.com> wrote:

Quoted 4 lines · Chuck Lever

Mimi's earlier point is that any IMA metadata format that involves unsigned digests is exposed to an alteration attack at rest or in transit, thus will not provide a robust end-to-end integrity guarantee.

Quoted 6 lines

I don't believe that is Mimi's point, because it's mostly not
correct: the xattr mechanism does provide this today. The point is the mechanism we use for storing IMA hashes and signatures today is xattrs because they have robust security properties for local filesystems that the kernel enforces. This use goes beyond IMA, selinux labels for instance use this property as well.

Quoted 2 lines

I don't buy this for a second. If storing a security label in a local xattr is so secure, we wouldn't have any need for EVM.

What don't you buy? Security xattrs can only be updated by local root. If you trust local root, the xattr mechanism is fine ... it's the only one a lot of LSMs use, for instance. If you don't trust local root or worry about offline backups, you use EVM. A thing isn't secure or insecure, it depends on the threat model. However, if you don't trust the NFS server it doesn't matter whether you do or don't trust local root, you can't believe the contents of the xattr.

Quoted 15 lines
Quoted 3 lines

What I think you're saying is that NFS can't provide the robust security for xattrs we've been relying on, so you need some other mechanism for storing them.

For NFS, there's a network traversal which is an attack surface.

A local xattr can be attacked as well: a device or bus malfunction can corrupt the content of an xattr, or a privileged user can modify it.

How does that metadata get from the software provider to the end user? It's got to go over a network, stored in various ways, some of which will not be trusted. To attain an unbroken chain of provenance, that metadata has to be signed.

Quoted 5 lines
Quoted 3 lines

I don't think the question is the storage mechanism, but rather the protection mechanism. Signing the metadata protects it in all of these cases.

I think we're saying about the same thing.

Roughly.

Quoted 3 lines

For most people the
security mechanism of local xattrs is sufficient. If you're paranoid, you don't believe it is and you use EVM.

When IMA metadata happens to be stored in local filesystems in a trusted xattr, it's going to enjoy the protection you describe without needing the addition of a cryptographic signature.

However, that metadata doesn't live its whole life there. It can reside in a tar file, it can cross a network, it can live on a back-up tape. I think we agree that any time that metadata is in transit or at rest outside of a Linux local filesystem, it is exposed.

Thus I'm interested in a metadata protection mechanism that does not rely on the security characteristics of a particular storage container. For me, a cryptographic signature fits that bill nicely.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

I think Mimi's other point is actually that IMA uses a flat hash which we derive by reading the entire file and then watching for mutations. Since you cannot guarantee we get notice of mutation with NFS, the entire IMA mechanism can't really be applied in its current form and we have to resort to chunk at a time verifications that a Merkel tree would provide.

I'm not sure what you mean by this. An NFS client relies on notification of mutation to maintain the integrity of its cache of NFS file content, and it's done that since the 1980s.

Quoted 5 lines

Mutation detection is part of the current IMA security model. If IMA sees a file mutate it has to be rehashed the next time it passes the gate. If we can't trust the NFS server, we can't trust the NFS mutation notification and we have to have a different mechanism to check the file.

When an NFS server lies about mtime and ctime, then NFS is completely broken. Untrusted NFS server doesn't mean "broken behavior" -- I would think that local filesystems will have the same problem if they can't trust a local block device to store filesystem metadata like indirect blocks and timestamps.

It's not clear to me that IMA as currently implemented can protect against broken storage devices or incorrect filesystem behavior.

Quoted 9 lines
Quoted 3 lines

In addition to examining a file's mtime and ctime as maintained by the NFS server, a client can rely on the file's NFSv4 change attribute or an NFSv4 delegation.

And that's secure in the face of a malicious or compromised server?

The bottom line is still, I think we can't use linear hashes with an open/exec/mmap gate with NFS and we have to move to chunk at a time verification like that provided by a merkel tree.

That's fine until we claim that remote filesystems require one form of metadata and local filesystems use some other form.

To guarantee an unbroken chain of provenance, everyone has to use the same portable metadata format that is signed once by the content creator. That's essentially why I believe the Merkle-based metadata format must require that the tree root is signed.

--
Chuck Lever
[email protected]

maintainer
#56 lore raw
Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 12, 2020, at 11:42 AM, James Bottomley <James.Bottomley@Hans enPartnership.com> wrote:

[...]

Quoted 14 lines
Quoted 3 lines

For most people the security mechanism of local xattrs is sufficient. If you're paranoid, you don't believe it is and you use EVM.

When IMA metadata happens to be stored in local filesystems in a trusted xattr, it's going to enjoy the protection you describe without needing the addition of a cryptographic signature.

However, that metadata doesn't live its whole life there. It can reside in a tar file, it can cross a network, it can live on a back-up tape. I think we agree that any time that metadata is in transit or at rest outside of a Linux local filesystem, it is exposed.

Quoted 4 lines

Thus I'm interested in a metadata protection mechanism that does not rely on the security characteristics of a particular storage container. For me, a cryptographic signature fits that bill nicely.

Sure, but one of the points about IMA is a separation of mechanism from policy. Signed hashes (called appraisal in IMA terms) is just one policy you can decide to require or not or even make it conditional on other things.

Quoted 17 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

I think Mimi's other point is actually that IMA uses a flat hash which we derive by reading the entire file and then watching for mutations. Since you cannot guarantee we get notice of mutation with NFS, the entire IMA mechanism can't really be applied in its current form and we have to resort to chunk at a time verifications that a Merkel tree would provide.

I'm not sure what you mean by this. An NFS client relies on notification of mutation to maintain the integrity of its cache of NFS file content, and it's done that since the 1980s.

Quoted 5 lines

Mutation detection is part of the current IMA security model. If IMA sees a file mutate it has to be rehashed the next time it passes the gate. If we can't trust the NFS server, we can't trust the NFS mutation notification and we have to have a different mechanism to check the file.

Quoted 8 lines

When an NFS server lies about mtime and ctime, then NFS is completely broken. Untrusted NFS server doesn't mean "broken behavior" -- I would think that local filesystems will have the same problem if they can't trust a local block device to store filesystem metadata like indirect blocks and timestamps.

It's not clear to me that IMA as currently implemented can protect against broken storage devices or incorrect filesystem behavior.

IMA doesn't really care about the storage. The gate check will fail if the storage corrupts the file because the hashes won't match. The mechanism for modification notification is the province of the filesystem and there are definitely some which don't do it (or other fs features) correctly and thus can't use IMA.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

In addition to examining a file's mtime and ctime as maintained by the NFS server, a client can rely on the file's NFSv4 change attribute or an NFSv4 delegation.

And that's secure in the face of a malicious or compromised server?

The bottom line is still, I think we can't use linear hashes with an open/exec/mmap gate with NFS and we have to move to chunk at a time verification like that provided by a merkel tree.

Quoted 7 lines

That's fine until we claim that remote filesystems require one form of metadata and local filesystems use some other form.

To guarantee an unbroken chain of provenance, everyone has to use the same portable metadata format that is signed once by the content creator. That's essentially why I believe the Merkle-based metadata format must require that the tree root is signed.

Well, no, that would be optional policy. We should certainly support signed head hashes and require it if the policy said so, but we shouldn't enforce it without the policy.

Suppose I'm a cloud service provider exporting files over NFS on the control (private) network. I use IMA to measure untrusted tenants to get a feel for what they're doing, but since I control the NFS server, the client and the private network, I wouldn't feel the requirement to have signed hashes because I trust other mechanisms for the security.

James

#49 lore raw
In reply to James Bottomley
Quoted 42 lines · James Bottomley
Quoted 4 lines · Chuck Lever
Quoted 4 lines

On Aug 11, 2020, at 11:53 AM, James Bottomley
<[email protected]> wrote:

On Tue, 2020-08-11 at 10:48 -0400, Chuck Lever wrote:

[...]

Quoted 32 lines
Quoted 31 lines
Quoted 11 lines
Quoted 6 lines

and what is nice to have to speed up the verification process. The choice for the latter is cache or reconstruct depending on the resources available. If the tree gets cached on the server, that would be a server implementation detail invisible to the client.

We assume that storage targets (for block or file) are not trusted. Therefore storage clients cannot rely on intermediate results (eg, middle nodes in a Merkle tree) unless those results are generated within the client's trust envelope.

Yes, they can ... because supplied nodes can be verified. That's the whole point of a merkle tree. As long as I'm sure of the root hash I can verify all the rest even if supplied by an untrusted source. If you consider a simple merkle tree covering 4 blocks:

R
/ \
H11 H12
/ \ / \
H21 H22 H23 H24

Quoted 1 line

| | |

B1 B2 B3 B4

Assume I have the verified root hash R. If you supply B3 you also supply H24 and H11 as proof. I verify by hashing B3 to produce H23 then hash H23 and H24 to produce H12 and if H12 and your supplied H11 hash to R the tree is correct and the B3 you supplied must likewise be correct.

Quoted 6 lines
Quoted 3 lines

I'm not sure what you are proving here. Obviously this has to work in order for a client to reconstruct the file's Merkle tree given only R and the file content.

You implied the server can't be trusted to generate the merkel tree. I'm showing above it can because of the tree path based verification.

What I was implying is that clients can't trust intermediate Merkle tree content that is not also signed. So far we are talking about signing only the tree root.

The storage server can store the tree durably, but if the intermediate parts of the tree are not signed, the client has to verify them anyway, and that reduces the value of storing potentially large data structures.

Quoted 11 lines
Quoted 6 lines

It's the construction of the tree and verification of the hashes that are potentially expensive. The point of caching intermediate hashes is so that the client verifies them as few times as possible. I don't see value in caching those hashes on an untrusted server -- the client will have to reverify them anyway, and there will be no savings.

I'm not making any claim about server caching, I'm just saying the client can request pieces of the tree from the server without having to reconstruct the whole thing itself because it can verify their correctness.

To be clear, my concern is about how much of the tree might be stored in a Merkle-based metadata format. I just don't see that it has much value to store more than the signed tree root, because the client will have to reconstitute or verify some tree contents on most every read.

For sufficiently large files, the tree itself can be larger than what can be stored in an xattr. This is the same problem that fs-verity faces. And, as I stated earlier, xattr objects are read in their entirety, they can't be seeked into or read piecemeal.

What it seemed to me that you were suggesting was an offloaded cache of the Merkle tree. Either the whole tree is stored on the storage server, or the storage server provides a service that reconstitutes that tree on behalf of clients. (Please correct me if I misunderstood). I just don't think that will be practicable or provide the kind of benefit you might want.

Quoted 55 lines
Quoted 55 lines

Cache once, as close as you can to where the data will be used.

Quoted 6 lines
Quoted 6 lines

So: if the storage target is considered inside the client's trust envelope, it can cache or store durably any intermediate parts of the verification process. If not, the network and file storage is considered untrusted, and the client has to rely on nothing but the signed digest of the tree root.

Quoted 6 lines
Quoted 2 lines

We could build a scheme around, say, fscache, that might save the intermediate results durably and locally.

I agree we want caching on the client, but we can always page in from the remote as long as we page enough to verify up to R, so we're always sure the remote supplied genuine information.

Agreed.

Quoted 35 lines
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

For this reason, the idea was to save only the signature of the tree's root on durable storage. The client would retrieve that signature possibly at open time, and reconstruct the tree at that time.

Right that's the integrity data you must have.

Quoted 2 lines

Or the tree could be partially constructed on-demand at the time each unit is to be checked (say, as part of 2. above).

Whether it's reconstructed or cached can be an implementation detail. You clearly have to reconstruct once, but whether you have to do it again depends on the memory available for caching and all the other resource calls in the system.

Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Quoted 7 lines
Quoted 3 lines

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

Quoted 8 lines
Quoted 3 lines

My point is there is a difference between a trusted cache and an untrusted cache. I argue there is not much value in a cache where the hashes have to be verified again.

And my point isn't about caching, it's about where the tree comes from. I claim and you agree the client can get the tree from the server a piece at a time (because it can path verify it) and doesn't have to generate it itself.

OK, let's focus on where the tree comes from. It is certainly possible to build protocol to exchange parts of a Merkle tree. The question is how it might be stored on the server. There are some underlying assumptions about the metadata storage mechanism that should be stated up front.

Current forms of IMA metadata are limited in size and stored in a container that is read and written in a single operation. If we stick with that container format, I don't see a way to store a Merkle tree in there for all file sizes.

Thus it seems to me that we cannot begin to consider the tree-on-the- server model unless there is a proposed storage mechanism for that whole tree. Otherwise, the client must have the primary role in unpacking and verifying the tree.

Storing only the tree root in the metadata means the metadata format is nicely bounded in size.

Quoted 3 lines

How much of the tree the client has to store and
whether the server caches, reads it in from somewhere or reconstructs it is an implementation detail.

Sure.

--
Chuck Lever
[email protected]

#57 lore raw
In reply to James Bottomley
Quoted 27 lines · James Bottomley
Quoted 2 lines · Chuck Lever
Quoted 2 lines

On Aug 12, 2020, at 11:42 AM, James Bottomley <James.Bottomley@Hans enPartnership.com> wrote:

[...]

Quoted 14 lines
Quoted 3 lines

For most people the security mechanism of local xattrs is sufficient. If you're paranoid, you don't believe it is and you use EVM.

When IMA metadata happens to be stored in local filesystems in a trusted xattr, it's going to enjoy the protection you describe without needing the addition of a cryptographic signature.

However, that metadata doesn't live its whole life there. It can reside in a tar file, it can cross a network, it can live on a back-up tape. I think we agree that any time that metadata is in transit or at rest outside of a Linux local filesystem, it is exposed.

Quoted 4 lines

Thus I'm interested in a metadata protection mechanism that does not rely on the security characteristics of a particular storage container. For me, a cryptographic signature fits that bill nicely.

Quoted 4 lines

Sure, but one of the points about IMA is a separation of mechanism from policy. Signed hashes (called appraisal in IMA terms) is just one policy you can decide to require or not or even make it conditional on other things.

AFAICT, the current EVM_IMA_DIGSIG and EVM_PORTABLE_DIGSIG formats are always signed. The policy choice is whether or not to verify the signature, not whether or not the metadata format is signed.

--
Chuck Lever
[email protected]

maintainer
#50 lore raw
In reply to Chuck Lever
Quoted 6 lines · Chuck Lever
Quoted 6 lines

On Aug 12, 2020, at 11:51 AM, James Bottomley <James.Bottomley@Hans enPartnership.com> wrote:

Quoted 3 lines · Chuck Lever
Quoted 3 lines

On Aug 11, 2020, at 11:53 AM, James Bottomley <[email protected]> wrote:
On Tue, 2020-08-11 at 10:48 -0400, Chuck Lever wrote:

[...]

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Quoted 4 lines

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Quoted 8 lines

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

My point is there is a difference between a trusted cache and an untrusted cache. I argue there is not much value in a cache where the hashes have to be verified again.

Quoted 7 lines
Quoted 4 lines

And my point isn't about caching, it's about where the tree comes from. I claim and you agree the client can get the tree from the server a piece at a time (because it can path verify it) and doesn't have to generate it itself.

OK, let's focus on where the tree comes from. It is certainly possible to build protocol to exchange parts of a Merkle tree.

Which is what I think we need to extend IMA to do.

Quoted 1 line

The question is how it might be stored on the server.

I think the only thing the server has to guarantee to store is the head hash, possibly signed.

Quoted 7 lines

There are some underlying assumptions about the metadata storage
mechanism that should be stated up front.

Current forms of IMA metadata are limited in size and stored in a container that is read and written in a single operation. If we stick with that container format, I don't see a way to store a Merkle tree in there for all file sizes.

Well, I don't think you need to. The only thing that needs to be stored is the head hash. Everything else can be reconstructed. If you asked me to implement it locally, I'd probably put the head hash in an xattr but use a CAM based cache for the merkel trees and construct the tree on first access if it weren't already in the cache.

However, the above isn't what fs-verity does: it stores the tree in a hidden section of the file. That's why I don't think we'd mandate anything about tree storage. Just describe the partial retrieval properties we'd like and leave the rest as an implementation detail.

Quoted 4 lines

Thus it seems to me that we cannot begin to consider the tree-on-the- server model unless there is a proposed storage mechanism for that whole tree. Otherwise, the client must have the primary role in unpacking and verifying the tree.

Well, as I said, I don't think you need to store the tree. You certainly could decide to store the entire tree (as fs-verity does) if it fitted your use case, but it's not required. Perhaps even in my case I'd make the CAM based cache persistent, like android's dalvik cache.

James

Quoted 2 lines

Storing only the tree root in the metadata means the metadata format is nicely bounded in size.

#51 lore raw
Quoted 62 lines · James Bottomley
Quoted 6 lines · Chuck Lever
Quoted 6 lines

On Aug 12, 2020, at 11:51 AM, James Bottomley <James.Bottomley@Hans enPartnership.com> wrote:

Quoted 3 lines · Chuck Lever
Quoted 3 lines

On Aug 11, 2020, at 11:53 AM, James Bottomley <[email protected]> wrote:
On Tue, 2020-08-11 at 10:48 -0400, Chuck Lever wrote:

[...]

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

The client would have to reconstruct that tree again if memory pressure caused some or all of the tree to be evicted, so perhaps an on-demand mechanism is preferable.

Right, but I think that's implementation detail. Probably what we need is a way to get the log(N) verification hashes from the server and it's up to the client whether it caches them or not.

Quoted 4 lines

Agreed, these are implementation details. But see above about the trustworthiness of the intermediate hashes. If they are conveyed on an untrusted network, then they can't be trusted either.

Quoted 8 lines

Yes, they can, provided enough of them are asked for to verify. If you look at the simple example above, suppose I have cached H11 and H12, but I've lost the entire H2X layer. I want to verify B3 so I also ask you for your copy of H24. Then I generate H23 from B3 and Hash H23 and H24. If this doesn't hash to H12 I know either you supplied me the wrong block or lied about H24. However, if it all hashes correctly I know you supplied me with both the correct B3 and the correct H24.

My point is there is a difference between a trusted cache and an untrusted cache. I argue there is not much value in a cache where the hashes have to be verified again.

Quoted 7 lines
Quoted 4 lines

And my point isn't about caching, it's about where the tree comes from. I claim and you agree the client can get the tree from the server a piece at a time (because it can path verify it) and doesn't have to generate it itself.

OK, let's focus on where the tree comes from. It is certainly possible to build protocol to exchange parts of a Merkle tree.

Which is what I think we need to extend IMA to do.

Quoted 1 line

The question is how it might be stored on the server.

I think the only thing the server has to guarantee to store is the head hash, possibly signed.

Quoted 7 lines

There are some underlying assumptions about the metadata storage mechanism that should be stated up front.

Current forms of IMA metadata are limited in size and stored in a container that is read and written in a single operation. If we stick with that container format, I don't see a way to store a Merkle tree in there for all file sizes.

Quoted 5 lines

Well, I don't think you need to. The only thing that needs to be stored is the head hash. Everything else can be reconstructed. If you asked me to implement it locally, I'd probably put the head hash in an xattr but use a CAM based cache for the merkel trees and construct the tree on first access if it weren't already in the cache.

The contents of the security.ima xattr might be modeled after EVM_IMA_DIGSIG:

- a format enumerator (used by all IMA metadata formats)
- the tree's unit size
- a fingerprint of the signer's certificate
- digest algorithm name and full digest
- the root hash, always signed
- signing algorithm name and signature

The rest of the hash tree is always stored somewhere else or constructed on-demand.

My experience of security communities both within and outside the IETF is that they would insist on always having a signature.

If one doesn't care about signing, a self-signed certificate can be automatically provisioned when ima-evm-utils is installed that can be used for those cases. That would make the signature process invisible to any administrator who doesn't care about signed metadata.

Because storage in NFS would cross trust boundaries, it would have to require the use of a signed root hash. I don't want to be in the position where copying a file with an unsigned root hash into NFS makes it unreadable because of a change in policy.

Quoted 4 lines

However, the above isn't what fs-verity does: it stores the tree in a hidden section of the file. That's why I don't think we'd mandate anything about tree storage. Just describe the partial retrieval properties we'd like and leave the rest as an implementation detail.

I'm starting to consider how much compatibility with fs-verity is required. There are several forms of hash-tree, and a specification of the IMA metadata format would need to describe exactly how to form the tree root. If we want compatibility with fs-verity, then it is reasonable to assume that this IMA metadata format might be required to use the same hash tree construction algorithm that fs-verity uses.

The original Merkle tree concept was patented 40 years ago. I'm not clear yet on whether the patent encumbers the use of Merkle trees in any way, but since their usage seems pretty widespread in P2P and BitCoin applications, I'm guessing the answer to that is favorable. More research needed.

There is an implementation used by several GNU utilities that is available as a piece of GPL code. It could be a potential blocker if that was the tree algorithm that fs-verity uses -- as discussed in the other thread.

Apparently there are some known weaknesses in older hash tree algorithms, including at least one CVE. We could choose a recent algorithm, but perhaps there needs to be a degree of extensibility in case that algorithm needs to be updated due to a subsequent security issue.

Tree construction could include a few items besides file content to help secure the hash further. For instance the file's size and mtime, as well as the depth of the tree, could be included in the signature. But that depends on whether it can be done while maintaining compatibility with fs-verity.

I would feel better if someone with more domain expertise chimed in.

Quoted 6 lines
Quoted 4 lines

Thus it seems to me that we cannot begin to consider the tree-on-the- server model unless there is a proposed storage mechanism for that whole tree. Otherwise, the client must have the primary role in unpacking and verifying the tree.

Well, as I said, I don't think you need to store the tree.

We basically agree there.

Quoted 10 lines

You certainly could decide to store the entire tree (as fs-verity does) if it fitted your use case, but it's not required. Perhaps even in my case I'd make the CAM based cache persistent, like android's dalvik cache.

James

Quoted 2 lines

Storing only the tree root in the metadata means the metadata format is nicely bounded in size.

--
Chuck Lever
[email protected]