module: Fix minor problems related to MODULE_NAME_LEN
Subsystems (2)
Petr Pavlu
maintainercover module: Fix minor problems related to MODULE_NAME_LEN
Fix a few minor problems related to MODULE_NAME_LEN and MAX_PARAM_PREFIX_LEN, and clean up their usage.
Petr Pavlu (5):
module: Prevent silent truncation of module name in delete_module(2)
module: Remove unnecessary +1 from last_unloaded_module::name size
module: Restore the moduleparam prefix length check
tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN
module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN
include/linux/module.h | 2 +- include/linux/moduleparam.h | 15 +++++++++------ kernel/module/main.c | 12 +++++++----- kernel/trace/trace.c | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-)
base-commit: d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
Signature · 1 line
2.49.0
Petr Pavlu
maintainerPATCH 1/5 module: Prevent silent truncation of module name in delete_module(2)
Passing a module name longer than MODULE_NAME_LEN to the delete_module syscall results in its silent truncation. This really isn't much of a problem in practice, but it could theoretically lead to the removal of an incorrect module. It is more sensible to return ENAMETOOLONG or ENOENT in such a case.
Update the syscall to return ENOENT, as documented in the delete_module(2) man page to mean "No module by that name exists." This is appropriate because a module with a name longer than MODULE_NAME_LEN cannot be loaded in the first place.
--- kernel/module/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/module/main.c +6 -4
@@ -751,14 +751,16 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,struct module *mod;char name[MODULE_NAME_LEN ];char buf[MODULE_FLAGS_BUF_SIZE ]; -int ret, forced =0 ; +int ret, len, forced =0 ;if (!capable (CAP_SYS_MODULE ) || modules_disabled)return -EPERM ; -if (strncpy_from_user (name, name_user,MODULE_NAME_LEN -1 ) <0 ) -return -EFAULT ; - name[MODULE_NAME_LEN -1 ] ='\0' ; + len =strncpy_from_user (name, name_user,MODULE_NAME_LEN ); +if (len ==0 || len ==MODULE_NAME_LEN ) +return -ENOENT ; +if (len <0 ) +return len;audit_log_kern_module (name);
Signature · 1 line
2.49.0
Re: [PATCH 1/5] module: Prevent silent truncation of module name in delete_module(2)
Quoted 9 lines · Petr Pavlu
Passing a module name longer than
MODULE_NAME_LENto thedelete_modulesyscall results in its silent truncation. This really isn't much of a problem in practice, but it could theoretically lead to the removal of an incorrect module. It is more sensible to return ENAMETOOLONG or ENOENT in such a case.Update the syscall to return ENOENT, as documented in the
delete_module(2)man page to mean "No module by that name exists." This is appropriate because a module with a name
Including the NUL byte...
Quoted 20 lines
longer than
MODULE_NAME_LENcannot be loaded
in the first place.Signed-off-by Petr Pavlu <[email protected]>--- kernel/module/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)kernel/module/main.c +1
-1@@ -751,14 +751,16 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,struct module *mod;char name[MODULE_NAME_LEN ];char buf[MODULE_FLAGS_BUF_SIZE ]; -int ret, forced =0 ; +int ret, len, forced =0 ;if (!capable (CAP_SYS_MODULE ) || modules_disabled)
kernel/module/main.c SYSCALL_DEFINE2(delete_module, const char __user *, name_user, · line 763
Quoted 10 lines
kernel/module/main.c +5
-3return -EPERM ; -if (strncpy_from_user (name, name_user,MODULE_NAME_LEN -1 ) <0 ) -return -EFAULT ; - name[MODULE_NAME_LEN -1 ] ='\0' ; + len =strncpy_from_user (name, name_user,MODULE_NAME_LEN ); +if (len ==0 || len ==MODULE_NAME_LEN ) +return -ENOENT ; +if (len <0 ) +return len;
This looks correct to me. The new code not only returns the correct errors indicated in delete_module(2) but also checks for the case user passes an empty string and the case where NUL char is not found when copying (with len == MODULE_NAME_LEN) as well as it's using the correct length (MODULE_NAME_LEN) for copying.
Petr Pavlu
maintainerPATCH 2/5 module: Remove unnecessary +1 from last_unloaded_module::name size
In reply to Petr PavluThe variable last_unloaded_module::name tracks the name of the last unloaded module. It is a string copy of module::name, which is MODULE_NAME_LEN bytes in size and includes the NUL terminator. Therefore, the size of last_unloaded_module::name can also be just MODULE_NAME_LEN, without the need for an extra byte.
--- kernel/module/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/module/main.c +1 -1
@@ -580,7 +580,7 @@ MODINFO_ATTR(version);MODINFO_ATTR (srcversion);static struct { -char name[MODULE_NAME_LEN +1 ]; +char name[MODULE_NAME_LEN ];char taints[MODULE_FLAGS_BUF_SIZE ]; } last_unloaded_module;
Signature · 1 line
2.49.0
Re: [PATCH 2/5] module: Remove unnecessary +1 from last_unloaded_module::name size
Quoted 17 lines · Petr Pavlu
The variable
last_unloaded_module::nametracks the name of the last unloaded module. It is a string copy ofmodule::name, which isMODULE_NAME_LENbytes in size and includes the NUL terminator. Therefore, the size oflast_unloaded_module::namecan also be justMODULE_NAME_LEN, without the need for an extra byte.Fixes e14af7eeb47e ("debug: track and print last unloaded module in the oops trace")Signed-off-by Petr Pavlu <[email protected]>--- kernel/module/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/module/main.c +0
-0
kernel/module/main.c MODINFO_ATTR(version); · line 586
Quoted 8 lines
kernel/module/main.c +1
-1@@ -580,7 +580,7 @@ MODINFO_ATTR(version);MODINFO_ATTR (srcversion);static struct { -char name[MODULE_NAME_LEN +1 ]; +char name[MODULE_NAME_LEN ];char taints[MODULE_FLAGS_BUF_SIZE ]; } last_unloaded_module;
LGTM,
Petr Pavlu
maintainerPATCH 3/5 module: Restore the moduleparam prefix length check
In reply to Petr PavluThe moduleparam code allows modules to provide their own definition of MODULE_PARAM_PREFIX, instead of using the default KBUILD_MODNAME ".".
Commit 730b69d22525 ("module: check kernel param length at compile time, not runtime") added a check to ensure the prefix doesn't exceed MODULE_NAME_LEN, as this is what param_sysfs_builtin() expects.
Later, commit 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.") removed this check, but there is no indication this was intentional.
Since the check is still useful for param_sysfs_builtin() to function properly, reintroduce it in __module_param_call(), but in a modernized form using static_assert().
While here, clean up the __module_param_call() comments. In particular, remove the comment "Default value instead of permissions?", which comes from commit 9774a1f54f17 ("[PATCH] Compile-time check re world-writeable module params"). This comment was related to the test variable __param_perm_check_##name, which was removed in the previously mentioned commit 58f86cc89c33.
--- include/linux/moduleparam.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
include/linux/moduleparam.h +2 -3
@@ -282,10 +282,9 @@ struct kparam_array#define __moduleparam_const const#endif -/* This is the fundamental function for registering boot/module -parameters. */ +/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ -/* Default value instead of permissions? */ \ + static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \ static const char __param_str_##name[] = prefix #name; \ static struct kernel_param __moduleparam_const __param_##name \ __used __section("__param") \
Signature · 1 line
2.49.0
Daniel Gomez
maintainerRe: [PATCH 3/5] module: Restore the moduleparam prefix length check
Quoted 33 lines · Petr Pavlu
The moduleparam code allows modules to provide their own definition of
MODULE_PARAM_PREFIX, instead of using the defaultKBUILD_MODNAME".".Commit
730b69d22525("module: check kernel param length at compile time, not runtime") added a check to ensure the prefix doesn't exceedMODULE_NAME_LEN, as this is whatparam_sysfs_builtin()expects.Later, commit
58f86cc89c33("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.") removed this check, but there is no indication this was intentional.Since the check is still useful for
param_sysfs_builtin()to function properly, reintroduce it in__module_param_call(), but in a modernized form usingstatic_assert().While here, clean up the
__module_param_call()comments. In particular, remove the comment "Default value instead of permissions?", which comes from commit9774a1f54f17("[PATCH] Compile-time check re world-writeable module params"). This comment was related to the test variable __param_perm_check_##name, which was removed in the previously mentioned commit58f86cc89c33.Fixes 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.")Signed-off-by Petr Pavlu <[email protected]>--- include/linux/moduleparam.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/moduleparam.h +0
-0
include/linux/moduleparam.h struct kparam_array · line 287
Quoted 9 lines
include/linux/moduleparam.h +2
-3@@ -282,10 +282,9 @@ struct kparam_array#define __moduleparam_const const#endif -/* This is the fundamental function for registering boot/module -parameters. */ +/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ -/* Default value instead of permissions? */ \ + static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \
Can you clarify if -1 to remove the dot from prefix?
Final code
static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \with __MODULE_NAME_LEN being:
#define __MODULE_NAME_LEN (64 - sizeof(unsigned long))
Quoted 3 lines
include/linux/moduleparam.h +0
-0static const char __param_str_##name[] = prefix #name; \ static struct kernel_param __moduleparam_const __param_##name \ __used __section("__param") \
Petr Pavlu
maintainerRe: [PATCH 3/5] module: Restore the moduleparam prefix length check
Quoted 46 lines · Daniel Gomez
Quoted 33 lines · Petr Pavlu
The moduleparam code allows modules to provide their own definition of
MODULE_PARAM_PREFIX, instead of using the defaultKBUILD_MODNAME".".Commit
730b69d22525("module: check kernel param length at compile time, not runtime") added a check to ensure the prefix doesn't exceedMODULE_NAME_LEN, as this is whatparam_sysfs_builtin()expects.Later, commit
58f86cc89c33("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.") removed this check, but there is no indication this was intentional.Since the check is still useful for
param_sysfs_builtin()to function properly, reintroduce it in__module_param_call(), but in a modernized form usingstatic_assert().While here, clean up the
__module_param_call()comments. In particular, remove the comment "Default value instead of permissions?", which comes from commit9774a1f54f17("[PATCH] Compile-time check re world-writeable module params"). This comment was related to the test variable __param_perm_check_##name, which was removed in the previously mentioned commit58f86cc89c33.Fixes 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.")Signed-off-by Petr Pavlu <[email protected]>--- include/linux/moduleparam.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/moduleparam.h +0
-0include/linux/moduleparam.h struct kparam_array · line 287
Quoted 9 lines
include/linux/moduleparam.h +2
-3@@ -282,10 +282,9 @@ struct kparam_array#define __moduleparam_const const#endif -/* This is the fundamental function for registering boot/module -parameters. */ +/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ -/* Default value instead of permissions? */ \ + static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \Can you clarify if -1 to remove the dot from prefix?
Quoted 6 lines
Final code
static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \with
__MODULE_NAME_LENbeing:#define
__MODULE_NAME_LEN(64 - sizeof(unsigned long))
Correct, -1 is to account for the dot at the end of the prefix.
I actually also wanted to assert that the prefix ends with a dot, but unfortunately prefix[sizeof(prefix)-2] (with prefix being a string literal) is not a constant expression in C.
Signature · 2 lines
Thanks, Petr
Re: [PATCH 3/5] module: Restore the moduleparam prefix length check
Quoted 47 lines · Petr Pavlu
Quoted 46 lines · Daniel Gomez
Quoted 33 lines · Petr Pavlu
The moduleparam code allows modules to provide their own definition of
MODULE_PARAM_PREFIX, instead of using the defaultKBUILD_MODNAME".".Commit
730b69d22525("module: check kernel param length at compile time, not runtime") added a check to ensure the prefix doesn't exceedMODULE_NAME_LEN, as this is whatparam_sysfs_builtin()expects.Later, commit
58f86cc89c33("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.") removed this check, but there is no indication this was intentional.Since the check is still useful for
param_sysfs_builtin()to function properly, reintroduce it in__module_param_call(), but in a modernized form usingstatic_assert().While here, clean up the
__module_param_call()comments. In particular, remove the comment "Default value instead of permissions?", which comes from commit9774a1f54f17("[PATCH] Compile-time check re world-writeable module params"). This comment was related to the test variable __param_perm_check_##name, which was removed in the previously mentioned commit58f86cc89c33.Fixes 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.")Signed-off-by Petr Pavlu <[email protected]>--- include/linux/moduleparam.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/moduleparam.h +0
-0include/linux/moduleparam.h struct kparam_array · line 287
Quoted 9 lines
include/linux/moduleparam.h +2
-3@@ -282,10 +282,9 @@ struct kparam_array#define __moduleparam_const const#endif -/* This is the fundamental function for registering boot/module -parameters. */ +/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ -/* Default value instead of permissions? */ \ + static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \Can you clarify if -1 to remove the dot from prefix?
Quoted 8 lines
Quoted 6 lines
Final code
static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \with
__MODULE_NAME_LENbeing:#define
__MODULE_NAME_LEN(64 - sizeof(unsigned long))Correct, -1 is to account for the dot at the end of the prefix.
LGTM,
Quoted 5 lines
I actually also wanted to assert that the prefix ends with a dot, but unfortunately prefix[sizeof(prefix)-2] (with prefix being a string literal) is not a constant expression in C.
But even if that would be possible, there are some calls that do not have a prefix with dot. For example,
#define core_param(name, var, type, perm) \
param_check_##type(name, &(var)); \
__module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0)So, you'd have to handle both cases. I mean, where __module_param_call(<prefix> is used with either MODULE_PARAM_PREFIX or an empty string "".
Petr Pavlu
maintainerPATCH 4/5 tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN
In reply to Petr PavluUse the MODULE_NAME_LEN definition in module_exists() to obtain the maximum size of a module name, instead of using MAX_PARAM_PREFIX_LEN. The values are the same but MODULE_NAME_LEN is more appropriate in this context. MAX_PARAM_PREFIX_LEN was added in commit 730b69d22525 ("module: check kernel param length at compile time, not runtime") only to break a circular dependency between module.h and moduleparam.h, and should mostly be limited to use in moduleparam.h.
---
As a side note, I suspect the function module_exists() would be better replaced with !!find_module() + RCU locking, but that is a separate issue.
kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -10373,7 +10373,7 @@ bool module_exists(const char *module) {/* All modules have the symbol __this_module */ static const char this_mod[] ="__this_module" ; -char modname[MAX_PARAM_PREFIX_LEN +sizeof (this_mod) +2 ]; +char modname[MODULE_NAME_LEN +sizeof (this_mod) +2 ];unsigned long val;int n;
Signature · 1 line
2.49.0
Re: [PATCH 4/5] tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN
Quoted 11 lines · Petr Pavlu
Use the
MODULE_NAME_LENdefinition inmodule_exists()to obtain the maximum size of a module name, instead of usingMAX_PARAM_PREFIX_LEN. The values are the same butMODULE_NAME_LENis more appropriate in this context.MAX_PARAM_PREFIX_LENwas added in commit730b69d22525("module: check kernel param length at compile time, not runtime") only to break a circular dependency betweenmodule.handmoduleparam.h, and should mostly be limited to use inmoduleparam.h.Signed-off-by Petr Pavlu <[email protected]>Cc Steven Rostedt <[email protected]>Cc Masami Hiramatsu <[email protected]>
Steven, Masami,
I'm planning to merge these series into modules-next. I think and Ack/Review would be great from you. Otherwise, let me know if you'd rather take this patch through tracing instead (in case it looks good from your side).
Quoted 13 lines
---
As a side note, I suspect the function
module_exists()would be better replaced with !!find_module() + RCU locking, but that is a separate issue.kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/trace.c +0
-0
kernel/trace/trace.c bool module_exists(const char *module) · line 10379
Quoted 8 lines
kernel/trace/trace.c +1
-1@@ -10373,7 +10373,7 @@ bool module_exists(const char *module) {/* All modules have the symbol __this_module */ static const char this_mod[] ="__this_module" ; -char modname[MAX_PARAM_PREFIX_LEN +sizeof (this_mod) +2 ]; +char modname[MODULE_NAME_LEN +sizeof (this_mod) +2 ];unsigned long val;int n;
LGTM,
Re: [PATCH 4/5] tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN
Quoted 13 lines · On Mon, 28 Jul 2025 08:48:01 +0200 Daniel Gomez <[email protected]> wrote:
Quoted 11 lines · Petr Pavlu
Use the
MODULE_NAME_LENdefinition inmodule_exists()to obtain the maximum size of a module name, instead of usingMAX_PARAM_PREFIX_LEN. The values are the same butMODULE_NAME_LENis more appropriate in this context.MAX_PARAM_PREFIX_LENwas added in commit730b69d22525("module: check kernel param length at compile time, not runtime") only to break a circular dependency betweenmodule.handmoduleparam.h, and should mostly be limited to use inmoduleparam.h.Signed-off-by Petr Pavlu <[email protected]>Cc Steven Rostedt <[email protected]>Cc Masami Hiramatsu <[email protected]>
Quoted 5 lines
Steven, Masami,
I'm planning to merge these series into modules-next. I think and Ack/Review would be great from you. Otherwise, let me know if you'd rather take this patch through tracing instead (in case it looks good from your side).
Quoted 5 lines
Quoted 5 lines
---
As a side note, I suspect the function
module_exists()would be better replaced with !!find_module() + RCU locking, but that is a separate issue.
Yeah, that is probably something that should be done too.
Thanks,
-- Steve
Petr Pavlu
maintainerPATCH 5/5 module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN
In reply to Petr PavluThe maximum module name length (MODULE_NAME_LEN) is somewhat confusingly defined in terms of the maximum parameter prefix length (MAX_PARAM_PREFIX_LEN), when in fact the dependency is in the opposite direction.
This split originates from commit 730b69d22525 ("module: check kernel param length at compile time, not runtime"). The code needed to use MODULE_NAME_LEN in moduleparam.h, but because module.h requires moduleparam.h, this created a circular dependency. It was resolved by introducing MAX_PARAM_PREFIX_LEN in moduleparam.h and defining MODULE_NAME_LEN in module.h in terms of MAX_PARAM_PREFIX_LEN.
Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN for clarity. This matches the similar approach of defining MODULE_INFO in module.h and __MODULE_INFO in moduleparam.h.
--- include/linux/module.h | 2 +- include/linux/moduleparam.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
include/linux/module.h +1 -1
@@ -32,7 +32,7 @@#include <linux/percpu.h> #include <asm/module.h> -#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN +#define MODULE_NAME_LEN __MODULE_NAME_LENstruct modversion_info {unsigned long crc;
include/linux/moduleparam.h +8 -4
@@ -6,6 +6,13 @@#include <linux/stringify.h> #include <linux/kernel.h> +/* +* The maximum module name length, including the NUL byte. +* Chosen so that structs with an unsigned long line up, specifically +* modversion_info. +*/ +#define __MODULE_NAME_LEN (64 - sizeof(unsigned long)) +/* You can override this manually, but generally this should match the module name. */ #ifdef MODULE
@@ -17,9 +24,6 @@#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."#endif -/* Chosen so that structs with an unsigned long line up. */ -#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) -#define __MODULE_INFO (tag, name, info) \ static const char __UNIQUE_ID(name)[] \ __used __section(".modinfo") __aligned(1) \
@@ -284,7 +288,7 @@ struct kparam_array/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ - static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \ + static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \ static const char __param_str_##name[] = prefix #name; \ static struct kernel_param __moduleparam_const __param_##name \ __used __section("__param") \
Signature · 1 line
2.49.0
Re: [PATCH 5/5] module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN
Quoted 64 lines · Petr Pavlu
The maximum module name length (
MODULE_NAME_LEN) is somewhat confusingly defined in terms of the maximum parameter prefix length (MAX_PARAM_PREFIX_LEN), when in fact the dependency is in the opposite direction.This split originates from commit
730b69d22525("module: check kernel param length at compile time, not runtime"). The code needed to useMODULE_NAME_LENinmoduleparam.h, but becausemodule.hrequiresmoduleparam.h, this created a circular dependency. It was resolved by introducingMAX_PARAM_PREFIX_LENinmoduleparam.hand definingMODULE_NAME_LENinmodule.hin terms ofMAX_PARAM_PREFIX_LEN.Rename
MAX_PARAM_PREFIX_LENto__MODULE_NAME_LENfor clarity. This matches the similar approach of definingMODULE_INFOinmodule.hand__MODULE_INFOinmoduleparam.h.Signed-off-by Petr Pavlu <[email protected]>--- include/linux/module.h | 2 +- include/linux/moduleparam.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)include/linux/module.h +1
-1@@ -32,7 +32,7 @@#include <linux/percpu.h> #include <asm/module.h> -#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN +#define MODULE_NAME_LEN __MODULE_NAME_LENstruct modversion_info {unsigned long crc;include/linux/moduleparam.h +7
-3@@ -6,6 +6,13 @@#include <linux/stringify.h> #include <linux/kernel.h> +/* +* The maximum module name length, including the NUL byte. +* Chosen so that structs with an unsigned long line up, specifically +* modversion_info. +*/ +#define __MODULE_NAME_LEN (64 - sizeof(unsigned long)) +/* You can override this manually, but generally this should match the module name. */ #ifdef MODULE @@ -17,9 +24,6 @@#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."#endif -/* Chosen so that structs with an unsigned long line up. */ -#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) -#define __MODULE_INFO (tag, name, info) \ static const char __UNIQUE_ID(name)[] \ __used __section(".modinfo") __aligned(1) \
include/linux/moduleparam.h struct kparam_array · line 294
Quoted 8 lines
include/linux/moduleparam.h +1
-1@@ -284,7 +288,7 @@ struct kparam_array/* This is the fundamental function for registering boot/module parameters. */ #define __module_param_call (prefix, name, ops, arg, perm, level, flags) \ - static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \ + static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \ static const char __param_str_##name[] = prefix #name; \ static struct kernel_param __moduleparam_const __param_##name \ __used __section("__param") \
LGTM,
Daniel Gomez
AppliedQuoted 11 lines · Petr Pavlu
Fix a few minor problems related to
MODULE_NAME_LENandMAX_PARAM_PREFIX_LEN, and clean up their usage.Petr Pavlu (5):
module: Prevent silent truncation of module name indelete_module(2)
module: Remove unnecessary +1 fromlast_unloaded_module::namesize
module: Restore the moduleparam prefix length check
tracing: ReplaceMAX_PARAM_PREFIX_LENwithMODULE_NAME_LEN
module: RenameMAX_PARAM_PREFIX_LENto__MODULE_NAME_LEN[...]
Applied, thanks!
[1/5] module: Prevent silent truncation of module name in delete_module(2)
commit: a6323bd4e611567913e23df5b58f2d4e4da06789
[2/5] module: Remove unnecessary +1 from last_unloaded_module::name size
commit: 6c171b2ccfe677ca97fc5334f853807959f26589
[3/5] module: Restore the moduleparam prefix length check
commit: bdc877ba6b7ff1b6d2ebeff11e63da4a50a54854
[4/5] tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN
commit: a7c54b2b41dd1f6ec780e7fbfb13f70c64c9731d
[5/5] module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN
commit: 40a826bd6c82ae45cfd3a19cd2a60a10f56b74c0Best regards,
Signature · 1 line
Daniel Gomez <[email protected]>