All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Deepanshu Kartikey <kartikey406@gmail.com>
Cc: brauner@kernel.org, jack@suse.cz, mjguzik@gmail.com,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.com
Subject: Re: [PATCH] fs/namei: fix UAF in pick_link() by unlazying before atime check
Date: Tue, 2 Jun 2026 01:43:20 +0100	[thread overview]
Message-ID: <20260602004320.GL2636677@ZenIV> (raw)
In-Reply-To: <20260602002607.110866-1-kartikey406@gmail.com>

On Tue, Jun 02, 2026 at 05:56:07AM +0530, Deepanshu Kartikey wrote:
> 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.

NAK.  This is *not* fixing the real problem; it's papering over the
real breakage.  At a guess - in bpffs, if that's the same thing as
in https://lore.kernel.org/all/20260423043906.GN3518998@ZenIV/

Prompt freeing of inode is allowed *ONLY* if inode is never exposed
to lazy pathwalk.  It's OK for pipes, but this is not a pipe.

  reply	other threads:[~2026-06-02  0:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02  0:26 [PATCH] fs/namei: fix UAF in pick_link() by unlazying before atime check Deepanshu Kartikey
2026-06-02  0:43 ` Al Viro [this message]
2026-06-02  1:40   ` Deepanshu Kartikey

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=20260602004320.GL2636677@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=kartikey406@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=syzbot+36e50496c8ac4bcde3f9@syzkaller.appspotmail.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 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.