All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: "open list:AUDIT SUBSYSTEM" <audit@vger.kernel.org>
Subject: Re: [PATCH] audit: unlink tree rules in the update_lsm_rule() error path
Date: Thu, 03 Dec 2026 09:43:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-247492@kernel.org> (raw)
In-Reply-To: <20261203092331.2258226-1-hdthky0@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] audit: data race on rule->tree in update_lsm_rule() error
  path
--

commit cac8913d0efae9fad82939eb55583b67b3cf861a
Author: Xingyuan Mo <hdthky0@gmail.com>

audit: unlink tree rules in the update_lsm_rule() error path

This patch calls audit_remove_tree_rule() in the update_lsm_rule() error
path when audit_dupe_rule() fails on a rule with an associated audit_tree.

> diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
> index cf91ba6f3617b..06fe7ab13eb7a 100644
> --- a/kernel/auditfilter.c
> +++ b/kernel/auditfilter.c
> @@ -1422,6 +1422,8 @@ static int update_lsm_rule(struct audit_krule *r)
>  		audit_panic("error updating LSM filters");
>  		if (r->watch)
>  			list_del(&r->rlist);
> +		if (r->tree)
> +			audit_remove_tree_rule(r);
>  		list_del_rcu(&entry->list);
>  		list_del(&r->list);
>  		audit_rule_unaccount(r);

[Severity: Medium]
Can calling audit_remove_tree_rule() before list_del_rcu() and without
synchronize_rcu() race on r->tree with lockless RCU readers?

audit_remove_tree_rule() performs a plain store setting rule->tree to NULL
while entry is still reachable on the RCU filter list.  Concurrently,
audit_filter_rules() reads rule->tree under rcu_read_lock() and passes it
to the static helper match_tree_refs():

CPU0                              CPU1
update_lsm_rule()                 audit_filter_syscall()
  audit_remove_tree_rule(r)         rcu_read_lock()
                                    audit_filter_rules()
                                      match_tree_refs(ctx, rule->tree)
                                        if (!tree) /* non-NULL */
    rule->tree = NULL;                  /* reloads rule->tree as NULL */
                                        audit_tree_match(chunk, NULL)
                                          <-- data race / false match
  list_del_rcu(&entry->list)

Because match_tree_refs() is inlined without READ_ONCE(), the compiler can
reload rule->tree after its NULL check and pass NULL to audit_tree_match().
Since remove_chunk_node() clears chunk->owners[n].owner to NULL in place,
this can match a cleared slot and cause a spurious AUDIT_DIR rule match.

Unlinking entry with list_del_rcu() and list_del() followed by
synchronize_rcu() before calling audit_remove_tree_rule(), matching
audit_del_rule(), avoids the race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203092331.2258226-1-hdthky0@gmail.com?part=1

      reply	other threads:[~2026-12-03  9:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:24 [PATCH] audit: unlink tree rules in the update_lsm_rule() error path Xingyuan Mo
2026-12-03  9:43 ` sashiko-bot [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=sashiko-outbox-247492@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=audit@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.