Skip to contentSkip to conversation

module: core code clean up

RFC PATCH Superseded Aaron Tomlin 6 participants 25 messages Jan 6, 2022 – Jan 14, 2022

Subsystems (3)

v2 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v2 cover module: core code clean up

Hi Luis,

As per your suggestion [1], this is an attempt to refactor and split optional code out of core module support code into separate components. Unfortunately, nothing has been thoroughly tested yet. Please let me know your thoughts.

Changes since v1 [2]:

- Moved module version support code into a new file

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: 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

 include/linux/module.h                        |   76 +-
 kernel/Makefile                               |    4 +-
 kernel/debug/kdb/kdb_main.c                   |    5 +
 kernel/module-internal.h                      |   31 -
 kernel/module/Makefile                        |   17 +
 kernel/module/arch_strict_rwx.c               |   44 +
 kernel/module/debug_kmemleak.c                |   30 +
 kernel/module/internal.h                      |  169 ++
 kernel/module/kallsyms.c                      |  506 +++++
 kernel/module/livepatch.c                     |   75 +
 kernel/{module.c => module/main.c}            | 1872 +----------------
 kernel/module/procfs.c                        |  111 +
 .../signature.c}                              |    0
 kernel/module/signing.c                       |  120 ++
 kernel/module/strict_rwx.c                    |   83 +
 kernel/module/sysfs.c                         |  426 ++++
 kernel/module/tree_lookup.c                   |  108 +
 kernel/module/version.c                       |  113 +
 kernel/module_signing.c                       |   45 -
 19 files changed, 1968 insertions(+), 1867 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
 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.c
Signature · 1 line
2.31.1
#1 lore raw

RFC PATCH v2 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.

---
 kernel/Makefile                                   | 4 +---
 kernel/module/Makefile                            | 8 ++++++++
 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 +-
 6 files changed, 11 insertions(+), 5 deletions(-)
 create mode 100644 kernel/module/Makefile
 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%)
kernel/Makefile +1 -3
index 4df609be42d0..466477d4dafe 100644
@@ -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,9 +67,6 @@ ifneq ($(CONFIG_SMP),y)
 obj-y += up.o
 endif
 obj-$(CONFIG_UID16) += uid16.o
-obj-$(CONFIG_MODULES) += module.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 +8 -0
new file mode 100644
index 000000000000..a9cf6e822075
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for linux kernel module support
+#
+
+obj-$(CONFIG_MODULES) += main.o
+obj-$(CONFIG_MODULE_SIG) += signing.o
+obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o
kernel/module/internal.h renamed from kernel/module-internal.h +0 -0
similarity index 100%
rename from kernel/module-internal.h
rename to kernel/module/internal.h
kernel/module/main.c renamed from kernel/module.c +1 -1
similarity index 99%
rename from kernel/module.c
rename to kernel/module/main.c
index ed13917ea5f3..bc997c3e2c95 100644
@@ -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
similarity index 100%
rename from kernel/module_signature.c
rename to kernel/module/signature.c
kernel/module/signing.c renamed from kernel/module_signing.c +1 -1
similarity index 97%
rename from kernel/module_signing.c
rename to kernel/module/signing.c
index 8723ae70ea1f..8aeb6d2ee94b 100644
@@ -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.31.1
#2 lore raw

RFC PATCH v2 2/13 module: Simple refactor in preparation for split

In reply to Aaron Tomlin

No 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
index 33783abc377b..ffc50df010a7 100644
@@ -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
index bc997c3e2c95..2a6b859716c0 100644
@@ -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
@@ -1491,7 +1476,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)
@@ -4498,9 +4482,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.31.1
#3 lore raw

RFC PATCH v2 3/13 module: Move livepatch support to a separate file

In reply to 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.

---
 kernel/module/Makefile    |  1 +
 kernel/module/internal.h  | 12 ++++++
 kernel/module/livepatch.c | 75 +++++++++++++++++++++++++++++++++
 kernel/module/main.c      | 89 +--------------------------------------
 4 files changed, 89 insertions(+), 88 deletions(-)
 create mode 100644 kernel/module/livepatch.c
kernel/module/Makefile +1 -0
index a9cf6e822075..47d70bb18da3 100644
@@ -6,3 +6,4 @@
 obj-$(CONFIG_MODULES) += main.o
 obj-$(CONFIG_MODULE_SIG) += signing.o
 obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o
