Skip to content

Commit 8877fcb

Browse files
committed
Merge tag 'modules-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux
Pull module updates from Daniel Gomez: "This is a small set of changes for modules, primarily to extend module users to use the module data structures in combination with the already no-op stub module functions, even when support for modules is disabled in the kernel configuration. This change follows the kernel's coding style for conditional compilation and allows kunit code to drop all CONFIG_MODULES ifdefs, which is also part of the changes. This should allow others part of the kernel to do the same cleanup. The remaining changes include a fix for module name length handling which could potentially lead to the removal of an incorrect module, and various cleanups" * tag 'modules-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN module: Restore the moduleparam prefix length check module: Remove unnecessary +1 from last_unloaded_module::name size module: Prevent silent truncation of module name in delete_module(2) kunit: test: Drop CONFIG_MODULE ifdeffery module: make structure definitions always visible module: move 'struct module_use' to internal.h
2 parents 546b0ad + 40a826b commit 8877fcb

File tree

6 files changed

+35
-38
lines changed

6 files changed

+35
-38
lines changed

include/linux/module.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/percpu.h>
3434
#include <asm/module.h>
3535

36-
#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
36+
#define MODULE_NAME_LEN __MODULE_NAME_LEN
3737

3838
struct modversion_info {
3939
unsigned long crc;
@@ -303,23 +303,6 @@ static typeof(name) __mod_device_table__##type##__##name \
303303

304304
struct notifier_block;
305305

306-
#ifdef CONFIG_MODULES
307-
308-
/* Get/put a kernel symbol (calls must be symmetric) */
309-
void *__symbol_get(const char *symbol);
310-
void *__symbol_get_gpl(const char *symbol);
311-
#define symbol_get(x) ({ \
312-
static const char __notrim[] \
313-
__used __section(".no_trim_symbol") = __stringify(x); \
314-
(typeof(&x))(__symbol_get(__stringify(x))); })
315-
316-
/* modules using other modules: kdb wants to see this. */
317-
struct module_use {
318-
struct list_head source_list;
319-
struct list_head target_list;
320-
struct module *source, *target;
321-
};
322-
323306
enum module_state {
324307
MODULE_STATE_LIVE, /* Normal state. */
325308
MODULE_STATE_COMING, /* Full formed, running module_init. */
@@ -604,6 +587,16 @@ struct module {
604587
#define MODULE_ARCH_INIT {}
605588
#endif
606589

590+
#ifdef CONFIG_MODULES
591+
592+
/* Get/put a kernel symbol (calls must be symmetric) */
593+
void *__symbol_get(const char *symbol);
594+
void *__symbol_get_gpl(const char *symbol);
595+
#define symbol_get(x) ({ \
596+
static const char __notrim[] \
597+
__used __section(".no_trim_symbol") = __stringify(x); \
598+
(typeof(&x))(__symbol_get(__stringify(x))); })
599+
607600
#ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
608601
static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
609602
{

include/linux/moduleparam.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
#include <linux/stringify.h>
77
#include <linux/kernel.h>
88

9+
/*
10+
* The maximum module name length, including the NUL byte.
11+
* Chosen so that structs with an unsigned long line up, specifically
12+
* modversion_info.
13+
*/
14+
#define __MODULE_NAME_LEN (64 - sizeof(unsigned long))
15+
916
/* You can override this manually, but generally this should match the
1017
module name. */
1118
#ifdef MODULE
@@ -17,9 +24,6 @@
1724
#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
1825
#endif
1926

20-
/* Chosen so that structs with an unsigned long line up. */
21-
#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
22-
2327
#define __MODULE_INFO(tag, name, info) \
2428
static const char __UNIQUE_ID(name)[] \
2529
__used __section(".modinfo") __aligned(1) \
@@ -282,10 +286,9 @@ struct kparam_array
282286
#define __moduleparam_const const
283287
#endif
284288

285-
/* This is the fundamental function for registering boot/module
286-
parameters. */
289+
/* This is the fundamental function for registering boot/module parameters. */
287290
#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
288-
/* Default value instead of permissions? */ \
291+
static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \
289292
static const char __param_str_##name[] = prefix #name; \
290293
static struct kernel_param __moduleparam_const __param_##name \
291294
__used __section("__param") \

kernel/module/internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ struct find_symbol_arg {
112112
enum mod_license license;
113113
};
114114

115+
/* modules using other modules */
116+
struct module_use {
117+
struct list_head source_list;
118+
struct list_head target_list;
119+
struct module *source, *target;
120+
};
121+
115122
int mod_verify_sig(const void *mod, struct load_info *info);
116123
int try_to_force_load(struct module *mod, const char *reason);
117124
bool find_symbol(struct find_symbol_arg *fsa);

kernel/module/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ MODINFO_ATTR(version);
608608
MODINFO_ATTR(srcversion);
609609

610610
static struct {
611-
char name[MODULE_NAME_LEN + 1];
611+
char name[MODULE_NAME_LEN];
612612
char taints[MODULE_FLAGS_BUF_SIZE];
613613
} last_unloaded_module;
614614

@@ -779,14 +779,16 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
779779
struct module *mod;
780780
char name[MODULE_NAME_LEN];
781781
char buf[MODULE_FLAGS_BUF_SIZE];
782-
int ret, forced = 0;
782+
int ret, len, forced = 0;
783783

784784
if (!capable(CAP_SYS_MODULE) || modules_disabled)
785785
return -EPERM;
786786

787-
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
788-
return -EFAULT;
789-
name[MODULE_NAME_LEN-1] = '\0';
787+
len = strncpy_from_user(name, name_user, MODULE_NAME_LEN);
788+
if (len == 0 || len == MODULE_NAME_LEN)
789+
return -ENOENT;
790+
if (len < 0)
791+
return len;
790792

791793
audit_log_kern_module(name);
792794

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10376,7 +10376,7 @@ bool module_exists(const char *module)
1037610376
{
1037710377
/* All modules have the symbol __this_module */
1037810378
static const char this_mod[] = "__this_module";
10379-
char modname[MAX_PARAM_PREFIX_LEN + sizeof(this_mod) + 2];
10379+
char modname[MODULE_NAME_LEN + sizeof(this_mod) + 2];
1038010380
unsigned long val;
1038110381
int n;
1038210382

lib/kunit/test.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
802802
}
803803
EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
804804

805-
#ifdef CONFIG_MODULES
806805
static void kunit_module_init(struct module *mod)
807806
{
808807
struct kunit_suite_set suite_set, filtered_set;
@@ -890,7 +889,6 @@ static struct notifier_block kunit_mod_nb = {
890889
.notifier_call = kunit_module_notify,
891890
.priority = 0,
892891
};
893-
#endif
894892

895893
KUNIT_DEFINE_ACTION_WRAPPER(kfree_action_wrapper, kfree, const void *)
896894

@@ -981,20 +979,14 @@ static int __init kunit_init(void)
981979
kunit_debugfs_init();
982980

983981
kunit_bus_init();
984-
#ifdef CONFIG_MODULES
985982
return register_module_notifier(&kunit_mod_nb);
986-
#else
987-
return 0;
988-
#endif
989983
}
990984
late_initcall(kunit_init);
991985

992986
static void __exit kunit_exit(void)
993987
{
994988
memset(&kunit_hooks, 0, sizeof(kunit_hooks));
995-
#ifdef CONFIG_MODULES
996989
unregister_module_notifier(&kunit_mod_nb);
997-
#endif
998990

999991
kunit_bus_shutdown();
1000992

0 commit comments

Comments
 (0)