block: nbd: add sanity check for first_minor
Subsystems (2)
PATCH 1/1 block: nbd: add sanity check for first_minor
Syzbot hit WARNING in internal_create_group(). The problem was in too big disk->first_minor.
disk->first_minor is initialized by value, which comes from userspace and there wasn't any sanity checks about value correctness. It can cause duplicate creation of sysfs files/links, because disk->first_minor will be passed to MKDEV() which causes truncation to byte. Since maximum minor value is 0xff, let's check if first_minor is correct minor number.
NOTE: the root case of the reported warning was in wrong error handling in register_disk(), but we can avoid passing knowingly wrong values to sysfs API, because sysfs error messages can confuse users. For example:
user passed 1048576 as index, but sysfs complains about duplicate creation of /dev/block/43:0. It's not obvious how 1048576 becomes 0. Log and reproducer for above example can be found on syzkaller bug report page.
--- drivers/block/nbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/block/nbd.c +10 -0
@@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)refcount_set (&nbd->refs,1 );INIT_LIST_HEAD (&nbd->list); disk->major =NBD_MAJOR ; + +/* Too big first_minor can cause duplicate creation of +* sysfs files/links, since first_minor will be truncated to +* byte in __device_add_disk(). +*/ disk->first_minor = index << part_shift; +if (disk->first_minor >0xff ) { + err = -EINVAL ; + goto out_free_idr; + } + disk->minors =1 << part_shift; disk->fops = &nbd_fops; disk->private_data = nbd;
Signature · 1 line
2.32.0
Looks good,
Quoted 38 lines · Pavel Skripkin
Syzbot hit WARNING in
internal_create_group(). The problem was in too bigdisk->first_minor.
disk->first_minoris initialized by value, which comes from userspace and there wasn't any sanity checks about value correctness. It can cause duplicate creation of sysfs files/links, becausedisk->first_minorwill be passed toMKDEV()which causes truncation to byte. Since maximum minor value is0xff, let's check iffirst_minoris correct minor number.NOTE: the root case of the reported warning was in wrong error handling in
register_disk(), but we can avoid passing knowingly wrong values to sysfs API, because sysfs error messages can confuse users. For example:
user passed 1048576 as index, but sysfs complains about duplicate creation of/dev/block/43:0. It's not obvious how 1048576 becomes 0. Log and reproducer for above example can be found on syzkaller bug report page.Fixes b0d9111a2d53 ("nbd: use an idr to keep track of nbd devices")Reported-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>--- drivers/block/nbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/block/nbd.c +4
-0@@ -1725,7 +1725,17 @@ static int nbd_dev_add(int index)refcount_set (&nbd->refs,1 );INIT_LIST_HEAD (&nbd->list); disk->major =NBD_MAJOR ; + +/* Too big first_minor can cause duplicate creation of +* sysfs files/links, since first_minor will be truncated to +* byte in __device_add_disk().
drivers/block/nbd.c static int nbd_dev_add(int index) · line 1741
Quoted 10 lines
drivers/block/nbd.c +6
-0+*/ disk->first_minor = index << part_shift; +if (disk->first_minor >0xff ) { + err = -EINVAL ; + goto out_free_idr; + } + disk->minors =1 << part_shift; disk->fops = &nbd_fops; disk->private_data = nbd;
Fun thing: I got a reply to this email from
[email protected], which is Hong Kong Police office email. Does anyone know what is going on? :) It's a bit scary...
With regards,
Pavel Skripkin
Quoted 4 lines · Pavel Skripkin
Fun thing: I got a reply to this email from [email protected], which is Hong Kong Police office email. Does anyone know what is going on? :) It's a bit scary...
You are not alone. Apparently, someone subscribed that address to the [email protected] list and it is auto-responding to every message it receives; hopefully, a list administrator (I am not one) will be willing to forcefully unsubscribe that address.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 10 lines · Eric Blake
Quoted 4 lines · Pavel Skripkin
Fun thing: I got a reply to this email from [email protected], which is Hong Kong Police office email. Does anyone know what is going on? :) It's a bit scary...
You are not alone. Apparently, someone subscribed that address to the [email protected] list and it is auto-responding to every message it receives; hopefully, a list administrator (I am not one) will be willing to forcefully unsubscribe that address.
FWIW, this has now happened, so you should no longer see such autoreplies.
Signature · 2 lines
w@uter.{be,co.za}
wouter@{grep.be,fosdem.org,debian.org}Quoted 7 lines · Wouter Verhelst
Quoted 6 lines · Eric Blake
Quoted 4 lines · Pavel Skripkin
Fun thing: I got a reply to this email from [email protected], which is Hong Kong Police office email. Does anyone know what is going on? :) It's a bit scary...
Quoted 6 lines
Quoted 4 lines
You are not alone. Apparently, someone subscribed that address to the [email protected] list and it is auto-responding to every message it receives; hopefully, a list administrator (I am not one) will be willing to forcefully unsubscribe that address.
FWIW, this has now happened, so you should no longer see such autoreplies.
... except I just received another one myself. I've taken it up with the list admins again.
I won't update the whole Cc list of this anymore, but rest assured I'll stay on this until it's been taken care of.
Signature · 2 lines
w@uter.{be,co.za}
wouter@{grep.be,fosdem.org,debian.org}Quoted 9 lines · Pavel Skripkin
Syzbot hit WARNING in
internal_create_group(). The problem was in too bigdisk->first_minor.
disk->first_minoris initialized by value, which comes from userspace and there wasn't any sanity checks about value correctness. It can cause duplicate creation of sysfs files/links, becausedisk->first_minorwill be passed toMKDEV()which causes truncation to byte. Since maximum minor value is0xff, let's check iffirst_minoris correct minor number.
Quoted 7 lines
NOTE: the root case of the reported warning was in wrong error handling in
register_disk(), but we can avoid passing knowingly wrong values to sysfs API, because sysfs error messages can confuse users. For example:
user passed 1048576 as index, but sysfs complains about duplicate creation of/dev/block/43:0. It's not obvious how 1048576 becomes 0. Log and reproducer for above example can be found on syzkaller bug report page.
Applied, thanks.
Signature · 1 line
Jens Axboe