diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 7ed888e99f09..93708b1938e8 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1770,7 +1770,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;