mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 01:53:29 +02:00
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. Note that this had a conflict with sysctl changes [1] but should be fixed now as I rebased on top. 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. The module name fix and related cleanup has been in linux-next since Thursday (July 31) while the rest of the changes for a bit more than 3 weeks. Note that this currently has conflicts in next with kbuild's tree [2]. Link: https://lore.kernel.org/all/20250714175916.774e6d79@canb.auug.org.au/ [1] Link: https://lore.kernel.org/all/20250801132941.6815d93d@canb.auug.org.au/ [2] -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE73Ua4R8Pc+G5xjxTQJ6jxB8ZUfsFAmiPQgkACgkQQJ6jxB8Z UfuPTA//XrRguJFBhQh6cUWqVleTNQJuhjiPsOSO5S52aVET4wsrnRNeM2eM5oqw 0+6ELvhIJINQ1LjpOP8D67d8P5Ds1/qM1pbQIkQsoKiEj6E7Q4dXH5N0uyf/BzO3 HaosLG9cpqcomlSorYEiYoPjqy9EChQzsi+YAYWAB+fW6bvU/AdUHTRH88m3ppBJ Y22BTTPOKKyj5/QgfY+kwH8TTnrzCzY8aoOqW7uimLI5h4c9dFQ2PigRJnoMfDG1 11w5VshOTzZJvNFrUk5GVSirwlxdJDbW6dKfG0DD5+eNWK5dfIEc+/EcuhaGoPvO Euwv8VQubdxHTAG6kzHI0MtxAVQUM1gyz8zHiu18eW++GTtnTFs6m8E6H9AC176G nDkUh3qSxJN2HHgxtS9VUExEEZpYqtWeB9Zts8K3oSWvTaQenHWpVHPADkxzS4JU Jvkjq8SiKo+RqHxaOKfyf1RfOtYe5tjMCLrP7zX39d1+cwGxuc6mip/omY9HFDgn op132fYdt24JSHoioJDzRz9mTfvj3nICEmgX4D4WDQx5lP27CUcLugPnBNHPp0fu 5hL+ajy8M8nq4zm/42Y+F7VS74TIA6mSnJKs9dMCknUWueD6HrDEU9xHi1YMpUMZ cBUSpU+P94dCIScwEzkp926vDnHyxCHLbpF1Jsq5qNNdj7AelHk= =4bGB -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
8877fcb70f
|
|
@ -33,7 +33,7 @@
|
|||
#include <linux/percpu.h>
|
||||
#include <asm/module.h>
|
||||
|
||||
#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
|
||||
#define MODULE_NAME_LEN __MODULE_NAME_LEN
|
||||
|
||||
struct modversion_info {
|
||||
unsigned long crc;
|
||||
|
|
@ -303,23 +303,6 @@ static typeof(name) __mod_device_table__##type##__##name \
|
|||
|
||||
struct notifier_block;
|
||||
|
||||
#ifdef CONFIG_MODULES
|
||||
|
||||
/* Get/put a kernel symbol (calls must be symmetric) */
|
||||
void *__symbol_get(const char *symbol);
|
||||
void *__symbol_get_gpl(const char *symbol);
|
||||
#define symbol_get(x) ({ \
|
||||
static const char __notrim[] \
|
||||
__used __section(".no_trim_symbol") = __stringify(x); \
|
||||
(typeof(&x))(__symbol_get(__stringify(x))); })
|
||||
|
||||
/* modules using other modules: kdb wants to see this. */
|
||||
struct module_use {
|
||||
struct list_head source_list;
|
||||
struct list_head target_list;
|
||||
struct module *source, *target;
|
||||
};
|
||||
|
||||
enum module_state {
|
||||
MODULE_STATE_LIVE, /* Normal state. */
|
||||
MODULE_STATE_COMING, /* Full formed, running module_init. */
|
||||
|
|
@ -604,6 +587,16 @@ struct module {
|
|||
#define MODULE_ARCH_INIT {}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MODULES
|
||||
|
||||
/* Get/put a kernel symbol (calls must be symmetric) */
|
||||
void *__symbol_get(const char *symbol);
|
||||
void *__symbol_get_gpl(const char *symbol);
|
||||
#define symbol_get(x) ({ \
|
||||
static const char __notrim[] \
|
||||
__used __section(".no_trim_symbol") = __stringify(x); \
|
||||
(typeof(&x))(__symbol_get(__stringify(x))); })
|
||||
|
||||
#ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
|
||||
static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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) \
|
||||
|
|
@ -282,10 +286,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 <= __MODULE_NAME_LEN); \
|
||||
static const char __param_str_##name[] = prefix #name; \
|
||||
static struct kernel_param __moduleparam_const __param_##name \
|
||||
__used __section("__param") \
|
||||
|
|
|
|||
|
|
@ -112,6 +112,13 @@ struct find_symbol_arg {
|
|||
enum mod_license license;
|
||||
};
|
||||
|
||||
/* modules using other modules */
|
||||
struct module_use {
|
||||
struct list_head source_list;
|
||||
struct list_head target_list;
|
||||
struct module *source, *target;
|
||||
};
|
||||
|
||||
int mod_verify_sig(const void *mod, struct load_info *info);
|
||||
int try_to_force_load(struct module *mod, const char *reason);
|
||||
bool find_symbol(struct find_symbol_arg *fsa);
|
||||
|
|
|
|||
|
|
@ -608,7 +608,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;
|
||||
|
||||
|
|
@ -779,14 +779,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);
|
||||
|
||||
|
|
|
|||
|
|
@ -10376,7 +10376,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;
|
||||
|
||||
|
|
|
|||
|
|
@ -802,7 +802,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
|
||||
|
||||
#ifdef CONFIG_MODULES
|
||||
static void kunit_module_init(struct module *mod)
|
||||
{
|
||||
struct kunit_suite_set suite_set, filtered_set;
|
||||
|
|
@ -890,7 +889,6 @@ static struct notifier_block kunit_mod_nb = {
|
|||
.notifier_call = kunit_module_notify,
|
||||
.priority = 0,
|
||||
};
|
||||
#endif
|
||||
|
||||
KUNIT_DEFINE_ACTION_WRAPPER(kfree_action_wrapper, kfree, const void *)
|
||||
|
||||
|
|
@ -981,20 +979,14 @@ static int __init kunit_init(void)
|
|||
kunit_debugfs_init();
|
||||
|
||||
kunit_bus_init();
|
||||
#ifdef CONFIG_MODULES
|
||||
return register_module_notifier(&kunit_mod_nb);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
late_initcall(kunit_init);
|
||||
|
||||
static void __exit kunit_exit(void)
|
||||
{
|
||||
memset(&kunit_hooks, 0, sizeof(kunit_hooks));
|
||||
#ifdef CONFIG_MODULES
|
||||
unregister_module_notifier(&kunit_mod_nb);
|
||||
#endif
|
||||
|
||||
kunit_bus_shutdown();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user