Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm init: Handle minors larger than 255

dm_parse_device_entry() simply copies the minor number into dmi.dev, but
the dev_t format splits the minor number between the lowest 8 bytes and
highest 12 bytes. If the minor number is larger than 255, part of it
will end up getting treated as the major number

Fix this by checking that the minor number is valid and then encoding it
as a dev_t.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Benjamin Marzinski and committed by
Mikulas Patocka
140ce37f c1a66a37

+3 -1
+3 -1
drivers/md/dm-init.c
··· 212 212 strscpy(dev->dmi.uuid, field[1], sizeof(dev->dmi.uuid)); 213 213 /* minor */ 214 214 if (strlen(field[2])) { 215 - if (kstrtoull(field[2], 0, &dev->dmi.dev)) 215 + if (kstrtoull(field[2], 0, &dev->dmi.dev) || 216 + dev->dmi.dev >= (1 << MINORBITS)) 216 217 return ERR_PTR(-EINVAL); 218 + dev->dmi.dev = huge_encode_dev((dev_t)dev->dmi.dev); 217 219 dev->dmi.flags |= DM_PERSISTENT_DEV_FLAG; 218 220 } 219 221 /* flags */