Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
btrfs: fix match incorrectly in dev_args_match_device
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Liu Shixin authored and kdave committed Nov 4, 2022
1 parent 18a783e commit 9ca9586
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6928,18 +6928,18 @@ static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args,
static bool dev_args_match_device(const struct btrfs_dev_lookup_args *args,
const struct btrfs_device *device)
{
ASSERT((args->devid != (u64)-1) || args->missing);
if (args->missing) {
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
!device->bdev)
return true;
return false;
}

if ((args->devid != (u64)-1) && device->devid != args->devid)
if (device->devid != args->devid)
return false;
if (args->uuid && memcmp(device->uuid, args->uuid, BTRFS_UUID_SIZE) != 0)
return false;
if (!args->missing)
return true;
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state) &&
!device->bdev)
return true;
return false;
return true;
}

/*
Expand Down

0 comments on commit 9ca9586

Please sign in to comment.