linux/security/integrity
Enrico Bravi f1e10b1087 ima: measure userspace policy writes before parsing
When a signed policy is not mandatory, userspace can write IMA policy rules
directly to the securityfs policy file:

echo -e "measure func=BPRM_CHECK mask=MAY_EXEC\n" \
        "audit func=BPRM_CHECK mask=MAY_EXEC\n" \
     > /sys/kernel/security/ima/policy

or by cat'ing the entire IMA custom policy file:

cat ima-policy-file > /sys/kernel/security/ima/policy

Because these rules originate from userspace and cross the userspace/kernel
trust boundary, measure the raw write buffer before parsing, regardless of
whether the new policy will be accepted or not. This can be caught when
'measure func=POLICY_CHECK' is enabled (e.g., ima_policy=tcb). The
measurement template is forced to ima-buf.
This follows the "measure & load" paradigm, exposing potential bugs in
the policy code and detecting attempts to corrupt IMA. It also completes
the POLICY_CHECK hook, which already measures partial policy load by file.

To verify the template data hash value, convert the buffer policy data
to binary:
grep "ima_policy_written" \
	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum

Suggested-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Enrico Bravi <enrico.bravi@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
2026-08-04 12:35:03 -04:00
..
evm evm: terminate and bound the evm_xattrs read buffer 2026-05-13 08:31:40 -04:00
ima ima: measure userspace policy writes before parsing 2026-08-04 12:35:03 -04:00
platform_certs integrity: Make arch_ima_get_secureboot integrity-wide 2026-03-05 11:10:08 -05:00
digsig_asymmetric.c integrity: Add support for sigv3 verification using ML-DSA keys 2026-05-13 08:21:19 -04:00
digsig.c ima: Define asymmetric_verify_v3() to verify IMA sigv3 signatures 2026-04-01 10:14:30 -04:00
efi_secureboot.c integrity: Make arch_ima_get_secureboot integrity-wide 2026-03-05 11:10:08 -05:00
iint.c ima,evm: move initcalls to the LSM framework 2025-10-22 19:24:27 -04:00
integrity_audit.c treewide: change inode->i_ino from unsigned long to u64 2026-03-06 14:31:28 +01:00
integrity.h ima: Define asymmetric_verify_v3() to verify IMA sigv3 signatures 2026-04-01 10:14:30 -04:00
Kconfig integrity: Select CRYPTO from INTEGRITY_ASYMMETRIC_KEYS 2025-10-03 07:50:56 -04:00
Makefile integrity: Eliminate weak definition of arch_get_secureboot() 2026-03-13 11:37:13 -04:00