Skip to content

Commit e82c936

Browse files
fdmananakdave
authored andcommitted
btrfs: send: check for read-only send root under critical section
We're checking if the send root is read-only without being under the protection of the root's root_item_lock spinlock, which is what protects the root's flags when clearing the read-only flag, done at btrfs_ioctl_subvol_setflags(). Furthermore, it should be done in the same critical section that increments the root's send_in_progress counter, as btrfs_ioctl_subvol_setflags() clears the read-only flag in the same critical section that checks the counter's value. So fix this by moving the read-only check under the critical section delimited by the root's root_item_lock which also increments the root's send_in_progress counter. Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent dc058f5 commit e82c936

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

fs/btrfs/send.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8133,23 +8133,19 @@ long btrfs_ioctl_send(struct btrfs_inode *inode, const struct btrfs_ioctl_send_a
81338133
spin_unlock(&send_root->root_item_lock);
81348134
return -EPERM;
81358135
}
8136-
if (btrfs_root_readonly(send_root) && send_root->dedupe_in_progress) {
8136+
/* Userspace tools do the checks and warn the user if it's not RO. */
8137+
if (!btrfs_root_readonly(send_root)) {
8138+
spin_unlock(&send_root->root_item_lock);
8139+
return -EPERM;
8140+
}
8141+
if (send_root->dedupe_in_progress) {
81378142
dedupe_in_progress_warn(send_root);
81388143
spin_unlock(&send_root->root_item_lock);
81398144
return -EAGAIN;
81408145
}
81418146
send_root->send_in_progress++;
81428147
spin_unlock(&send_root->root_item_lock);
81438148

8144-
/*
8145-
* Userspace tools do the checks and warn the user if it's
8146-
* not RO.
8147-
*/
8148-
if (!btrfs_root_readonly(send_root)) {
8149-
ret = -EPERM;
8150-
goto out;
8151-
}
8152-
81538149
/*
81548150
* Check that we don't overflow at later allocations, we request
81558151
* clone_sources_count + 1 items, and compare to unsigned long inside

0 commit comments

Comments
 (0)