diff options
author | Chengguang Xu <cgxu519@gmx.com> | 2019-02-15 07:27:12 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-04-02 11:49:58 -0400 |
commit | 4712d3796f19b32241b41e538107fb7ae7a3fcff (patch) | |
tree | 662545733a34a647a2c884312617c8cb0c48168e /fs/char_dev.c | |
parent | de36e16d1557a0b6eb328bc3516359a12ba5c25c (diff) |
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>
Diffstat (limited to 'fs/char_dev.c')
-rw-r--r-- | fs/char_dev.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/char_dev.c b/fs/char_dev.c index 8a63cfa29005..6803e98414f1 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c | |||
@@ -104,6 +104,12 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, | |||
104 | int ret = 0; | 104 | int ret = 0; |
105 | int i; | 105 | int i; |
106 | 106 | ||
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 | |||
107 | cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL); | 113 | cd = kzalloc(sizeof(struct char_device_struct), GFP_KERNEL); |
108 | if (cd == NULL) | 114 | if (cd == NULL) |
109 | return ERR_PTR(-ENOMEM); | 115 | return ERR_PTR(-ENOMEM); |