Skip to contentSkip to conversation

block: nbd: fix sanity check for first_minor

PATCH Superseded Yan, Zheng 2 participants 2 messages Oct 9, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 1/1 block: nbd: fix sanity check for first_minor

From: "Yan, Zheng" <[email protected]>

Device's minor is a 20-bits number, max value is 0xfffff.

Fixes b1a811633f ("block: nbd: add sanity check for first_minor").
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 1183f7872b71..53cd038c96e9 100644
@@ -1753,7 +1753,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 	 * byte in __device_add_disk().
 	 */
 	disk->first_minor = index << part_shift;
-	if (disk->first_minor > 0xff) {
+	if (disk->first_minor > MINORMASK) {
 		err = -EINVAL;
 		goto out_free_idr;
 	}
Signature · 1 line
2.12.2
#1 lore raw

On 10/9/21 08:35, Yan, Zheng wrote:

+CC Christoph

Quoted 16 lines

From: "Yan, Zheng" <[email protected]>

Device's minor is a 20-bits number, max value is 0xfffff.

Fixes b1a811633f ("block: nbd: add sanity check for first_minor").
---
  drivers/block/nbd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +0 -0
index 1183f7872b71..53cd038c96e9 100644

drivers/block/nbd.c static struct nbd_device *nbd_dev_add(int index, unsigned int refs) · line 1759

Quoted 8 lines
drivers/block/nbd.c +1 -1
@@ -1753,7 +1753,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
  	 * byte in __device_add_disk().
  	 */
  	disk->first_minor = index << part_shift;
-	if (disk->first_minor > 0xff) {
+	if (disk->first_minor > MINORMASK) {
  		err = -EINVAL;
  		goto out_free_idr;
  	}

I've looked into what confused me with 0xff and I found that uapi's kdev_t.h has following MINOR definition:

#define MINOR(dev) ((dev) & 0xff)

But kernel's kdev_t.h is really allows 20 bit minor number :)

Also, can you, please, fix up comment above this check, since it contains info about max minor 0xff and it can confuse readers.

With regards,
Pavel Skripkin