linux-stable/security
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
..
apparmor lsm: make security_socket_getpeersec_stream() sockptr_t safe 2024-03-15 10:48:20 -04:00
bpf
integrity ima: fix deadlock when traversing "ima_default_rules". 2024-05-25 16:19:06 +02:00
keys keys: Fix overwrite of key expiration on instantiation 2024-05-17 11:48:11 +02:00
loadpin LoadPin: Ignore the "contents" argument of the LSM hooks 2023-01-14 10:16:22 +01:00
lockdown
safesetid LSM: SafeSetID: Fix warnings reported by test bot 2020-10-13 09:17:36 -07:00
selinux lsm: make security_socket_getpeersec_stream() sockptr_t safe 2024-03-15 10:48:20 -04:00
smack smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() 2024-04-13 12:58:00 +02:00
tomoyo tomoyo: fix UAF write bug in tomoyo_write_control() 2024-03-06 14:37:49 +00:00
yama task_work: cleanup notification modes 2020-10-17 15:05:30 -06:00
commoncap.c capabilities: fix potential memleak on error path from vfs_getxattr_alloc() 2022-11-10 18:14:26 +01:00
device_cgroup.c device_cgroup: Roll back to original exceptions after copy failure 2023-01-14 10:16:36 +01:00
inode.c
Kconfig x86/retbleed: Add fine grained Kconfig knobs 2022-07-25 11:26:50 +02:00
Kconfig.hardening hardening: Remove Clang's enable flag for -ftrivial-auto-var-init=zero 2022-10-26 13:25:12 +02:00
lsm_audit.c
Makefile
min_addr.c
security.c lsm: fix default return value of the socket_getpeersec_*() hooks 2024-03-15 10:48:20 -04:00