Skip to contentSkip to conversation

btrfs: ioctl: fix assertion compatible sets when cocurrently adding multiple devices

PATCH New xiaoshoukui 1 participant 1 message Apr 6, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: ioctl: fix assertion compatible sets when cocurrently adding multiple devices

ASSERT in btrfs_exclop_balance should also check for NONE and BALANCE_PAUSED status.

Scenario 1: With exclusive_operation state == BTRFS_EXCLOP_NONE. Cocurrently adding multiple devices to the same mount point and btrfs_exclop_finish executed finish before assertion in btrfs_exclop_balance, exclusive_operation will changed to BTRFS_EXCLOP_NONE state which lead to assertion failed:
fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE || fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD,

in fs/btrfs/ioctl.c:456
Call Trace:
 <TASK>
 btrfs_exclop_balance+0x13c/0x310
 ? memdup_user+0xab/0xc0
 ? PTR_ERR+0x17/0x20
 btrfs_ioctl_add_dev+0x2ee/0x320
 btrfs_ioctl+0x9d5/0x10d0
 ? btrfs_ioctl_encoded_write+0xb80/0xb80
 __x64_sys_ioctl+0x197/0x210
 do_syscall_64+0x3c/0xb0
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Scenario 2: With exclusive_operation state == BTRFS_EXCLOP_BALANCE_PAUSED. Cocurrently adding multiple devices to the same mount point and btrfs_exclop_balance executed finish before the latter thread execute assertion in btrfs_exclop_balance, exclusive_operation will changed to BTRFS_EXCLOP_BALANCE_PAUSED state which lead to assertion failed:

fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE ||
fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD ||
fs_info->exclusive_operation == BTRFS_EXCLOP_NONE,
fs/btrfs/ioctl.c:458
Call Trace:
 <TASK>
 btrfs_exclop_balance+0x240/0x410
 ? memdup_user+0xab/0xc0
 ? PTR_ERR+0x17/0x20
 btrfs_ioctl_add_dev+0x2ee/0x320
 btrfs_ioctl+0x9d5/0x10d0
 ? btrfs_ioctl_encoded_write+0xb80/0xb80
 __x64_sys_ioctl+0x197/0x210
 do_syscall_64+0x3c/0xb0
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
---
 fs/btrfs/ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/ioctl.c +3 -1
index a0ef1a1784c7..7df80b37bc44 100644
@@ -454,7 +454,9 @@ void btrfs_exclop_balance(struct btrfs_fs_info *fs_info,
 	case BTRFS_EXCLOP_BALANCE_PAUSED:
 		spin_lock(&fs_info->super_lock);
 		ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE ||
-		       fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD);
+		       fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD ||
+		       fs_info->exclusive_operation == BTRFS_EXCLOP_NONE ||
+		       fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED);
 		fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE_PAUSED;
 		spin_unlock(&fs_info->super_lock);
 		break;
Signature · 1 line
2.20.1