Skip to content

Commit

Permalink
chardev: add a check for given minor range
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Chengguang Xu authored and gregkh committed Apr 2, 2019
1 parent de36e16 commit 4712d37
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fs/char_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4712d37

Please sign in to comment.