Audit system development
 help / color / mirror / Atom feed
* [PATCH] audit: use rcu_access_pointer() to test inode->i_fsnotify_marks
@ 2026-12-02 18:14 Jiayi Zhang
  2026-12-02 18:16 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Jiayi Zhang @ 2026-12-02 18:14 UTC (permalink / raw)
  To: Paul Moore, Eric Paris; +Cc: Jan Kara, audit, linux-kernel

handle_one() and handle_path() test inode->i_fsnotify_marks for NULL to
skip inodes that have no marks before they look up an audit tree chunk. The pointer is an __rcu
pointer that fsnotify_detach_connector_from_object() clears with
rcu_assign_pointer() when the last mark of the inode goes away, but the
tests read it with a plain load. syzbot reports the same race on this
pointer in fsnotify(), which does the same test:

  BUG: KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object

The race has no functional effect: the tests only compare the pointer
with NULL, and audit_tree_lookup() then searches the chunk hash under
RCU and finds no chunk if the mark is gone.
The plain loads still let the compiler tear or reload them.

Use rcu_access_pointer(), the accessor for testing an __rcu pointer
without dereferencing it.

Fixes: 08991e83b728 ("fsnotify: Free fsnotify_mark_connector when there is no mark attached")
Link: https://syzkaller.appspot.com/bug?extid=f968afcac117a84b7f14
Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>
---
The syzbot report (in moderation, not sent to the lists) is about the
same test in fsnotify(); its fix is sent to the fsnotify maintainers
separately as "fsnotify: use rcu_access_pointer() to test the mark
connector pointers". This audit part was not tested on its own: the
test program for that report does not run audited syscalls with audit
trees.

AI tools assisted with the analysis, the code and the changelog.

 kernel/auditsc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 552ba9f..ed5e70f 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -2065,7 +2065,7 @@ static inline void handle_one(const struct inode *inode)
 	struct audit_chunk *chunk;
 	int count;
 
-	if (likely(!inode->i_fsnotify_marks))
+	if (likely(!rcu_access_pointer(inode->i_fsnotify_marks)))
 		return;
 	context = audit_context();
 	p = context->trees;
@@ -2107,7 +2107,7 @@ retry:
 	for (;;) {
 		struct inode *inode = d_backing_inode(d);
 
-		if (inode && unlikely(inode->i_fsnotify_marks)) {
+		if (inode && unlikely(rcu_access_pointer(inode->i_fsnotify_marks))) {
 			struct audit_chunk *chunk;
 
 			chunk = audit_tree_lookup(inode);
-- 
2.53.0


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

* Re: [PATCH] audit: use rcu_access_pointer() to test inode->i_fsnotify_marks
  2026-12-02 18:14 [PATCH] audit: use rcu_access_pointer() to test inode->i_fsnotify_marks Jiayi Zhang
@ 2026-12-02 18:16 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 18:16 UTC (permalink / raw)
  Cc: audit

> handle_one() and handle_path() test inode->i_fsnotify_marks for NULL to
> skip inodes that have no marks before they look up an audit tree chunk. The pointer is an __rcu
> pointer that fsnotify_detach_connector_from_object() clears with
> rcu_assign_pointer() when the last mark of the inode goes away, but the
> tests read it with a plain load. syzbot reports the same race on this
> pointer in fsnotify(), which does the same test:
> 
>   BUG: KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object
> 
> The race has no functional effect: the tests only compare the pointer
> with NULL, and audit_tree_lookup() then searches the chunk hash under
> RCU and finds no chunk if the mark is gone.
> The plain loads still let the compiler tear or reload them.
> 
> Use rcu_access_pointer(), the accessor for testing an __rcu pointer
> without dereferencing it.
> 
> Fixes: 08991e83b728 ("fsnotify: Free fsnotify_mark_connector when there is no mark attached")
> Link: https://syzkaller.appspot.com/bug?extid=f968afcac117a84b7f14
> Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>

Sashiko has reviewed this patch and found no issues.

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

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

end of thread, other threads:[~2026-12-02 18:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:14 [PATCH] audit: use rcu_access_pointer() to test inode->i_fsnotify_marks Jiayi Zhang
2026-12-02 18:16 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox