[PATCH] ima: fix deadlock when traversing "ima_default_rules".

Mimi Zohar zohar at linux.ibm.com
Thu Sep 30 19:46:52 UTC 2021

Hi Liqiong,

On Sat, 2021-09-18 at 11:11 +0800, liqiong wrote:
> 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 at nfschina.com>
> Reviewed-by: THOBY Simon <Simon.THOBY at viveris.fr>
> Fixes: 38d859f991f3 ("IMA: policy can now be updated multiple times")
> Signed-off-by: Mimi Zohar <zohar at linux.ibm.com>
> Reported-by: kernel test robot <lkp at intel.com>
> Fix sparse: incompatible types in comparison expression.

The "Fix sparse" line shouldn't be on a separate line.  Either post the
one line fix as a separate patch using the normal "Fixes:" tag or fix
the "Reported-by" line, as previously suggested.



More information about the Linux-security-module-archive mailing list