]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Revert "Revert "block: nbd: add sanity check for first_minor""
authorWen Yang <wenyang.linux@foxmail.com>
Mon, 20 Feb 2023 18:04:46 +0000 (02:04 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Feb 2023 10:55:03 +0000 (11:55 +0100)
This reverts commit 0daa75bf750c400af0a0127fae37cd959d36dee7.

These problems such as:
https://lore.kernel.org/all/CACPK8XfUWoOHr-0RwRoYoskia4fbAbZ7DYf5wWBnv6qUnGq18w@mail.gmail.com/
It was introduced by introduced by commit b1a811633f73 ("block: nbd: add sanity check for first_minor")
and has been have been fixed by commit e4c4871a7394 ("nbd: fix max value for 'first_minor'").

Cc: Joel Stanley <joel@jms.id.au>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Pavel Skripkin <paskripkin@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/nbd.c

index b0d3dadeb9643199453b5915db90fce86d05478d..bf8148ebd8587a8e678e81fd2f641f9113930716 100644 (file)
@@ -1771,7 +1771,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->fops = &nbd_fops;
        disk->private_data = nbd;
        sprintf(disk->disk_name, "nbd%d", index);