* Re: [PATCH] btrfs: fix match incorrectly in dev_args_match_device
2022-11-03 8:33 [PATCH] btrfs: fix match incorrectly in dev_args_match_device Liu Shixin
@ 2022-11-03 8:20 ` Nikolay Borisov
2022-11-03 16:33 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2022-11-03 8:20 UTC (permalink / raw)
To: Liu Shixin, Chris Mason, Josef Bacik, David Sterba
Cc: linux-btrfs, linux-kernel
On 3.11.22 г. 10:33 ч., Liu Shixin wrote:
> syzkaller found an assert failed:
>
> assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921
>
> This can be trigger 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 be succeed
> incorrectly.
>
> Patch 562d7b1512f7 introduced this function which is used to match device.
> This function contaions 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: syzbot+031687116258450f9853@syzkaller.appspotmail.com
> Fixes: 562d7b1512f7 ("btrfs: handle device lookup with btrfs_dev_lookup_args")
> Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/volumes.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 94ba46d57920..bf2d886cfb4b 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -6918,18 +6918,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;
> }
>
> /*
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] btrfs: fix match incorrectly in dev_args_match_device
@ 2022-11-03 8:33 Liu Shixin
2022-11-03 8:20 ` Nikolay Borisov
2022-11-03 16:33 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Liu Shixin @ 2022-11-03 8:33 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba
Cc: linux-btrfs, linux-kernel, Liu Shixin
syzkaller found an assert failed:
assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921
This can be trigger 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 be succeed
incorrectly.
Patch 562d7b1512f7 introduced this function which is used to match device.
This function contaions 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: syzbot+031687116258450f9853@syzkaller.appspotmail.com
Fixes: 562d7b1512f7 ("btrfs: handle device lookup with btrfs_dev_lookup_args")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
fs/btrfs/volumes.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 94ba46d57920..bf2d886cfb4b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6918,18 +6918,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;
}
/*
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: fix match incorrectly in dev_args_match_device
2022-11-03 8:33 [PATCH] btrfs: fix match incorrectly in dev_args_match_device Liu Shixin
2022-11-03 8:20 ` Nikolay Borisov
@ 2022-11-03 16:33 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2022-11-03 16:33 UTC (permalink / raw)
To: Liu Shixin
Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs, linux-kernel
On Thu, Nov 03, 2022 at 04:33:01PM +0800, Liu Shixin wrote:
> syzkaller found an assert failed:
>
> assertion failed: (args->devid != (u64)-1) || args->missing, in fs/btrfs/volumes.c:6921
>
> This can be trigger 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 be succeed
> incorrectly.
>
> Patch 562d7b1512f7 introduced this function which is used to match device.
> This function contaions 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: syzbot+031687116258450f9853@syzkaller.appspotmail.com
> Fixes: 562d7b1512f7 ("btrfs: handle device lookup with btrfs_dev_lookup_args")
> Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-03 16:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 8:33 [PATCH] btrfs: fix match incorrectly in dev_args_match_device Liu Shixin
2022-11-03 8:20 ` Nikolay Borisov
2022-11-03 16:33 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®