public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: "Guozihua (Scott)" <guozihua@huawei.com>
To: Mimi Zohar <zohar@linux.ibm.com>, <dmitry.kasatkin@gmail.com>,
	<jmorris@namei.org>, <serge@hallyn.com>
Cc: <linux-integrity@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH] ima: fix deadlock when traversing "ima_default_rules".
Date: Wed, 8 May 2024 15:06:30 +0800	[thread overview]
Message-ID: <af9692da-dede-bedd-a373-70981da41dee@huawei.com> (raw)
In-Reply-To: <3a155ac1-b97a-9ee3-a609-469502653f28@huawei.com>

On 2024/5/8 10:06, Guozihua (Scott) wrote:
> On 2024/5/7 19:54, Mimi Zohar wrote:
>> On Tue, 2024-05-07 at 09:37 +0000, GUO Zihua wrote:
>>> From: liqiong <liqiong@nfschina.com>
>>>
>>> [ Upstream commit eb0782bbdfd0d7c4786216659277c3fd585afc0e ]
>>>
>>> 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.
>>>
>>> Addition:
>>>
>>> A rcu_read_lock pair is added within ima_update_policy_flag to avoid
>>> suspicious RCU usage warning. This pair of RCU lock was added with
>>> commit 4f2946aa0c45 ("IMA: introduce a new policy option
>>> func=SETXATTR_CHECK") on mainstream.
>>>
>>> Signed-off-by: liqiong <liqiong@nfschina.com>
>>> Reviewed-by: THOBY Simon <Simon.THOBY@viveris.fr>
>>> Fixes: 38d859f991f3 ("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>
>>> Sig=ned-off-by: GUO Zihua <guozihua@huawei.com>
>>
>> Hi Scott,
>>
>> I'm confused by this patch.  Is it meant for upstream?
>>
>> thanks,
>>
>> Mimi
>>
> It's a backport from upstream.
> 
To clarify, it's meant for Linux-5.10.y.

-- 
Best
GUO Zihua


  reply	other threads:[~2024-05-08  7:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  9:37 [PATCH] ima: fix deadlock when traversing "ima_default_rules" GUO Zihua
2024-05-07 11:54 ` Mimi Zohar
2024-05-08  2:06   ` Guozihua (Scott)
2024-05-08  7:06     ` Guozihua (Scott) [this message]
2024-05-23 11:44       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af9692da-dede-bedd-a373-70981da41dee@huawei.com \
    --to=guozihua@huawei.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=jmorris@namei.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=stable@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox