Skip to content

Commit ef98f9c

Browse files
committed
Merge tag 'modules-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux
Pull modules updates from Luis Chamberlain: - It was time to tidy up kernel/module.c and one way of starting with that effort was to split it up into files. At my request Aaron Tomlin spearheaded that effort with the goal to not introduce any functional at all during that endeavour. The penalty for the split is +1322 bytes total, +112 bytes in data, +1210 bytes in text while bss is unchanged. One of the benefits of this other than helping make the code easier to read and review is summoning more help on review for changes with livepatching so kernel/module/livepatch.c is now pegged as maintained by the live patching folks. The before and after with just the move on a defconfig on x86-64: $ size kernel/module.o text data bss dec hex filename 38434 4540 104 43078 a846 kernel/module.o $ size -t kernel/module/*.o text data bss dec hex filename 4785 120 0 4905 1329 kernel/module/kallsyms.o 28577 4416 104 33097 8149 kernel/module/main.o 1158 8 0 1166 48e kernel/module/procfs.o 902 108 0 1010 3f2 kernel/module/strict_rwx.o 3390 0 0 3390 d3e kernel/module/sysfs.o 832 0 0 832 340 kernel/module/tree_lookup.o 39644 4652 104 44400 ad70 (TOTALS) - Aaron added module unload taint tracking (MODULE_UNLOAD_TAINT_TRACKING), to enable tracking unloaded modules which did taint the kernel. - Christophe Leroy added CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC which lets architectures to request having modules data in vmalloc area instead of module area. There are three reasons why an architecture might want this: a) On some architectures (like book3s/32) it is not possible to protect against execution on a page basis. The exec stuff can be mapped by different arch segment sizes (on book3s/32 that is 256M segments). By default the module area is in an Exec segment while vmalloc area is in a NoExec segment. Using vmalloc lets you muck with module data as NoExec on those architectures whereas before you could not. b) By pushing more module data to vmalloc you also increase the probability of module text to remain within a closer distance from kernel core text and this reduces trampolines, this has been reported on arm first and powerpc folks are following that lead. c) Free'ing module_alloc() (Exec by default) area leaves this exposed as Exec by default, some architectures have some security enhancements to set this as NoExec on free, and splitting module data with text let's future generic special allocators be added to the kernel without having developers try to grok the tribal knowledge per arch. Work like Rick Edgecombe's permission vmalloc interface [0] becomes easier to address over time. [0] https://lore.kernel.org/lkml/[email protected]/#r - Masahiro Yamada's symbol search enhancements * tag 'modules-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: (33 commits) module: merge check_exported_symbol() into find_exported_symbol_in_section() module: do not binary-search in __ksymtab_gpl if fsa->gplok is false module: do not pass opaque pointer for symbol search module: show disallowed symbol name for inherit_taint() module: fix [e_shstrndx].sh_size=0 OOB access module: Introduce module unload taint tracking module: Move module_assert_mutex_or_preempt() to internal.h module: Make module_flags_taint() accept a module's taints bitmap and usable outside core code module.h: simplify MODULE_IMPORT_NS powerpc: Select ARCH_WANTS_MODULES_DATA_IN_VMALLOC on book3s/32 and 8xx module: Remove module_addr_min and module_addr_max module: Add CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC module: Introduce data_layout module: Prepare for handling several RB trees module: Always have struct mod_tree_root module: Rename debug_align() as strict_align() module: Rework layout alignment to avoid BUG_ON()s module: Move module_enable_x() and frob_text() in strict_rwx.c module: Make module_enable_x() independent of CONFIG_ARCH_HAS_STRICT_MODULE_RWX module: Move version support into a separate file ...
2 parents 44d3572 + 7390b94 commit ef98f9c

29 files changed

+2384
-2052
lines changed

MAINTAINERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10987,6 +10987,7 @@ F: drivers/tty/serial/kgdboc.c
1098710987
F: include/linux/kdb.h
1098810988
F: include/linux/kgdb.h
1098910989
F: kernel/debug/
10990+
F: kernel/module/kdb.c
1099010991

1099110992
KHADAS MCU MFD DRIVER
1099210993
M: Neil Armstrong <[email protected]>
@@ -11440,6 +11441,7 @@ F: arch/s390/include/asm/livepatch.h
1144011441
F: arch/x86/include/asm/livepatch.h
1144111442
F: include/linux/livepatch.h
1144211443
F: kernel/livepatch/
11444+
F: kernel/module/livepatch.c
1144311445
F: lib/livepatch/
1144411446
F: samples/livepatch/
1144511447
F: tools/testing/selftests/livepatch/
@@ -13371,7 +13373,7 @@ L: [email protected]
1337113373
S: Maintained
1337213374
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
1337313375
F: include/linux/module.h
13374-
F: kernel/module.c
13376+
F: kernel/module/
1337513377

1337613378
MONOLITHIC POWER SYSTEM PMIC DRIVER
1337713379
M: Saravanan Sekar <[email protected]>

arch/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,12 @@ config MODULES_USE_ELF_REL
892892
Modules only use ELF REL relocations. Modules with ELF RELA
893893
relocations will give an error.
894894

895+
config ARCH_WANTS_MODULES_DATA_IN_VMALLOC
896+
bool
897+
help
898+
For architectures like powerpc/32 which have constraints on module
899+
allocation and need to allocate module data outside of module area.
900+
895901
config HAVE_IRQ_EXIT_ON_IRQ_STACK
896902
bool
897903
help

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ config PPC
158158
select ARCH_WANT_IPC_PARSE_VERSION
159159
select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
160160
select ARCH_WANT_LD_ORPHAN_WARN
161+
select ARCH_WANTS_MODULES_DATA_IN_VMALLOC if PPC_BOOK3S_32 || PPC_8xx
161162
select ARCH_WEAK_RELEASE_ACQUIRE
162163
select BINFMT_ELF
163164
select BUILDTIME_TABLE_SORT

include/linux/kdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,6 @@ enum {
222222

223223
extern int kdbgetintenv(const char *, int *);
224224
extern int kdb_set(int, const char **);
225+
int kdb_lsmod(int argc, const char **argv);
225226

226227
#endif /* !_KDB_H */

