linux/security/integrity/ima
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
..
ima_api.c ima: Remove ima_h_table structure 2026-06-08 11:42:40 -04:00
ima_appraise.c ima: fix out-of-bounds read in xattr_verify() 2026-08-04 12:35:02 -04:00
ima_asymmetric_keys.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
ima_crypto.c ima: remove buggy support for asynchronous hashes 2026-03-17 18:53:49 -04:00
ima_efi.c ima: add critical data measurement for loaded policy 2026-08-04 12:35:03 -04:00
ima_fs.c ima: measure userspace policy writes before parsing 2026-08-04 12:35:03 -04:00
ima_iint.c lsm: add the inode_free_security_rcu() LSM implementation hook 2024-08-12 15:35:04 -04:00
ima_init.c security: ima: rename boot_aggregate when ima is initialised at late_sync 2026-08-04 12:35:02 -04:00
ima_kexec.c ima: Add support for staging measurements with prompt 2026-06-08 11:43:21 -04:00
ima_main.c ima: measure userspace policy writes before parsing 2026-08-04 12:35:03 -04:00
ima_modsig.c module: Give MODULE_SIG_STRING a more descriptive name 2026-03-24 21:42:37 +00:00
ima_mok.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ima_policy.c ima: measure userspace policy writes before parsing 2026-08-04 12:35:03 -04:00
ima_queue_keys.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ima_queue.c ima: Support staging and deleting N measurements records 2026-06-08 11:43:34 -04:00
ima_template_lib.c security: ima: rename boot_aggregate when ima is initialised at late_sync 2026-08-04 12:35:02 -04:00
ima_template_lib.h ima: define a new template field named 'd-ngv2' and templates 2022-05-05 11:49:13 -04:00
ima_template.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ima.h ima: measure userspace policy writes before parsing 2026-08-04 12:35:03 -04:00
Kconfig security: ima: introduce IMA_INIT_LATE_SYNC option 2026-08-04 12:35:02 -04:00
Makefile ima: Make it independent from 'integrity' LSM 2024-02-15 23:43:47 -05:00