Re: [PATCH v3] xfs: fix slab-use-after-free in xrep_newbt_free()
From: Christoph Hellwig
Date: Fri Dec 04 2026 - 03:57:40 EST
The email format is a bit odd. It obviously is a reply continuing
the previous discussion, but it breaks threading and adds a new subject.
On Thu, Dec 03, 2026 at 09:22:03PM +0800, Zheng Shuhao wrote:
> On Wed, Dec 2, 2026 at 07:28:34AM +0000, Christoph Hellwig wrote:
> > Using the control flow instead of global state is usually preferable.
> > I.e. check which path can free the autoreap information and treat them
> > differently using a goto or similar. I think the only relevant call is
> > xrep_newbt_free in the xrep_newbt_free loop, but I'm not an expert on
> > this code, so please double check.
>
> I considered changing the control flow, but found that this would make
> error-path handling more complex because the defer-finish failure paths
> would need to be handled separately.
>
> I therefore kept the existing control flow and used a standard list
> traversal to check whether the exact deferred item is still pending
> before unpausing it.
This now pokes into defer_ops implementation details. I spent some
time looking at this, but AFAICS the call to xfs_alloc_commit_autoreap
in xrep_newbt_free is always superfluous. The only way we can end up
in that error path is with a file system either already shut down,
or about to shut down due to corruption.
So xfs_alloc_commit_autoreap won't have any effect and we can just
remove it entirely.