Re: [PATCH next] btrfs: Accessing head_ref within delayed_refs lock

From: David Sterba
Date: Tue Oct 15 2024 - 12:38:41 EST


On Tue, Oct 15, 2024 at 01:49:04PM +0100, Filipe Manana wrote:
> On Tue, Oct 15, 2024 at 1:40 PM Edward Adam Davis <eadavis@xxxxxx> wrote:
> >
> > This is because the thread routine btrfs_work_helper released head_def after
> > exiting delayed_refs->lock in add_delayed_ref.
>
> This should be explained a lot better. Starting the changelog with
> "This is because..." is odd. It should explain why the head reference
> was freed (because delayed references were run).
>
> > Causing add_delayed_ref to encounter uaf when accessing head_def->bytenr
> > outside the delayed_refs->lock.
> >
> > Move head_ref->bytenr into the protection range of delayed_refs->lock
> > to avoid uaf in add_delayed_ref.
>
>
> This was already fixed yesterday, in a simpler way and with an
> explanation of what's going on to trigger the use-after-free:
>
> https://lore.kernel.org/linux-btrfs/02fc507b62b19be2348fc08de8b13bd7af1a440e.1728922973.git.fdmanana@xxxxxxxx/

This will be in the upcoming linux-next, so we'll not get the syzbot and
build reports anymore.