OSDN Git Service

chardev: add a check for given minor range
authorChengguang Xu <cgxu519@gmx.com>
Fri, 15 Feb 2019 12:27:12 +0000 (20:27 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 2 Apr 2019 15:49:58 +0000 (17:49 +0200)
register_chrdev_region() carefully checks minor range
before calling __register_chrdev_region() but there is
another path from alloc_chrdev_region() which does not
check the range properly. So add a check for given minor
range in __register_chrdev_region().

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/char_dev.c

index 8a63cfa..6803e98 100644 (file)
@@ -104,6 +104,12 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
        int ret = 0;
        int i;
 
+       if (minorct > MINORMASK + 1 - baseminor) {
+               pr_err("CHRDEV \"%s\" minor range requested (%u-%u) is out of range of maximum range (%u-%u) for a single major\n",
+                       name, baseminor, baseminor + minorct - 1, 0, MINORMASK);
+               return ERR_PTR(-EINVAL);
+       }
+
        cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL);
        if (cd == NULL)
                return ERR_PTR(-ENOMEM);