+obj-$(CONFIG_LIVEPATCH) += livepatch.o
kernel/module/internal.h +12 -0
index ffc50df010a7..91ef152aeffb 100644
@@ -51,3 +51,15 @@ 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);
+extern int check_modinfo_livepatch(struct module *mod, struct load_info *info);
+#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 */
kernel/module/livepatch.c new file +75 -0

75 lines not on this page · raw message

kernel/module/main.c +1 -88

101 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#4 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

Quoted 34 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.

---
 kernel/module/Makefile    |  1 +
 kernel/module/internal.h  | 12 ++++++
 kernel/module/livepatch.c | 75 +++++++++++++++++++++++++++++++++
 kernel/module/main.c      | 89 +--------------------------------------
 4 files changed, 89 insertions(+), 88 deletions(-)
 create mode 100644 kernel/module/livepatch.c
kernel/module/Makefile +1 -0
index a9cf6e822075..47d70bb18da3 100644
@@ -6,3 +6,4 @@
 obj-$(CONFIG_MODULES) += main.o
 obj-$(CONFIG_MODULE_SIG) += signing.o
 obj-$(CONFIG_MODULE_SIG_FORMAT) += signature.o
+obj-$(CONFIG_LIVEPATCH) += livepatch.o
kernel/module/internal.h +1 -0
index ffc50df010a7..91ef152aeffb 100644
@@ -51,3 +51,15 @@ struct load_info {
 };
 
 extern int mod_verify_sig(const void *mod, struct load_info *info);
+

