Skip to content

Commit c9fe471

Browse files
Liu Shixingregkh
authored andcommitted
btrfs: fix match incorrectly in dev_args_match_device
commit 0fca385 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f96fd36 commit c9fe471

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
@@ -6841,18 +6841,18 @@ static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args,
68416841
static bool dev_args_match_device(const struct btrfs_dev_lookup_args *args,
68426842
const struct btrfs_device *device)
68436843
{
6844-
ASSERT((args->devid != (u64)-1) || args->missing);
6844+
if (args->missing) {
6845+
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
6846+
!device->bdev)
6847+
return true;
6848+
return false;
6849+
}
68456850

6846-
if ((args->devid != (u64)-1) && device->devid != args->devid)
6851+
if (device->devid != args->devid)
68476852
return false;
68486853
if (args->uuid && memcmp(device->uuid, args->uuid, BTRFS_UUID_SIZE) != 0)
68496854
return false;
6850-
if (!args->missing)
6851-
return true;
6852-
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
6853-
!device->bdev)
6854-
return true;
6855-
return false;
6855+
return true;
68566856
}
68576857

68586858
/*

0 commit comments

Comments
 (0)