Re: [PATCH] super: make iterate_supers_type() deletion-safe
From: Christian Brauner
Date: Fri Sep 04 2026 - 07:08:28 EST
On Thu, Sep 03, 2026 at 12:16:14PM +0200, Jan Kara wrote:
> On Thu 03-09-26 03:33:36, Karl Mehltretter wrote:
> > iterate_supers_type() drops sb_lock while invoking the callback and keeps
> > only a passive reference to the current superblock. That reference keeps
> > the object allocated, but does not keep its s_instances node linked.
> >
> > After the callback releases s_umount, final teardown can unlink the current
> > s_instances node. The iterator then advances through a reinitialized node.
> > With the current hlist it stops without visiting the remaining superblocks.
> > The unlink moved from generic_shutdown_super() to kill_super_notify(), but
> > the cursor lifetime has been unsafe since the helper was introduced.
> >
> > The CIFS DFS lookup can consequently miss a matching superblock and return
> > -EINVAL.
> >
> > Walk the global superblock list in reverse and filter it by filesystem
> > type. A passive reference keeps its s_list node linked, and reverse
> > traversal preserves newest-first visitation. Superblocks removed from
> > fs_supers remain on the global list, but teardown marks them SB_DYING
> > before unlinking them, so the existing filter excludes them.
> >
> > This broadens the scan from superblocks of one type to all superblocks.
> > The only in-tree caller is the CIFS DFS lookup, so the broader scan is
> > limited to that path.
> >
> > Fixes: 43e15cdbefea ("new helper: iterate_supers_type()")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Assisted-by: LLM
> > Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
>
> Good spotting! But what I'm wondering about is whether we just shouldn't
> move where we delete sb from fs_supers. Currently we do that in
> kill_super_notify() to hide the sb from sget_fc() (which would otherwise
> permanently retry and call test() for S_DEAD sb which can cause problems).
> But if we just skipped S_DEAD superblocks in sget_fc(), we could move
> removal from fs_supers list to put_super() (make it symmetric with the
> handling of super_blocks list) and that would also fix
> iterate_supers_type(). Christian, what do you think?
Yes, that might work work.