kernel/module/internal.h struct load_info { · line 64

Quoted 10 lines
kernel/module/internal.h +10 -0
+#ifdef CONFIG_LIVEPATCH
+extern int copy_module_elf(struct module *mod, struct load_info *info);
+extern void free_module_elf(struct module *mod);
+extern int check_modinfo_livepatch(struct module *mod, struct load_info *info);
+#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) { }

It looks like there is no check_modinfo_livepatch() variant when CONFIG_LIPATCH is disabled.

Quoted 16 lines
kernel/module/internal.h +1 -0
+#endif /* CONFIG_LIVEPATCH */
kernel/module/main.c +0 -7
index 2a6b859716c0..9bcaf251e109 100644
@@ -3052,19 +2977,7 @@ static int copy_chunked_from_user(void *dst, const void __user *usrc, unsigned l
 	return 0;
 }
 
-#ifdef CONFIG_LIVEPATCH
-static int check_modinfo_livepatch(struct module *mod, struct load_info *info)
-{
-	if (get_modinfo(info, "livepatch")) {
-		mod->klp = true;
-		add_taint_module(mod, TAINT_LIVEPATCH, LOCKDEP_STILL_OK);
-		pr_notice_once("%s: tainting kernel with TAINT_LIVEPATCH\n",

kernel/module/main.c static int copy_chunked_from_user(void *dst, const void __user *usrc, unsigned l · line 2983

Quoted 10 lines
kernel/module/main.c +1 -6
-			       mod->name);
-	}
-
-	return 0;
-}
-#else /* !CONFIG_LIVEPATCH */
+#ifndef CONFIG_LIVEPATCH
 static int check_modinfo_livepatch(struct module *mod, struct load_info *info)
 {
 	if (get_modinfo(info, "livepatch")) {

But it exist here.

It would be better to have the two variants close each other. I mean to have it somewhere like:

#ifdef CONFIG_LIVEPATCH

variant A

#else

variant B

#endif

A solution would be to do it a similar way like in check_modinfo_retpoline(). Have a generic:

static int check_modinfo_livepatch(struct module *mod, struct load_info *info)

{
	if (!get_modinfo(info, "livepatch"))
		return 0;

	if (set_livepatch_module(mod)) {
		add_taint_module(mod, TAINT_LIVEPATCH, LOCKDEP_STILL_OK);
		pr_notice_once("%s: tainting kernel with TAINT_LIVEPATCH\n",
			       mod->name);
		return 0;
       }

       pr_err("%s: module is marked as livepatch module, but livepatch support is disabled",
	       mod->name);
       return -ENOEXEC;
}

, where set_livepatch_module(mod) might be defined inline similar way like is_livepatch_module():

#ifdef CONFIG_LIVEPATCH
static inline bool set_livepatch_module(struct module *mod)

{
	mod->klp = true;
	return true;
}
#else /* !CONFIG_LIVEPATCH */
static inline bool set_livepatch_module(struct module *mod)
{
	return false;
}

#endif /* CONFIG_LIVEPATCH */

Well, it might be matter of taste. Others might prefer another solution. Adding live-patching mailing list into Cc.

Anyway, if we do any code refactoring, we should do it in a separate preparatory patch.

Best Regards,
Petr

#5 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

Petr Mladek <[email protected]> wrote on Wed [2022-Jan-12 17:53:56 +0100]:

Quoted 13 lines

It would be better to have the two variants close each other. I mean to have it somewhere like:

#ifdef CONFIG_LIVEPATCH

variant A

#else

variant B

#endif

<snip>

Quoted 11 lines

#ifdef CONFIG_LIVEPATCH
static inline bool set_livepatch_module(struct module *mod)

{
	mod->klp = true;
	return true;
}
#else /* !CONFIG_LIVEPATCH */
static inline bool set_livepatch_module(struct module *mod)
{
	return false;
}
Quoted 5 lines

#endif /* CONFIG_LIVEPATCH */

Well, it might be matter of taste. Others might prefer another solution. Adding live-patching mailing list into Cc.

+1 -- this seems like a cleaner approach.

- David

#6 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

In reply to Petr Mladek
Quoted 5 lines · Petr Mladek

It would be better to have the two variants close each other. I mean to have it somewhere like:

#ifdef CONFIG_LIVEPATCH

Quoted 7 lines

variant A

#else

variant B

#endif

Petr,

I agree. I'll incorporate this approach into RFC PATCH v3.

Kind regards,

Signature · 1 line
Aaron Tomlin
#7 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

In reply to Aaron Tomlin

Thanks for doing this refactor. +1 to doing this, though Petr had some suggestions in another thread that I'll wait on before Acking.

Aaron Tomlin <[email protected]> wrote on Thu [2022-Jan-06 23:43:09 +0000]:

kernel/module/livepatch.c line 6

Quoted 12 lines
kernel/module/livepatch.c new file +6 -0
new file mode 100644
index 000000000000..e147f5418327
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * kernel/module/livepatch.c - module livepatch support
+ *
+ * Copyright (C) 2016 Jessica Yu <[email protected]>
+ */

Should the copyright year (and possibly author) be updated? Or just removed entirely?

- David

reviewer
#8 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

Quoted 2 lines · David Vernet

Thanks for doing this refactor. +1 to doing this, though Petr had some suggestions in another thread that I'll wait on before Acking.

No problem and yes, I will make the suggested modifications then add you on Cc.

Quoted 16 lines

Aaron Tomlin <[email protected]> wrote on Thu [2022-Jan-06 23:43:09 +0000]:

kernel/module/livepatch.c line 6

Quoted 12 lines
kernel/module/livepatch.c new file +6 -0
new file mode 100644
index 000000000000..e147f5418327
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * kernel/module/livepatch.c - module livepatch support
+ *
+ * Copyright (C) 2016 Jessica Yu <[email protected]>
+ */

Should the copyright year (and possibly author) be updated? Or just removed entirely?

Who should I specify? I'm not entirely sure. If I understand correctly, Jessica was the original author of the majority.

Kind regards,

Signature · 1 line
Aaron Tomlin
#9 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

Aaron Tomlin <[email protected]> wrote on Thu [2022-Jan-13 10:35:31 +0000]:

Quoted 2 lines

Who should I specify? I'm not entirely sure. If I understand correctly, Jessica was the original author of the majority.

Personally I would just remove the whole copyright as the SPDX identifier should be sufficient. I'll let Luis weigh in here as the Modules maintainer, though.

maintainer
#10 lore raw

Re: [RFC PATCH v2 03/13] module: Move livepatch support to a separate file

Quoted 7 lines · David Vernet

Aaron Tomlin <[email protected]> wrote on Thu [2022-Jan-13 10:35:31 +0000]:

Quoted 2 lines

Who should I specify? I'm not entirely sure. If I understand correctly, Jessica was the original author of the majority.

Personally I would just remove the whole copyright as the SPDX identifier should be sufficient. I'll let Luis weigh in here as the Modules maintainer, though.

Technically every contributor to the file has a copyright entry added, one does not need to add the name to the header, that's just common practice though. If someone goes through the work of at least adding the name of the main author, that a nice effort. Tons of files don't have authors listed, so I'd be fine with that too and it keeps things simple. What we should not do ever is remove the copyright notice so code which Rusty wrote should be maintained with the notice.

Luis

#11 lore raw

RFC PATCH v2 4/13 module: Move latched RB-tree support to a separate file

In reply to Aaron Tomlin

No 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
index 8a298d820dbc..8b4d254a84c0 100644
@@ -339,11 +339,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 = 0;
+
+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
index 47d70bb18da3..9d593362156d 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_MODULES) += main.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.31.1
#12 lore raw

RFC PATCH v2 5/13 module: Move arch strict rwx support to a separate file

In reply to Aaron Tomlin

No 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          | 16 +++++++++++
 kernel/module/Makefile          |  1 +
 kernel/module/arch_strict_rwx.c | 44 ++++++++++++++++++++++++++++
 kernel/module/main.c            | 51 ---------------------------------
 4 files changed, 61 insertions(+), 51 deletions(-)
 create mode 100644 kernel/module/arch_strict_rwx.c
include/linux/module.h +16 -0
index 8b4d254a84c0..caa7212cf754 100644
@@ -338,6 +338,22 @@ 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
index 9d593362156d..95fad95a0549 100644
@@ -8,3 +8,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.31.1
#13 lore raw

RFC PATCH v2 6/13 module: Move strict rwx support to a separate file

In reply to Aaron Tomlin

No 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 into
kernel/module/strict_rwx.c.

---
 include/linux/module.h     | 18 ++++++++
 kernel/module/Makefile     |  1 +
 kernel/module/main.c       | 84 --------------------------------------
 kernel/module/strict_rwx.c | 83 +++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 84 deletions(-)
 create mode 100644 kernel/module/strict_rwx.c
include/linux/module.h +18 -0
index caa7212cf754..218ac6768433 100644
@@ -354,6 +354,24 @@ 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
index 95fad95a0549..795fe10ac530 100644
@@ -9,3 +9,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.31.1
#14 lore raw

RFC PATCH v2 7/13 module: Move extra signature support out of core code

In reply to Aaron Tomlin

No 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     | 86 ----------------------------------------
 kernel/module/signing.c  | 75 +++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+), 88 deletions(-)
include/linux/module.h +3 -2
index 218ac6768433..3383912268af 100644
@@ -736,8 +736,8 @@ static inline bool is_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... */
 
@@ -927,6 +927,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
index 91ef152aeffb..b4db57bafcd3 100644
@@ -63,3 +63,12 @@ static inline int copy_module_elf(struct module *mod, struct load_info *info)
 }
 static inline void free_module_elf(struct module *mod) { }
 #endif /* CONFIG_LIVEPATCH */
+
+#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 -86

104 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.31.1
#15 lore raw

RFC PATCH v2 8/13 module: Move kmemleak support to a separate file

In reply to Aaron Tomlin

No 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       |  7 +++++++
 kernel/module/main.c           | 27 ---------------------------
 4 files changed, 38 insertions(+), 27 deletions(-)
 create mode 100644 kernel/module/debug_kmemleak.c
kernel/module/Makefile +1 -0
index 795fe10ac530..2e03da799833 100644
@@ -10,3 +10,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
new file mode 100644
index 000000000000..818c9d168aed
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * kernel/module/debug_kmemleak.c - 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 +7 -0
index b4db57bafcd3..31d767416f0c 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/elf.h>
+#include <linux/compiler.h>
 #include <asm/module.h>
 #include <linux/mutex.h>
 
@@ -72,3 +73,9 @@ 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
index 8f8a904d5ba7..672a977b1320 100644
@@ -2467,33 +2467,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)
 {
 	unsigned long secend;
Signature · 1 line
2.31.1
#16 lore raw

RFC PATCH v2 9/13 module: Move kallsyms support into a separate file

In reply to Aaron Tomlin

No functional change.

This patch migrates kallsyms code out of core module code kernel/module/kallsyms.c

---
 kernel/module/Makefile   |   1 +
 kernel/module/internal.h |  20 ++
 kernel/module/kallsyms.c | 506 ++++++++++++++++++++++++++++++++++++++
 kernel/module/main.c     | 516 +--------------------------------------
 4 files changed, 531 insertions(+), 512 deletions(-)
 create mode 100644 kernel/module/kallsyms.c
kernel/module/Makefile +1 -0
index 2e03da799833..23582011ab08 100644
@@ -11,3 +11,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 +20 -0
index 31d767416f0c..119d42c304a1 100644
@@ -79,3 +79,23 @@ extern void kmemleak_load_module(const struct module *mod, const struct load_inf
 #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 */
+
+#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 +506 -0

506 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.31.1
#17 lore raw

RFC PATCH v2 10/13 module: Move procfs support into a separate file

In reply to Aaron Tomlin

No 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/main.c   |  98 -------------------------------------
 kernel/module/procfs.c | 108 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 98 deletions(-)
 create mode 100644 kernel/module/procfs.c
kernel/module/Makefile +1 -0
index 23582011ab08..cba3e608b4ca 100644
@@ -12,3 +12,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/main.c +0 -98

110 lines not on this page · raw message

kernel/module/procfs.c new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.31.1
#18 lore raw

RFC PATCH v2 11/13 module: Move sysfs support into a separate file

In reply to Aaron Tomlin

No 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 |  20 ++
 kernel/module/main.c     | 462 +--------------------------------------
 kernel/module/procfs.c   |   3 +
 kernel/module/sysfs.c    | 426 ++++++++++++++++++++++++++++++++++++
 5 files changed, 455 insertions(+), 457 deletions(-)
 create mode 100644 kernel/module/sysfs.c
kernel/module/Makefile +1 -0
index cba3e608b4ca..917910302ac0 100644
@@ -13,3 +13,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 +20 -0
index 119d42c304a1..4d81eb1f58ef 100644
@@ -99,3 +99,23 @@ 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 +5 -457

499 lines not on this page · raw message

kernel/module/procfs.c +3 -0
index 98d898250475..365d5e52ac23 100644
@@ -12,6 +12,9 @@
 #include <linux/proc_fs.h>
 #include "internal.h"
 
+extern void print_unload_info(struct seq_file *m, struct module *mod);
+extern char *module_flags(struct module *mod, char *buf);
+
 /* Called by the /proc file system to return a list of modules. */
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
kernel/module/sysfs.c new file +426 -0

426 lines not on this page · raw message

Signature · 1 line
2.31.1
#19 lore raw

RFC PATCH v2 12/13 module: Move kdb_modules list out of core code

In reply to Aaron Tomlin

No 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
index d8ee5647b732..ef61fb65671a 100644
@@ -60,6 +60,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
index 354fb2697188..09012246907a 100644
@@ -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.31.1
#20 lore raw
In reply to Aaron Tomlin

Hi Aaron,

My apologies for not replying earlier.

Thank you so much for doing this. I had a very similar approach, to
move code out based on the
flags. I will am in the process of reviewing and testing the changes
you have posted.

Thanks.

Quoted 70 lines · Aaron Tomlin

Hi Luis,

As per your suggestion [1], this is an attempt to refactor and split optional code out of core module support code into separate components. Unfortunately, nothing has been thoroughly tested yet. Please let me know your thoughts.

Changes since v1 [2]:

- Moved module version support code into a new file

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: 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

 include/linux/module.h                        |   76 +-
 kernel/Makefile                               |    4 +-
 kernel/debug/kdb/kdb_main.c                   |    5 +
 kernel/module-internal.h                      |   31 -
 kernel/module/Makefile                        |   17 +
 kernel/module/arch_strict_rwx.c               |   44 +
 kernel/module/debug_kmemleak.c                |   30 +
 kernel/module/internal.h                      |  169 ++
 kernel/module/kallsyms.c                      |  506 +++++
 kernel/module/livepatch.c                     |   75 +
 kernel/{module.c => module/main.c}            | 1872 +----------------
 kernel/module/procfs.c                        |  111 +
 .../signature.c}                              |    0
 kernel/module/signing.c                       |  120 ++
 kernel/module/strict_rwx.c                    |   83 +
 kernel/module/sysfs.c                         |  426 ++++
 kernel/module/tree_lookup.c                   |  108 +
 kernel/module/version.c                       |  113 +
 kernel/module_signing.c                       |   45 -
 19 files changed, 1968 insertions(+), 1867 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
 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.c

--
2.31.1

Signature · 1 line
       - Allen
#21 lore raw

Hi Aaron,

Was the code compile tested?

Unfortunately, I could not apply the series cleanly on top of the
latest 5.17-rc1.
I did rebase the patches and fixed minor compile time failures as
well a few small checkpatch errors.
I have pushed the series to
https://github.com/allenpais/Linux/commits/refactor_module_v3
[The series now is based on
84bfcc0b6994 2022-01-11 Merge tag 'integrity-v5.17' of
git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity]

So far I could only manage to compile test the patches. Will test it
on BM(x86/arm) in a day or two.

Thanks,
- Allen

Quoted 87 lines · Allen

Hi Aaron,

My apologies for not replying earlier.

Thank you so much for doing this. I had a very similar approach, to
move code out based on the
flags. I will am in the process of reviewing and testing the changes
you have posted.

Thanks.

Quoted 67 lines · Aaron Tomlin

Hi Luis,

As per your suggestion [1], this is an attempt to refactor and split optional code out of core module support code into separate components. Unfortunately, nothing has been thoroughly tested yet. Please let me know your thoughts.

Changes since v1 [2]:

- Moved module version support code into a new file

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: 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

 include/linux/module.h                        |   76 +-
 kernel/Makefile                               |    4 +-
 kernel/debug/kdb/kdb_main.c                   |    5 +
 kernel/module-internal.h                      |   31 -
 kernel/module/Makefile                        |   17 +
 kernel/module/arch_strict_rwx.c               |   44 +
 kernel/module/debug_kmemleak.c                |   30 +
 kernel/module/internal.h                      |  169 ++
 kernel/module/kallsyms.c                      |  506 +++++
 kernel/module/livepatch.c                     |   75 +
 kernel/{module.c => module/main.c}            | 1872 +----------------
 kernel/module/procfs.c                        |  111 +
 .../signature.c}                              |    0
 kernel/module/signing.c                       |  120 ++
 kernel/module/strict_rwx.c                    |   83 +
 kernel/module/sysfs.c                         |  426 ++++
 kernel/module/tree_lookup.c                   |  108 +
 kernel/module/version.c                       |  113 +
 kernel/module_signing.c                       |   45 -
 19 files changed, 1968 insertions(+), 1867 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
 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.c
