btrfs: scrub: fix several races which can lead to UAF
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest2 patches 1 replyIn review
- v12 patches 4 repliesSuperseded
Changes in v2 from the cover letter
- Fix the race charts where the sequence is incorrect All functions are shown when there is enough space.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | btrfs: scrub: fix use-after-free when waking up the repair waiterfs/ | +8 | 0 replies | |
| 2/2 | btrfs: scrub: fix use-after-free when waking up the stripe I/O waiterfs/ | +69 | 0 replies |
Reviews trailers per patch
None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Filipe Manana |
|---|---|
| Series | R-b |
| 1/2 | |
| 2/2 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 0/2] btrfs: scrub: fix several races which can lead to UAF
[CHANGELOG]
v2:
- Fix the race charts where the sequence is incorrect All functions are shown when there is enough space.
Also re-order the functions to properly represent their correct time sequence.
- Do not use non-upstream commit number in the commit message
This is inspired by the fix in raid56:
https://lore.kernel.org/linux-btrfs/[email protected]/
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(-)
Signature · 1 line
2.56.0