Linux filesystem development
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Michael Greenberg <michael@greenberg.science>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, mgreenbe@stevens.edu
Subject: Re: [PATCH] namei: don't count symlinks twice when a lookup restarts
Date: Tue, 24 Nov 2026 03:52:45 +0000	[thread overview]
Message-ID: <20261124035245.GX989762@ZenIV> (raw)
In-Reply-To: <20261124031649.GW989762@ZenIV>

On Tue, Nov 24, 2026 at 03:16:49AM +0000, Al Viro wrote:
> On Mon, Nov 23, 2026 at 02:44:28PM -0500, Michael Greenberg wrote:
> > So a path that crosses n symlinks fails with -ELOOP if the RCU walk
> > got through more than MAXSYMLINKS - n of them before giving up, which
> > is possible for any n > MAXSYMLINKS / 2. A mount or umount anywhere
> > on the system can make an RCU walk give up, since it changes
> > mount_lock's sequence count, so whether such a lookup fails depends on
> > unrelated activity. Opening the first link of a chain for 3 s, in a
> > 4-CPU KVM guest, while another process mounted and unmounted a tmpfs
> > in its own mount namespace:
> 
> You don't need mount to kick you out of RCU mode - just walk through
> /proc/self/root/... at given step of the chain and you'll get deterministic
> behaviour; no races needed at all.
> 
> Bug is real, but I'm not sure I like your solution - duplication
> between path_init() and __set_nameidata() is confusing.  We can't
> just drop that part of __set_nameidata() - it's possible to get
> from set_nameidata() to restore_nameidata() without ever reaching
> path_init(), e.g. in do_file_open() if alloc_empty_file() fails,
> so it can't be dealt with that way, but...
> 
> Let me think a bit; if we go with your variant, we'll need a very clear
> comment along the lines of "it's not really redundant - removing either
> will break things" added in both places.

One possibility would be
	p->total_link_count = -1;
in __set_nameidata(), same change as in your variant in path_init()
and
	if (unlikely(old) && now->total_link_count > 0)
		old->total_link_count = now->total_link_count;
in restore_nameidata().  Not sure I like that variant, though...

One thing to keep in mind is that reserve_stack() is not the only
place where we bump that thing - follow_automount() is another and
there we don't have nameidata on hand...

      reply	other threads:[~2026-11-24  3:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 19:44 [PATCH] namei: don't count symlinks twice when a lookup restarts Michael Greenberg
2026-11-24  3:16 ` Al Viro
2026-11-24  3:52   ` Al Viro [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=20261124035245.GX989762@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mgreenbe@stevens.edu \
    --cc=michael@greenberg.science \
    /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