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

Configure Feed

Select the types of activity you want to include in your feed.

char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR

Currently, It is allowed to register miscdevice with minor > 255
which is defined by macro MISC_DYNAMIC_MINOR, and cause:

- Chaos regarding division and management of minor codes.
- Registering failure if the minor was allocated to other dynamic request.

Fortunately, in-kernel users have not had such usage yet.
Fix by refusing to register miscdevice whose minor > 255.

Also bring in a very simple minor code space division and management:

< 255 : Fixed minor code
== 255 : Indicator to request dynamic minor code
> 255 : Dynamic minor code requested, 1048320 minor codes totally
And all fixed minors allocated should be registered in 'linux/miscdevice.h'

Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20250714-rfc_miscdev-v6-3-2ed949665bde@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Zijun Hu and committed by
Greg Kroah-Hartman
f5597840 f4e47aff

+14
+6
drivers/char/misc.c
··· 210 210 int err = 0; 211 211 bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR); 212 212 213 + if (misc->minor > MISC_DYNAMIC_MINOR) { 214 + pr_err("Invalid fixed minor %d for miscdevice '%s'\n", 215 + misc->minor, misc->name); 216 + return -EINVAL; 217 + } 218 + 213 219 INIT_LIST_HEAD(&misc->list); 214 220 215 221 mutex_lock(&misc_mtx);
+8
include/linux/miscdevice.h
··· 71 71 #define USERIO_MINOR 240 72 72 #define VHOST_VSOCK_MINOR 241 73 73 #define RFKILL_MINOR 242 74 + 75 + /* 76 + * Misc char device minor code space division related to below macro: 77 + * 78 + * < 255 : Fixed minor code 79 + * == 255 : Indicator to request dynamic minor code 80 + * > 255 : Dynamic minor code requested, 1048320 minor codes totally. 81 + */ 74 82 #define MISC_DYNAMIC_MINOR 255 75 83 76 84 struct miscdevice {