All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] audit: fix exe mark UAF in kill_rules()
@ 2026-09-21 19:59 Jérémy Jean
  2026-09-21 20:15 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jérémy Jean @ 2026-09-21 19:59 UTC (permalink / raw)
  To: Paul Moore, Eric Paris; +Cc: audit, linux-kernel, Jérémy Jean

kill_rules() removes mixed AUDIT_DIR and AUDIT_EXE rules when an audit
tree is pruned. It drops entry->rule.exe before removing the rule from
the RCU-visible filter lists.

After a rule has been installed with AUDIT_ADD_RULE, which requires
CAP_AUDIT_CONTROL, removing or moving the watched directory can race
with another task that is still evaluating the rule. In that case,
fsnotify can free the executable mark before the reader reaches
audit_mark_compare(), causing a use-after-free.

KASAN reports:

    BUG: KASAN: slab-use-after-free in audit_mark_compare+0x8d/0xa0

Remove the rule from the RCU-visible filter lists first, wait for a grace
period, and only then drop the executable mark. audit_del_rule() already
uses this ordering.

Fixes: 34d99af52ad4 ("audit: implement audit by executable")
Assisted-by: Codex:gpt-5
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
 kernel/audit_tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index 1ed19b7..864a58b 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -553,11 +553,12 @@ static void kill_rules(struct audit_context *context, struct audit_tree *tree)
 		if (rule->tree) {
 			/* not a half-baked one */
 			audit_tree_log_remove_rule(context, rule);
-			if (entry->rule.exe)
-				audit_remove_mark(entry->rule.exe);
 			rule->tree = NULL;
 			list_del_rcu(&entry->list);
 			list_del(&entry->rule.list);
+			synchronize_rcu();
+			if (entry->rule.exe)
+				audit_remove_mark(entry->rule.exe);
 			call_rcu(&entry->rcu, audit_free_rule_rcu);
 		}
 	}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-22 20:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-21 19:59 [PATCH] audit: fix exe mark UAF in kill_rules() Jérémy Jean
2026-09-21 20:15 ` sashiko-bot
2026-09-22  6:38 ` Bradley Morgan
2026-09-22 11:26 ` Ricardo Robaina
2026-09-22 13:46   ` Jérémy Jean
2026-09-22 15:08     ` Bradley Morgan
2026-09-22 20:07     ` Ricardo Robaina

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.