include/linux/module.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ extern typeof(name) __mod_##type##__##name##_device_table \
290290
* files require multiple MODULE_FIRMWARE() specifiers */
291291
#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
292292

293-
#define _MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)
294-
#define MODULE_IMPORT_NS(ns) _MODULE_IMPORT_NS(ns)
293+
#define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, __stringify(ns))
295294

296295
struct notifier_block;
297296

@@ -422,6 +421,9 @@ struct module {
422421
/* Core layout: rbtree is accessed frequently, so keep together. */
423422
struct module_layout core_layout __module_layout_align;
424423
struct module_layout init_layout;
424+
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
425+
struct module_layout data_layout;
426+
#endif
425427

426428
/* Arch-specific module values */
427429
struct mod_arch_specific arch;
@@ -569,6 +571,11 @@ bool is_module_text_address(unsigned long addr);
569571
static inline bool within_module_core(unsigned long addr,
570572
const struct module *mod)
571573
{
574+
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
575+
if ((unsigned long)mod->data_layout.base <= addr &&
576+
addr < (unsigned long)mod->data_layout.base + mod->data_layout.size)
577+
return true;
578+
#endif
572579
return (unsigned long)mod->core_layout.base <= addr &&
573580
addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
574581
}
@@ -663,19 +670,15 @@ static inline bool module_requested_async_probing(struct module *module)
663670
return module && module->async_probe_requested;
664671
}
665672

666-
#ifdef CONFIG_LIVEPATCH
667673
static inline bool is_livepatch_module(struct module *mod)
668674
{
675+
#ifdef CONFIG_LIVEPATCH
669676
return mod->klp;
670-
}
671-
#else /* !CONFIG_LIVEPATCH */
672-
static inline bool is_livepatch_module(struct module *mod)
673-
{
677+
#else
674678
return false;
679+
#endif
675680
}
676-
#endif /* CONFIG_LIVEPATCH */
677681

678-
bool is_module_sig_enforced(void);
679682
void set_module_sig_enforced(void);
680683

681684
#else /* !CONFIG_MODULES... */
@@ -802,10 +805,6 @@ static inline bool module_requested_async_probing(struct module *module)
802805
return false;
803806
}
804807

805-
static inline bool is_module_sig_enforced(void)
806-
{
807-
return false;
808-
}
809808

