From: Greg KH <greg@kroah.com>
To: "Guozihua (Scott)" <guozihua@huawei.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>,
dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com,
linux-integrity@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] ima: fix deadlock when traversing "ima_default_rules".
Date: Thu, 23 May 2024 13:44:24 +0200 [thread overview]
Message-ID: <2024052317-reassign-keep-ea77@gregkh> (raw)
In-Reply-To: <af9692da-dede-bedd-a373-70981da41dee@huawei.com>
On Wed, May 08, 2024 at 03:06:30PM +0800, Guozihua (Scott) wrote:
> 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.
Now queued up, thanks.
greg k-h
prev parent reply other threads:[~2024-05-23 11:44 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)
2024-05-23 11:44 ` Greg KH [this message]
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=2024052317-reassign-keep-ea77@gregkh \
--to=greg@kroah.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=guozihua@huawei.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