module: core code clean up
Subsystems (3)
v3 cover module: core code clean up
Hi Luis,
[Note: Cc'd live-patching for feedback on livepatch specific changes]
Firstly, apologies for the delay.
As per your suggestion [1], this is an attempt to refactor and split optional code out of core module support code into separate components. This version is based on branch mcgrof/modules-next since a97ac8cb24a3/or modules-5.17-rc1. Please let me know your thoughts.
Changes since v1 [2]:
- Moved module version support code into a new file
Changes since v2 [3]:
- Move module decompress support to a separate file
- Make check_modinfo_livepatch() generic (Petr Mladek)
- Remove filename from each newly created file (Luis Chamberlain)
- Addressed some (i.e. --ignore=ASSIGN_IN_IF,AVOID_BUG was used) minor scripts/checkpatch.pl concerns e.g., use strscpy over strlcpy and missing a blank line after declarations (Allen)
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
Aaron Tomlin (13):
module: Move all into module/
module: Simple refactor in preparation for split
module: Move livepatch support to a separate file
module: Move latched RB-tree support to a separate file
module: Move arch strict rwx support to a separate file
module: Move strict rwx support to a separate file
module: Move extra signature support out of core code
module: Move kmemleak support to a separate file
module: Move kallsyms support into a separate file
module: Move procfs support into a separate file
module: Move sysfs support into a separate file
module: Move kdb_modules list out of core code
module: Move version support into a separate file
MAINTAINERS | 2 +-
include/linux/module.h | 92 +-
kernel/Makefile | 5 +-
kernel/debug/kdb/kdb_main.c | 5 +
kernel/module-internal.h | 50 -
kernel/module/Makefile | 18 +
kernel/module/arch_strict_rwx.c | 44 +
kernel/module/debug_kmemleak.c | 30 +
.../decompress.c} | 2 +-
kernel/module/internal.h | 202 ++
kernel/module/kallsyms.c | 502 +++++
kernel/module/livepatch.c | 74 +
kernel/{module.c => module/main.c} | 1879 +----------------
kernel/module/procfs.c | 142 ++
.../signature.c} | 0
kernel/module/signing.c | 120 ++
kernel/module/strict_rwx.c | 83 +
kernel/module/sysfs.c | 425 ++++
kernel/module/tree_lookup.c | 108 +
kernel/module/version.c | 110 +
kernel/module_signing.c | 45 -
21 files changed, 2032 insertions(+), 1906 deletions(-)
delete mode 100644 kernel/module-internal.h
create mode 100644 kernel/module/Makefile
create mode 100644 kernel/module/arch_strict_rwx.c
create mode 100644 kernel/module/debug_kmemleak.c
rename kernel/{module_decompress.c => module/decompress.c} (99%)
create mode 100644 kernel/module/internal.h
create mode 100644 kernel/module/kallsyms.c
create mode 100644 kernel/module/livepatch.c
rename kernel/{module.c => module/main.c} (63%)
create mode 100644 kernel/module/procfs.c
rename kernel/{module_signature.c => module/signature.c} (100%)
create mode 100644 kernel/module/signing.c
create mode 100644 kernel/module/strict_rwx.c
create mode 100644 kernel/module/sysfs.c
create mode 100644 kernel/module/tree_lookup.c
create mode 100644 kernel/module/version.c
delete mode 100644 kernel/module_signing.cbase-commit: a97ac8cb24a3c3ad74794adb83717ef1605d1b47
Signature · 1 line
2.34.1
RFC PATCH v3 1/13 module: Move all into module/
No functional changes.
This patch moves all module related code into a separate directory, modifies each file name and creates a new Makefile. Note: this effort is in preparation to refactor core module code.
---
MAINTAINERS | 2 +-
kernel/Makefile | 5 +----
kernel/module/Makefile | 9 +++++++++
kernel/{module_decompress.c => module/decompress.c} | 2 +-
kernel/{module-internal.h => module/internal.h} | 0
kernel/{module.c => module/main.c} | 2 +-
kernel/{module_signature.c => module/signature.c} | 0
kernel/{module_signing.c => module/signing.c} | 2 +-
8 files changed, 14 insertions(+), 8 deletions(-)
create mode 100644 kernel/module/Makefile
rename kernel/{module_decompress.c => module/decompress.c} (99%)
rename kernel/{module-internal.h => module/internal.h} (100%)
rename kernel/{module.c => module/main.c} (99%)
rename kernel/{module_signature.c => module/signature.c} (100%)
rename kernel/{module_signing.c => module/signing.c} (97%)MAINTAINERS +1 -1
@@ -12976,7 +12976,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next F: include/linux/module.h -F: kernel/module.c +F: kernel/module/main.c MONOLITHIC POWER SYSTEM PMIC DRIVER M: Saravanan Sekar <[email protected]>
kernel/Makefile +1 -4
@@ -53,6 +53,7 @@ obj-y += rcu/ obj-y += livepatch/ obj-y += dma/ obj-y += entry/ +obj-y += module/ obj-$(CONFIG_KCMP) += kcmp.o obj-$(CONFIG_FREEZER) += freezer.o
@@ -66,10 +67,6 @@ ifneq ($(CONFIG_SMP),y) obj-y += up.o endif obj-$(CONFIG_UID16) += uid16.o -obj-$(CONFIG_MODULES) += module.o -obj-$(CONFIG_MODULE_DECOMPRESS) += module_decompress.o -obj-$(CONFIG_MODULE_SIG) += module_signing.o -obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_CRASH_CORE) += crash_core.o
kernel/module/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for linux kernel module support +# + +obj-$(CONFIG_MODULES) += main.o +obj-$(CONFIG_MODULE_DECOMPRESS) += decompress.o +obj-$(CONFIG_MODULE_SIG) += signing.o +obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o
kernel/module/decompress.c renamed from kernel/module_decompress.c +1 -1
@@ -12,7 +12,7 @@#include <linux/sysfs.h> #include <linux/vmalloc.h> -#include "module-internal.h" +#include "internal.h" static int module_extend_max_pages (struct load_info *info,unsigned int extent) {
kernel/module/internal.h renamed from kernel/module-internal.h +0 -0
kernel/module/main.c renamed from kernel/module.c +1 -1
@@ -58,7 +58,7 @@#include <linux/dynamic_debug.h> #include <linux/audit.h> #include <uapi/linux/module.h> -#include "module-internal.h" +#include "internal.h" #define CREATE_TRACE_POINTS #include <trace/events/module.h>
kernel/module/signature.c renamed from kernel/module_signature.c +0 -0
kernel/module/signing.c renamed from kernel/module_signing.c +1 -1
@@ -12,7 +12,7 @@#include <linux/string.h> #include <linux/verification.h> #include <crypto/public_key.h> -#include "module-internal.h" +#include "internal.h" /* * Verify the signature on a module.
Signature · 1 line
2.34.1
RFC PATCH v3 2/13 module: Simple refactor in preparation for split
In reply to Aaron TomlinNo functional change.
This patch makes it possible to move non-essential code out of core module code.
--- kernel/module/internal.h | 22 ++++++++++++++++++++++ kernel/module/main.c | 23 ++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-)
kernel/module/internal.h +22 -0
@@ -7,6 +7,28 @@#include <linux/elf.h> #include <asm/module.h> +#include <linux/mutex.h> + +#ifndef ARCH_SHF_SMALL +#define ARCH_SHF_SMALL 0 +#endif + +/* If this is set, the section belongs in the init part of the module */ +#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) +/* Maximum number of characters written by module_flags() */ +#define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4) +#define MODULE_SECT_READ_SIZE (3 /* "0x", "\n" */ + (BITS_PER_LONG / 4)) + +extern struct mutex module_mutex; +extern struct list_head modules; + +/* Provided by the linker */ +extern const struct kernel_symbol __start___ksymtab[]; +extern const struct kernel_symbol __stop___ksymtab[]; +extern const struct kernel_symbol __start___ksymtab_gpl[]; +extern const struct kernel_symbol __stop___ksymtab_gpl[]; +extern const s32 __start___kcrctab[]; +extern const s32 __start___kcrctab_gpl[];struct load_info {const char *name;
kernel/module/main.c +2 -21
@@ -63,10 +63,6 @@#define CREATE_TRACE_POINTS #include <trace/events/module.h> -#ifndef ARCH_SHF_SMALL -#define ARCH_SHF_SMALL 0 -#endif -/* * Modules' sections will be aligned on page boundaries * to ensure complete separation of code and data, but
@@ -78,9 +74,6 @@# define debug_align (X ) (X)#endif -/* If this is set, the section belongs in the init part of the module */ -#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) -/* * Mutex protects: * 1) List of modules (also safely readable with preempt_disable),
@@ -88,8 +81,8 @@* 3) module_addr_min/module_addr_max. * (delete and add uses RCU list operations). */ -static DEFINE_MUTEX (module_mutex); -static LIST_HEAD (modules); +DEFINE_MUTEX (module_mutex); +LIST_HEAD (modules);/* Work queue for freeing init sections in success case */ static void do_free_init (struct work_struct *w);
@@ -408,14 +401,6 @@ static __maybe_unused void *any_section_objs(const struct load_info *info,return (void *)info->sechdrs[sec].sh_addr; } -/* Provided by the linker */ -extern const struct kernel_symbol __start___ksymtab[]; -extern const struct kernel_symbol __stop___ksymtab[]; -extern const struct kernel_symbol __start___ksymtab_gpl[]; -extern const struct kernel_symbol __stop___ksymtab_gpl[]; -extern const s32 __start___kcrctab[]; -extern const s32 __start___kcrctab_gpl[]; -#ifndef CONFIG_MODVERSIONS #define symversion (base, idx) NULL#else
@@ -1490,7 +1475,6 @@ struct module_sect_attrs {struct module_sect_attr attrs[]; }; -#define MODULE_SECT_READ_SIZE (3 /* "0x", "\n" */ + (BITS_PER_LONG / 4))static ssize_t module_sect_read (struct file *file,struct kobject *kobj,struct bin_attribute *battr,char *buf,loff_t pos,size_t count)
@@ -4555,9 +4539,6 @@ static void cfi_cleanup(struct module *mod)#endif } -/* Maximum number of characters written by module_flags() */ -#define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4) -/* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */ static char *module_flags (struct module *mod,char *buf) {
Signature · 1 line
2.34.1
RFC PATCH v3 3/13 module: Move livepatch support to a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates livepatch support (i.e. used during module add/or load and remove/or deletion) from core module code into kernel/module/livepatch.c. At the moment it contains code to persist Elf information about a given livepatch module, only.
--- include/linux/module.h | 11 ++++ kernel/module/Makefile | 1 + kernel/module/internal.h | 10 ++++ kernel/module/livepatch.c | 74 +++++++++++++++++++++++++++ kernel/module/main.c | 102 ++++---------------------------------- 5 files changed, 106 insertions(+), 92 deletions(-) create mode 100644 kernel/module/livepatch.c
include/linux/module.h +11 -0
@@ -668,11 +668,22 @@ static inline bool is_livepatch_module(struct module *mod) {return mod->klp; } + +static inline bool set_livepatch_module (struct module *mod) +{ + mod->klp = true; +return true; +}#else /* !CONFIG_LIVEPATCH */ static inline bool is_livepatch_module (struct module *mod) {return false; } + +static inline bool set_livepatch_module (struct module *mod) +{ +return false; +}#endif /* CONFIG_LIVEPATCH */ bool is_module_sig_enforced (void );
kernel/module/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_MODULES) += main.o obj-$(CONFIG_MODULE_DECOMPRESS) += decompress.o obj-$(CONFIG_MODULE_SIG) += signing.o obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o +obj-$(CONFIG_LIVEPATCH) += livepatch.o
kernel/module/internal.h +10 -0
@@ -57,6 +57,16 @@ struct load_info {extern int mod_verify_sig (const void *mod,struct load_info *info); +#ifdef CONFIG_LIVEPATCH +extern int copy_module_elf (struct module *mod,struct load_info *info); +extern void free_module_elf (struct module *mod); +#else /* !CONFIG_LIVEPATCH */ +static inline int copy_module_elf (struct module *mod,struct load_info *info) +{ +return 0 ; +} +static inline void free_module_elf (struct module *mod) { } +#endif /* CONFIG_LIVEPATCH */ #ifdef CONFIG_MODULE_DECOMPRESS int module_decompress (struct load_info *info,const void *buf,size_t size);void module_decompress_cleanup (struct load_info *info);
kernel/module/livepatch.c new file +74 -0
74 lines not on this page · raw message
kernel/module/main.c +10 -92
121 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 4/13 module: Move latched RB-tree support to a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates module latched RB-tree support (e.g. see __module_address()) from core module code into kernel/module/tree_lookup.c.
--- include/linux/module.h | 37 +++++++++- kernel/module/Makefile | 1 + kernel/module/main.c | 134 ------------------------------------ kernel/module/tree_lookup.c | 108 +++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 136 deletions(-) create mode 100644 kernel/module/tree_lookup.c
include/linux/module.h +35 -2
@@ -340,11 +340,44 @@ struct module_layout { };#ifdef CONFIG_MODULES_TREE_LOOKUP +struct mod_tree_root { +struct latch_tree_root root; +unsigned long addr_min; +unsigned long addr_max; +} mod_tree __cacheline_aligned = { + .addr_min =-1UL , +}; + +#define module_addr_min mod_tree.addr_min +#define module_addr_max mod_tree.addr_max + +extern void mod_tree_insert (struct module *mod); +extern void mod_tree_remove_init (struct module *mod); +extern void mod_tree_remove (struct module *mod); +extern struct module *mod_find (unsigned long addr);/* Only touch one cacheline for common rbtree-for-core-layout case. */ #define __module_layout_align ____cacheline_aligned -#else +#else /* !CONFIG_MODULES_TREE_LOOKUP */ + +static unsigned long module_addr_min =-1UL , module_addr_max; + +static void mod_tree_insert (struct module *mod) { } +static void mod_tree_remove_init (struct module *mod) { } +static void mod_tree_remove (struct module *mod) { } +static struct module *mod_find (unsigned long addr) +{ +struct module *mod; + +list_for_each_entry_rcu (mod, &modules, list, +lockdep_is_held (&module_mutex)) { +if (within_module (addr, mod)) +return mod; + } + +return NULL ; +}#define __module_layout_align -#endif +#endif /* CONFIG_MODULES_TREE_LOOKUP */ struct mod_kallsyms {Elf_Sym *symtab;
kernel/module/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_MODULE_DECOMPRESS) += decompress.o obj-$(CONFIG_MODULE_SIG) += signing.o obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o obj-$(CONFIG_LIVEPATCH) += livepatch.o +obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o
kernel/module/main.c +0 -134
140 lines not on this page · raw message
kernel/module/tree_lookup.c new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 5/13 module: Move arch strict rwx support to a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates applicable architecture code that support strict module rwx from core module code into kernel/module/arch_strict_rwx.c
--- include/linux/module.h | 17 +++++++++++ kernel/module/Makefile | 1 + kernel/module/arch_strict_rwx.c | 44 ++++++++++++++++++++++++++++ kernel/module/main.c | 51 --------------------------------- 4 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 kernel/module/arch_strict_rwx.c
include/linux/module.h +17 -0
@@ -339,6 +339,23 @@ struct module_layout {#endif }; +/* +* Modules' sections will be aligned on page boundaries +* to ensure complete separation of code and data, but +* only when CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y +*/ +#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX +# define debug_align (X ) ALIGN(X, PAGE_SIZE) + +extern void frob_text (const struct module_layout *layout, +int (*set_memory)(unsigned long start,int num_pages)); +extern void module_enable_x (const struct module *mod); +#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ +# define debug_align (X ) (X) + +static void module_enable_x (const struct module *mod) { } +#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ + #ifdef CONFIG_MODULES_TREE_LOOKUP struct mod_tree_root { struct latch_tree_root root;
kernel/module/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_MODULE_SIG) += signing.o obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o +obj-$(CONFIG_ARCH_HAS_STRICT_MODULE_RWX) += arch_strict_rwx.o
kernel/module/arch_strict_rwx.c new file +44 -0
44 lines not on this page · raw message
kernel/module/main.c +0 -51
69 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 6/13 module: Move strict rwx support to a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates code that makes module text
and rodata memory read-only and non-text memory
non-executable from core module code intokernel/module/strict_rwx.c.
--- include/linux/module.h | 22 ++++++++++ kernel/module/Makefile | 1 + kernel/module/main.c | 84 -------------------------------------- kernel/module/strict_rwx.c | 83 +++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 84 deletions(-) create mode 100644 kernel/module/strict_rwx.c
include/linux/module.h +22 -0
@@ -356,6 +356,28 @@ extern void module_enable_x(const struct module *mod);static void module_enable_x (const struct module *mod) { }#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */ +#ifdef CONFIG_STRICT_MODULE_RWX +extern void frob_rodata (const struct module_layout *layout, +int (*set_memory)(unsigned long start,int num_pages)); +extern void frob_ro_after_init (const struct module_layout *layout, +int (*set_memory)(unsigned long start,int num_pages)); +extern void frob_writable_data (const struct module_layout *layout, +int (*set_memory)(unsigned long start,int num_pages)); +extern void module_enable_ro (const struct module *mod,bool after_init); +extern void module_enable_nx (const struct module *mod); +extern int module_enforce_rwx_sections (Elf_Ehdr *hdr,Elf_Shdr *sechdrs, +char *secstrings,struct module *mod); + +#else /* !CONFIG_STRICT_MODULE_RWX */ +static void module_enable_nx (const struct module *mod) { } +static void module_enable_ro (const struct module *mod,bool after_init) {} +static int module_enforce_rwx_sections (Elf_Ehdr *hdr,Elf_Shdr *sechdrs, +char *secstrings,struct module *mod) +{ +return 0 ; +} +#endif /* CONFIG_STRICT_MODULE_RWX */ + #ifdef CONFIG_MODULES_TREE_LOOKUP struct mod_tree_root { struct latch_tree_root root;
kernel/module/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o obj-$(CONFIG_ARCH_HAS_STRICT_MODULE_RWX) += arch_strict_rwx.o +obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o
kernel/module/main.c +0 -84
90 lines not on this page · raw message
kernel/module/strict_rwx.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 7/13 module: Move extra signature support out of core code
In reply to Aaron TomlinNo functional change.
This patch migrates additional module signature check code from core module code into kernel/module/signing.c.
--- include/linux/module.h | 5 ++- kernel/module/internal.h | 9 +++++ kernel/module/main.c | 87 ---------------------------------------- kernel/module/signing.c | 75 ++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 89 deletions(-)
include/linux/module.h +3 -2
@@ -758,8 +758,8 @@ static inline bool set_livepatch_module(struct module *mod) }#endif /* CONFIG_LIVEPATCH */ -bool is_module_sig_enforced (void ); -void set_module_sig_enforced (void ); +extern bool is_module_sig_enforced (void ); +extern void set_module_sig_enforced (void );#else /* !CONFIG_MODULES... */
@@ -949,6 +949,7 @@ static inline bool module_sig_ok(struct module *module) {return true; } +#define sig_enforce false#endif /* CONFIG_MODULE_SIG */ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
kernel/module/internal.h +9 -0
@@ -80,3 +80,12 @@ static inline void module_decompress_cleanup(struct load_info *info) { }#endif + +#ifdef CONFIG_MODULE_SIG +extern int module_sig_check (struct load_info *info,int flags); +#else /* !CONFIG_MODULE_SIG */ +static int module_sig_check (struct load_info *info,int flags) +{ +return 0 ; +} +#endif /* !CONFIG_MODULE_SIG */
kernel/module/main.c +0 -87
105 lines not on this page · raw message
kernel/module/signing.c +75 -0
87 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 8/13 module: Move kmemleak support to a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates kmemleak code out of core module code into kernel/module/debug_kmemleak.c
--- kernel/module/Makefile | 1 + kernel/module/debug_kmemleak.c | 30 ++++++++++++++++++++++++++++++ kernel/module/internal.h | 8 ++++++++ kernel/module/main.c | 27 --------------------------- 4 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 kernel/module/debug_kmemleak.c
kernel/module/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o obj-$(CONFIG_ARCH_HAS_STRICT_MODULE_RWX) += arch_strict_rwx.o obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o +obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
kernel/module/debug_kmemleak.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Module kmemleak support +* +* Copyright (C) 2009 Catalin Marinas +*/ + +#include <linux/module.h> +#include <linux/kmemleak.h> +#include "internal.h" + +void kmemleak_load_module (const struct module *mod, +const struct load_info *info) +{ +unsigned int i; + +/* only scan the sections containing data */ +kmemleak_scan_area (mod,sizeof (struct module ),GFP_KERNEL ); + +for (i =1 ; i < info->hdr->e_shnum; i++) { +/* Scan all writable sections that's not executable */ +if (!(info->sechdrs[i].sh_flags &SHF_ALLOC ) || + !(info->sechdrs[i].sh_flags &SHF_WRITE ) || + (info->sechdrs[i].sh_flags &SHF_EXECINSTR )) +continue ; + +kmemleak_scan_area ((void *)info->sechdrs[i].sh_addr, + info->sechdrs[i].sh_size,GFP_KERNEL ); + } +}
kernel/module/internal.h +8 -0
@@ -6,6 +6,7 @@*/ #include <linux/elf.h> +#include <linux/compiler.h> #include <asm/module.h> #include <linux/mutex.h>
@@ -89,3 +90,10 @@ static int module_sig_check(struct load_info *info, int flags) return 0; }#endif /* !CONFIG_MODULE_SIG */ + +#ifdef CONFIG_DEBUG_KMEMLEAK +extern void kmemleak_load_module (const struct module *mod,const struct load_info *info); +#else /* !CONFIG_DEBUG_KMEMLEAK */ +static inline void __maybe_unused kmemleak_load_module (const struct module *mod, +const struct load_info *info) { } +#endif /* CONFIG_DEBUG_KMEMLEAK */
kernel/module/main.c +0 -27
@@ -2466,33 +2466,6 @@ bool __weak module_exit_section(const char *name)return strstarts (name,".exit" ); } -#ifdef CONFIG_DEBUG_KMEMLEAK -static void kmemleak_load_module (const struct module *mod, -const struct load_info *info) -{ -unsigned int i; - -/* only scan the sections containing data */ -kmemleak_scan_area (mod,sizeof (struct module ),GFP_KERNEL ); - -for (i =1 ; i < info->hdr->e_shnum; i++) { -/* Scan all writable sections that's not executable */ -if (!(info->sechdrs[i].sh_flags &SHF_ALLOC ) || - !(info->sechdrs[i].sh_flags &SHF_WRITE ) || - (info->sechdrs[i].sh_flags &SHF_EXECINSTR )) -continue ; - -kmemleak_scan_area ((void *)info->sechdrs[i].sh_addr, - info->sechdrs[i].sh_size,GFP_KERNEL ); - } -} -#else -static inline void kmemleak_load_module (const struct module *mod, -const struct load_info *info) -{ -} -#endif -static int validate_section_offset (struct load_info *info,Elf_Shdr *shdr) {#if defined(CONFIG_64BIT )
Signature · 1 line
2.34.1
RFC PATCH v3 9/13 module: Move kallsyms support into a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates kallsyms code out of core module code kernel/module/kallsyms.c
--- kernel/module/Makefile | 1 + kernel/module/internal.h | 27 ++ kernel/module/kallsyms.c | 502 +++++++++++++++++++++++++++++++++++++ kernel/module/main.c | 516 +-------------------------------------- 4 files changed, 534 insertions(+), 512 deletions(-) create mode 100644 kernel/module/kallsyms.c
kernel/module/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o obj-$(CONFIG_ARCH_HAS_STRICT_MODULE_RWX) += arch_strict_rwx.o obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o +obj-$(CONFIG_KALLSYMS) += kallsyms.o
kernel/module/internal.h +27 -0
@@ -57,6 +57,11 @@ struct load_info { };extern int mod_verify_sig (const void *mod,struct load_info *info); +extern struct module *find_module_all (const char *name,size_t len,bool even_unformed); +extern unsigned long kernel_symbol_value (const struct kernel_symbol *sym); +extern int cmp_name (const void *name,const void *sym); +extern long get_offset (struct module *mod,unsigned int *size,Elf_Shdr *sechdr, +unsigned int section);#ifdef CONFIG_LIVEPATCH extern int copy_module_elf (struct module *mod,struct load_info *info);
@@ -97,3 +102,25 @@ extern void kmemleak_load_module(const struct module *mod, const struct load_infstatic inline void __maybe_unused kmemleak_load_module (const struct module *mod,const struct load_info *info) { }#endif /* CONFIG_DEBUG_KMEMLEAK */ + +#ifdef CONFIG_KALLSYMS +#ifdef CONFIG_STACKTRACE_BUILD_ID +extern void init_build_id (struct module *mod,const struct load_info *info); +#else /* !CONFIG_STACKTRACE_BUILD_ID */ +static inline void init_build_id (struct module *mod,const struct load_info *info) { } + +#endif +extern void layout_symtab (struct module *mod,struct load_info *info); +extern void add_kallsyms (struct module *mod,const struct load_info *info); +extern bool sect_empty (const Elf_Shdr *sect); +extern const char *find_kallsyms_symbol (struct module *mod,unsigned long addr, +unsigned long *size,unsigned long *offset); +#else /* !CONFIG_KALLSYMS */ +static inline void layout_symtab (struct module *mod,struct load_info *info) { } +static inline void add_kallsyms (struct module *mod,const struct load_info *info) { } +static inline char *find_kallsyms_symbol (struct module *mod,unsigned long addr, +unsigned long *size,unsigned long *offset) +{ +return NULL ; +} +#endif /* CONFIG_KALLSYMS */
kernel/module/kallsyms.c new file +502 -0
502 lines not on this page · raw message
kernel/module/main.c +4 -512
558 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 10/13 module: Move procfs support into a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates code that allows one to generate a list of loaded/or linked modules via /proc when procfs support is enabled into kernel/module/procfs.c.
--- kernel/module/Makefile | 1 + kernel/module/internal.h | 1 + kernel/module/main.c | 131 +----------------------------------- kernel/module/procfs.c | 142 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 130 deletions(-) create mode 100644 kernel/module/procfs.c
kernel/module/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_ARCH_HAS_STRICT_MODULE_RWX) += arch_strict_rwx.o obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o obj-$(CONFIG_KALLSYMS) += kallsyms.o +obj-$(CONFIG_PROC_FS) += procfs.o
kernel/module/internal.h +1 -0
@@ -62,6 +62,7 @@ extern unsigned long kernel_symbol_value(const struct kernel_symbol *sym);extern int cmp_name (const void *name,const void *sym);extern long get_offset (struct module *mod,unsigned int *size,Elf_Shdr *sechdr,unsigned int section); +extern char *module_flags (struct module *mod,char *buf);#ifdef CONFIG_LIVEPATCH extern int copy_module_elf (struct module *mod,struct load_info *info);
kernel/module/main.c +1 -130
161 lines not on this page · raw message
kernel/module/procfs.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 12/13 module: Move kdb_modules list out of core code
In reply to Aaron TomlinNo functional change.
This patch migrates kdb_modules list to core kdb code since the list of added/or loaded modules is no longer private.
--- kernel/debug/kdb/kdb_main.c | 5 +++++ kernel/module/main.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-)
kernel/debug/kdb/kdb_main.c +5 -0
@@ -59,6 +59,11 @@ EXPORT_SYMBOL(kdb_grepping_flag);int kdb_grep_leading;int kdb_grep_trailing; +#ifdef CONFIG_MODULES +extern struct list_head modules; +struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ +#endif /* CONFIG_MODULES */ +/* * Kernel debugger state flags */
kernel/module/main.c +0 -4
@@ -95,10 +95,6 @@ static void mod_update_bounds(struct module *mod)__mod_update_bounds (mod->init_layout.base, mod->init_layout.size); } -#ifdef CONFIG_KGDB_KDB -struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ -#endif /* CONFIG_KGDB_KDB */ -static void module_assert_mutex_or_preempt (void ) {#ifdef CONFIG_LOCKDEP
Signature · 1 line
2.34.1
RFC PATCH v3 11/13 module: Move sysfs support into a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates module sysfs support out of core code into kernel/module/sysfs.c. In addition simple code refactoring to make this possible.
--- kernel/module/Makefile | 1 + kernel/module/internal.h | 24 ++ kernel/module/main.c | 458 +-------------------------------------- kernel/module/sysfs.c | 425 ++++++++++++++++++++++++++++++++++++ 4 files changed, 453 insertions(+), 455 deletions(-) create mode 100644 kernel/module/sysfs.c
kernel/module/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-$(CONFIG_PROC_FS) += procfs.o +obj-$(CONFIG_SYSFS) += sysfs.o
kernel/module/internal.h +24 -0
@@ -23,6 +23,9 @@extern struct mutex module_mutex;extern struct list_head modules; +extern struct module_attribute *modinfo_attrs[]; +extern size_t modinfo_attrs_count; +/* Provided by the linker */ extern const struct kernel_symbol __start___ksymtab[];extern const struct kernel_symbol __stop___ksymtab[];
@@ -125,3 +128,24 @@ static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr,return NULL ; }#endif /* CONFIG_KALLSYMS */ + +#ifdef CONFIG_SYSFS +extern int mod_sysfs_setup (struct module *mod,const struct load_info *info, +struct kernel_param *kparam,unsigned int num_params); +extern void mod_sysfs_fini (struct module *mod); +extern void module_remove_modinfo_attrs (struct module *mod,int end); +extern void del_usage_links (struct module *mod); +extern void init_param_lock (struct module *mod); +#else /* !CONFIG_SYSFS */ +static int mod_sysfs_setup (struct module *mod, +const struct load_info *info, +struct kernel_param *kparam, +unsigned int num_params) +{ +return 0 ; +} +static inline void mod_sysfs_fini (struct module *mod) { } +static inline void module_remove_modinfo_attrs (struct module *mod,int end) { } +static inline void del_usage_links (struct module *mod) { } +static inline void init_param_lock (struct module *mod) { } +#endif /* CONFIG_SYSFS */
kernel/module/main.c +3 -455
483 lines not on this page · raw message
kernel/module/sysfs.c new file +425 -0
425 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 13/13 module: Move version support into a separate file
In reply to Aaron TomlinNo functional change.
This patch migrates module version support out of core code into kernel/module/version.c. In addition simple code refactoring to make this possible.
--- kernel/module/Makefile | 1 + kernel/module/internal.h | 51 +++++++++++++ kernel/module/main.c | 150 +-------------------------------------- kernel/module/version.c | 110 ++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 148 deletions(-) create mode 100644 kernel/module/version.c
kernel/module/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-$(CONFIG_PROC_FS) += procfs.o obj-$(CONFIG_SYSFS) += sysfs.o +obj-$(CONFIG_MODVERSIONS) += version.o
kernel/module/internal.h +51 -0
61 lines not on this page · raw message
kernel/module/main.c +2 -148
177 lines not on this page · raw message
kernel/module/version.c new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [RFC PATCH v3 04/13] module: Move latched RB-tree support to a separate file
In reply to Aaron Tomlinreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross #…
Hi Aaron,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on a97ac8cb24a3c3ad74794adb83717ef1605d1b47]
url: https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-core-code-clean-up/20220129-044218 base: a97ac8cb24a3c3ad74794adb83717ef1605d1b47 config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20220129/202201290517.OgZ0MwIs-lkp(a)intel.com/config) compiler: mips-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/3d841e1ce526183860c90d80129f849cf5234b1d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-core-code-clean-up/20220129-044218
git checkout 3d841e1ce526183860c90d80129f849cf5234b1d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash kernel/module/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/module/tree_lookup.c:63:15: warning: no previous prototype for '__mod_tree_insert' [-Wmissing-prototypes]
63 | noinline void __mod_tree_insert(struct mod_tree_node *node)
| ^~~~~~~~~~~~~~~~~
>> kernel/module/tree_lookup.c:68:6: warning: no previous prototype for '__mod_tree_remove' [-Wmissing-prototypes] 68 | void __mod_tree_remove(struct mod_tree_node *node)
| ^~~~~~~~~~~~~~~~~
vim +/__mod_tree_insert +63 kernel/module/tree_lookup.c
62
> 63 noinline void __mod_tree_insert(struct mod_tree_node *node)
64 {
65 latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops);
66 }
67
> 68 void __mod_tree_remove(struct mod_tree_node *node)
69 {
70 latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops);
71 }
72 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Hello.
Quoted 15 lines · On pátek 28. ledna 2022 21:39:21 CET Aaron Tomlin wrote:
Hi Luis,
[Note: Cc'd live-patching for feedback on livepatch specific changes]
Firstly, apologies for the delay.
As per your suggestion [1], this is an attempt to refactor and split optional code out of core module support code into separate components. This version is based on branch mcgrof/modules-next since a97ac8cb24a3/or modules-5.17-rc1. Please let me know your thoughts.
Changes since v1 [2]:
- Moved module version support code into a new file
Quoted 8 lines
Changes since v2 [3]:
- Move module decompress support to a separate file
- Makecheck_modinfo_livepatch()generic (Petr Mladek)
- Remove filename from each newly created file (Luis Chamberlain)
- Addressed some (i.e. --ignore=ASSIGN_IN_IF,AVOID_BUG was used) minorscripts/checkpatch.plconcerns e.g., use strscpy over strlcpy and missing a blank line after declarations (Allen)
Thanks for your submission.
Aaron, could you please also include stats from ./scripts/bloat-o-meter to compare vmlinux sections size before and after your modifications?
Quoted 63 lines
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/Aaron Tomlin (13):
module: Move all into module/
module: Simple refactor in preparation for split
module: Move livepatch support to a separate file
module: Move latched RB-tree support to a separate file
module: Move arch strict rwx support to a separate file
module: Move strict rwx support to a separate file
module: Move extra signature support out of core code
module: Move kmemleak support to a separate file
module: Move kallsyms support into a separate file
module: Move procfs support into a separate file
module: Move sysfs support into a separate file
module: Movekdb_moduleslist out of core code
module: Move version support into a separate fileMAINTAINERS | 2 +- include/linux/module.h | 92 +- kernel/Makefile | 5 +- kernel/debug/kdb/kdb_main.c | 5 + kernel/module-internal.h | 50 - kernel/module/Makefile | 18 + kernel/module/arch_strict_rwx.c | 44 + kernel/module/debug_kmemleak.c | 30 + .../decompress.c} | 2 +- kernel/module/internal.h | 202 ++ kernel/module/kallsyms.c | 502 +++++ kernel/module/livepatch.c | 74 + kernel/{module.c => module/main.c} | 1879 +---------------- kernel/module/procfs.c | 142 ++ .../signature.c} | 0 kernel/module/signing.c | 120 ++ kernel/module/strict_rwx.c | 83 + kernel/module/sysfs.c | 425 ++++ kernel/module/tree_lookup.c | 108 + kernel/module/version.c | 110 + kernel/module_signing.c | 45 - 21 files changed, 2032 insertions(+), 1906 deletions(-) delete mode 100644 kernel/module-internal.h create mode 100644 kernel/module/Makefile create mode 100644 kernel/module/arch_strict_rwx.c create mode 100644 kernel/module/debug_kmemleak.c rename kernel/{module_decompress.c => module/decompress.c} (99%) create mode 100644 kernel/module/internal.h create mode 100644 kernel/module/kallsyms.c create mode 100644 kernel/module/livepatch.c rename kernel/{module.c => module/main.c} (63%) create mode 100644 kernel/module/procfs.c rename kernel/{module_signature.c => module/signature.c} (100%) create mode 100644 kernel/module/signing.c create mode 100644 kernel/module/strict_rwx.c create mode 100644 kernel/module/sysfs.c create mode 100644 kernel/module/tree_lookup.c create mode 100644 kernel/module/version.c delete mode 100644 kernel/module_signing.cbase-commit:
a97ac8cb24a3c3ad74794adb83717ef1605d1b47
Signature · 1 line
Oleksandr Natalenko (post-factum)
kernel test robot
build botRe: [RFC PATCH v3 13/13] module: Move version support into a separate file
In reply to Aaron Tomlinreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross #…
Hi Aaron,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on a97ac8cb24a3c3ad74794adb83717ef1605d1b47]
url: https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-core-code-clean-up/20220129-044218 base: a97ac8cb24a3c3ad74794adb83717ef1605d1b47 config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20220129/202201290622.wUZhhlyA-lkp(a)intel.com/config) compiler: mips-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/201551e21d44a3860e99b3cf3371d3e4823d9eb1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-core-code-clean-up/20220129-044218 git checkout 201551e21d44a3860e99b3cf3371d3e4823d9eb1
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash kernel/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/module/version.c:17:6: warning: no previous prototype for 'module_layout' [-Wmissing-prototypes]
17 | void module_layout(struct module *mod,
| ^~~~~~~~~~~~~
In file included from kernel/module/version.c:8:
include/linux/module.h:374:12: warning: 'module_enforce_rwx_sections' defined but not used [-Wunused-function]
374 | static int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/module.h:373:13: warning: 'module_enable_ro' defined but not used [-Wunused-function]
373 | static void module_enable_ro(const struct module *mod, bool after_init) {}
| ^~~~~~~~~~~~~~~~
include/linux/module.h:372:13: warning: 'module_enable_nx' defined but not used [-Wunused-function]
372 | static void module_enable_nx(const struct module *mod) { }
| ^~~~~~~~~~~~~~~~
include/linux/module.h:356:13: warning: 'module_enable_x' defined but not used [-Wunused-function]
356 | static void module_enable_x(const struct module *mod) { }
| ^~~~~~~~~~~~~~~vim +/module_layout +17 kernel/module/version.c
12
13 /*
14 * Generate the signature for all relevant module structures here.
15 * If these change, we don't want to try to parse the module.
16 */
> 17 void module_layout(struct module *mod,
18 struct modversion_info *ver,
19 struct kernel_param *kp,
20 struct kernel_symbol *ks,
21 struct tracepoint * const *tp)
22 {
23 }
24 EXPORT_SYMBOL(module_layout);
25 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC PATCH v3 09/13] module: Move kallsyms support into a separate file
In reply to Aaron Tomlinreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross #…
Hi Aaron,
[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on a97ac8cb24a3c3ad74794adb83717ef1605d1b47]
url: https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-core-code-clean-up/20220129-044218 base: a97ac8cb24a3c3ad74794adb83717ef1605d1b47 config: nds32-allnoconfig (https://download.01.org/0day-ci/archive/20220129/202201290605.RGByo8yC-lkp(a)intel.com/config) compiler: nds32le-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/fd6ae2d3fa439baa614e32c58b4c2f0dd0faa186
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-core-code-clean-up/20220129-044218
git checkout fd6ae2d3fa439baa614e32c58b4c2f0dd0faa186
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nds32 SHELL=/bin/bash kernel/module/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
kernel/module/kallsyms.c: In function 'is_exported':
>> kernel/module/kallsyms.c:31:54: error: invalid use of undefined type 'const struct module'
31 | ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
| ^~
kernel/module/kallsyms.c:31:65: error: invalid use of undefined type 'const struct module'
31 | ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
| ^~
kernel/module/kallsyms.c:31:77: error: invalid use of undefined type 'const struct module'
31 | ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
| ^~
kernel/module/kallsyms.c: In function 'layout_symtab':
>> kernel/module/kallsyms.c:119:51: error: invalid use of undefined type 'struct module'
119 | symsect->sh_entsize = get_offset(mod, &mod->init_layout.size, symsect,
| ^~
>> kernel/module/kallsyms.c:128:31: error: implicit declaration of function 'is_livepatch_module' [-Werror=implicit-function-declaration]
128 | if (i == 0 || is_livepatch_module(mod) ||
| ^~~~~~~~~~~~~~~~~~~
In file included from include/vdso/const.h:5,
from include/linux/const.h:4,
from include/linux/list.h:9,
from include/linux/module.h:12,
from kernel/module/kallsyms.c:8:
kernel/module/kallsyms.c:137:34: error: invalid use of undefined type 'struct module'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~
include/uapi/linux/const.h:32:44: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:137:25: note: in expansion of macro 'ALIGN'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~~~~
kernel/module/kallsyms.c:137:34: error: invalid use of undefined type 'struct module'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~
include/uapi/linux/const.h:32:50: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:137:25: note: in expansion of macro 'ALIGN'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~~~~
kernel/module/kallsyms.c:137:34: error: invalid use of undefined type 'struct module'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~
include/uapi/linux/const.h:32:61: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:137:25: note: in expansion of macro 'ALIGN'
137 | info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
| ^~~~~
kernel/module/kallsyms.c:138:28: error: invalid use of undefined type 'struct module'
138 | info->stroffs = mod->core_layout.size = info->symoffs + ndst * sizeof(Elf_Sym);
| ^~
kernel/module/kallsyms.c:139:12: error: invalid use of undefined type 'struct module'
139 | mod->core_layout.size += strtab_size;
| ^~
kernel/module/kallsyms.c:140:34: error: invalid use of undefined type 'struct module'
140 | info->core_typeoffs = mod->core_layout.size;
| ^~
kernel/module/kallsyms.c:141:12: error: invalid use of undefined type 'struct module'
141 | mod->core_layout.size += ndst * sizeof(char);
| ^~
kernel/module/kallsyms.c:142:12: error: invalid use of undefined type 'struct module'
142 | mod->core_layout.size = debug_align(mod->core_layout.size);
| ^~
>> kernel/module/kallsyms.c:142:33: error: implicit declaration of function 'debug_align' [-Werror=implicit-function-declaration]
142 | mod->core_layout.size = debug_align(mod->core_layout.size);
| ^~~~~~~~~~~
kernel/module/kallsyms.c:142:48: error: invalid use of undefined type 'struct module'
142 | mod->core_layout.size = debug_align(mod->core_layout.size);
| ^~
kernel/module/kallsyms.c:146:51: error: invalid use of undefined type 'struct module'
146 | strsect->sh_entsize = get_offset(mod, &mod->init_layout.size, strsect,
| ^~
kernel/module/kallsyms.c:151:12: error: invalid use of undefined type 'struct module'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~
In file included from include/vdso/const.h:5,
from include/linux/const.h:4,
from include/linux/list.h:9,
from include/linux/module.h:12,
from kernel/module/kallsyms.c:8:
kernel/module/kallsyms.c:151:42: error: invalid use of undefined type 'struct module'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~
include/uapi/linux/const.h:32:44: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:151:33: note: in expansion of macro 'ALIGN'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~~~~
kernel/module/kallsyms.c:151:42: error: invalid use of undefined type 'struct module'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~
include/uapi/linux/const.h:32:50: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:151:33: note: in expansion of macro 'ALIGN'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~~~~
>> kernel/module/kallsyms.c:152:51: error: invalid application of '__alignof__' to incomplete type 'struct mod_kallsyms'
152 | __alignof__(struct mod_kallsyms));
| ^~~~~~
include/uapi/linux/const.h:32:50: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:151:33: note: in expansion of macro 'ALIGN'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~~~~
kernel/module/kallsyms.c:151:42: error: invalid use of undefined type 'struct module'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~
include/uapi/linux/const.h:32:61: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:151:33: note: in expansion of macro 'ALIGN'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~~~~
>> kernel/module/kallsyms.c:152:51: error: invalid application of '__alignof__' to incomplete type 'struct mod_kallsyms'
152 | __alignof__(struct mod_kallsyms));
| ^~~~~~
include/uapi/linux/const.h:32:61: note: in definition of macro '__ALIGN_KERNEL_MASK'
32 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
| ^~~~
include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
8 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
| ^~~~~~~~~~~~~~
kernel/module/kallsyms.c:151:33: note: in expansion of macro 'ALIGN'
151 | mod->init_layout.size = ALIGN(mod->init_layout.size,
| ^~~~~
kernel/module/kallsyms.c:153:42: error: invalid use of undefined type 'struct module'
153 | info->mod_kallsyms_init_off = mod->init_layout.size;
| ^~
kernel/module/kallsyms.c:154:12: error: invalid use of undefined type 'struct module'
154 | mod->init_layout.size += sizeof(struct mod_kallsyms);
| ^~
>> kernel/module/kallsyms.c:154:41: error: invalid application of 'sizeof' to incomplete type 'struct mod_kallsyms'
154 | mod->init_layout.size += sizeof(struct mod_kallsyms);
| ^~~~~~
kernel/module/kallsyms.c:155:34: error: invalid use of undefined type 'struct module'
155 | info->init_typeoffs = mod->init_layout.size;
| ^~
kernel/module/kallsyms.c:156:12: error: invalid use of undefined type 'struct module'
156 | mod->init_layout.size += nsrc * sizeof(char);
| ^~
kernel/module/kallsyms.c:157:12: error: invalid use of undefined type 'struct module'
157 | mod->init_layout.size = debug_align(mod->init_layout.size);
| ^~
kernel/module/kallsyms.c:157:48: error: invalid use of undefined type 'struct module'
157 | mod->init_layout.size = debug_align(mod->init_layout.size);
| ^~
kernel/module/kallsyms.c: In function 'add_kallsyms':
kernel/module/kallsyms.c:174:12: error: invalid use of undefined type 'struct module'
174 | mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off;
| ^~
kernel/module/kallsyms.c:174:28: error: invalid use of undefined type 'struct module'
174 | mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off;
| ^~
kernel/module/kallsyms.c:176:12: error: invalid use of undefined type 'struct module'
176 | mod->kallsyms->symtab = (void *)symsec->sh_addr;
| ^~
kernel/module/kallsyms.c:177:12: error: invalid use of undefined type 'struct module'
177 | mod->kallsyms->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
| ^~
kernel/module/kallsyms.c:179:12: error: invalid use of undefined type 'struct module'
179 | mod->kallsyms->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
| ^~
kernel/module/kallsyms.c:180:12: error: invalid use of undefined type 'struct module'
180 | mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
| ^~
kernel/module/kallsyms.c:180:37: error: invalid use of undefined type 'struct module'
180 | mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
| ^~
kernel/module/kallsyms.c:186:12: error: invalid use of undefined type 'struct module'
186 | mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
| ^~
kernel/module/kallsyms.c:186:46: error: invalid use of undefined type 'struct module'
186 | mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
| ^~
kernel/module/kallsyms.c:187:12: error: invalid use of undefined type 'struct module'
187 | mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
| ^~
kernel/module/kallsyms.c:187:44: error: invalid use of undefined type 'struct module'
187 | mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
| ^~
kernel/module/kallsyms.c:188:12: error: invalid use of undefined type 'struct module'
188 | mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
| ^~
kernel/module/kallsyms.c:188:41: error: invalid use of undefined type 'struct module'
188 | mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
| ^~
kernel/module/kallsyms.c:189:18: error: invalid use of undefined type 'struct module'
189 | src = mod->kallsyms->symtab;
| ^~
kernel/module/kallsyms.c:190:35: error: invalid use of undefined type 'struct module'
190 | for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) {
| ^~
kernel/module/kallsyms.c:191:20: error: invalid use of undefined type 'struct module'
191 | mod->kallsyms->typetab[i] = elf_type(src + i, info);
| ^~
kernel/module/kallsyms.c:195:28: error: invalid use of undefined type 'struct module'
195 | mod->core_kallsyms.typetab[ndst] =
| ^~
kernel/module/kallsyms.c:196:32: error: invalid use of undefined type 'struct module'
196 | mod->kallsyms->typetab[i];
| ^~
kernel/module/kallsyms.c:198:54: error: invalid use of undefined type 'struct module'
198 | dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
| ^~
kernel/module/kallsyms.c:199:45: error: invalid use of undefined type 'struct module'
199 | s += strscpy(s, &mod->kallsyms->strtab[src[i].st_name],
| ^~
kernel/module/kallsyms.c:203:12: error: invalid use of undefined type 'struct module'
203 | mod->core_kallsyms.num_symtab = ndst;
| ^~
kernel/module/kallsyms.c: At top level:
>> kernel/module/kallsyms.c:239:48: warning: 'struct mod_kallsyms' declared inside parameter list will not be visible outside of this definition or declaration
239 | static const char *kallsyms_symbol_name(struct mod_kallsyms *kallsyms, unsigned int symnum)
| ^~~~~~~~~~~~
kernel/module/kallsyms.c: In function 'kallsyms_symbol_name':
>> kernel/module/kallsyms.c:241:24: error: invalid use of undefined type 'struct mod_kallsyms'
241 | return kallsyms->strtab + kallsyms->symtab[symnum].st_name;
| ^~
kernel/module/kallsyms.c:241:43: error: invalid use of undefined type 'struct mod_kallsyms'
241 | return kallsyms->strtab + kallsyms->symtab[symnum].st_name;
| ^~
>> kernel/module/kallsyms.c:239:85: warning: parameter 'symnum' set but not used [-Wunused-but-set-parameter]
239 | static const char *kallsyms_symbol_name(struct mod_kallsyms *kallsyms, unsigned int symnum)
| ~~~~~~~~~~~~~^~~~~~
In file included from include/linux/rbtree.h:24,
from include/linux/mm_types.h:10,
from include/linux/buildid.h:5,
from include/linux/module.h:14,
from kernel/module/kallsyms.c:8:
kernel/module/kallsyms.c: In function 'find_kallsyms_symbol':
kernel/module/kallsyms.c:255:66: error: invalid use of undefined type 'struct module'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~
include/linux/rcupdate.h:391:17: note: in definition of macro '__rcu_dereference_check'
391 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
| ^
include/linux/rcupdate.h:619:34: note: in expansion of macro 'rcu_dereference_sched_check'
619 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:41: note: in expansion of macro 'rcu_dereference_sched'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:66: error: invalid use of undefined type 'struct module'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~
include/linux/rcupdate.h:391:38: note: in definition of macro '__rcu_dereference_check'
391 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
| ^
include/linux/rcupdate.h:619:34: note: in expansion of macro 'rcu_dereference_sched_check'
619 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:41: note: in expansion of macro 'rcu_dereference_sched'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from <command-line>:
kernel/module/kallsyms.c:255:66: error: invalid use of undefined type 'struct module'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~
include/linux/compiler_types.h:326:23: note: in definition of macro '__compiletime_assert'
326 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:346:9: note: in expansion of macro '_compiletime_assert'
346 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/rcupdate.h:391:50: note: in expansion of macro 'READ_ONCE'
391 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
| ^~~~~~~~~
include/linux/rcupdate.h:563:9: note: in expansion of macro '__rcu_dereference_check'
563 | __rcu_dereference_check((p), __UNIQUE_ID(rcu), \
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/rcupdate.h:619:34: note: in expansion of macro 'rcu_dereference_sched_check'
619 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:41: note: in expansion of macro 'rcu_dereference_sched'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:66: error: invalid use of undefined type 'struct module'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~
include/linux/compiler_types.h:326:23: note: in definition of macro '__compiletime_assert'
326 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:346:9: note: in expansion of macro '_compiletime_assert'
346 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/rcupdate.h:391:50: note: in expansion of macro 'READ_ONCE'
391 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
| ^~~~~~~~~
include/linux/rcupdate.h:563:9: note: in expansion of macro '__rcu_dereference_check'
563 | __rcu_dereference_check((p), __UNIQUE_ID(rcu), \
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/rcupdate.h:619:34: note: in expansion of macro 'rcu_dereference_sched_check'
619 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:41: note: in expansion of macro 'rcu_dereference_sched'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~~~~~~~~~~~~~~~~~~~~
kernel/module/kallsyms.c:255:66: error: invalid use of undefined type 'struct module'
255 | struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
| ^~
include/linux/compiler_types.h:326:23: note: in definition of macro '__compiletime_assert'
326 | if (!(condition)) \
| ^~~~~~~~~ include/linux/compiler_types.h:346:9: note: in expansion of macro '_compiletime_assert'
..
vim +31 kernel/module/kallsyms.c
22
23 static int is_exported(const char *name, unsigned long value,
24 const struct module *mod)
25 {
26 const struct kernel_symbol *ks;
27
28 if (!mod)
29 ks = lookup_exported_symbol(name, __start___ksymtab, __stop___ksymtab);
30 else
> 31 ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
32
33 return ks != NULL && kernel_symbol_value(ks) == value;
34 }
35
36 /* As per nm */
37 static char elf_type(const Elf_Sym *sym, const struct load_info *info)
38 {
39 const Elf_Shdr *sechdrs = info->sechdrs;
40
41 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
42 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
43 return 'v';
44 else
45 return 'w';
46 }
47 if (sym->st_shndx == SHN_UNDEF)
48 return 'U';
49 if (sym->st_shndx == SHN_ABS || sym->st_shndx == info->index.pcpu)
50 return 'a';
51 if (sym->st_shndx >= SHN_LORESERVE)
52 return '?';
53 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
54 return 't';
55 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
56 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
57 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
58 return 'r';
59 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
60 return 'g';
61 else
62 return 'd';
63 }
64 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
65 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
66 return 's';
67 else
68 return 'b';
69 }
70 if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name,
71 ".debug")) {
72 return 'n';
73 }
74 return '?';
75 }
76
77 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
78 unsigned int shnum, unsigned int pcpundx)
79 {
80 const Elf_Shdr *sec;
81
82 if (src->st_shndx == SHN_UNDEF
83 || src->st_shndx >= shnum
84 || !src->st_name)
85 return false;
86
87 #ifdef CONFIG_KALLSYMS_ALL
88 if (src->st_shndx == pcpundx)
89 return true;
90 #endif
91
92 sec = sechdrs + src->st_shndx;
93 if (!(sec->sh_flags & SHF_ALLOC)
94 #ifndef CONFIG_KALLSYMS_ALL
95 || !(sec->sh_flags & SHF_EXECINSTR)
96 #endif
97 || (sec->sh_entsize & INIT_OFFSET_MASK))
98 return false;
99
100 return true;
101 }
102
103 /*
104 * We only allocate and copy the strings needed by the parts of symtab
105 * we keep. This is simple, but has the effect of making multiple
106 * copies of duplicates. We could be more sophisticated, see
107 * linux-kernel thread starting with
108 * <73defb5e4bca04a6431392cc341112b1@localhost>.
109 */
110 void layout_symtab(struct module *mod, struct load_info *info)
111 {
112 Elf_Shdr *symsect = info->sechdrs + info->index.sym;
113 Elf_Shdr *strsect = info->sechdrs + info->index.str;
114 const Elf_Sym *src;
115 unsigned int i, nsrc, ndst, strtab_size = 0;
116
117 /* Put symbol section at end of init part of module. */
118 symsect->sh_flags |= SHF_ALLOC;
> 119 symsect->sh_entsize = get_offset(mod, &mod->init_layout.size, symsect,
120 info->index.sym) | INIT_OFFSET_MASK;
121 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
122
123 src = (void *)info->hdr + symsect->sh_offset;
124 nsrc = symsect->sh_size / sizeof(*src);
125
126 /* Compute total space required for the core symbols' strtab. */
127 for (ndst = i = 0; i < nsrc; i++) {
> 128 if (i == 0 || is_livepatch_module(mod) ||
129 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum,
130 info->index.pcpu)) {
131 strtab_size += strlen(&info->strtab[src[i].st_name])+1;
132 ndst++;
133 }
134 }
135
136 /* Append room for core symbols at end of core part. */
137 info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
138 info->stroffs = mod->core_layout.size = info->symoffs + ndst * sizeof(Elf_Sym);
139 mod->core_layout.size += strtab_size;
140 info->core_typeoffs = mod->core_layout.size;
141 mod->core_layout.size += ndst * sizeof(char);
> 142 mod->core_layout.size = debug_align(mod->core_layout.size);
143
144 /* Put string table section at end of init part of module. */
145 strsect->sh_flags |= SHF_ALLOC;
146 strsect->sh_entsize = get_offset(mod, &mod->init_layout.size, strsect,
147 info->index.str) | INIT_OFFSET_MASK;
148 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
149
150 /* We'll tack temporary mod_kallsyms on the end. */
151 mod->init_layout.size = ALIGN(mod->init_layout.size,
> 152 __alignof__(struct mod_kallsyms));
153 info->mod_kallsyms_init_off = mod->init_layout.size;
> 154 mod->init_layout.size += sizeof(struct mod_kallsyms); 155 info->init_typeoffs = mod->init_layout.size;
156 mod->init_layout.size += nsrc * sizeof(char);
157 mod->init_layout.size = debug_align(mod->init_layout.size);
158 }
159
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC PATCH v3 09/13] module: Move kallsyms support into a separate file
In reply to Aaron Tomlinreproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # apt-get install sparse # sparse version: v0.6.4-dirty #…
Hi Aaron,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on a97ac8cb24a3c3ad74794adb83717ef1605d1b47]
url: https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-core-code-clean-up/20220129-044218 base: a97ac8cb24a3c3ad74794adb83717ef1605d1b47 config: arc-randconfig-s032-20220124 (https://download.01.org/0day-ci/archive/20220129/202201291433.XLcEC5fB-lkp(a)intel.com/config) compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/fd6ae2d3fa439baa614e32c58b4c2f0dd0faa186
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-core-code-clean-up/20220129-044218
git checkout fd6ae2d3fa439baa614e32c58b4c2f0dd0faa186
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arc SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
kernel/module/kallsyms.c: note: in included file:
include/linux/module.h:386:3: sparse: sparse: symbol 'mod_tree' was not declared. Should it be static?
>> kernel/module/kallsyms.c:174:23: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct mod_kallsyms [noderef] __rcu *kallsyms @@ got void * @@ kernel/module/kallsyms.c:174:23: sparse: expected struct mod_kallsyms [noderef] __rcu *kallsyms kernel/module/kallsyms.c:174:23: sparse: got void * >> kernel/module/kallsyms.c:176:12: sparse: sparse: dereference of noderef expression
kernel/module/kallsyms.c:177:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:179:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:180:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:189:18: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:190:35: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:191:20: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:196:32: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:199:45: sparse: sparse: dereference of noderef expression
vim +174 kernel/module/kallsyms.c
159
160 /*
161 * We use the full symtab and strtab which layout_symtab arranged to
162 * be appended to the init section. Later we switch to the cut-down
163 * core-only ones.
164 */
165 void add_kallsyms(struct module *mod, const struct load_info *info)
166 {
167 unsigned int i, ndst;
168 const Elf_Sym *src;
169 Elf_Sym *dst;
170 char *s;
171 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
172
173 /* Set up to point into init section. */
> 174 mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off; 175 > 176 mod->kallsyms->symtab = (void *)symsec->sh_addr;
177 mod->kallsyms->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
178 /* Make sure we get permanent strtab: don't use info->strtab. */
179 mod->kallsyms->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
180 mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
181
182 /*
183 * Now populate the cut down core kallsyms for after init
184 * and set types up while we still have access to sections.
185 */
186 mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
187 mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
188 mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
189 src = mod->kallsyms->symtab;
190 for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) {
191 mod->kallsyms->typetab[i] = elf_type(src + i, info);
192 if (i == 0 || is_livepatch_module(mod) ||
193 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum,
194 info->index.pcpu)) {
195 mod->core_kallsyms.typetab[ndst] =
196 mod->kallsyms->typetab[i];
197 dst[ndst] = src[i];
198 dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
199 s += strscpy(s, &mod->kallsyms->strtab[src[i].st_name],
200 KSYM_NAME_LEN) + 1;
201 }
202 }
203 mod->core_kallsyms.num_symtab = ndst;
204 }
205
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [RFC PATCH v3 03/13] module: Move livepatch support to a separate file
In reply to Aaron TomlinQuoted 6 lines · Aaron Tomlin
No functional change.
This patch migrates livepatch support (i.e. used during module add/or load and remove/or deletion) from core module code into
kernel/module/livepatch.c. At the moment it contains code to persist Elf information about a given livepatch module, only.
[]
include/linux/module.h
Quoted 1 line
include/linux/module.h +0
-0
[]
Quoted 11 lines
include/linux/module.h +6
-0@@ -668,11 +668,22 @@ static inline bool is_livepatch_module(struct module *mod) {return mod->klp; } + +static inline bool set_livepatch_module (struct module *mod) +{ + mod->klp = true; +return true; +}#else /* !CONFIG_LIVEPATCH */
include/linux/module.h static inline bool is_livepatch_module(struct module *mod) · line 687
Quoted 10 lines
include/linux/module.h +5
-0static inline bool is_livepatch_module (struct module *mod) {return false; } + +static inline bool set_livepatch_module (struct module *mod) +{ +return false; +}#endif /* CONFIG_LIVEPATCH */
style trivia:
Generally, these static inlines can be written deduplicating the function declaration and using IS_ENABLED or #if inside the definition.
Something like:
static inline bool is_livepatch_module(struct module *mod)
{
if (IS_ENABLED(CONFIG_LIVEPATCH)) {
mod->klp = true;
return true;
}
return false;
}or
static inline bool is_livepatch_module(struct module *mod) {
#ifdef CONFIG_LIVEPATCH mod->klp = true; return true; #else return false;
#endif
}