Commit 3324d05
btrfs: avoid copying BTRFS_ROOT_SUBVOL_DEAD flag to snapshot of subvolume being deleted
Sweet Tea spotted a race between subvolume deletion and snapshotting
that can result in the root item for the snapshot having the
BTRFS_ROOT_SUBVOL_DEAD flag set. The race is:
Thread 1 | Thread 2
----------------------------------------------|----------
btrfs_delete_subvolume |
btrfs_set_root_flags(BTRFS_ROOT_SUBVOL_DEAD)|
|btrfs_mksubvol
| down_read(subvol_sem)
| create_snapshot
| ...
| create_pending_snapshot
| copy root item from source
down_write(subvol_sem) |
This flag is only checked in send and swap activate, which this would
cause to fail mysteriously.
create_snapshot() now checks the root refs to reject a deleted
subvolume, so we can fix this by locking subvol_sem earlier so that the
BTRFS_ROOT_SUBVOL_DEAD flag and the root refs are updated atomically.
CC: stable@vger.kernel.org # 4.14+
Reported-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Reviewed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>1 parent 7081929 commit 3324d05
1 file changed
Lines changed: 13 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4458 | 4458 | | |
4459 | 4459 | | |
4460 | 4460 | | |
| 4461 | + | |
| 4462 | + | |
4461 | 4463 | | |
4462 | 4464 | | |
4463 | 4465 | | |
| |||
4469 | 4471 | | |
4470 | 4472 | | |
4471 | 4473 | | |
4472 | | - | |
| 4474 | + | |
| 4475 | + | |
4473 | 4476 | | |
4474 | 4477 | | |
4475 | 4478 | | |
4476 | 4479 | | |
4477 | 4480 | | |
4478 | 4481 | | |
4479 | | - | |
| 4482 | + | |
| 4483 | + | |
4480 | 4484 | | |
4481 | 4485 | | |
4482 | 4486 | | |
4483 | 4487 | | |
4484 | 4488 | | |
4485 | 4489 | | |
4486 | | - | |
4487 | | - | |
4488 | 4490 | | |
4489 | 4491 | | |
4490 | | - | |
| 4492 | + | |
4491 | 4493 | | |
4492 | 4494 | | |
4493 | 4495 | | |
| |||
4497 | 4499 | | |
4498 | 4500 | | |
4499 | 4501 | | |
4500 | | - | |
| 4502 | + | |
4501 | 4503 | | |
4502 | 4504 | | |
4503 | 4505 | | |
| |||
4563 | 4565 | | |
4564 | 4566 | | |
4565 | 4567 | | |
4566 | | - | |
4567 | | - | |
| 4568 | + | |
4568 | 4569 | | |
4569 | 4570 | | |
4570 | 4571 | | |
4571 | 4572 | | |
4572 | 4573 | | |
4573 | 4574 | | |
4574 | | - | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
4575 | 4579 | | |
4576 | 4580 | | |
4577 | 4581 | | |
| |||
0 commit comments