Skip to content

Commit 4712d37

Browse files
Chengguang Xugregkh
authored andcommitted
chardev: add a check for given minor range
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>
1 parent de36e16 commit 4712d37

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎fs/char_dev.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
104104
int ret = 0;
105105
int i;
106106

107+
if (minorct > MINORMASK + 1 - baseminor) {
108+
pr_err("CHRDEV \"%s\" minor range requested (%u-%u) is out of range of maximum range (%u-%u) for a single major\n",
109+
name, baseminor, baseminor + minorct - 1, 0, MINORMASK);
110+
return ERR_PTR(-EINVAL);
111+
}
112+
107113
cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL);
108114
if (cd == NULL)
109115
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)