mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: syzbot <syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] fs/namei: fix UAF in pick_link() by unlazying before atime check
Date: Mon, 01 Jun 2026 16:48:58 -0700	[thread overview]
Message-ID: <6a1e1a6a.b111c304.35cd64.0029.GAE@google.com> (raw)
In-Reply-To: <6a1dbc91.fbc46276.3c3783.0004.GAE@google.com>

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] fs/namei: fix UAF in pick_link() by unlazying before atime check
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master


In pick_link(), atime_needs_update() is called while the path walk
may still be in RCU mode (LOOKUP_RCU set), meaning no reference is
held on the inode. A concurrent iput() from another task can free
the inode while atime_needs_update() reads inode->i_opflags (offset
+2) inside current_time() -> is_mgtime(), causing a use-after-free.

KASAN reports:
  BUG: KASAN: slab-use-after-free in is_mgtime include/linux/fs.h:2313
  Read of size 2 at addr ffff8880407e4282 (offset +2 = i_opflags)

The race:
  Task A (pick_link)             Task B (unlinkat)
  ------------------             -----------------
  atime_needs_update(inode)      iput(inode)
    current_time(inode)            evict()
      is_mgtime(inode)               destroy_inode()
        inode->i_opflags  UAF          inode FREED

Fix: call try_to_unlazy() before atime_needs_update() so that
a proper inode reference is held before any inode fields are read.
If try_to_unlazy() detects the inode is already gone, it returns
false and we exit safely with -ECHILD without touching freed memory.

Reported-by: syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=36e50496c8ac4bcde3f9
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>"
---
 fs/namei.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index c7fac83c9a85..eac0ec35be37 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2037,11 +2037,11 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
 			unlikely(link->mnt->mnt_flags & MNT_NOSYMFOLLOW))
 		return ERR_PTR(-ELOOP);
 
+	if (nd->flags & LOOKUP_RCU) {
+		if (!try_to_unlazy(nd))
+			return ERR_PTR(-ECHILD);
+	}
 	if (unlikely(atime_needs_update(&last->link, inode))) {
-		if (nd->flags & LOOKUP_RCU) {
-			if (!try_to_unlazy(nd))
-				return ERR_PTR(-ECHILD);
-		}
 		touch_atime(&last->link);
 		cond_resched();
 	}
-- 
2.43.0


  reply	other threads:[~2026-06-01 23:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 17:08 [syzbot] [fs?] KASAN: slab-use-after-free Read in current_time syzbot
2026-06-01 23:48 ` syzbot [this message]
2026-06-02  1:39 ` Forwarded: [PATCH] bpf: fix UAF by restoring RCU-delayed inode freeing in bpffs syzbot

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=6a1e1a6a.b111c304.35cd64.0029.GAE@google.com \
    --to=syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzkaller-bugs@googlegroups.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

Powered by JetHome