Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 0/2] btrfs: scrub: fix several races which can lead to UAF
Date: Tue, 17 Nov 2026 09:04:15 +1030	[thread overview]
Message-ID: <cover.1794867985.git.wqu@suse.com> (raw)

This is inspired by the fix in raid56:
https://lore.kernel.org/linux-btrfs/20261116001903.63524-1-mc@raidlab.org/

And there are two similar cases inside scrub.c:
- scrub_stripe::repair_wait
- scrub_stripe::io_wait

The only difference is, the window is much smaller compared to RAID56,
as most scrub_stripe structure have a very long lifespan, as long as the
scrub/replace ioctl. Only the RAID56 data stripes has a shorter
lifespan.

But still it's possible in theory, so here comes the same fix for scrub.

For repair_wait it's pretty straight foward.

For io_wait we have several locations that we submit a batch of bios in
one go, and pending_io may drop to zero during IOs.
Follow the existing behavior by grabbing one extra ref to ensure the
pending_io won't reach zero during IOs.

Qu Wenruo (2):
  btrfs: scrub: fix use-after-free when waking up the repair waiter
  btrfs: scrub: fix use-after-free when waking up the stripe I/O waiter

 fs/btrfs/scrub.c | 116 +++++++++++++++++++++++++++++++----------------
 1 file changed, 77 insertions(+), 39 deletions(-)

-- 
2.56.0


             reply	other threads:[~2026-11-16 22:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:34 Qu Wenruo [this message]
2026-11-16 22:34 ` [PATCH 1/2] btrfs: scrub: fix use-after-free when waking up the repair waiter Qu Wenruo
2026-11-16 22:34 ` [PATCH 2/2] btrfs: scrub: fix use-after-free when waking up the stripe I/O waiter Qu Wenruo

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=cover.1794867985.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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