linux-stable/security/integrity
liqiong eb15243bc9 ima: fix deadlock when traversing "ima_default_rules".
commit eb0782bbdf upstream.

The current IMA ruleset is identified by the variable "ima_rules"
that default to "&ima_default_rules". When loading a custom policy
for the first time, the variable is updated to "&ima_policy_rules"
instead. That update isn't RCU-safe, and deadlocks are possible.
Indeed, some functions like ima_match_policy() may loop indefinitely
when traversing "ima_default_rules" with list_for_each_entry_rcu().

When iterating over the default ruleset back to head, if the list
head is "ima_default_rules", and "ima_rules" have been updated to
"&ima_policy_rules", the loop condition (&entry->list != ima_rules)
stays always true, traversing won't terminate, causing a soft lockup
and RCU stalls.

Introduce a temporary value for "ima_rules" when iterating over
the ruleset to avoid the deadlocks.

Signed-off-by: liqiong <liqiong@nfschina.com>
Reviewed-by: THOBY Simon <Simon.THOBY@viveris.fr>
Fixes: 38d859f991 ("IMA: policy can now be updated multiple times")
Reported-by: kernel test robot <lkp@intel.com> (Fix sparse: incompatible types in comparison expression.)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: GUO Zihua <guozihua@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-05-25 16:19:06 +02:00
..
evm evm: Complete description of evm_inode_setattr() 2023-07-27 08:43:35 +02:00
ima ima: fix deadlock when traversing "ima_default_rules". 2024-05-25 16:19:06 +02:00
platform_certs efi: Add iMac Pro 2017 to uefi skip cert quirk 2023-01-14 10:16:34 +01:00
Kconfig
Makefile
digsig.c integrity: Fix memory leakage in keyring allocation error path 2023-01-14 10:15:29 +01:00
digsig_asymmetric.c integrity-v5.10 2020-10-15 15:58:18 -07:00
iint.c ima: annotate iint mutex to avoid lockdep false positive warnings 2023-12-08 08:46:15 +01:00
integrity.h ima: detect changes to the backing overlay file 2023-11-28 16:54:57 +00:00
integrity_audit.c integrity: check the return value of audit_log_start() 2022-02-16 12:54:16 +01:00