Quoted 3 lines

--
2.31.1

--
- Allen

Signature · 1 line
       - Allen
#22 lore raw
Quoted 1 line · Allen

Hi Aaron,

Hi Allen,

Quoted 1 line

Was the code compile tested?

Not entirely i.e. not the whole of kernel/module/Makefile, unfortunately. Furthermore, only x86-64 was compiled tested. At the moment, I felt the need to share the concept/or approach thus far to simply obtain some overall feedback before further modifications.

Quoted 2 lines

Unfortunately, I could not apply the series cleanly on top of the
latest 5.17-rc1.

Sorry about that: this work was based on Linus' commit 81361b837a34 ("Merge tag 'kbuild-v5.14' of
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.").

Quoted 7 lines

I did rebase the patches and fixed minor compile time failures as
well a few small checkpatch errors.
I have pushed the series to
https://github.com/allenpais/Linux/commits/refactor_module_v3
[The series now is based on
84bfcc0b6994 2022-01-11 Merge tag 'integrity-v5.17' of
git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity]

Thanks for that. I'll have a look shortly to incorporate into RFC PATCH v3.

Quoted 2 lines

So far I could only manage to compile test the patches. Will test it
on BM(x86/arm) in a day or two.

Much appreciated.

Kind regards,

Signature · 1 line
Aaron Tomlin
maintainer
#23 lore raw
Quoted 12 lines · Aaron Tomlin
Quoted 1 line · Allen

Hi Aaron,

Hi Allen,

Quoted 1 line

Was the code compile tested?

Not entirely i.e. not the whole of kernel/module/Makefile, unfortunately. Furthermore, only x86-64 was compiled tested. At the moment, I felt the need to share the concept/or approach thus far to simply obtain some overall feedback before further modifications.

Quoted 6 lines
Quoted 2 lines

Unfortunately, I could not apply the series cleanly on top of the
latest 5.17-rc1.

Sorry about that: this work was based on Linus' commit 81361b837a34 ("Merge tag 'kbuild-v5.14' of
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.").

Please work off of modules-next tree:

https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=modules-next

That is, this tree on the modules-next branch:

git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git

Luis