810809
static inline void set_module_sig_enforced(void)
811810
{
@@ -857,11 +856,18 @@ static inline bool retpoline_module_ok(bool has_retpoline)
857856
#endif
858857

859858
#ifdef CONFIG_MODULE_SIG
859+
bool is_module_sig_enforced(void);
860+
860861
static inline bool module_sig_ok(struct module *module)
861862
{
862863
return module->sig_ok;
863864
}
864865
#else /* !CONFIG_MODULE_SIG */
866+
static inline bool is_module_sig_enforced(void)
867+
{
868+
return false;
869+
}
870+
865871
static inline bool module_sig_ok(struct module *module)
866872
{
867873
return true;

init/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,17 @@ config MODULE_FORCE_UNLOAD
19831983
rmmod). This is mainly for kernel developers and desperate users.
19841984
If unsure, say N.
19851985

1986+
config MODULE_UNLOAD_TAINT_TRACKING
1987+
bool "Tainted module unload tracking"
1988+
depends on MODULE_UNLOAD
1989+
default n
1990+
help
1991+
This option allows you to maintain a record of each unloaded
1992+
module that tainted the kernel. In addition to displaying a
1993+
list of linked (or loaded) modules e.g. on detection of a bad
1994+
page (see bad_page()), the aforementioned details are also
1995+
shown. If unsure, say N.
1996+
19861997
config MODVERSIONS
19871998
bool "Module versioning support"
19881999
help

kernel/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ KCOV_INSTRUMENT_softirq.o := n
2929
KCSAN_SANITIZE_softirq.o = n
3030
# These are called from save_stack_trace() on slub debug path,
3131
# and produce insane amounts of uninteresting coverage.
32-
KCOV_INSTRUMENT_module.o := n
3332
KCOV_INSTRUMENT_extable.o := n
3433
KCOV_INSTRUMENT_stacktrace.o := n
3534
# Don't self-instrument.
@@ -53,6 +52,7 @@ obj-y += rcu/
5352
obj-y += livepatch/
5453
obj-y += dma/
5554
obj-y += entry/
55+
obj-$(CONFIG_MODULES) += module/
5656

5757
obj-$(CONFIG_KCMP) += kcmp.o
5858
obj-$(CONFIG_FREEZER) += freezer.o
@@ -66,9 +66,6 @@ ifneq ($(CONFIG_SMP),y)
6666
obj-y += up.o
6767
endif
6868
obj-$(CONFIG_UID16) += uid16.o
69-
obj-$(CONFIG_MODULES) += module.o
70-
obj-$(CONFIG_MODULE_DECOMPRESS) += module_decompress.o
71-
obj-$(CONFIG_MODULE_SIG) += module_signing.o
7269
obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o
7370
obj-$(CONFIG_KALLSYMS) += kallsyms.o
7471
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o

kernel/debug/kdb/kdb_io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
1010
*/
1111

12-
#include <linux/module.h>
1312
#include <linux/types.h>
1413
#include <linux/ctype.h>
1514
#include <linux/kernel.h>

kernel/debug/kdb/kdb_keyboard.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/kdb.h>
1212
#include <linux/keyboard.h>
1313
#include <linux/ctype.h>
14-
#include <linux/module.h>
1514
#include <linux/io.h>
1615

1716
/* Keyboard Controller Registers on normal PCs. */

kernel/debug/kdb/kdb_main.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <linux/utsname.h>
2727
#include <linux/vmalloc.h>
2828
#include <linux/atomic.h>
29-
#include <linux/module.h>
3029
#include <linux/moduleparam.h>
3130
#include <linux/mm.h>
3231
#include <linux/init.h>
@@ -2060,54 +2059,6 @@ static int kdb_ef(int argc, const char **argv)
20602059
return 0;
20612060
}
20622061

2063-
#if defined(CONFIG_MODULES)
2064-
/*
2065-
* kdb_lsmod - This function implements the 'lsmod' command. Lists
2066-
* currently loaded kernel modules.
2067-
* Mostly taken from userland lsmod.
2068-
*/
2069-
static int kdb_lsmod(int argc, const char **argv)
2070-
{
2071-
struct module *mod;
2072-
2073-
if (argc != 0)
2074-
return KDB_ARGCOUNT;
2075-
2076-
kdb_printf("Module Size modstruct Used by\n");
2077-
list_for_each_entry(mod, kdb_modules, list) {
2078-
if (mod->state == MODULE_STATE_UNFORMED)
2079-
continue;
2080-
2081-
kdb_printf("%-20s%8u 0x%px ", mod->name,
2082-
mod->core_layout.size, (void *)mod);
2083-
#ifdef CONFIG_MODULE_UNLOAD
2084-
kdb_printf("%4d ", module_refcount(mod));
2085-
#endif
2086-
if (mod->state == MODULE_STATE_GOING)
2087-
kdb_printf(" (Unloading)");
2088-
else if (mod->state == MODULE_STATE_COMING)
2089-
kdb_printf(" (Loading)");
2090-
else
2091-
kdb_printf(" (Live)");
2092-
kdb_printf(" 0x%px", mod->core_layout.base);
2093-
2094-
#ifdef CONFIG_MODULE_UNLOAD
2095-
{
2096-
struct module_use *use;
2097-
kdb_printf(" [ ");
2098-
list_for_each_entry(use, &mod->source_list,
2099-
source_list)
2100-
kdb_printf("%s ", use->target->name);
2101-
kdb_printf("]\n");
2102-
}
2103-
#endif
2104-
}
2105-
2106-
return 0;
2107-
}
2108-
2109-
#endif /* CONFIG_MODULES */
2110-
21112062
/*
21122063
* kdb_env - This function implements the 'env' command. Display the
21132064
* current environment variables.

0 commit comments

Comments
 (0)