Skip to content

Commit 3c6bd90

Browse files
Liu Shixinkdave
authored andcommitted
btrfs: fix match incorrectly in dev_args_match_device
syzkaller found a failed assertion: assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921 This can be triggered when we set devid to (u64)-1 by ioctl. In this case, the match of devid will be skipped and the match of device may succeed incorrectly. Patch 562d7b1 introduced this function which is used to match device. This function contains two matching scenarios, we can distinguish them by checking the value of args->missing rather than check whether args->devid and args->uuid is default value. Reported-by: [email protected] Fixes: 562d7b1 ("btrfs: handle device lookup with btrfs_dev_lookup_args") CC: [email protected] # 5.16+ Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Liu Shixin <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 23d1ed8 commit 3c6bd90

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fs/btrfs/volumes.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,18 +6928,18 @@ static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args,
69286928
static bool dev_args_match_device(const struct btrfs_dev_lookup_args *args,
69296929
const struct btrfs_device *device)
69306930
{
6931-
ASSERT((args->devid != (u64)-1) || args->missing);
6931+
if (args->missing) {
6932+
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
6933+
!device->bdev)
6934+
return true;
6935+
return false;
6936+
}
69326937

6933-
if ((args->devid != (u64)-1) && device->devid != args->devid)
6938+
if (device->devid != args->devid)
69346939
return false;
69356940
if (args->uuid && memcmp(device->uuid, args->uuid, BTRFS_UUID_SIZE) != 0)
69366941
return false;
6937-
if (!args->missing)
6938-
return true;
6939-
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
6940-
!device->bdev)
6941-
return true;
6942-
return false;
6942+
return true;
69436943
}
69446944

69456945
/*

0 commit comments

Comments
 (0)