835 lines · 41.4 KB · Text
RawDownload
.. SPDX-License-Identifier: GPL-2.0 Integrity Policy Enforcement (IPE)================================== .. NOTE::    This is the documentation for admins, system builders, or individuals   attempting to use IPE. If you're looking for more developer-focused   documentation about IPE please see :doc:`the design docs </security/ipe>`. Overview-------- Integrity Policy Enforcement (IPE) is a Linux Security Module that takes acomplementary approach to access control. Unlike traditional access controlmechanisms that rely on labels and paths for decision-making, IPE focuseson the immutable security properties inherent to system components. Theseproperties are fundamental attributes or features of a system componentthat cannot be altered, ensuring a consistent and reliable basis forsecurity decisions. To elaborate, in the context of IPE, system components primarily refer tofiles or the devices these files reside on. However, this is just astarting point. The concept of system components is flexible and can beextended to include new elements as the system evolves. The immutableproperties include the origin of a file, which remains constant andunchangeable over time. For example, IPE policies can be crafted to trustfiles originating from the initramfs. Since initramfs is typically verifiedby the bootloader, its files are deemed trustworthy; "file is frominitramfs" becomes an immutable property under IPE's consideration. The immutable property concept extends to the security features enabled ona file's origin, such as dm-verity or fs-verity, which provide a layer ofintegrity and trust. For example, IPE allows the definition of policiesthat trust files from a dm-verity protected device. dm-verity ensures theintegrity of an entire device by providing a verifiable and immutable stateof its contents. Similarly, fs-verity offers filesystem-level integritychecks, allowing IPE to enforce policies that trust files protected byfs-verity. These two features cannot be turned off once established, sothey are considered immutable properties. These examples demonstrate howIPE leverages immutable properties, such as a file's origin and itsintegrity protection mechanisms, to make access control decisions. For the IPE policy, specifically, it grants the ability to enforcestringent access controls by assessing security properties againstreference values defined within the policy. This assessment can be based onthe existence of a security property (e.g., verifying if a file originatesfrom initramfs) or evaluating the internal state of an immutable securityproperty. The latter includes checking the roothash of a dm-verityprotected device, determining whether dm-verity possesses a validsignature, assessing the digest of a fs-verity protected file, ordetermining whether fs-verity possesses a valid built-in signature. Thisnuanced approach to policy enforcement enables a highly secure andcustomizable system defense mechanism, tailored to specific securityrequirements and trust models. To enable IPE, ensure that ``CONFIG_SECURITY_IPE`` (under:menuselection:`Security -> Integrity Policy Enforcement (IPE)`) configoption is enabled. Use Cases--------- IPE works best in fixed-function devices: devices in which their purposeis clearly defined and not supposed to be changed (e.g. network firewalldevice in a data center, an IoT device, etcetera), where all software andconfiguration is built and provisioned by the system owner. IPE is a long-way off for use in general-purpose computing: the Linuxcommunity as a whole tends to follow a decentralized trust model (known asthe web of trust), which IPE has no support for it yet. Instead, IPEsupports PKI (public key infrastructure), which generally designates aset of trusted entities that provide a measure of absolute trust. Additionally, while most packages are signed today, the files insidethe packages (for instance, the executables), tend to be unsigned. Thismakes it difficult to utilize IPE in systems where a package manager isexpected to be functional, without major changes to the package managerand ecosystem behind it. The digest_cache LSM [#digest_cache_lsm]_ is a system that when combined with IPE,could be used to enable and support general-purpose computing use cases. Known Limitations----------------- IPE cannot verify the integrity of anonymous executable memory, such asthe trampolines created by gcc closures and libffi (<3.4.2), or JIT'd code.Unfortunately, as this is dynamically generated code, there is no wayfor IPE to ensure the integrity of this code to form a trust basis. IPE cannot verify the integrity of programs written in interpretedlanguages when these scripts are invoked by passing these program filesto the interpreter. This is because the way interpreters execute thesefiles; the scripts themselves are not evaluated as executable codethrough one of IPE's hooks, but they are merely text files that are read(as opposed to compiled executables). However, with the introduction of the``AT_EXECVE_CHECK`` flag (:doc:`AT_EXECVE_CHECK </userspace-api/check_exec>`),interpreters can use it to signal the kernel that a script file will be executed,and request the kernel to perform LSM security checks on it. IPE's EXECUTE operation enforcement differs between compiled executables andinterpreted scripts: For compiled executables, enforcement is triggeredautomatically by the kernel during ``execve()``, ``execveat()``, ``mmap()``and ``mprotect()`` syscalls when loading executable content. For interpretedscripts, enforcement requires explicit interpreter integration using``execveat()`` with ``AT_EXECVE_CHECK`` flag. Unlike exec syscalls that IPEintercepts during the execution process, this mechanism needs the interpreterto take the initiative, and existing interpreters won't be automaticallysupported unless the signal call is added. Threat Model------------ IPE specifically targets the risk of tampering with user-space executablecode after the kernel has initially booted, including the kernel modulesloaded from userspace via ``modprobe`` or ``insmod``. To illustrate, consider a scenario where an untrusted binary, possiblymalicious, is downloaded along with all necessary dependencies, including aloader and libc. The primary function of IPE in this context is to preventthe execution of such binaries and their dependencies. IPE achieves this by verifying the integrity and authenticity of allexecutable code before allowing them to run. It conducts a thoroughcheck to ensure that the code's integrity is intact and that they match anauthorized reference value (digest, signature, etc) as per the definedpolicy. If a binary does not pass this verification process, eitherbecause its integrity has been compromised or it does not meet theauthorization criteria, IPE will deny its execution. Additionally, IPEgenerates audit logs which may be utilized to detect and analyze failuresresulting from policy violation. Tampering threat scenarios include modification or replacement ofexecutable code by a range of actors including: -  Actors with physical access to the hardware-  Actors with local network access to the system-  Actors with access to the deployment system-  Compromised internal systems under external control-  Malicious end users of the system-  Compromised end users of the system-  Remote (external) compromise of the system IPE does not mitigate threats arising from malicious but authorizeddevelopers (with access to a signing certificate), or compromiseddeveloper tools used by them (i.e. return-oriented programming attacks).Additionally, IPE draws hard security boundary between userspace andkernelspace. As a result, kernel-level exploits are considered outsidethe scope of IPE and mitigation is left to other mechanisms. Policy------ IPE policy is a plain-text [#devdoc]_ policy composed of multiple statementsover several lines. There is one required line, at the top of thepolicy, indicating the policy name, and the policy version, forinstance::    policy_name=Ex_Policy policy_version=0.0.0 The policy name is a unique key identifying this policy in a humanreadable name. This is used to create nodes under securityfs as well asuniquely identify policies to deploy new policies vs update existingpolicies. The policy version indicates the current version of the policy (NOT thepolicy syntax version). This is used to prevent rollback of policy topotentially insecure previous versions of the policy. The next portion of IPE policy are rules. Rules are formed by key=valuepairs, known as properties. IPE rules require two properties: ``action``,which determines what IPE does when it encounters a match against therule, and ``op``, which determines when the rule should be evaluated.The ordering is significant, a rule must start with ``op``, and end with``action``. Thus, a minimal rule is::    op=EXECUTE action=ALLOW This example will allow any execution. Additional properties are used toassess immutable security properties about the files being evaluated.These properties are intended to be descriptions of systems within thekernel that can provide a measure of integrity verification, such that IPEcan determine the trust of the resource based on the value of the property. 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 rulesare evaluated before a rule with ``action=ALLOW``. IPE policy supports comments. The character '#' will function as acomment, ignoring all characters to the right of '#' until the newline. The default behavior of IPE evaluations can also be expressed in policy,through the ``DEFAULT`` statement. This can be done at a global level,or a per-operation level::    # Global   DEFAULT action=ALLOW    # Operation Specific   DEFAULT op=EXECUTE action=ALLOW A default must be set for all known operations in IPE. If you want topreserve older policies being compatible with newer kernels that can introducenew operations, set a global default of ``ALLOW``, then override thedefaults on a per-operation basis (as above). With configurable policy-based LSMs, there's several issues withenforcing the configurable policies at startup, around reading andparsing the policy: 1. The kernel *should* not read files from userspace, so directly reading   the policy file is prohibited.2. The kernel command line has a character limit, and one kernel module   should not reserve the entire character limit for its own   configuration.3. There are various boot loaders in the kernel ecosystem, so handing   off a memory block would be costly to maintain. As a result, IPE has addressed this problem through a concept of a "bootpolicy". A boot policy is a minimal policy which is compiled into thekernel. This policy is intended to get the system to a state whereuserspace is set up and ready to receive commands, at which point a morecomplex policy can be deployed via securityfs. The boot policy can bespecified via ``SECURITY_IPE_BOOT_POLICY`` config option, which acceptsa path to a plain-text version of the IPE policy to apply. This policywill be compiled into the kernel. If not specified, IPE will be disableduntil a policy is deployed and activated through securityfs. Deploying Policies~~~~~~~~~~~~~~~~~~ Policies can be deployed from userspace through securityfs. These policiesare signed through the PKCS#7 message format to enforce some level ofauthorization of the policies (prohibiting an attacker from gainingunconstrained root, and deploying an "allow all" policy). Thesepolicies must be signed by a certificate that chains to the``SYSTEM_TRUSTED_KEYRING``, or to the secondary and/or platform keyrings if``CONFIG_IPE_POLICY_SIG_SECONDARY_KEYRING`` and/or``CONFIG_IPE_POLICY_SIG_PLATFORM_KEYRING`` are enabled, respectively.With openssl, the policy can be signed by::    openssl smime -sign \      -in "$MY_POLICY" \      -signer "$MY_CERTIFICATE" \      -inkey "$MY_PRIVATE_KEY" \      -noattr \      -nodetach \      -nosmimecap \      -outform der \      -out "$MY_POLICY.p7b" Deploying the policies is done through securityfs, through the``new_policy`` node. To deploy a policy, simply cat the file into thesecurityfs node::    cat "$MY_POLICY.p7b" > /sys/kernel/security/ipe/new_policy Upon success, this will create one subdirectory under``/sys/kernel/security/ipe/policies/``. The subdirectory will be the``policy_name`` field of the policy deployed, so for the example above,the directory will be ``/sys/kernel/security/ipe/policies/Ex_Policy``.Within this directory, there will be seven files: ``pkcs7``, ``policy``,``name``, ``version``, ``active``, ``update``, and ``delete``. The ``pkcs7`` file is read-only. Reading it returns the raw PKCS#7 datathat was provided to the kernel, representing the policy. If the policy beingread is the boot policy, this will return ``ENOENT``, as it is not signed. The ``policy`` file is read only. Reading it returns the PKCS#7 innercontent of the policy, which will be the plain text policy. The ``active`` file is used to set a policy as the currently active policy.This file is rw, and accepts a value of ``"1"`` to set the policy as active.Since only a single policy can be active at one time, all other policieswill be marked inactive. The policy being marked active must have a policyversion greater or equal to the currently-running version. The ``update`` file is used to update a policy that is already presentin the kernel. This file is write-only and accepts a PKCS#7 signedpolicy. Two checks will always be performed on this policy: First, the``policy_names`` must match with the updated version and the existingversion. Second the updated policy must have a policy version greater thanthe currently-running version. This is to prevent rollback attacks. The ``delete`` file is used to remove a policy that is no longer needed.This file is write-only and accepts a value of ``1`` to delete the policy.On deletion, the securityfs node representing the policy will be removed.However, delete the current active policy is not allowed and will returnan operation not permitted error. Similarly, writing to both ``update`` and ``new_policy`` could result inbad message(policy syntax error) or file exists error. The latter error happenswhen trying to deploy a policy with a ``policy_name`` while the kernel alreadyhas a deployed policy with the same ``policy_name``. Deploying a policy will *not* cause IPE to start enforcing the policy. IPE willonly enforce the policy marked active. Note that only one policy can be activeat a time. Once deployment is successful, the policy can be activated, by writing file``/sys/kernel/security/ipe/policies/$policy_name/active``.For example, the ``Ex_Policy`` can be activated by::    echo 1 > "/sys/kernel/security/ipe/policies/Ex_Policy/active" From above point on, ``Ex_Policy`` is now the enforced policy on thesystem. IPE also provides a way to delete policies. This can be done via the``delete`` securityfs node,``/sys/kernel/security/ipe/policies/$policy_name/delete``.Writing ``1`` to that file deletes the policy::    echo 1 > "/sys/kernel/security/ipe/policies/$policy_name/delete" There is only one requirement to delete a policy: the policy being deletedmust be inactive. .. NOTE::    If a traditional MAC system is enabled (SELinux, apparmor, smack), all   writes to ipe's securityfs nodes require ``CAP_MAC_ADMIN``. Modes~~~~~ IPE supports two modes of operation: permissive (similar to SELinux'spermissive mode) and enforced. In permissive mode, all events arechecked and policy violations are logged, but the policy is not reallyenforced. 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``. .. NOTE::    If a traditional MAC system is enabled (SELinux, apparmor, smack, etcetera),   all writes to ipe's securityfs nodes require ``CAP_MAC_ADMIN``. Audit Events~~~~~~~~~~~~ 1420 AUDIT_IPE_ACCESS^^^^^^^^^^^^^^^^^^^^^Event Examples::    type=1420 audit(1653364370.067:61): ipe_op=EXECUTE ipe_hook=MMAP enforcing=1 pid=2241 comm="ld-linux.so" path="/deny/lib/libc.so.6" dev="sda2" ino=14549020 rule="DEFAULT action=DENY"   type=1300 audit(1653364370.067:61): SYSCALL arch=c000003e syscall=9 success=no exit=-13 a0=7f1105a28000 a1=195000 a2=5 a3=812 items=0 ppid=2219 pid=2241 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=2 comm="ld-linux.so" exe="/tmp/ipe-test/lib/ld-linux.so" subj=unconfined key=(null)   type=1327 audit(1653364370.067:61): 707974686F6E3300746573742F6D61696E2E7079002D6E00    type=1420 audit(1653364735.161:64): ipe_op=EXECUTE ipe_hook=MMAP enforcing=1 pid=2472 comm="mmap_test" path=? dev=? ino=? rule="DEFAULT action=DENY"   type=1300 audit(1653364735.161:64): SYSCALL arch=c000003e syscall=9 success=no exit=-13 a0=0 a1=1000 a2=4 a3=21 items=0 ppid=2219 pid=2472 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=2 comm="mmap_test" exe="/root/overlake_test/upstream_test/vol_fsverity/bin/mmap_test" subj=unconfined key=(null)   type=1327 audit(1653364735.161:64): 707974686F6E3300746573742F6D61696E2E7079002D6E00 This event indicates that IPE made an access control decision; the IPEspecific record (1420) is always emitted in conjunction with a``AUDITSYSCALL`` record. Determining whether IPE is in permissive or enforced mode can be derivedfrom ``success`` property and exit code of the ``AUDITSYSCALL`` record.  Field descriptions: +-----------+------------+-----------+---------------------------------------------------------------------------------+| Field     | Value Type | Optional? | Description of Value                                                            |+===========+============+===========+=================================================================================+| ipe_op    | string     | No        | The IPE operation name associated with the log                                  |+-----------+------------+-----------+---------------------------------------------------------------------------------+| ipe_hook  | string     | No        | The name of the LSM hook that triggered the IPE event                           |+-----------+------------+-----------+---------------------------------------------------------------------------------+| enforcing | integer    | No        | The current IPE enforcing state 1 is in enforcing mode, 0 is in permissive mode |+-----------+------------+-----------+---------------------------------------------------------------------------------+| pid       | integer    | No        | The pid of the process that triggered the IPE event.                            |+-----------+------------+-----------+---------------------------------------------------------------------------------+| comm      | string     | No        | The command line program name of the process that triggered the IPE event       |+-----------+------------+-----------+---------------------------------------------------------------------------------+| path      | string     | Yes       | The absolute path to the evaluated file                                         |+-----------+------------+-----------+---------------------------------------------------------------------------------+| ino       | integer    | Yes       | The inode number of the evaluated file                                          |+-----------+------------+-----------+---------------------------------------------------------------------------------+| dev       | string     | Yes       | The device name of the evaluated file, e.g. vda                                 |+-----------+------------+-----------+---------------------------------------------------------------------------------+| rule      | string     | No        | The matched policy rule                                                         |+-----------+------------+-----------+---------------------------------------------------------------------------------+ 1421 AUDIT_IPE_CONFIG_CHANGE^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Event Example::    type=1421 audit(1653425583.136:54): old_active_pol_name="Allow_All" old_active_pol_version=0.0.0 old_policy_digest=sha256:E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 new_active_pol_name="boot_verified" new_active_pol_version=0.0.0 new_policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F26765076DD8EED7B8F4DB auid=4294967295 ses=4294967295 lsm=ipe res=1   type=1300 audit(1653425583.136:54): SYSCALL arch=c000003e syscall=1 success=yes exit=2 a0=3 a1=5596fcae1fb0 a2=2 a3=2 items=0 ppid=184 pid=229 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=4294967295 comm="python3" exe="/usr/bin/python3.10" key=(null)   type=1327 audit(1653425583.136:54): PROCTITLE proctitle=707974686F6E3300746573742F6D61696E2E7079002D66002E2 This event indicates that IPE switched the active poliy from one to anotheralong with the version and the hash digest of the two policies.Note IPE can only have one policy active at a time, all access decisionevaluation is based on the current active policy.The normal procedure to deploy a new policy is loading the policy to deployinto the kernel first, then switch the active policy to it. This record will always be emitted in conjunction with a ``AUDITSYSCALL`` record for the ``write`` syscall. Field descriptions: +------------------------+------------+-----------+---------------------------------------------------+| Field                  | Value Type | Optional? | Description of Value                              |+========================+============+===========+===================================================+| old_active_pol_name    | string     | Yes       | The name of previous active policy                |+------------------------+------------+-----------+---------------------------------------------------+| old_active_pol_version | string     | Yes       | The version of previous active policy             |+------------------------+------------+-----------+---------------------------------------------------+| old_policy_digest      | string     | Yes       | The hash of previous active policy                |+------------------------+------------+-----------+---------------------------------------------------+| new_active_pol_name    | string     | No        | The name of current active policy                 |+------------------------+------------+-----------+---------------------------------------------------+| new_active_pol_version | string     | No        | The version of current active policy              |+------------------------+------------+-----------+---------------------------------------------------+| new_policy_digest      | string     | No        | The hash of current active policy                 |+------------------------+------------+-----------+---------------------------------------------------+| auid                   | integer    | No        | The login user ID                                 |+------------------------+------------+-----------+---------------------------------------------------+| ses                    | integer    | No        | The login session ID                              |+------------------------+------------+-----------+---------------------------------------------------+| lsm                    | string     | No        | The lsm name associated with the event            |+------------------------+------------+-----------+---------------------------------------------------+| res                    | integer    | No        | The result of the audited operation(success/fail) |+------------------------+------------+-----------+---------------------------------------------------+ 1422 AUDIT_IPE_POLICY_LOAD^^^^^^^^^^^^^^^^^^^^^^^^^^ Event Example::    type=1422 audit(1653425529.927:53): policy_name="boot_verified" policy_version=0.0.0 policy_digest=sha256:820EEA5B40CA42B51F68962354BA083122A20BB846F26765076DD8EED7B8F4DB auid=4294967295 ses=4294967295 lsm=ipe res=1 errno=0   type=1300 audit(1653425529.927:53): arch=c000003e syscall=1 success=yes exit=2567 a0=3 a1=5596fcae1fb0 a2=a07 a3=2 items=0 ppid=184 pid=229 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=4294967295 comm="python3" exe="/usr/bin/python3.10" key=(null)   type=1327 audit(1653425529.927:53): PROCTITLE proctitle=707974686F6E3300746573742F6D61696E2E7079002D66002E2E This record indicates a new policy has been loaded into the kernel with the policy name, policy version and policy hash. This record will always be emitted in conjunction with a ``AUDITSYSCALL`` record for the ``write`` syscall. Field descriptions: +----------------+------------+-----------+-------------------------------------------------------------+| Field          | Value Type | Optional? | Description of Value                                        |+================+============+===========+=============================================================+| policy_name    | string     | Yes       | The policy_name                                             |+----------------+------------+-----------+-------------------------------------------------------------+| policy_version | string     | Yes       | The policy_version                                          |+----------------+------------+-----------+-------------------------------------------------------------+| policy_digest  | string     | Yes       | The policy hash                                             |+----------------+------------+-----------+-------------------------------------------------------------+| auid           | integer    | No        | The login user ID                                           |+----------------+------------+-----------+-------------------------------------------------------------+| ses            | integer    | No        | The login session ID                                        |+----------------+------------+-----------+-------------------------------------------------------------+| lsm            | string     | No        | The lsm name associated with the event                      |+----------------+------------+-----------+-------------------------------------------------------------+| res            | integer    | No        | The result of the audited operation(success/fail)           |+----------------+------------+-----------+-------------------------------------------------------------+| errno          | integer    | No        | Error code from policy loading operations (see table below) |+----------------+------------+-----------+-------------------------------------------------------------+ Policy error codes (errno): The following table lists the error codes that may appear in the errno field while loading or updating the policy: +----------------+--------------------------------------------------------+| Error Code     | Description                                            |+================+========================================================+| 0              | Success                                                |+----------------+--------------------------------------------------------+| -EPERM         | Insufficient permission                                |+----------------+--------------------------------------------------------+| -EEXIST        | Same name policy already deployed                      |+----------------+--------------------------------------------------------+| -EBADMSG       | Policy is invalid                                      |+----------------+--------------------------------------------------------+| -ENOMEM        | Out of memory (OOM)                                    |+----------------+--------------------------------------------------------+| -ERANGE        | Policy version number overflow                         |+----------------+--------------------------------------------------------+| -EINVAL        | Policy version parsing error                           |+----------------+--------------------------------------------------------+| -ENOKEY        | Key used to sign the IPE policy not found in keyring   |+----------------+--------------------------------------------------------+| -EKEYREJECTED  | Policy signature verification failed                   |+----------------+--------------------------------------------------------+| -ESTALE        | Attempting to update an IPE policy with older version  |+----------------+--------------------------------------------------------+| -ENOENT        | Policy was deleted while updating                      |+----------------+--------------------------------------------------------+ 1404 AUDIT_MAC_STATUS^^^^^^^^^^^^^^^^^^^^^

Lines 1–500 of 835.