linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: nbd: add sanity check for first_minor
@ 2021-08-12  9:15 Pavel Skripkin
  2021-08-12  9:16 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pavel Skripkin @ 2021-08-12  9:15 UTC (permalink / raw)
  To: josef, axboe
  Cc: hch, linux-block, nbd, linux-kernel, Pavel Skripkin,
	syzbot+9937dc42271cd87d4b98

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.

Link: https://syzkaller.appspot.com/bug?id=03c2ae9146416edf811958d5fd7acfab75b143d1
Fixes: b0d9111a2d53 ("nbd: use an idr to keep track of nbd devices")
Reported-by: syzbot+9937dc42271cd87d4b98@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/block/nbd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c38317979f74..600e9bab5d43 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -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;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-12  9:15 [PATCH] block: nbd: add sanity check for first_minor Pavel Skripkin
@ 2021-08-12  9:16 ` Christoph Hellwig
  2021-08-12  9:42 ` Pavel Skripkin
  2021-08-16 16:56 ` Jens Axboe
  2 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2021-08-12  9:16 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: josef, axboe, hch, linux-block, nbd, linux-kernel,
	syzbot+9937dc42271cd87d4b98

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-12  9:15 [PATCH] block: nbd: add sanity check for first_minor Pavel Skripkin
  2021-08-12  9:16 ` Christoph Hellwig
@ 2021-08-12  9:42 ` Pavel Skripkin
  2021-08-12 15:35   ` Eric Blake
  2021-08-16 16:56 ` Jens Axboe
  2 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2021-08-12  9:42 UTC (permalink / raw)
  To: josef, axboe
  Cc: hch, linux-block, nbd, linux-kernel, syzbot+9937dc42271cd87d4b98

On 8/12/21 12:15 PM, Pavel Skripkin wrote:
> 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.
> 
> Link: https://syzkaller.appspot.com/bug?id=03c2ae9146416edf811958d5fd7acfab75b143d1
> Fixes: b0d9111a2d53 ("nbd: use an idr to keep track of nbd devices")
> Reported-by: syzbot+9937dc42271cd87d4b98@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> ---
>   drivers/block/nbd.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index c38317979f74..600e9bab5d43 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -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;
> 

Fun thing: I got a reply to this email from
nsd-public@police.gov.hk, which is Hong Kong Police office email. Does 
anyone know what is going on? :) It's a bit scary...



With regards,
Pavel Skripkin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-12  9:42 ` Pavel Skripkin
@ 2021-08-12 15:35   ` Eric Blake
  2021-08-16 15:26     ` Wouter Verhelst
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Blake @ 2021-08-12 15:35 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: josef, axboe, hch, linux-block, nbd, linux-kernel,
	syzbot+9937dc42271cd87d4b98

On Thu, Aug 12, 2021 at 12:42:38PM +0300, Pavel Skripkin wrote:
> 
> Fun thing: I got a reply to this email from
> nsd-public@police.gov.hk, 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
nbd@other.debian.org 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.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-12 15:35   ` Eric Blake
@ 2021-08-16 15:26     ` Wouter Verhelst
  2021-08-16 15:55       ` Wouter Verhelst
  0 siblings, 1 reply; 7+ messages in thread
From: Wouter Verhelst @ 2021-08-16 15:26 UTC (permalink / raw)
  To: Eric Blake
  Cc: Pavel Skripkin, josef, axboe, hch, linux-block, nbd,
	linux-kernel, syzbot+9937dc42271cd87d4b98

On Thu, Aug 12, 2021 at 10:35:25AM -0500, Eric Blake wrote:
> On Thu, Aug 12, 2021 at 12:42:38PM +0300, Pavel Skripkin wrote:
> > 
> > Fun thing: I got a reply to this email from
> > nsd-public@police.gov.hk, 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
> nbd@other.debian.org 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.

-- 
     w@uter.{be,co.za}
wouter@{grep.be,fosdem.org,debian.org}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-16 15:26     ` Wouter Verhelst
@ 2021-08-16 15:55       ` Wouter Verhelst
  0 siblings, 0 replies; 7+ messages in thread
From: Wouter Verhelst @ 2021-08-16 15:55 UTC (permalink / raw)
  To: Eric Blake
  Cc: Pavel Skripkin, josef, axboe, hch, linux-block, nbd,
	linux-kernel, syzbot+9937dc42271cd87d4b98

On Mon, Aug 16, 2021 at 05:26:23PM +0200, Wouter Verhelst wrote:
> On Thu, Aug 12, 2021 at 10:35:25AM -0500, Eric Blake wrote:
> > On Thu, Aug 12, 2021 at 12:42:38PM +0300, Pavel Skripkin wrote:
> > > 
> > > Fun thing: I got a reply to this email from
> > > nsd-public@police.gov.hk, 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
> > nbd@other.debian.org 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.

-- 
     w@uter.{be,co.za}
wouter@{grep.be,fosdem.org,debian.org}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] block: nbd: add sanity check for first_minor
  2021-08-12  9:15 [PATCH] block: nbd: add sanity check for first_minor Pavel Skripkin
  2021-08-12  9:16 ` Christoph Hellwig
  2021-08-12  9:42 ` Pavel Skripkin
@ 2021-08-16 16:56 ` Jens Axboe
  2 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2021-08-16 16:56 UTC (permalink / raw)
  To: Pavel Skripkin, josef
  Cc: hch, linux-block, nbd, linux-kernel, syzbot+9937dc42271cd87d4b98

On 8/12/21 3:15 AM, Pavel Skripkin wrote:
> 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.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-16 16:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12  9:15 [PATCH] block: nbd: add sanity check for first_minor Pavel Skripkin
2021-08-12  9:16 ` Christoph Hellwig
2021-08-12  9:42 ` Pavel Skripkin
2021-08-12 15:35   ` Eric Blake
2021-08-16 15:26     ` Wouter Verhelst
2021-08-16 15:55       ` Wouter Verhelst
2021-08-16 16:56 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).