Skip to contentSkip to conversation

module: Introduce module unload taint tracking

RFC PATCH Superseded Aaron Tomlin 5 participants 38 messages Nov 24, 2021 – Jan 12, 2022

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 module: Introduce module unload taint tracking

Currently, only the initial module that tainted the kernel is recorded e.g. when an out-of-tree module is loaded.

So the purpose of this patch is to allow the kernel to maintain a record of each unloaded module that taints the kernel. Now, in addition to displaying a list of linked modules (see print_modules()) e.g. in the event of an Oops, unloaded modules that carried a taint/or taints are also displayed. If the previously unloaded module is loaded once again it will be removed from the list only if the taints bitmask is the same.

The number of tracked modules is not fixed and can be modified accordingly. This feature is disabled by default.

---
 include/linux/module.h |   5 ++
 init/Kconfig           |   9 ++++
 kernel/module.c        | 106 +++++++++++++++++++++++++++++++++++++++--
 kernel/sysctl.c        |  10 ++++
 4 files changed, 126 insertions(+), 4 deletions(-)
include/linux/module.h +5 -0
index 8a298d820dbc..6f089953f28a 100644
@@ -672,6 +672,11 @@ static inline bool is_livepatch_module(struct module *mod)
 bool is_module_sig_enforced(void);
 void set_module_sig_enforced(void);
 
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+
+extern int tainted_list_max_count; /* for sysctl */
+
+#endif
 #else /* !CONFIG_MODULES... */
 
 static inline struct module *__module_address(unsigned long addr)
init/Kconfig +9 -0
index bb0d6e6262b1..699c6cf948d8 100644
@@ -2087,6 +2087,15 @@ config MODULE_FORCE_UNLOAD
 	  rmmod).  This is mainly for kernel developers and desperate users.
 	  If unsure, say N.
 
+config MODULE_UNLOAD_TAINT_TRACKING
+	bool "Tainted module unload tracking"
+	default n
+	help
+          This option allows you to maintain a record of each unloaded
+          module that taints the kernel. Now in addition to displaying a
+          list of linked modules e.g. in the event of an Oops, the
+          aforementioned details are also displayed. If unsure, say N.
+
 config MODVERSIONS
 	bool "Module versioning support"
 	help
kernel/module.c +102 -4

177 lines not on this page · raw message

kernel/sysctl.c +10 -0
index 272f4a272f8c..290ffaa5b553 100644
@@ -2078,6 +2078,16 @@ static struct ctl_table kern_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_ONE,
 	},
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	{
+		.procname	= "tainted_list_max_count",
+		.data		= &tainted_list_max_count,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &neg_one,
+	},
+#endif
 #endif
 #ifdef CONFIG_UEVENT_HELPER
 	{
Signature · 1 line
2.31.1
#1 lore raw
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linux/master]
[also build test ERROR on linus/master jeyu/modules-next v5.16-rc2 next-20211124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Introduce-module-unload-taint-tracking/20211125-013753
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 136057256686de39cc3a07c2e39ef6bc43003ff6
config: hexagon-randconfig-r041-20211124 (https://download.01.org/0day-ci/archive/20211125/202111250617.SNgvKWHi-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 67a1c45def8a75061203461ab0060c75c864df1c)

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/c843ee3eaddb5f5cf7e0d1bf927679da1f6eb608
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Introduce-module-unload-taint-tracking/20211125-013753 git checkout c843ee3eaddb5f5cf7e0d1bf927679da1f6eb608
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> kernel/module.c:2266:3: error: implicit declaration of function 'pr_error' [-Werror,-Wimplicit-function-declaration]

pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n", ^
1 error generated.

vim +/pr_error +2266 kernel/module.c

2225
2226 /* Free a module, remove from lists, etc. */
2227 static void free_module(struct module *mod)
2228 {
2229 trace_module_free(mod);
2230
2231 mod_sysfs_teardown(mod);
2232
2233 /*
2234 * We leave it in list to prevent duplicate loads, but make sure
2235 * that noone uses it while it's being deconstructed.
2236 */
2237 mutex_lock(&module_mutex);
2238 mod->state = MODULE_STATE_UNFORMED;
2239 mutex_unlock(&module_mutex);
2240
2241 /* Remove dynamic debug info */
2242 ddebug_remove_module(mod->name);
2243
2244 /* Arch-specific cleanup. */
2245 module_arch_cleanup(mod);
2246
2247 /* Module unload stuff */
2248 module_unload_free(mod);
2249
2250 /* Free any allocated parameters. */
2251 destroy_params(mod->kp, mod->num_kp);
2252
2253 if (is_livepatch_module(mod))
2254 free_module_elf(mod);
2255
2256 /* Now we can delete it from the lists */
2257 mutex_lock(&module_mutex);
2258 /* Unlink carefully: kallsyms could be walking list. */
2259 list_del_rcu(&mod->list);
2260 mod_tree_remove(mod);
2261 /* Remove this module from bug list, this uses list_del_rcu */
2262 module_bug_cleanup(mod);
2263 /* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */
2264 synchronize_rcu();
2265 if (try_add_tainted_module(mod))

> 2266			pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",

2267 mod->name);
2268 mutex_unlock(&module_mutex);
2269
2270 /* Clean up CFI for the module. */
2271 cfi_cleanup(mod);
2272
2273 /* This may be empty, but that's OK */
2274 module_arch_freeing_init(mod);
2275 module_memfree(mod->init_layout.base);
2276 kfree(mod->args);
2277 percpu_modfree(mod);
2278
2279 /* Free lock-classes; relies on the preceding sync_rcu(). */
2280 lockdep_free_key_range(mod->core_layout.base, mod->core_layout.size);
2281
2282 /* Finally, free the core (containing the module structure) */
2283 module_memfree(mod->core_layout.base);
2284 }
2285

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.16-rc2 next-20211125] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Introduce-module-unload-taint-tracking/20211125-013753
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 136057256686de39cc3a07c2e39ef6bc43003ff6
config: h8300-buildonly-randconfig-r001-20211125 (https://download.01.org/0day-ci/archive/20211125/202111251438.bq7eynot-lkp(a)intel.com/config)
compiler: h8300-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/c843ee3eaddb5f5cf7e0d1bf927679da1f6eb608
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Introduce-module-unload-taint-tracking/20211125-013753 git checkout c843ee3eaddb5f5cf7e0d1bf927679da1f6eb608
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=h8300

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

kernel/module.c: In function 'free_module':

>> kernel/module.c:2266:17: error: implicit declaration of function 'pr_error'; did you mean 'pr_err'? [-Werror=implicit-function-declaration]
    2266 |                 pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",
         |                 ^~~~~~~~
         |                 pr_err

cc1: some warnings being treated as errors

vim +2266 kernel/module.c

2225
2226 /* Free a module, remove from lists, etc. */
2227 static void free_module(struct module *mod)
2228 {
2229 trace_module_free(mod);
2230
2231 mod_sysfs_teardown(mod);
2232
2233 /*
2234 * We leave it in list to prevent duplicate loads, but make sure
2235 * that noone uses it while it's being deconstructed.
2236 */
2237 mutex_lock(&module_mutex);
2238 mod->state = MODULE_STATE_UNFORMED;
2239 mutex_unlock(&module_mutex);
2240
2241 /* Remove dynamic debug info */
2242 ddebug_remove_module(mod->name);
2243
2244 /* Arch-specific cleanup. */
2245 module_arch_cleanup(mod);
2246
2247 /* Module unload stuff */
2248 module_unload_free(mod);
2249
2250 /* Free any allocated parameters. */
2251 destroy_params(mod->kp, mod->num_kp);
2252
2253 if (is_livepatch_module(mod))
2254 free_module_elf(mod);
2255
2256 /* Now we can delete it from the lists */
2257 mutex_lock(&module_mutex);
2258 /* Unlink carefully: kallsyms could be walking list. */
2259 list_del_rcu(&mod->list);
2260 mod_tree_remove(mod);
2261 /* Remove this module from bug list, this uses list_del_rcu */
2262 module_bug_cleanup(mod);
2263 /* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */
2264 synchronize_rcu();
2265 if (try_add_tainted_module(mod))

> 2266			pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",

2267 mod->name);
2268 mutex_unlock(&module_mutex);
2269
2270 /* Clean up CFI for the module. */
2271 cfi_cleanup(mod);
2272
2273 /* This may be empty, but that's OK */
2274 module_arch_freeing_init(mod);
2275 module_memfree(mod->init_layout.base);
2276 kfree(mod->args);
2277 percpu_modfree(mod);
2278
2279 /* Free lock-classes; relies on the preceding sync_rcu(). */
2280 lockdep_free_key_range(mod->core_layout.base, mod->core_layout.size);
2281
2282 /* Finally, free the core (containing the module structure) */
2283 module_memfree(mod->core_layout.base);
2284 }
2285

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#3 lore raw
In reply to Aaron Tomlin

Hey Aaron thanks for your patch! Please Cc the folks I added in future iterations. My review below.

Andrew,

just Cc'ing you in case the sysctl changes in here need to rely on your changes. If so then we'll have these changes (if and once reviewed) go through your tree.

Quoted 7 lines · Aaron Tomlin

Currently, only the initial module that tainted the kernel is recorded e.g. when an out-of-tree module is loaded.

So the purpose of this patch is to allow the kernel to maintain a record of each unloaded module that taints the kernel. Now, in addition to displaying a list of linked modules (see print_modules()) e.g. in the event of an Oops, unloaded modules that carried a taint/or taints are also displayed.

This all does indeed seem useful to me.

Quoted 2 lines

If the previously unloaded module is loaded once again it will be removed from the list only if the taints bitmask is the same.

That doesn't seem to be clear. What if say a user loads a module which taints the kernel, and then unloads it, and then tries to load a similar module with the same name but that it does not taint the kernel?

Would't we loose visibility that at one point the tainting module was loaded? OK I see after reviewing the patch that we keep track of each module instance unloaded with an attached unsigned long taints. So if a module was unloaded with a different taint, we'd see it twice. Is that right?

Quoted 1 line

The number of tracked modules is not fixed and can be modified accordingly.

The commit should mention what happens if the limit is reached.

Quoted 51 lines

This feature is disabled by default.

---
 include/linux/module.h |   5 ++
 init/Kconfig           |   9 ++++
 kernel/module.c        | 106 +++++++++++++++++++++++++++++++++++++++--
 kernel/sysctl.c        |  10 ++++
 4 files changed, 126 insertions(+), 4 deletions(-)
include/linux/module.h +5 -0
index 8a298d820dbc..6f089953f28a 100644
@@ -672,6 +672,11 @@ static inline bool is_livepatch_module(struct module *mod)
 bool is_module_sig_enforced(void);
 void set_module_sig_enforced(void);
 
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+
+extern int tainted_list_max_count; /* for sysctl */
+
+#endif
 #else /* !CONFIG_MODULES... */
 
 static inline struct module *__module_address(unsigned long addr)
init/Kconfig +9 -0
index bb0d6e6262b1..699c6cf948d8 100644
@@ -2087,6 +2087,15 @@ config MODULE_FORCE_UNLOAD
 	  rmmod).  This is mainly for kernel developers and desperate users.
 	  If unsure, say N.
 
+config MODULE_UNLOAD_TAINT_TRACKING
+	bool "Tainted module unload tracking"
+	default n
+	help
+          This option allows you to maintain a record of each unloaded
+          module that taints the kernel. Now in addition to displaying a
+          list of linked modules e.g. in the event of an Oops, the
+          aforementioned details are also displayed. If unsure, say N.
+
 config MODVERSIONS
 	bool "Module versioning support"
 	help
kernel/module.c +0 -0
index ed13917ea5f3..11e10b571d64 100644

kernel/module.c line 93

Quoted 4 lines
kernel/module.c +1 -0
@@ -90,6 +90,17 @@
  */
 static DEFINE_MUTEX(module_mutex);
 static LIST_HEAD(modules);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING

wc -l kernel/*.c| sort -r -n -k 1| head
84550 total
6143 kernel/workqueue.c
4810 kernel/module.c
4789 kernel/signal.c
3170 kernel/fork.c
2997 kernel/auditsc.c
2902 kernel/kprobes.c
2857 kernel/sysctl.c
2760 kernel/sys.c
2712 kernel/cpu.c

I think it is time we start splitting module.c out into components, and here we might have a good opportunity to do that. There are tons of nasty cob webs I'd like to start cleaning up from module.c. So how about we start by moving module stuff out to kernel/modules/main.c and then you can bring in your taint friend into that directory.

That way we can avoid the #ifdefs, which seem to attract huge spiders.

Maybe live patch stuff go in its own file too?

kernel/module.c line 96

Quoted 3 lines
kernel/module.c +3 -0
+static LIST_HEAD(unloaded_tainted_modules);
+static int tainted_list_count;
+int __read_mostly tainted_list_max_count = 20;

Please read the guidance for __read_mostly on include/linux/cache.h. I don't see performance metrics on your commit log to justify this use. We don't want people to just be using that for anything they think is read often... but not really in the context of what it was originally desinged for.

Loading and unloading modules... to keep track of *which ones are tainted*. I'd find it extremely hard to believe this is such a common thing and hot path that we need this.

In any case, since a linked list is used, I'm curious why did you decide to bound this to an arbitrary limit of say 20? If this feature is enabled why not make this boundless?

Quoted 86 lines
kernel/module.c +64 -1
+struct mod_unloaded_taint {
+	struct list_head list;
+	char name[MODULE_NAME_LEN];
+	unsigned long taints;
+};
+#endif
 
 /* Work queue for freeing init sections in success case */
 static void do_free_init(struct work_struct *w);
@@ -310,6 +321,47 @@ int unregister_module_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_module_notifier);
 
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+
+static int try_add_tainted_module(struct module *mod)
+{
+	struct mod_unload_taint *mod_taint;
+
+	module_assert_mutex_or_preempt();
+
+	if (tainted_list_max_count >= 0 && mod->taints) {
+		if (!tainted_list_max_count &&
+			tainted_list_count >= tainted_list_max_count) {
+			pr_warn_once("%s: limit reached on the unloaded tainted modules list (count: %d).\n",
+				     mod->name, tainted_list_count);
+			goto out;
+		}
+
+		mod_taint = kmalloc(sizeof(*mod_taint), GFP_KERNEL);
+		if (unlikely(!mod_taint))
+			return -ENOMEM;
+		else {
+			strlcpy(mod_taint->name, mod->name,
+				MODULE_NAME_LEN);
+			mod_taint->taints = mod->taints;
+			list_add_rcu(&mod_taint->list,
+				&unloaded_tainted_modules);
+			tainted_list_count++;
+		}
+out:
+	}
+	return 0;
+}
+
+#else /* MODULE_UNLOAD_TAINT_TRACKING */
+
+static int try_add_tainted_module(struct module *mod)
+{
+	return 0;
+}
+
+#endif /* MODULE_UNLOAD_TAINT_TRACKING */
+
 /*
  * We require a truly strong try_module_get(): 0 means success.
  * Otherwise an error is returned due to ongoing or failed
@@ -579,6 +631,23 @@ struct module *find_module(const char *name)
 {
 	return find_module_all(name, strlen(name), false);
 }
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+struct mod_unload_taint *find_mod_unload_taint(const char *name, size_t len,
+					    unsigned long taints)
+{
+	struct mod_unload_taint *mod_taint;
+
+	module_assert_mutex_or_preempt();
+
+	list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules, list,
+				lockdep_is_held(&module_mutex)) {
+		if (strlen(mod_taint->name) == len && !memcmp(mod_taint->name,
+			name, len) && mod_taint->taints & taints) {
+			return mod_taint;
+		}
+	}
+	return NULL;
+#endif
 
 #ifdef CONFIG_SMP
 
@@ -1121,13 +1190,13 @@ static inline int module_unload_init(struct module *mod)
 }
 #endif /* CONFIG_MODULE_UNLOAD */
 
-static size_t module_flags_taint(struct module *mod, char *buf)

kernel/module.c static inline int module_unload_init(struct module *mod) · line 1201

Quoted 10 lines
kernel/module.c +2 -1
+static size_t module_flags_taint(unsigned long taints, char *buf)
 {
 	size_t l = 0;
 	int i;
 
 	for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
-		if (taint_flags[i].module && test_bit(i, &mod->taints))
+		if (taint_flags[i].module && test_bit(i, &taints))
 			buf[l++] = taint_flags[i].c_true;
 	}

Please make this its own separate patch. This makes it easier to review the other changes.

Quoted 33 lines
kernel/module.c +7 -1
@@ -1194,7 +1263,7 @@ static ssize_t show_taint(struct module_attribute *mattr,
 {
 	size_t l;
 
-	l = module_flags_taint(mk->mod, buffer);
+	l = module_flags_taint(mk->mod->taints, buffer);
 	buffer[l++] = '\n';
 	return l;
 }
@@ -2193,6 +2262,9 @@ static void free_module(struct module *mod)
 	module_bug_cleanup(mod);
 	/* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */
 	synchronize_rcu();
+	if (try_add_tainted_module(mod))
+		pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",
+			 mod->name);
 	mutex_unlock(&module_mutex);
 
 	/* Clean up CFI for the module. */
@@ -3670,6 +3742,9 @@ static noinline int do_init_module(struct module *mod)
 {
 	int ret = 0;
 	struct mod_initfree *freeinit;
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	struct mod_unload_taint *old;
+#endif
 
 	freeinit = kmalloc(sizeof(*freeinit), GFP_KERNEL);
 	if (!freeinit) {
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
 	mod->state = MODULE_STATE_LIVE;
 	blocking_notifier_call_chain(&module_notify_list,

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 10 lines
kernel/module.c +9 -0
 				     MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	mutex_lock(&module_mutex);
+	old = find_mod_unload_taint(mod->name, strlen(mod->name),
+				mod->taints);
+	if (old) {
+		list_del_rcu(&old->list);
+		synchronize_rcu();
+	}
+	mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

I mean, if a taint happened once, and our goal is to keep track of them, I'd imagine I'd want to know that this had happened before, so instead how about just an increment counter for this, so know how many times this has happened? Please use u64 for that. I have some test environments where module unloaded happens *a lot*.

kernel/module.c static char *module_flags(struct module *mod, char *buf) · line 4599

Quoted 10 lines
kernel/module.c +2 -1
+#endif
 
 	/* Delay uevent until module has finished its init routine */
 	kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
@@ -4511,7 +4596,7 @@ static char *module_flags(struct module *mod, char *buf)
 	    mod->state == MODULE_STATE_GOING ||
 	    mod->state == MODULE_STATE_COMING) {
 		buf[bx++] = '(';
-		bx += module_flags_taint(mod, buf + bx);
+		bx += module_flags_taint(mod->taints, buf + bx);

This change can be its own separate patch.

Quoted 17 lines
kernel/module.c +4 -0
 		/* Show a - for module-is-being-unloaded */
 		if (mod->state == MODULE_STATE_GOING)
 			buf[bx++] = '-';
@@ -4735,6 +4820,10 @@ void print_modules(void)
 {
 	struct module *mod;
 	char buf[MODULE_FLAGS_BUF_SIZE];
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	struct mod_unload_taint *mod_taint;
+	size_t l;
+#endif
 
 	printk(KERN_DEFAULT "Modules linked in:");
 	/* Most callers should already have preempt disabled, but make sure */
@@ -4744,6 +4833,15 @@ void print_modules(void)
 			continue;
 		pr_cont(" %s%s", mod->name, module_flags(mod, buf));

kernel/module.c void print_modules(void) · line 4844

Quoted 10 lines
kernel/module.c +9 -0
 	}
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	printk(KERN_DEFAULT "\nUnloaded tainted modules:");
+	list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules,
+				list) {
+		l = module_flags_taint(mod_taint->taints, buf);
+		buf[l++] = '\0';
+		pr_cont(" %s(%s)", mod_taint->name, buf);
+	}
+#endif

Ugh yeah no, this has to be in its own file. Reading this file is just one huge effort right now. Please make this a helper so we don't have to see this eye blinding code.

Quoted 13 lines
kernel/module.c +0 -0
 	preempt_enable();
 	if (last_unloaded_module[0])
 		pr_cont(" [last unloaded: %s]", last_unloaded_module);
kernel/sysctl.c +2 -0
index 272f4a272f8c..290ffaa5b553 100644
@@ -2078,6 +2078,16 @@ static struct ctl_table kern_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_ONE,
 	},
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	{

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 2092

Quoted 10 lines
kernel/sysctl.c +8 -0
+		.procname	= "tainted_list_max_count",
+		.data		= &tainted_list_max_count,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &neg_one,
+	},
+#endif
 #endif
 #ifdef CONFIG_UEVENT_HELPER

Please see kernel/sysctl.c changes on linux-next, we're moving away from everyone stuffing their sysclts in kernel/sysctl.c and there you can find helpers and examples of how *not* to do this. Its on the kernel table so you should be able to just register_sysctl_init("kernel", modules_sysctls) and while at it, if you spot any sysctls for module under the kern_table, please move those over and then your patch would be adding just one new entry to that new local modules_sysctls table.

We'll have to coordinate with Andrew given that if your changes depend on those changes then we might as well get all your changes through Andrew for the next release cycle.

Luis

#4 lore raw
Quoted 1 line · Luis Chamberlain

Hey Aaron thanks for your patch!

Hi Luis,

Firstly, thank you for your review and feedback thus far.

Quoted 1 line

Please Cc the folks I added in future iterations.

All right.

Quoted 7 lines
Quoted 2 lines

If the previously unloaded module is loaded once again it will be removed from the list only if the taints bitmask is the same.

That doesn't seem to be clear. What if say a user loads a module which taints the kernel, and then unloads it, and then tries to load a similar module with the same name but that it does not taint the kernel?

Quoted 5 lines

Would't we loose visibility that at one point the tainting module was loaded? OK I see after reviewing the patch that we keep track of each module instance unloaded with an attached unsigned long taints. So if a module was unloaded with a different taint, we'd see it twice. Is that right?

Indeed - is this acceptable to you? I prefer this approach rather than remove it from the aforementioned list solely based on the module name.

Quoted 3 lines
Quoted 1 line

The number of tracked modules is not fixed and can be modified accordingly.

The commit should mention what happens if the limit is reached.

I will mention this accordingly.

Quoted 12 lines

wc -l kernel/*.c| sort -r -n -k 1| head
84550 total
6143 kernel/workqueue.c
4810 kernel/module.c
4789 kernel/signal.c
3170 kernel/fork.c
2997 kernel/auditsc.c
2902 kernel/kprobes.c
2857 kernel/sysctl.c
2760 kernel/sys.c
2712 kernel/cpu.c

Quoted 7 lines

I think it is time we start splitting module.c out into components, and here we might have a good opportunity to do that. There are tons of nasty cob webs I'd like to start cleaning up from module.c. So how about we start by moving module stuff out to kernel/modules/main.c and then you can bring in your taint friend into that directory.

That way we can avoid the #ifdefs, which seem to attract huge spiders.

Agreed. This makes sense. I'll work on it.

Quoted 1 line

Maybe live patch stuff go in its own file too?

At first glance, I believe this is possible too.

Quoted 10 lines

kernel/module.c line 96

Quoted 4 lines
kernel/module.c +3 -0
+static LIST_HEAD(unloaded_tainted_modules);
+static int tainted_list_count;
+int __read_mostly tainted_list_max_count = 20;

Please read the guidance for __read_mostly on include/linux/cache.h. I don't see performance metrics on your commit log to justify this use. We don't want people to just be using that for anything they think is read often... but not really in the context of what it was originally desinged for.

Understood.

Quoted 7 lines

Loading and unloading modules... to keep track of *which ones are tainted*. I'd find it extremely hard to believe this is such a common thing and hot path that we need this.

In any case, since a linked list is used, I'm curious why did you decide to bound this to an arbitrary limit of say 20? If this feature is enabled why not make this boundless?

It can be, once set to 0. Indeed, the limit specified above is arbitrary. Personally, I prefer to have some limit that can be controlled by the user. In fact, if agreed, I can incorporate the limit [when specified] into the output generated via print_modules().

Quoted 92 lines
Quoted 92 lines
kernel/module.c +65 -1
+struct mod_unloaded_taint {
+	struct list_head list;
+	char name[MODULE_NAME_LEN];
+	unsigned long taints;
+};
+#endif
 
 /* Work queue for freeing init sections in success case */
 static void do_free_init(struct work_struct *w);
@@ -310,6 +321,47 @@ int unregister_module_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_module_notifier);
 
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+
+static int try_add_tainted_module(struct module *mod)
+{
+	struct mod_unload_taint *mod_taint;
+
+	module_assert_mutex_or_preempt();
+
+	if (tainted_list_max_count >= 0 && mod->taints) {
+		if (!tainted_list_max_count &&
+			tainted_list_count >= tainted_list_max_count) {
+			pr_warn_once("%s: limit reached on the unloaded tainted modules list (count: %d).\n",
+				     mod->name, tainted_list_count);
+			goto out;
+		}
+
+		mod_taint = kmalloc(sizeof(*mod_taint), GFP_KERNEL);
+		if (unlikely(!mod_taint))
+			return -ENOMEM;
+		else {
+			strlcpy(mod_taint->name, mod->name,
+				MODULE_NAME_LEN);
+			mod_taint->taints = mod->taints;
+			list_add_rcu(&mod_taint->list,
+				&unloaded_tainted_modules);
+			tainted_list_count++;
+		}
+out:
+	}
+	return 0;
+}
+
+#else /* MODULE_UNLOAD_TAINT_TRACKING */
+
+static int try_add_tainted_module(struct module *mod)
+{
+	return 0;
+}
+
+#endif /* MODULE_UNLOAD_TAINT_TRACKING */
+
 /*
  * We require a truly strong try_module_get(): 0 means success.
  * Otherwise an error is returned due to ongoing or failed
@@ -579,6 +631,23 @@ struct module *find_module(const char *name)
 {
 	return find_module_all(name, strlen(name), false);
 }
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+struct mod_unload_taint *find_mod_unload_taint(const char *name, size_t len,
+					    unsigned long taints)
+{
+	struct mod_unload_taint *mod_taint;
+
+	module_assert_mutex_or_preempt();
+
+	list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules, list,
+				lockdep_is_held(&module_mutex)) {
+		if (strlen(mod_taint->name) == len && !memcmp(mod_taint->name,
+			name, len) && mod_taint->taints & taints) {
+			return mod_taint;
+		}
+	}
+	return NULL;
+#endif
 
 #ifdef CONFIG_SMP
 
@@ -1121,13 +1190,13 @@ static inline int module_unload_init(struct module *mod)
 }
 #endif /* CONFIG_MODULE_UNLOAD */
 
-static size_t module_flags_taint(struct module *mod, char *buf)
+static size_t module_flags_taint(unsigned long taints, char *buf)
 {
 	size_t l = 0;
 	int i;
 
Quoted 8 lines

kernel/module.c static inline int module_unload_init(struct module *mod) · line 1201

Quoted 5 lines
kernel/module.c +1 -1
 	for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
-		if (taint_flags[i].module && test_bit(i, &mod->taints))
+		if (taint_flags[i].module && test_bit(i, &taints))
 			buf[l++] = taint_flags[i].c_true;
 	}

Please make this its own separate patch. This makes it easier to review the other changes.

No problem, will do.

Quoted 39 lines
Quoted 39 lines
kernel/module.c +12 -1
@@ -1194,7 +1263,7 @@ static ssize_t show_taint(struct module_attribute *mattr,
 {
 	size_t l;
 
-	l = module_flags_taint(mk->mod, buffer);
+	l = module_flags_taint(mk->mod->taints, buffer);
 	buffer[l++] = '\n';
 	return l;
 }
@@ -2193,6 +2262,9 @@ static void free_module(struct module *mod)
 	module_bug_cleanup(mod);
 	/* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */
 	synchronize_rcu();
+	if (try_add_tainted_module(mod))
+		pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",
+			 mod->name);
 	mutex_unlock(&module_mutex);
 
 	/* Clean up CFI for the module. */
@@ -3670,6 +3742,9 @@ static noinline int do_init_module(struct module *mod)
 {
 	int ret = 0;
 	struct mod_initfree *freeinit;
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	struct mod_unload_taint *old;
+#endif
 
 	freeinit = kmalloc(sizeof(*freeinit), GFP_KERNEL);
 	if (!freeinit) {
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
 	mod->state = MODULE_STATE_LIVE;
 	blocking_notifier_call_chain(&module_notify_list,
 				     MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	mutex_lock(&module_mutex);
+	old = find_mod_unload_taint(mod->name, strlen(mod->name),
+				mod->taints);
+	if (old) {
Quoted 8 lines

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 4 lines
kernel/module.c +4 -0
+		list_del_rcu(&old->list);
+		synchronize_rcu();
+	}
+	mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

At first glance, in this particular case, I believe this makes sense to avoid duplication i.e. the taint module would be stored in the 'modules' list thus should be shown once via print_modules(). So, the initial objective was to only track a "tainted" module when unloaded and once added/or loaded again [with the same taint(s)] further tracking cease.

Quoted 5 lines

I mean, if a taint happened once, and our goal is to keep track of them, I'd imagine I'd want to know that this had happened before, so instead how about just an increment counter for this, so know how many times this has happened? Please use u64 for that. I have some test environments where module unloaded happens *a lot*.

If I understand correctly, I do not like this approach but indeed it could work. Personally, I would like to incorporate the above idea i.e. track the unload count, into the initial goal.

Quoted 13 lines

kernel/module.c static char *module_flags(struct module *mod, char *buf) · line 4599

Quoted 11 lines
kernel/module.c +2 -1
+#endif
 
 	/* Delay uevent until module has finished its init routine */
 	kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
@@ -4511,7 +4596,7 @@ static char *module_flags(struct module *mod, char *buf)
 	    mod->state == MODULE_STATE_GOING ||
 	    mod->state == MODULE_STATE_COMING) {
 		buf[bx++] = '(';
-		bx += module_flags_taint(mod, buf + bx);
+		bx += module_flags_taint(mod->taints, buf + bx);

This change can be its own separate patch.

Will do.

Quoted 24 lines
Quoted 24 lines
kernel/module.c +9 -0
 		/* Show a - for module-is-being-unloaded */
 		if (mod->state == MODULE_STATE_GOING)
 			buf[bx++] = '-';
@@ -4735,6 +4820,10 @@ void print_modules(void)
 {
 	struct module *mod;
 	char buf[MODULE_FLAGS_BUF_SIZE];
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	struct mod_unload_taint *mod_taint;
+	size_t l;
+#endif
 
 	printk(KERN_DEFAULT "Modules linked in:");
 	/* Most callers should already have preempt disabled, but make sure */
@@ -4744,6 +4833,15 @@ void print_modules(void)
 			continue;
 		pr_cont(" %s%s", mod->name, module_flags(mod, buf));
 	}
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	printk(KERN_DEFAULT "\nUnloaded tainted modules:");
+	list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules,
+				list) {
+		l = module_flags_taint(mod_taint->taints, buf);
Quoted 8 lines

kernel/module.c void print_modules(void) · line 4844

Quoted 4 lines
kernel/module.c +4 -0
+		buf[l++] = '\0';
+		pr_cont(" %s(%s)", mod_taint->name, buf);
+	}
+#endif

Ugh yeah no, this has to be in its own file. Reading this file is just one huge effort right now. Please make this a helper so we don't have to see this eye blinding code.

Sure, no problem.

Quoted 34 lines
Quoted 14 lines
kernel/module.c +0 -0
 	preempt_enable();
 	if (last_unloaded_module[0])
 		pr_cont(" [last unloaded: %s]", last_unloaded_module);
kernel/sysctl.c +2 -0
index 272f4a272f8c..290ffaa5b553 100644
@@ -2078,6 +2078,16 @@ static struct ctl_table kern_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_ONE,
 	},
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	{

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 2092

Quoted 10 lines
kernel/sysctl.c +8 -0
+		.procname	= "tainted_list_max_count",
+		.data		= &tainted_list_max_count,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &neg_one,
+	},
+#endif
 #endif
 #ifdef CONFIG_UEVENT_HELPER

Please see kernel/sysctl.c changes on linux-next, we're moving away from everyone stuffing their sysclts in kernel/sysctl.c and there you can find helpers and examples of how *not* to do this. Its on the kernel table so you should be able to just register_sysctl_init("kernel", modules_sysctls) and while at it, if you spot any sysctls for module under the kern_table, please move those over and then your patch would be adding just one new entry to that new local modules_sysctls table.

Quoted 3 lines

We'll have to coordinate with Andrew given that if your changes depend on those changes then we might as well get all your changes through Andrew for the next release cycle.

All right. I will make the required changes. Thanks once again.

Regards,

Signature · 1 line
Aaron Tomlin
maintainer
#5 lore raw
Quoted 8 lines · Aaron Tomlin
Quoted 7 lines · Luis Chamberlain
Quoted 2 lines

If the previously unloaded module is loaded once again it will be removed from the list only if the taints bitmask is the same.

That doesn't seem to be clear. What if say a user loads a module which taints the kernel, and then unloads it, and then tries to load a similar module with the same name but that it does not taint the kernel?

Quoted 8 lines
Quoted 5 lines

Would't we loose visibility that at one point the tainting module was loaded? OK I see after reviewing the patch that we keep track of each module instance unloaded with an attached unsigned long taints. So if a module was unloaded with a different taint, we'd see it twice. Is that right?

Indeed - is this acceptable to you? I prefer this approach rather than remove it from the aforementioned list solely based on the module name.

Sure, it makes sense to keep all the stupid ways we are harming the kernel. Makes sense. The other point I made about count though would be good, in case the taint was the same.

Quoted 18 lines
Quoted 18 lines

wc -l kernel/*.c| sort -r -n -k 1| head
84550 total
6143 kernel/workqueue.c
4810 kernel/module.c
4789 kernel/signal.c
3170 kernel/fork.c
2997 kernel/auditsc.c
2902 kernel/kprobes.c
2857 kernel/sysctl.c
2760 kernel/sys.c
2712 kernel/cpu.c

I think it is time we start splitting module.c out into components, and here we might have a good opportunity to do that. There are tons of nasty cob webs I'd like to start cleaning up from module.c. So how about we start by moving module stuff out to kernel/modules/main.c and then you can bring in your taint friend into that directory.

Quoted 3 lines
Quoted 1 line

That way we can avoid the #ifdefs, which seem to attract huge spiders.

Agreed. This makes sense. I'll work on it.

Wonderful, thanks!

Quoted 3 lines
Quoted 1 line

Maybe live patch stuff go in its own file too?

At first glance, I believe this is possible too.

Great! Thanks for being willing to doing this!

Quoted 4 lines
Quoted 4 lines

Loading and unloading modules... to keep track of *which ones are tainted*. I'd find it extremely hard to believe this is such a common thing and hot path that we need this.

Quoted 8 lines
Quoted 3 lines

In any case, since a linked list is used, I'm curious why did you decide to bound this to an arbitrary limit of say 20? If this feature is enabled why not make this boundless?

It can be, once set to 0. Indeed, the limit specified above is arbitrary. Personally, I prefer to have some limit that can be controlled by the user. In fact, if agreed, I can incorporate the limit [when specified] into the output generated via print_modules().

If someone enables this feature I can't think of a reason why they would want to limit this to some arbitrary number. So my preference is to remove that limitation completely. I see no point to it.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
kernel/module.c +5 -0
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
 	mod->state = MODULE_STATE_LIVE;
 	blocking_notifier_call_chain(&module_notify_list,
 				     MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	mutex_lock(&module_mutex);
+	old = find_mod_unload_taint(mod->name, strlen(mod->name),
+				mod->taints);
+	if (old) {
Quoted 8 lines

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 4 lines
kernel/module.c +4 -0
+		list_del_rcu(&old->list);
+		synchronize_rcu();
+	}
+	mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

Quoted 2 lines

At first glance, in this particular case, I believe this makes sense to avoid duplication

If you just bump the count then its not duplication, it just adds more information that the same module name with the same taint flag has been unloaded now more than once.

Quoted 4 lines

i.e. the taint module would be stored in the 'modules'
list thus should be shown once via print_modules(). So, the initial objective was to only track a "tainted" module when unloaded and once added/or loaded again [with the same taint(s)] further tracking cease.

This makes me wonder, why not just grow the list at driver insertion time, rather than removal.

Quoted 8 lines
Quoted 5 lines

I mean, if a taint happened once, and our goal is to keep track of them, I'd imagine I'd want to know that this had happened before, so instead how about just an increment counter for this, so know how many times this has happened? Please use u64 for that. I have some test environments where module unloaded happens *a lot*.

If I understand correctly, I do not like this approach but indeed it could work.

I'm a bit confused, because here you seem to suggest you don't like the idea, and then...

Quoted 2 lines

Personally, I would like to incorporate the above idea i.e. track the unload count, into the initial goal.

Here you say you'd like to keep the unloud count.

Quoted 9 lines
Quoted 9 lines

Please see kernel/sysctl.c changes on linux-next, we're moving away from everyone stuffing their sysclts in kernel/sysctl.c and there you can find helpers and examples of how *not* to do this. Its on the kernel table so you should be able to just register_sysctl_init("kernel", modules_sysctls) and while at it, if you spot any sysctls for module under the kern_table, please move those over and then your patch would be adding just one new entry to that new local modules_sysctls table.

Quoted 5 lines
Quoted 3 lines

We'll have to coordinate with Andrew given that if your changes depend on those changes then we might as well get all your changes through Andrew for the next release cycle.

All right. I will make the required changes. Thanks once again.

Sure, so hey just one more thing. Can you add a simple selftest lib/test_taint.c which can be used to test tainting and you new tracker ? You can add a new selftest on

tools/testing/selftests/module/

I had already written some module based testing on tools/testing/selftests/kmod/kmod.sh so you can borrow stuff from there if you find it useful. But I think we need to start doing basic testing for module. I know Lucas has tons of test on kmod, so we should also look at what is there and what needs testing outside of that.

Then there is the question of what should be tested using kunit and or selftests. From my experience, if you need a shell, use selftests. Also, if you need parallelization, use selftests, given kunit by default uses a uniprocessor architecture, user-mode-linux. I'll let you figure out what is the best place to add the test for this. It could just be its a better place to add these tests to kmod upstream as there are tons of tests there already. But kunit test can't be added there.

Live patching already has its own set of selftests.

Luis

maintainer
#6 lore raw
Quoted 10 lines · Luis Chamberlain
Quoted 9 lines · Aaron Tomlin
Quoted 7 lines · Luis Chamberlain

Loading and unloading modules... to keep track of *which ones are tainted*. I'd find it extremely hard to believe this is such a common thing and hot path that we need this.

In any case, since a linked list is used, I'm curious why did you decide to bound this to an arbitrary limit of say 20? If this feature is enabled why not make this boundless?

Quoted 8 lines
Quoted 4 lines

It can be, once set to 0. Indeed, the limit specified above is arbitrary. Personally, I prefer to have some limit that can be controlled by the user. In fact, if agreed, I can incorporate the limit [when specified] into the output generated via print_modules().

If someone enables this feature I can't think of a reason why they would want to limit this to some arbitrary number. So my preference is to remove that limitation completely. I see no point to it.

I agree with Luis here. We could always add the limit later when people report some real life problems with too long list. It is always good to know that someone did some heavy lifting in the system.

It might be even interesting to remember timestamp of the removal to match it with another events reported in the system log.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 13 lines
kernel/module.c +9 -0
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
 	mod->state = MODULE_STATE_LIVE;
 	blocking_notifier_call_chain(&module_notify_list,
 				     MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	mutex_lock(&module_mutex);
+	old = find_mod_unload_taint(mod->name, strlen(mod->name),
+				mod->taints);
+	if (old) {
+		list_del_rcu(&old->list);
+		synchronize_rcu();
+	}
+	mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

Quoted 6 lines
Quoted 2 lines

At first glance, in this particular case, I believe this makes sense to avoid duplication

If you just bump the count then its not duplication, it just adds more information that the same module name with the same taint flag has been unloaded now more than once.

Please, do not remove records that a module was removed. IMHO, it might be useful to track all removed module, including the non-tainted ones. Module removal is always tricky and not much tested. The tain flags might be just shown as extra information in the output.

Best Regards,
Petr

#12 lore raw
In reply to Luis Chamberlain
Quoted 6 lines · Luis Chamberlain
Quoted 2 lines

Indeed - is this acceptable to you? I prefer this approach rather than remove it from the aforementioned list solely based on the module name.

Sure, it makes sense to keep all the stupid ways we are harming the kernel. Makes sense. The other point I made about count though would be good, in case the taint was the same.

Agreed. So, just to confirm you'd prefer not remove any module that tainted the kernel from the aforementioned list when the same module and taints bitmask is reintroduced? If I understand correctly, we'd simply maintain a list of modules that tainted the kernel during module deletion/or unload and their respective unload count? If so then this was not my original objective yet I'm happy with this approach too - I'll take on this implementation in the next iteration.

Quoted 8 lines
Quoted 4 lines

It can be, once set to 0. Indeed, the limit specified above is arbitrary. Personally, I prefer to have some limit that can be controlled by the user. In fact, if agreed, I can incorporate the limit [when specified] into the output generated via print_modules().

If someone enables this feature I can't think of a reason why they would want to limit this to some arbitrary number. So my preference is to remove that limitation completely. I see no point to it.

Fair enough. If necessary we could introduce the above later.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
kernel/module.c +5 -0
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
 	mod->state = MODULE_STATE_LIVE;
 	blocking_notifier_call_chain(&module_notify_list,
 				     MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+	mutex_lock(&module_mutex);
+	old = find_mod_unload_taint(mod->name, strlen(mod->name),
+				mod->taints);
+	if (old) {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 4 lines
kernel/module.c +4 -0
+		list_del_rcu(&old->list);
+		synchronize_rcu();
+	}
+	mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

Yes, this was my original approach. Once the same module [with the same taints bitmask] is reintroduced it will be listed on the 'modules' list thus no need to track it on the unloaded list anymore. That being said, as per the above, let's now keep track of each removal and maintain an unload count.

Quoted 6 lines
Quoted 2 lines

At first glance, in this particular case, I believe this makes sense to avoid duplication

If you just bump the count then its not duplication, it just adds more information that the same module name with the same taint flag has been unloaded now more than once.

Agreed.

Quoted 24 lines
Quoted 1 line

All right. I will make the required changes. Thanks once again.

Sure, so hey just one more thing. Can you add a simple selftest lib/test_taint.c which can be used to test tainting and you new tracker ? You can add a new selftest on

tools/testing/selftests/module/

I had already written some module based testing on tools/testing/selftests/kmod/kmod.sh so you can borrow stuff from there if you find it useful. But I think we need to start doing basic testing for module. I know Lucas has tons of test on kmod, so we should also look at what is there and what needs testing outside of that.

Then there is the question of what should be tested using kunit and or selftests. From my experience, if you need a shell, use selftests. Also, if you need parallelization, use selftests, given kunit by default uses a uniprocessor architecture, user-mode-linux. I'll let you figure out what is the best place to add the test for this. It could just be its a better place to add these tests to kmod upstream as there are tons of tests there already. But kunit test can't be added there.

Quoted 1 line

Live patching already has its own set of selftests.

Sure - will do. Thanks once again!

Signature · 1 line
Aaron Tomlin
#7 lore raw
In reply to Petr Mladek
Quoted 8 lines · Petr Mladek
Quoted 3 lines

If someone enables this feature I can't think of a reason why they would want to limit this to some arbitrary number. So my preference is to remove that limitation completely. I see no point to it.

I agree with Luis here. We could always add the limit later when people report some real life problems with too long list. It is always good to know that someone did some heavy lifting in the system.

Fair enough.

Quoted 2 lines

It might be even interesting to remember timestamp of the removal to match it with another events reported in the system log.

I'm not so sure about this. We could gather such details already via Ftrace (e.g. see load_module()). Personally, I'd prefer to maintain a simple list.

Quoted 8 lines
Quoted 3 lines

If you just bump the count then its not duplication, it just adds more information that the same module name with the same taint flag has been unloaded now more than once.

Please, do not remove records that a module was removed. IMHO, it might be useful to track all removed module, including the non-tainted ones. Module removal is always tricky and not much tested. The tain flags might be just shown as extra information in the output.

This is an interesting suggestion. Albeit, as per the subject, I prefer to just keep track of any module that tainted the kernel. That being said, Petr, if you'd prefer to track each module unload/or deletion event, then I would suggest for instance to remove a module once it has been reintroduced or maintain an unload count as suggested by Luis.

Please let me know your thoughts.

Kind regards,

Signature · 1 line
Aaron Tomlin
maintainer
#11 lore raw
In reply to Petr Mladek
Quoted 3 lines · Petr Mladek

Please, do not remove records that a module was removed. IMHO, it might be useful to track all removed module, including the non-tainted ones.

Then we'd need two features. One modules removed, and another which limits this to only tainted modules. On kernel-ci systems where I try to reproduce issues with fstests or blktests I might be unloading a module 10,000 times, and so for those systems I'd like to disable the tracking of all modules removed, otherwise we'd end up with -ENOMEM eventually.

Quoted 1 line

Module removal is always tricky and not much tested.

It is tricky but I have been trying to correct issues along that path and given that fstests and blktests uses it heavily I want to start dispelling the false narrative that this is not a common use case.

Quoted 1 line

The tain flags might be just shown as extra information in the output.

Yes!

Luis

maintainer
#8 lore raw
In reply to Aaron Tomlin
Quoted 6 lines · Aaron Tomlin

On Fri 2021-12-10 11:00 +0100, Petr Mladek wrote:
This is an interesting suggestion. Albeit, as per the subject, I prefer to just keep track of any module that tainted the kernel. That being said, Petr, if you'd prefer to track each module unload/or deletion event, then I would suggest for instance to remove a module once it has been reintroduced or maintain an unload count as suggested by Luis.

Come to think of this again, although at first it might be enticing to keep track of module unloads (without taint), we have to ask ourselves who would need / enable such a feature. And I think Aaron is right that this might be better tracked in userspace.

The taint though, that seems critical due to the potential harm.

Maybe how many unloads one has done though, that might be useful debugging information and does not create a huge overhead like a pontential -ENOMEM.

Luis

#35 lore raw
In reply to Aaron Tomlin
Quoted 49 lines

Hi Luis,

Firstly, thank you for your review and feedback thus far.

Quoted 1 line

Please Cc the folks I added in future iterations.

All right.

Quoted 7 lines
Quoted 2 lines

If the previously unloaded module is loaded once again it will be removed from the list only if the taints bitmask is the same.

That doesn't seem to be clear. What if say a user loads a module which taints the kernel, and then unloads it, and then tries to load a similar module with the same name but that it does not taint the kernel?

Quoted 5 lines

Would't we loose visibility that at one point the tainting module was loaded? OK I see after reviewing the patch that we keep track of each module instance unloaded with an attached unsigned long taints. So if a module was unloaded with a different taint, we'd see it twice. Is that right?

Indeed - is this acceptable to you? I prefer this approach rather than remove it from the aforementioned list solely based on the module name.

Quoted 3 lines
Quoted 1 line

The number of tracked modules is not fixed and can be modified accordingly.

The commit should mention what happens if the limit is reached.

I will mention this accordingly.

Quoted 18 lines

wc -l kernel/*.c| sort -r -n -k 1| head
84550 total
6143 kernel/workqueue.c
4810 kernel/module.c
4789 kernel/signal.c
3170 kernel/fork.c
2997 kernel/auditsc.c
2902 kernel/kprobes.c
2857 kernel/sysctl.c
2760 kernel/sys.c
2712 kernel/cpu.c

I think it is time we start splitting module.c out into components, and here we might have a good opportunity to do that. There are tons of nasty cob webs I'd like to start cleaning up from module.c. So how about we start by moving module stuff out to kernel/modules/main.c and then you can bring in your taint friend into that directory.

Quoted 3 lines
Quoted 1 line

That way we can avoid the #ifdefs, which seem to attract huge spiders.

Agreed. This makes sense. I'll work on it.

Aaron, Luis,

I have some ideas and did some work on it. Let me know if we could
work together on this.

- Allen

Quoted 296 lines
Quoted 2 lines

Maybe live patch stuff go in its own file too?

At first glance, I believe this is possible too.

Quoted 10 lines

kernel/module.c line 96

Quoted 4 lines
kernel/module.c +3 -0
+static LIST_HEAD(unloaded_tainted_modules);
+static int tainted_list_count;
+int __read_mostly tainted_list_max_count = 20;

Please read the guidance for __read_mostly on include/linux/cache.h. I don't see performance metrics on your commit log to justify this use. We don't want people to just be using that for anything they think is read often... but not really in the context of what it was originally desinged for.

Understood.

Quoted 7 lines

Loading and unloading modules... to keep track of *which ones are tainted*. I'd find it extremely hard to believe this is such a common thing and hot path that we need this.

In any case, since a linked list is used, I'm curious why did you decide to bound this to an arbitrary limit of say 20? If this feature is enabled why not make this boundless?

It can be, once set to 0. Indeed, the limit specified above is arbitrary. Personally, I prefer to have some limit that can be controlled by the user. In fact, if agreed, I can incorporate the limit [when specified] into the output generated via print_modules().

Quoted 92 lines
Quoted 92 lines
kernel/module.c +65 -1
+struct mod_unloaded_taint {
+   struct list_head list;
+   char name[MODULE_NAME_LEN];
+   unsigned long taints;
+};
+#endif
 
 /* Work queue for freeing init sections in success case */
 static void do_free_init(struct work_struct *w);
@@ -310,6 +321,47 @@ int unregister_module_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_module_notifier);
 
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+
+static int try_add_tainted_module(struct module *mod)
+{
+   struct mod_unload_taint *mod_taint;
+
+   module_assert_mutex_or_preempt();
+
+   if (tainted_list_max_count >= 0 && mod->taints) {
+           if (!tainted_list_max_count &&
+                   tainted_list_count >= tainted_list_max_count) {
+                   pr_warn_once("%s: limit reached on the unloaded tainted modules list (count: %d).\n",
+                                mod->name, tainted_list_count);
+                   goto out;
+           }
+
+           mod_taint = kmalloc(sizeof(*mod_taint), GFP_KERNEL);
+           if (unlikely(!mod_taint))
+                   return -ENOMEM;
+           else {
+                   strlcpy(mod_taint->name, mod->name,
+                           MODULE_NAME_LEN);
+                   mod_taint->taints = mod->taints;
+                   list_add_rcu(&mod_taint->list,
+                           &unloaded_tainted_modules);
+                   tainted_list_count++;
+           }
+out:
+   }
+   return 0;
+}
+
+#else /* MODULE_UNLOAD_TAINT_TRACKING */
+
+static int try_add_tainted_module(struct module *mod)
+{
+   return 0;
+}
+
+#endif /* MODULE_UNLOAD_TAINT_TRACKING */
+
 /*
  * We require a truly strong try_module_get(): 0 means success.
  * Otherwise an error is returned due to ongoing or failed
@@ -579,6 +631,23 @@ struct module *find_module(const char *name)
 {
    return find_module_all(name, strlen(name), false);
 }
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+struct mod_unload_taint *find_mod_unload_taint(const char *name, size_t len,
+                                       unsigned long taints)
+{
+   struct mod_unload_taint *mod_taint;
+
+   module_assert_mutex_or_preempt();
+
+   list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules, list,
+                           lockdep_is_held(&module_mutex)) {
+           if (strlen(mod_taint->name) == len && !memcmp(mod_taint->name,
+                   name, len) && mod_taint->taints & taints) {
+                   return mod_taint;
+           }
+   }
+   return NULL;
+#endif
 
 #ifdef CONFIG_SMP
 
@@ -1121,13 +1190,13 @@ static inline int module_unload_init(struct module *mod)
 }
 #endif /* CONFIG_MODULE_UNLOAD */
 
-static size_t module_flags_taint(struct module *mod, char *buf)
+static size_t module_flags_taint(unsigned long taints, char *buf)
 {
    size_t l = 0;
    int i;
 
Quoted 8 lines

kernel/module.c static inline int module_unload_init(struct module *mod) · line 1201

Quoted 5 lines
kernel/module.c +1 -1
    for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
-           if (taint_flags[i].module && test_bit(i, &mod->taints))
+           if (taint_flags[i].module && test_bit(i, &taints))
                    buf[l++] = taint_flags[i].c_true;
    }

Please make this its own separate patch. This makes it easier to review the other changes.

No problem, will do.

Quoted 39 lines
Quoted 39 lines
kernel/module.c +12 -1
@@ -1194,7 +1263,7 @@ static ssize_t show_taint(struct module_attribute *mattr,
 {
    size_t l;
 
-   l = module_flags_taint(mk->mod, buffer);
+   l = module_flags_taint(mk->mod->taints, buffer);
    buffer[l++] = '\n';
    return l;
 }
@@ -2193,6 +2262,9 @@ static void free_module(struct module *mod)
    module_bug_cleanup(mod);
    /* Wait for RCU-sched synchronizing before releasing mod->list and buglist. */
    synchronize_rcu();
+   if (try_add_tainted_module(mod))
+           pr_error("%s: adding tainted module to the unloaded tainted modules list failed.\n",
+                    mod->name);
    mutex_unlock(&module_mutex);
 
    /* Clean up CFI for the module. */
@@ -3670,6 +3742,9 @@ static noinline int do_init_module(struct module *mod)
 {
    int ret = 0;
    struct mod_initfree *freeinit;
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+   struct mod_unload_taint *old;
+#endif
 
    freeinit = kmalloc(sizeof(*freeinit), GFP_KERNEL);
    if (!freeinit) {
@@ -3703,6 +3778,16 @@ static noinline int do_init_module(struct module *mod)
    mod->state = MODULE_STATE_LIVE;
    blocking_notifier_call_chain(&module_notify_list,
                                 MODULE_STATE_LIVE, mod);
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+   mutex_lock(&module_mutex);
+   old = find_mod_unload_taint(mod->name, strlen(mod->name),
+                           mod->taints);
+   if (old) {
Quoted 8 lines

kernel/module.c static noinline int do_init_module(struct module *mod) · line 3789

Quoted 4 lines
kernel/module.c +4 -0
+           list_del_rcu(&old->list);
+           synchronize_rcu();
+   }
+   mutex_unlock(&module_mutex);

But here we seem to delete an old instance of the module taint history if it is loaded again and has the same taint properties. Why?

At first glance, in this particular case, I believe this makes sense to avoid duplication i.e. the taint module would be stored in the 'modules' list thus should be shown once via print_modules(). So, the initial objective was to only track a "tainted" module when unloaded and once added/or loaded again [with the same taint(s)] further tracking cease.

Quoted 5 lines

I mean, if a taint happened once, and our goal is to keep track of them, I'd imagine I'd want to know that this had happened before, so instead how about just an increment counter for this, so know how many times this has happened? Please use u64 for that. I have some test environments where module unloaded happens *a lot*.

If I understand correctly, I do not like this approach but indeed it could work. Personally, I would like to incorporate the above idea i.e. track the unload count, into the initial goal.

Quoted 13 lines

kernel/module.c static char *module_flags(struct module *mod, char *buf) · line 4599

Quoted 11 lines
kernel/module.c +2 -1
+#endif
 
    /* Delay uevent until module has finished its init routine */
    kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
@@ -4511,7 +4596,7 @@ static char *module_flags(struct module *mod, char *buf)
        mod->state == MODULE_STATE_GOING ||
        mod->state == MODULE_STATE_COMING) {
            buf[bx++] = '(';
-           bx += module_flags_taint(mod, buf + bx);
+           bx += module_flags_taint(mod->taints, buf + bx);

This change can be its own separate patch.

Will do.

Quoted 24 lines
Quoted 24 lines
kernel/module.c +9 -0
            /* Show a - for module-is-being-unloaded */
            if (mod->state == MODULE_STATE_GOING)
                    buf[bx++] = '-';
@@ -4735,6 +4820,10 @@ void print_modules(void)
 {
    struct module *mod;
    char buf[MODULE_FLAGS_BUF_SIZE];
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+   struct mod_unload_taint *mod_taint;
+   size_t l;
+#endif
 
    printk(KERN_DEFAULT "Modules linked in:");
    /* Most callers should already have preempt disabled, but make sure */
@@ -4744,6 +4833,15 @@ void print_modules(void)
                    continue;
            pr_cont(" %s%s", mod->name, module_flags(mod, buf));
    }
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+   printk(KERN_DEFAULT "\nUnloaded tainted modules:");
+   list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules,
+                           list) {
+           l = module_flags_taint(mod_taint->taints, buf);
Quoted 8 lines

kernel/module.c void print_modules(void) · line 4844

Quoted 4 lines
kernel/module.c +4 -0
+           buf[l++] = '\0';
+           pr_cont(" %s(%s)", mod_taint->name, buf);
+   }
+#endif

Ugh yeah no, this has to be in its own file. Reading this file is just one huge effort right now. Please make this a helper so we don't have to see this eye blinding code.

Sure, no problem.

Quoted 34 lines
Quoted 14 lines
kernel/module.c +0 -0
    preempt_enable();
    if (last_unloaded_module[0])
            pr_cont(" [last unloaded: %s]", last_unloaded_module);
kernel/sysctl.c +2 -0
index 272f4a272f8c..290ffaa5b553 100644
@@ -2078,6 +2078,16 @@ static struct ctl_table kern_table[] = {
            .extra1         = SYSCTL_ONE,
            .extra2         = SYSCTL_ONE,
    },
+#ifdef CONFIG_MODULE_UNLOAD_TAINT_TRACKING
+   {

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 2092

Quoted 10 lines
kernel/sysctl.c +8 -0
+           .procname       = "tainted_list_max_count",
+           .data           = &tainted_list_max_count,
+           .maxlen         = sizeof(int),
+           .mode           = 0644,
+           .proc_handler   = proc_dointvec_minmax,
+           .extra1         = &neg_one,
+   },
+#endif
 #endif
 #ifdef CONFIG_UEVENT_HELPER

Please see kernel/sysctl.c changes on linux-next, we're moving away from everyone stuffing their sysclts in kernel/sysctl.c and there you can find helpers and examples of how *not* to do this. Its on the kernel table so you should be able to just register_sysctl_init("kernel", modules_sysctls) and while at it, if you spot any sysctls for module under the kern_table, please move those over and then your patch would be adding just one new entry to that new local modules_sysctls table.

Quoted 3 lines

We'll have to coordinate with Andrew given that if your changes depend on those changes then we might as well get all your changes through Andrew for the next release cycle.

All right. I will make the required changes. Thanks once again.

Regards,

--
Aaron Tomlin

Signature · 1 line
       - Allen
maintainer
#9 lore raw
In reply to Aaron Tomlin
Quoted 10 lines · Aaron Tomlin
Quoted 8 lines · Petr Mladek
Quoted 3 lines

If someone enables this feature I can't think of a reason why they would want to limit this to some arbitrary number. So my preference is to remove that limitation completely. I see no point to it.

I agree with Luis here. We could always add the limit later when people report some real life problems with too long list. It is always good to know that someone did some heavy lifting in the system.

Quoted 7 lines

Fair enough.

Quoted 2 lines

It might be even interesting to remember timestamp of the removal to match it with another events reported in the system log.

I'm not so sure about this. We could gather such details already via Ftrace (e.g. see load_module()). Personally, I'd prefer to maintain a simple list.

Fair enough. It was just an idea. Simple list is a good start. We could always add more details if people find it useful.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

If you just bump the count then its not duplication, it just adds more information that the same module name with the same taint flag has been unloaded now more than once.

Please, do not remove records that a module was removed. IMHO, it might be useful to track all removed module, including the non-tainted ones. Module removal is always tricky and not much tested. The tain flags might be just shown as extra information in the output.

Quoted 5 lines

This is an interesting suggestion. Albeit, as per the subject, I prefer to just keep track of any module that tainted the kernel. That being said, Petr, if you'd prefer to track each module unload/or deletion event, then I would suggest for instance to remove a module once it has been reintroduced or maintain an unload count as suggested by Luis.

I just have fresh in mind the patchset
https://lore.kernel.org/r/[email protected]
It is about that removing sysfs interface is tricky and might lead to use after free problems. I could imagine many other similar problems that might happen with any module.

But I agree that the information about modules that tainted the kernel is more important. I do not want to block the feature by requiring more requirements.

Also we should keep in mind that the default panic() message should be reasonably short. Only the last lines might be visible on screen. Serial consoles might be really slow.

It is perfectly fine to add few lines, like the existing list of loaded modules. Any potentially extensive output should be optional. There already is support for optional info, see panic_print_sys_info().

Best Regards,
Petr

maintainer
#36 lore raw
In reply to Allen
Quoted 4 lines · Allen

Aaron, Luis,

I have some ideas and did some work on it. Let me know if we could
work together on this.

Patches welcomed.

Luis

#37 lore raw
In reply to Allen
Quoted 1 line · Allen

Aaron, Luis,

Hi Allen

Quoted 2 lines

I have some ideas and did some work on it. Let me know if we could work together on this.

Yes, we can. What have you done so far?

Kind regards,

Signature · 1 line
Aaron Tomlin
#10 lore raw
In reply to Petr Mladek
Quoted 5 lines · Petr Mladek
Quoted 2 lines

I'm not so sure about this. We could gather such details already via Ftrace (e.g. see load_module()). Personally, I'd prefer to maintain a simple list.

Fair enough. It was just an idea. Simple list is a good start. We could always add more details if people find it useful.

Indeed we could.

Quoted 3 lines

Also we should keep in mind that the default panic() message should be reasonably short. Only the last lines might be visible on screen. Serial consoles might be really slow.

Absolutely, I agree. This feature should be entirely optional. In fact, it is likely only useful while reviewing the data via /proc/vmcore given the potential amount of data generated, in addition to that seen in panic_print_sys_info(), when explicitly enabled.

Kind regards,

Signature · 1 line
Aaron Tomlin
#13 lore raw

cover module: core code clean up

In reply to Luis Chamberlain

Hi Luis, Allen,

I had some free time so decided to make a quick start. There is more outstanding; albeit, I wanted to share what was accomplished thus far. Unfortunately, nothing has been thoroughly tested yet. Please let me know your thoughts.

Aaron Tomlin (12):
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

 include/linux/module.h                        |   76 +-
 kernel/Makefile                               |    4 +-
 kernel/debug/kdb/kdb_main.c                   |    5 +
 kernel/module-internal.h                      |   31 -
 kernel/module/Makefile                        |   16 +
 kernel/module/arch_strict_rwx.c               |   44 +
 kernel/module/debug_kmemleak.c                |   30 +
 kernel/module/internal.h                      |  121 ++
 kernel/module/kallsyms.c                      |  506 ++++++
 kernel/module/livepatch.c                     |   75 +
 kernel/{module.c => module/main.c}            | 1616 +----------------
 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_signing.c                       |   45 -
 18 files changed, 1751 insertions(+), 1666 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} (66%)
 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
 delete mode 100644 kernel/module_signing.c
Signature · 1 line
2.31.1
#14 lore raw

RFC PATCH 1/12 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
#15 lore raw

RFC PATCH 2/12 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
#16 lore raw

RFC PATCH 3/12 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
#17 lore raw

RFC PATCH 4/12 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
#20 lore raw

RFC PATCH 5/12 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
#22 lore raw

RFC PATCH 6/12 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
#29 lore raw

RFC PATCH 10/12 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
#24 lore raw

RFC PATCH 8/12 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
#23 lore raw

RFC PATCH 7/12 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
#25 lore raw

RFC PATCH 9/12 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
#32 lore raw

RFC PATCH 12/12 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
#30 lore raw

RFC PATCH 11/12 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
#18 lore raw

Re: [RFC PATCH 04/12] module: Move latched RB-tree support to a separate file

In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on jeyu/modules-next]
[also build test ERROR on v5.16-rc7 next-20211224]
[cannot apply to linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Move-all-into-module/20211229-063051
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux.git modules-next
config: riscv-randconfig-r022-20211229 (https://download.01.org/0day-ci/archive/20211229/202112290804.sntYFDL7-lkp(a)intel.com/config)
compiler: riscv32-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/dd28c799193d8a45ed717910883b4c0b335774fe
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Move-all-into-module/20211229-063051
git checkout dd28c799193d8a45ed717910883b4c0b335774fe
# 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=riscv SHELL=/bin/bash kernel/module/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from <command-line>:
kernel/module/tree_lookup.c: In function '__mod_tree_val':

>> include/linux/kernel.h:495:58: error: invalid use of undefined type 'struct module_layout'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                                                          ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
     328 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |         ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:27: note: in expansion of macro '__same_type'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                           ^~~~~~~~~~~
   kernel/module/tree_lookup.c:23:40: note: in expansion of macro 'container_of'
      23 |         struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                        ^~~~~~~~~~~~
   include/linux/compiler_types.h:140:41: error: invalid use of undefined type 'struct module_layout'
     140 | #define __compiler_offsetof(a, b)       __builtin_offsetof(a, b)
         |                                         ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:33: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER)  __compiler_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:28: note: in expansion of macro 'offsetof'
     498 |         ((type *)(__mptr - offsetof(type, member))); })
         |                            ^~~~~~~~
   kernel/module/tree_lookup.c:23:40: note: in expansion of macro 'container_of'
      23 |         struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                        ^~~~~~~~~~~~
>> kernel/module/tree_lookup.c:25:37: error: invalid use of undefined type 'struct module_layout'
      25 |         return (unsigned long)layout->base;
         |                                     ^~
   In file included from <command-line>:
   kernel/module/tree_lookup.c: In function '__mod_tree_size':
>> include/linux/kernel.h:495:58: error: invalid use of undefined type 'struct module_layout'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                                                          ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
     328 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |         ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:27: note: in expansion of macro '__same_type'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                           ^~~~~~~~~~~
   kernel/module/tree_lookup.c:30:40: note: in expansion of macro 'container_of'
      30 |         struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                        ^~~~~~~~~~~~
   include/linux/compiler_types.h:140:41: error: invalid use of undefined type 'struct module_layout'
     140 | #define __compiler_offsetof(a, b)       __builtin_offsetof(a, b)
         |                                         ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:33: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER)  __compiler_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:28: note: in expansion of macro 'offsetof'
     498 |         ((type *)(__mptr - offsetof(type, member))); })
         |                            ^~~~~~~~
   kernel/module/tree_lookup.c:30:40: note: in expansion of macro 'container_of'
      30 |         struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                        ^~~~~~~~~~~~
   kernel/module/tree_lookup.c:32:37: error: invalid use of undefined type 'struct module_layout'
      32 |         return (unsigned long)layout->size;
         |                                     ^~
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:63:40: warning: 'struct mod_tree_node' declared inside parameter list will not be visible outside of this definition or declaration
      63 | noinline void __mod_tree_insert(struct mod_tree_node *node)
         |                                        ^~~~~~~~~~~~~
   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: In function '__mod_tree_insert':
>> kernel/module/tree_lookup.c:65:32: error: invalid use of undefined type 'struct mod_tree_node'
      65 |         latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops);
         |                                ^~
   kernel/module/tree_lookup.c:65:41: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
      65 |         latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops);
         |                                         ^~~~~~~~
         |                                         mod_timer
   kernel/module/tree_lookup.c:65:41: note: each undeclared identifier is reported only once for each function it appears in
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:68:31: warning: 'struct mod_tree_node' declared inside parameter list will not be visible outside of this definition or declaration
      68 | void __mod_tree_remove(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)
         |      ^~~~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function '__mod_tree_remove':
   kernel/module/tree_lookup.c:70:31: error: invalid use of undefined type 'struct mod_tree_node'
      70 |         latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops);
         |                               ^~
   kernel/module/tree_lookup.c:70:40: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
      70 |         latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops);
         |                                        ^~~~~~~~
         |                                        mod_timer
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:77:6: warning: no previous prototype for 'mod_tree_insert' [-Wmissing-prototypes]
      77 | void mod_tree_insert(struct module *mod)
         |      ^~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_tree_insert':
>> kernel/module/tree_lookup.c:79:12: error: invalid use of undefined type 'struct module'
      79 |         mod->core_layout.mtn.mod = mod;
         |            ^~
   kernel/module/tree_lookup.c:80:12: error: invalid use of undefined type 'struct module'
      80 |         mod->init_layout.mtn.mod = mod;
         |            ^~
   kernel/module/tree_lookup.c:82:31: error: invalid use of undefined type 'struct module'
      82 |         __mod_tree_insert(&mod->core_layout.mtn);
         |                               ^~
   kernel/module/tree_lookup.c:83:16: error: invalid use of undefined type 'struct module'
      83 |         if (mod->init_layout.size)
         |                ^~
   kernel/module/tree_lookup.c:84:39: error: invalid use of undefined type 'struct module'
      84 |                 __mod_tree_insert(&mod->init_layout.mtn);
         |                                       ^~
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:87:6: warning: no previous prototype for 'mod_tree_remove_init' [-Wmissing-prototypes]
      87 | void mod_tree_remove_init(struct module *mod)
         |      ^~~~~~~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_tree_remove_init':
   kernel/module/tree_lookup.c:89:16: error: invalid use of undefined type 'struct module'
      89 |         if (mod->init_layout.size)
         |                ^~
   kernel/module/tree_lookup.c:90:39: error: invalid use of undefined type 'struct module'
      90 |                 __mod_tree_remove(&mod->init_layout.mtn);
         |                                       ^~
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:93:6: warning: no previous prototype for 'mod_tree_remove' [-Wmissing-prototypes]
      93 | void mod_tree_remove(struct module *mod)
         |      ^~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_tree_remove':
   kernel/module/tree_lookup.c:95:31: error: invalid use of undefined type 'struct module'
      95 |         __mod_tree_remove(&mod->core_layout.mtn);
         |                               ^~
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:99:16: warning: no previous prototype for 'mod_find' [-Wmissing-prototypes]
      99 | struct module *mod_find(unsigned long addr)
         |                ^~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_find':
   kernel/module/tree_lookup.c:103:46: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
     103 |         ltn = latch_tree_find((void *)addr, &mod_tree.root, &mod_tree_ops);
         |                                              ^~~~~~~~
         |                                              mod_timer
   In file included from <command-line>:
>> include/linux/kernel.h:495:58: error: invalid use of undefined type 'struct mod_tree_node'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                                                          ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
     328 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |         ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:27: note: in expansion of macro '__same_type'
     495 |         BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
         |                           ^~~~~~~~~~~
   kernel/module/tree_lookup.c:107:16: note: in expansion of macro 'container_of'
     107 |         return container_of(ltn, struct mod_tree_node, node)->mod;
         |                ^~~~~~~~~~~~
   include/linux/compiler_types.h:140:41: error: invalid use of undefined type 'struct mod_tree_node'
     140 | #define __compiler_offsetof(a, b)       __builtin_offsetof(a, b)
         |                                         ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:33: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER)  __compiler_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:28: note: in expansion of macro 'offsetof'
     498 |         ((type *)(__mptr - offsetof(type, member))); })
         |                            ^~~~~~~~
   kernel/module/tree_lookup.c:107:16: note: in expansion of macro 'container_of'
     107 |         return container_of(ltn, struct mod_tree_node, node)->mod;
         |                ^~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function '__mod_tree_val':
   kernel/module/tree_lookup.c:26:1: error: control reaches end of non-void function [-Werror=return-type]
      26 | }
         | ^
   kernel/module/tree_lookup.c: In function '__mod_tree_size':
   kernel/module/tree_lookup.c:33:1: error: control reaches end of non-void function [-Werror=return-type]
      33 | }
         | ^
   kernel/module/tree_lookup.c: In function 'mod_find':
   kernel/module/tree_lookup.c:108:1: error: control reaches end of non-void function [-Werror=return-type]
     108 | }
         | ^

cc1: some warnings being treated as errors

vim +495 include/linux/kernel.h

cf14f27f82af78 Alexei Starovoitov 2018-03-28  485  
^1da177e4c3f41 Linus Torvalds     2005-04-16  486  /**
^1da177e4c3f41 Linus Torvalds     2005-04-16  487   * container_of - cast a member of a structure out to the containing structure
^1da177e4c3f41 Linus Torvalds     2005-04-16  488   * @ptr:	the pointer to the member.
^1da177e4c3f41 Linus Torvalds     2005-04-16  489   * @type:	the type of the container struct this is embedded in.
^1da177e4c3f41 Linus Torvalds     2005-04-16  490   * @member:	the name of the member within the struct.
^1da177e4c3f41 Linus Torvalds     2005-04-16  491   *
^1da177e4c3f41 Linus Torvalds     2005-04-16  492   */
^1da177e4c3f41 Linus Torvalds     2005-04-16  493  #define container_of(ptr, type, member) ({				\
c7acec713d14c6 Ian Abbott         2017-07-12  494  	void *__mptr = (void *)(ptr);					\
c7acec713d14c6 Ian Abbott         2017-07-12 @495  	BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&	\
c7acec713d14c6 Ian Abbott         2017-07-12  496  			 !__same_type(*(ptr), void),			\
c7acec713d14c6 Ian Abbott         2017-07-12  497  			 "pointer type mismatch in container_of()");	\
c7acec713d14c6 Ian Abbott         2017-07-12  498  	((type *)(__mptr - offsetof(type, member))); })
^1da177e4c3f41 Linus Torvalds     2005-04-16  499  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#26 lore raw

Re: [RFC PATCH 09/12] module: Move kallsyms support into a separate file

In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on jeyu/modules-next]
[also build test ERROR on v5.16-rc7 next-20211224]
[cannot apply to linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Move-all-into-module/20211229-063051
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux.git modules-next
config: nds32-allnoconfig (https://download.01.org/0day-ci/archive/20211229/202112290801.rMohBXAo-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/dca0a654ac33ddd67bc916d2b906e610d94d9dfc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Move-all-into-module/20211229-063051
git checkout dca0a654ac33ddd67bc916d2b906e610d94d9dfc
# 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:35:54: error: invalid use of undefined type 'const struct module'
      35 |                 ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
         |                                                      ^~
   kernel/module/kallsyms.c:35:65: error: invalid use of undefined type 'const struct module'
      35 |                 ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
         |                                                                 ^~
   kernel/module/kallsyms.c:35:77: error: invalid use of undefined type 'const struct module'
      35 |                 ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
         |                                                                             ^~
   kernel/module/kallsyms.c: In function 'layout_symtab':
>> kernel/module/kallsyms.c:123:51: error: invalid use of undefined type 'struct module'
     123 |         symsect->sh_entsize = get_offset(mod, &mod->init_layout.size, symsect,
         |                                                   ^~
>> kernel/module/kallsyms.c:132:31: error: implicit declaration of function 'is_livepatch_module' [-Werror=implicit-function-declaration]
     132 |                 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:8,
                    from include/linux/module.h:12,
                    from kernel/module/kallsyms.c:8:
   kernel/module/kallsyms.c:141:34: error: invalid use of undefined type 'struct module'
     141 |         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:141:25: note: in expansion of macro 'ALIGN'
     141 |         info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
         |                         ^~~~~
   kernel/module/kallsyms.c:141:34: error: invalid use of undefined type 'struct module'
     141 |         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:141:25: note: in expansion of macro 'ALIGN'
     141 |         info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
         |                         ^~~~~
   kernel/module/kallsyms.c:141:34: error: invalid use of undefined type 'struct module'
     141 |         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:141:25: note: in expansion of macro 'ALIGN'
     141 |         info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
         |                         ^~~~~
   kernel/module/kallsyms.c:142:28: error: invalid use of undefined type 'struct module'
     142 |         info->stroffs = mod->core_layout.size = info->symoffs + ndst * sizeof(Elf_Sym);
         |                            ^~
   kernel/module/kallsyms.c:143:12: error: invalid use of undefined type 'struct module'
     143 |         mod->core_layout.size += strtab_size;
         |            ^~
   kernel/module/kallsyms.c:144:34: error: invalid use of undefined type 'struct module'
     144 |         info->core_typeoffs = mod->core_layout.size;
         |                                  ^~
   kernel/module/kallsyms.c:145:12: error: invalid use of undefined type 'struct module'
     145 |         mod->core_layout.size += ndst * sizeof(char);
         |            ^~
   kernel/module/kallsyms.c:146:12: error: invalid use of undefined type 'struct module'
     146 |         mod->core_layout.size = debug_align(mod->core_layout.size);
         |            ^~
>> kernel/module/kallsyms.c:146:33: error: implicit declaration of function 'debug_align' [-Werror=implicit-function-declaration]
     146 |         mod->core_layout.size = debug_align(mod->core_layout.size);
         |                                 ^~~~~~~~~~~
   kernel/module/kallsyms.c:146:48: error: invalid use of undefined type 'struct module'
     146 |         mod->core_layout.size = debug_align(mod->core_layout.size);
         |                                                ^~
   kernel/module/kallsyms.c:150:51: error: invalid use of undefined type 'struct module'
     150 |         strsect->sh_entsize = get_offset(mod, &mod->init_layout.size, strsect,
         |                                                   ^~
   kernel/module/kallsyms.c:155:12: error: invalid use of undefined type 'struct module'
     155 |         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:8,
                    from include/linux/module.h:12,
                    from kernel/module/kallsyms.c:8:
   kernel/module/kallsyms.c:155:42: error: invalid use of undefined type 'struct module'
     155 |         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:155:33: note: in expansion of macro 'ALIGN'
     155 |         mod->init_layout.size = ALIGN(mod->init_layout.size,
         |                                 ^~~~~
   kernel/module/kallsyms.c:155:42: error: invalid use of undefined type 'struct module'
     155 |         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:155:33: note: in expansion of macro 'ALIGN'
     155 |         mod->init_layout.size = ALIGN(mod->init_layout.size,
         |                                 ^~~~~
>> kernel/module/kallsyms.c:156:51: error: invalid application of '__alignof__' to incomplete type 'struct mod_kallsyms'
     156 |                                       __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:155:33: note: in expansion of macro 'ALIGN'
     155 |         mod->init_layout.size = ALIGN(mod->init_layout.size,
         |                                 ^~~~~
   kernel/module/kallsyms.c:155:42: error: invalid use of undefined type 'struct module'
     155 |         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:155:33: note: in expansion of macro 'ALIGN'
     155 |         mod->init_layout.size = ALIGN(mod->init_layout.size,
         |                                 ^~~~~
>> kernel/module/kallsyms.c:156:51: error: invalid application of '__alignof__' to incomplete type 'struct mod_kallsyms'
     156 |                                       __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:155:33: note: in expansion of macro 'ALIGN'
     155 |         mod->init_layout.size = ALIGN(mod->init_layout.size,
         |                                 ^~~~~
   kernel/module/kallsyms.c:157:42: error: invalid use of undefined type 'struct module'
     157 |         info->mod_kallsyms_init_off = mod->init_layout.size;
         |                                          ^~
   kernel/module/kallsyms.c:158:12: error: invalid use of undefined type 'struct module'
     158 |         mod->init_layout.size += sizeof(struct mod_kallsyms);
         |            ^~
>> kernel/module/kallsyms.c:158:41: error: invalid application of 'sizeof' to incomplete type 'struct mod_kallsyms'
     158 |         mod->init_layout.size += sizeof(struct mod_kallsyms);
         |                                         ^~~~~~
   kernel/module/kallsyms.c:159:34: error: invalid use of undefined type 'struct module'
     159 |         info->init_typeoffs = mod->init_layout.size;
         |                                  ^~
   kernel/module/kallsyms.c:160:12: error: invalid use of undefined type 'struct module'
     160 |         mod->init_layout.size += nsrc * sizeof(char);
         |            ^~
   kernel/module/kallsyms.c:161:12: error: invalid use of undefined type 'struct module'
     161 |         mod->init_layout.size = debug_align(mod->init_layout.size);
         |            ^~
   kernel/module/kallsyms.c:161:48: error: invalid use of undefined type 'struct module'
     161 |         mod->init_layout.size = debug_align(mod->init_layout.size);
         |                                                ^~
   kernel/module/kallsyms.c: In function 'add_kallsyms':
   kernel/module/kallsyms.c:178:12: error: invalid use of undefined type 'struct module'
     178 |         mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off;
         |            ^~
   kernel/module/kallsyms.c:178:28: error: invalid use of undefined type 'struct module'
     178 |         mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off;
         |                            ^~
   kernel/module/kallsyms.c:180:12: error: invalid use of undefined type 'struct module'
     180 |         mod->kallsyms->symtab = (void *)symsec->sh_addr;
         |            ^~
   kernel/module/kallsyms.c:181:12: error: invalid use of undefined type 'struct module'
     181 |         mod->kallsyms->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
         |            ^~
   kernel/module/kallsyms.c:183:12: error: invalid use of undefined type 'struct module'
     183 |         mod->kallsyms->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
         |            ^~
   kernel/module/kallsyms.c:184:12: error: invalid use of undefined type 'struct module'
     184 |         mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
         |            ^~
   kernel/module/kallsyms.c:184:37: error: invalid use of undefined type 'struct module'
     184 |         mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
         |                                     ^~
   kernel/module/kallsyms.c:190:12: error: invalid use of undefined type 'struct module'
     190 |         mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
         |            ^~
   kernel/module/kallsyms.c:190:46: error: invalid use of undefined type 'struct module'
     190 |         mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
         |                                              ^~
   kernel/module/kallsyms.c:191:12: error: invalid use of undefined type 'struct module'
     191 |         mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
         |            ^~
   kernel/module/kallsyms.c:191:44: error: invalid use of undefined type 'struct module'
     191 |         mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
         |                                            ^~
   kernel/module/kallsyms.c:192:12: error: invalid use of undefined type 'struct module'
     192 |         mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
         |            ^~
   kernel/module/kallsyms.c:192:41: error: invalid use of undefined type 'struct module'
     192 |         mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
         |                                         ^~
   kernel/module/kallsyms.c:193:18: error: invalid use of undefined type 'struct module'
     193 |         src = mod->kallsyms->symtab;
         |                  ^~
   kernel/module/kallsyms.c:194:35: error: invalid use of undefined type 'struct module'
     194 |         for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) {
         |                                   ^~
   kernel/module/kallsyms.c:195:20: error: invalid use of undefined type 'struct module'
     195 |                 mod->kallsyms->typetab[i] = elf_type(src + i, info);
         |                    ^~
   kernel/module/kallsyms.c:199:28: error: invalid use of undefined type 'struct module'
     199 |                         mod->core_kallsyms.typetab[ndst] =
         |                            ^~
   kernel/module/kallsyms.c:200:32: error: invalid use of undefined type 'struct module'
     200 |                             mod->kallsyms->typetab[i];
         |                                ^~
   kernel/module/kallsyms.c:202:54: error: invalid use of undefined type 'struct module'
     202 |                         dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
         |                                                      ^~
   kernel/module/kallsyms.c:203:45: error: invalid use of undefined type 'struct module'
     203 |                         s += strlcpy(s, &mod->kallsyms->strtab[src[i].st_name],
         |                                             ^~
   kernel/module/kallsyms.c:207:12: error: invalid use of undefined type 'struct module'
     207 |         mod->core_kallsyms.num_symtab = ndst;
         |            ^~
   kernel/module/kallsyms.c: At top level:
>> kernel/module/kallsyms.c:243:48: warning: 'struct mod_kallsyms' declared inside parameter list will not be visible outside of this definition or declaration
     243 | 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:245:24: error: invalid use of undefined type 'struct mod_kallsyms'
     245 |         return kallsyms->strtab + kallsyms->symtab[symnum].st_name;
         |                        ^~
   kernel/module/kallsyms.c:245:43: error: invalid use of undefined type 'struct mod_kallsyms'
     245 |         return kallsyms->strtab + kallsyms->symtab[symnum].st_name;
         |                                           ^~
>> kernel/module/kallsyms.c:243:85: warning: parameter 'symnum' set but not used [-Wunused-but-set-parameter]
     243 | static const char *kallsyms_symbol_name(struct mod_kallsyms *kallsyms, unsigned int symnum)
         |                                                                        ~~~~~~~~~~~~~^~~~~~
   In file included from include/linux/rbtree.h:22,
                    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:259:66: error: invalid use of undefined type 'struct module'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                                                  ^~
   include/linux/rcupdate.h:389:17: note: in definition of macro '__rcu_dereference_check'
     389 |         typeof(*p) *________p1 = (typeof(*p) *__force)READ_ONCE(p); \
         |                 ^
   include/linux/rcupdate.h:612:34: note: in expansion of macro 'rcu_dereference_sched_check'
     612 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
         |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:41: note: in expansion of macro 'rcu_dereference_sched'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                         ^~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:66: error: invalid use of undefined type 'struct module'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                                                  ^~
   include/linux/rcupdate.h:389:43: note: in definition of macro '__rcu_dereference_check'
     389 |         typeof(*p) *________p1 = (typeof(*p) *__force)READ_ONCE(p); \
         |                                           ^
   include/linux/rcupdate.h:612:34: note: in expansion of macro 'rcu_dereference_sched_check'
     612 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
         |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:41: note: in expansion of macro 'rcu_dereference_sched'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                         ^~~~~~~~~~~~~~~~~~~~~
   In file included from <command-line>:
   kernel/module/kallsyms.c:259:66: error: invalid use of undefined type 'struct module'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                                                  ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
     328 |         _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:389:55: note: in expansion of macro 'READ_ONCE'
     389 |         typeof(*p) *________p1 = (typeof(*p) *__force)READ_ONCE(p); \
         |                                                       ^~~~~~~~~
   include/linux/rcupdate.h:558:9: note: in expansion of macro '__rcu_dereference_check'
     558 |         __rcu_dereference_check((p), (c) || rcu_read_lock_sched_held(), \
         |         ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:612:34: note: in expansion of macro 'rcu_dereference_sched_check'
     612 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
         |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:41: note: in expansion of macro 'rcu_dereference_sched'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                         ^~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:66: error: invalid use of undefined type 'struct module'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                                                  ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
     328 |         _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:389:55: note: in expansion of macro 'READ_ONCE'
     389 |         typeof(*p) *________p1 = (typeof(*p) *__force)READ_ONCE(p); \
         |                                                       ^~~~~~~~~
   include/linux/rcupdate.h:558:9: note: in expansion of macro '__rcu_dereference_check'
     558 |         __rcu_dereference_check((p), (c) || rcu_read_lock_sched_held(), \
         |         ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:612:34: note: in expansion of macro 'rcu_dereference_sched_check'
     612 | #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
         |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:41: note: in expansion of macro 'rcu_dereference_sched'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                         ^~~~~~~~~~~~~~~~~~~~~
   kernel/module/kallsyms.c:259:66: error: invalid use of undefined type 'struct module'
     259 |         struct mod_kallsyms *kallsyms = rcu_dereference_sched(mod->kallsyms);
         |                                                                  ^~
   include/linux/compiler_types.h:308:23: note: in definition of macro '__compiletime_assert'
     308 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~

include/linux/compiler_types.h:328:9: note: in expansion of macro '_compiletime_assert'
..

vim +35 kernel/module/kallsyms.c

    27	
    28	static int is_exported(const char *name, unsigned long value,
    29			       const struct module *mod)
    30	{
    31		const struct kernel_symbol *ks;
    32		if (!mod)
    33			ks = lookup_exported_symbol(name, __start___ksymtab, __stop___ksymtab);
    34		else
  > 35			ks = lookup_exported_symbol(name, mod->syms, mod->syms + mod->num_syms);
    36	
    37		return ks != NULL && kernel_symbol_value(ks) == value;
    38	}
    39	
    40	/* As per nm */
    41	static char elf_type(const Elf_Sym *sym, const struct load_info *info)
    42	{
    43		const Elf_Shdr *sechdrs = info->sechdrs;
    44	
    45		if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
    46			if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
    47				return 'v';
    48			else
    49				return 'w';
    50		}
    51		if (sym->st_shndx == SHN_UNDEF)
    52			return 'U';
    53		if (sym->st_shndx == SHN_ABS || sym->st_shndx == info->index.pcpu)
    54			return 'a';
    55		if (sym->st_shndx >= SHN_LORESERVE)
    56			return '?';
    57		if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
    58			return 't';
    59		if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
    60		    && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
    61			if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
    62				return 'r';
    63			else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
    64				return 'g';
    65			else
    66				return 'd';
    67		}
    68		if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
    69			if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
    70				return 's';
    71			else
    72				return 'b';
    73		}
    74		if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name,
    75			      ".debug")) {
    76			return 'n';
    77		}
    78		return '?';
    79	}
    80	
    81	static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
    82				unsigned int shnum, unsigned int pcpundx)
    83	{
    84		const Elf_Shdr *sec;
    85	
    86		if (src->st_shndx == SHN_UNDEF
    87		    || src->st_shndx >= shnum
    88		    || !src->st_name)
    89			return false;
    90	
    91	#ifdef CONFIG_KALLSYMS_ALL
    92		if (src->st_shndx == pcpundx)
    93			return true;
    94	#endif
    95	
    96		sec = sechdrs + src->st_shndx;
    97		if (!(sec->sh_flags & SHF_ALLOC)
    98	#ifndef CONFIG_KALLSYMS_ALL
    99		    || !(sec->sh_flags & SHF_EXECINSTR)
   100	#endif
   101		    || (sec->sh_entsize & INIT_OFFSET_MASK))
   102			return false;
   103	
   104		return true;
   105	}
   106	
   107	/*
   108	 * We only allocate and copy the strings needed by the parts of symtab
   109	 * we keep.  This is simple, but has the effect of making multiple
   110	 * copies of duplicates.  We could be more sophisticated, see
   111	 * linux-kernel thread starting with
   112	 * <73defb5e4bca04a6431392cc341112b1@localhost>.
   113	 */
   114	void layout_symtab(struct module *mod, struct load_info *info)
   115	{
   116		Elf_Shdr *symsect = info->sechdrs + info->index.sym;
   117		Elf_Shdr *strsect = info->sechdrs + info->index.str;
   118		const Elf_Sym *src;
   119		unsigned int i, nsrc, ndst, strtab_size = 0;
   120	
   121		/* Put symbol section at end of init part of module. */
   122		symsect->sh_flags |= SHF_ALLOC;
 > 123		symsect->sh_entsize = get_offset(mod, &mod->init_layout.size, symsect,
   124						 info->index.sym) | INIT_OFFSET_MASK;
   125		pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
   126	
   127		src = (void *)info->hdr + symsect->sh_offset;
   128		nsrc = symsect->sh_size / sizeof(*src);
   129	
   130		/* Compute total space required for the core symbols' strtab. */
   131		for (ndst = i = 0; i < nsrc; i++) {
 > 132			if (i == 0 || is_livepatch_module(mod) ||
   133			    is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum,
   134					   info->index.pcpu)) {
   135				strtab_size += strlen(&info->strtab[src[i].st_name])+1;
   136				ndst++;
   137			}
   138		}
   139	
   140		/* Append room for core symbols at end of core part. */
   141		info->symoffs = ALIGN(mod->core_layout.size, symsect->sh_addralign ?: 1);
   142		info->stroffs = mod->core_layout.size = info->symoffs + ndst * sizeof(Elf_Sym);
   143		mod->core_layout.size += strtab_size;
   144		info->core_typeoffs = mod->core_layout.size;
   145		mod->core_layout.size += ndst * sizeof(char);
 > 146		mod->core_layout.size = debug_align(mod->core_layout.size);
   147	
   148		/* Put string table section at end of init part of module. */
   149		strsect->sh_flags |= SHF_ALLOC;
   150		strsect->sh_entsize = get_offset(mod, &mod->init_layout.size, strsect,
   151						 info->index.str) | INIT_OFFSET_MASK;
   152		pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
   153	
   154		/* We'll tack temporary mod_kallsyms on the end. */
   155		mod->init_layout.size = ALIGN(mod->init_layout.size,
 > 156					      __alignof__(struct mod_kallsyms));
   157		info->mod_kallsyms_init_off = mod->init_layout.size;
 > 158		mod->init_layout.size += sizeof(struct mod_kallsyms);

159 info->init_typeoffs = mod->init_layout.size;
160 mod->init_layout.size += nsrc * sizeof(char);
161 mod->init_layout.size = debug_align(mod->init_layout.size);
162 }
163

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#19 lore raw

Re: [RFC PATCH 04/12] module: Move latched RB-tree support to a separate file

In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on jeyu/modules-next]
[also build test ERROR on v5.16-rc7 next-20211224]
[cannot apply to linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Move-all-into-module/20211229-063051
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux.git modules-next
config: i386-tinyconfig (https://download.01.org/0day-ci/archive/20211229/202112290839.p18Q37Av-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/dd28c799193d8a45ed717910883b4c0b335774fe
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Move-all-into-module/20211229-063051 git checkout dd28c799193d8a45ed717910883b4c0b335774fe
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/module/

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:
kernel/module/tree_lookup.c: In function '__mod_tree_val':

>> include/linux/kernel.h:495:51: error: dereferencing pointer to incomplete type 'struct module_layout'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                                                   ^~
   include/linux/compiler_types.h:308:9: note: in definition of macro '__compiletime_assert'
     308 |   if (!(condition))     \
         |         ^~~~~~~~~
   include/linux/compiler_types.h:328:2: note: in expansion of macro '_compiletime_assert'
     328 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |  ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:20: note: in expansion of macro '__same_type'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                    ^~~~~~~~~~~
   kernel/module/tree_lookup.c:23:33: note: in expansion of macro 'container_of'
      23 |  struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                 ^~~~~~~~~~~~
>> include/linux/compiler_types.h:140:35: error: invalid use of undefined type 'struct module_layout'
     140 | #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
         |                                   ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:32: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
         |                                ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:21: note: in expansion of macro 'offsetof'
     498 |  ((type *)(__mptr - offsetof(type, member))); })
         |                     ^~~~~~~~
   kernel/module/tree_lookup.c:23:33: note: in expansion of macro 'container_of'
      23 |  struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                 ^~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function '__mod_tree_size':
>> include/linux/kernel.h:495:51: error: dereferencing pointer to incomplete type 'struct module_layout'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                                                   ^~
   include/linux/compiler_types.h:308:9: note: in definition of macro '__compiletime_assert'
     308 |   if (!(condition))     \
         |         ^~~~~~~~~
   include/linux/compiler_types.h:328:2: note: in expansion of macro '_compiletime_assert'
     328 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |  ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:20: note: in expansion of macro '__same_type'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                    ^~~~~~~~~~~
   kernel/module/tree_lookup.c:30:33: note: in expansion of macro 'container_of'
      30 |  struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                 ^~~~~~~~~~~~
>> include/linux/compiler_types.h:140:35: error: invalid use of undefined type 'struct module_layout'
     140 | #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
         |                                   ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:32: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
         |                                ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:21: note: in expansion of macro 'offsetof'
     498 |  ((type *)(__mptr - offsetof(type, member))); })
         |                     ^~~~~~~~
   kernel/module/tree_lookup.c:30:33: note: in expansion of macro 'container_of'
      30 |  struct module_layout *layout = container_of(n, struct module_layout, mtn.node);
         |                                 ^~~~~~~~~~~~
   kernel/module/tree_lookup.c: At top level:
>> kernel/module/tree_lookup.c:63:40: warning: 'struct mod_tree_node' declared inside parameter list will not be visible outside of this definition or declaration
      63 | noinline void __mod_tree_insert(struct mod_tree_node *node)
         |                                        ^~~~~~~~~~~~~
   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: In function '__mod_tree_insert':
>> kernel/module/tree_lookup.c:65:25: error: dereferencing pointer to incomplete type 'struct mod_tree_node'
      65 |  latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops);
         |                         ^~
>> kernel/module/tree_lookup.c:65:34: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
      65 |  latch_tree_insert(&node->node, &mod_tree.root, &mod_tree_ops);
         |                                  ^~~~~~~~
         |                                  mod_timer
   kernel/module/tree_lookup.c:65:34: note: each undeclared identifier is reported only once for each function it appears in
   kernel/module/tree_lookup.c: At top level:
   kernel/module/tree_lookup.c:68:31: warning: 'struct mod_tree_node' declared inside parameter list will not be visible outside of this definition or declaration
      68 | void __mod_tree_remove(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)
         |      ^~~~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function '__mod_tree_remove':
   kernel/module/tree_lookup.c:70:24: error: dereferencing pointer to incomplete type 'struct mod_tree_node'
      70 |  latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops);
         |                        ^~
   kernel/module/tree_lookup.c:70:33: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
      70 |  latch_tree_erase(&node->node, &mod_tree.root, &mod_tree_ops);
         |                                 ^~~~~~~~
         |                                 mod_timer
   kernel/module/tree_lookup.c: At top level:
>> kernel/module/tree_lookup.c:77:6: warning: no previous prototype for 'mod_tree_insert' [-Wmissing-prototypes]
      77 | void mod_tree_insert(struct module *mod)
         |      ^~~~~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_tree_insert':
>> kernel/module/tree_lookup.c:79:5: error: dereferencing pointer to incomplete type 'struct module'
      79 |  mod->core_layout.mtn.mod = mod;
         |     ^~
   kernel/module/tree_lookup.c: At top level:
>> kernel/module/tree_lookup.c:87:6: warning: no previous prototype for 'mod_tree_remove_init' [-Wmissing-prototypes]
      87 | void mod_tree_remove_init(struct module *mod)
         |      ^~~~~~~~~~~~~~~~~~~~
>> kernel/module/tree_lookup.c:93:6: warning: no previous prototype for 'mod_tree_remove' [-Wmissing-prototypes]
      93 | void mod_tree_remove(struct module *mod)
         |      ^~~~~~~~~~~~~~~
>> kernel/module/tree_lookup.c:99:16: warning: no previous prototype for 'mod_find' [-Wmissing-prototypes]
      99 | struct module *mod_find(unsigned long addr)
         |                ^~~~~~~~
   kernel/module/tree_lookup.c: In function 'mod_find':
   kernel/module/tree_lookup.c:103:39: error: 'mod_tree' undeclared (first use in this function); did you mean 'mod_timer'?
     103 |  ltn = latch_tree_find((void *)addr, &mod_tree.root, &mod_tree_ops);
         |                                       ^~~~~~~~
         |                                       mod_timer
   In file included from <command-line>:
>> include/linux/kernel.h:495:51: error: dereferencing pointer to incomplete type 'struct mod_tree_node'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                                                   ^~
   include/linux/compiler_types.h:308:9: note: in definition of macro '__compiletime_assert'
     308 |   if (!(condition))     \
         |         ^~~~~~~~~
   include/linux/compiler_types.h:328:2: note: in expansion of macro '_compiletime_assert'
     328 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |  ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:495:20: note: in expansion of macro '__same_type'
     495 |  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
         |                    ^~~~~~~~~~~
   kernel/module/tree_lookup.c:107:9: note: in expansion of macro 'container_of'
     107 |  return container_of(ltn, struct mod_tree_node, node)->mod;
         |         ^~~~~~~~~~~~
>> include/linux/compiler_types.h:140:35: error: invalid use of undefined type 'struct mod_tree_node'
     140 | #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
         |                                   ^~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:17:32: note: in expansion of macro '__compiler_offsetof'
      17 | #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
         |                                ^~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:498:21: note: in expansion of macro 'offsetof'
     498 |  ((type *)(__mptr - offsetof(type, member))); })
         |                     ^~~~~~~~
   kernel/module/tree_lookup.c:107:9: note: in expansion of macro 'container_of'
     107 |  return container_of(ltn, struct mod_tree_node, node)->mod;
         |         ^~~~~~~~~~~~
   kernel/module/tree_lookup.c: In function '__mod_tree_val':
   kernel/module/tree_lookup.c:26:1: error: control reaches end of non-void function [-Werror=return-type]
      26 | }
         | ^
   kernel/module/tree_lookup.c: In function '__mod_tree_size':
   kernel/module/tree_lookup.c:33:1: error: control reaches end of non-void function [-Werror=return-type]
      33 | }
         | ^
   kernel/module/tree_lookup.c: In function 'mod_find':
   kernel/module/tree_lookup.c:108:1: error: control reaches end of non-void function [-Werror=return-type]
     108 | }
         | ^

cc1: some warnings being treated as errors

vim +495 include/linux/kernel.h

cf14f27f82af78 Alexei Starovoitov 2018-03-28  485  
^1da177e4c3f41 Linus Torvalds     2005-04-16  486  /**
^1da177e4c3f41 Linus Torvalds     2005-04-16  487   * container_of - cast a member of a structure out to the containing structure
^1da177e4c3f41 Linus Torvalds     2005-04-16  488   * @ptr:	the pointer to the member.
^1da177e4c3f41 Linus Torvalds     2005-04-16  489   * @type:	the type of the container struct this is embedded in.
^1da177e4c3f41 Linus Torvalds     2005-04-16  490   * @member:	the name of the member within the struct.
^1da177e4c3f41 Linus Torvalds     2005-04-16  491   *
^1da177e4c3f41 Linus Torvalds     2005-04-16  492   */
^1da177e4c3f41 Linus Torvalds     2005-04-16  493  #define container_of(ptr, type, member) ({				\
c7acec713d14c6 Ian Abbott         2017-07-12  494  	void *__mptr = (void *)(ptr);					\
c7acec713d14c6 Ian Abbott         2017-07-12 @495  	BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&	\
c7acec713d14c6 Ian Abbott         2017-07-12  496  			 !__same_type(*(ptr), void),			\
c7acec713d14c6 Ian Abbott         2017-07-12  497  			 "pointer type mismatch in container_of()");	\
c7acec713d14c6 Ian Abbott         2017-07-12  498  	((type *)(__mptr - offsetof(type, member))); })
^1da177e4c3f41 Linus Torvalds     2005-04-16  499  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#27 lore raw

Re: [RFC PATCH 09/12] module: Move kallsyms support into a separate file

In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on jeyu/modules-next]
[also build test WARNING on v5.16-rc7 next-20211224]
[cannot apply to linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Move-all-into-module/20211229-063051
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux.git modules-next
config: alpha-randconfig-s032-20211228 (https://download.01.org/0day-ci/archive/20211229/202112291156.o8nytvqf-lkp(a)intel.com/config)
compiler: alpha-linux-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/dca0a654ac33ddd67bc916d2b906e610d94d9dfc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aaron-Tomlin/module-Move-all-into-module/20211229-063051
git checkout dca0a654ac33ddd67bc916d2b906e610d94d9dfc
# 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=alpha 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:380:3: sparse: sparse: symbol 'mod_tree' was not declared. Should it be static?

>> kernel/module/kallsyms.c:178:23: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct mod_kallsyms [noderef] __rcu *kallsyms @@     got void * @@
   kernel/module/kallsyms.c:178:23: sparse:     expected struct mod_kallsyms [noderef] __rcu *kallsyms
   kernel/module/kallsyms.c:178:23: sparse:     got void *
>> kernel/module/kallsyms.c:180:12: sparse: sparse: dereference of noderef expression

kernel/module/kallsyms.c:181:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:183:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:184:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:193:18: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:194:35: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:195:20: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:200:32: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:203:45: sparse: sparse: dereference of noderef expression

vim +178 kernel/module/kallsyms.c

163
164 /*
165 * We use the full symtab and strtab which layout_symtab arranged to
166 * be appended to the init section. Later we switch to the cut-down
167 * core-only ones.
168 */
169 void add_kallsyms(struct module *mod, const struct load_info *info)
170 {
171 unsigned int i, ndst;
172 const Elf_Sym *src;
173 Elf_Sym *dst;
174 char *s;
175 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
176
177 /* Set up to point into init section. */

 > 178		mod->kallsyms = mod->init_layout.base + info->mod_kallsyms_init_off;
   179	
 > 180		mod->kallsyms->symtab = (void *)symsec->sh_addr;

181 mod->kallsyms->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
182 /* Make sure we get permanent strtab: don't use info->strtab. */
183 mod->kallsyms->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
184 mod->kallsyms->typetab = mod->init_layout.base + info->init_typeoffs;
185
186 /*
187 * Now populate the cut down core kallsyms for after init
188 * and set types up while we still have access to sections.
189 */
190 mod->core_kallsyms.symtab = dst = mod->core_layout.base + info->symoffs;
191 mod->core_kallsyms.strtab = s = mod->core_layout.base + info->stroffs;
192 mod->core_kallsyms.typetab = mod->core_layout.base + info->core_typeoffs;
193 src = mod->kallsyms->symtab;
194 for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) {
195 mod->kallsyms->typetab[i] = elf_type(src + i, info);
196 if (i == 0 || is_livepatch_module(mod) ||
197 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum,
198 info->index.pcpu)) {
199 mod->core_kallsyms.typetab[ndst] =
200 mod->kallsyms->typetab[i];
201 dst[ndst] = src[i];
202 dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
203 s += strlcpy(s, &mod->kallsyms->strtab[src[i].st_name],
204 KSYM_NAME_LEN) + 1;
205 }
206 }
207 mod->core_kallsyms.num_symtab = ndst;
208 }
209

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#28 lore raw

Re: [RFC PATCH 09/12] module: Move kallsyms support into a separate file

In reply to Aaron Tomlin
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Aaron,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on jeyu/modules-next]
[also build test WARNING on v5.16-rc7 next-20211224]
[cannot apply to linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Aaron-Tomlin/module-Move-all-into-module/20211229-063051
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux.git modules-next
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20211230/202112301104.CFQGCV4b-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/dca0a654ac33ddd67bc916d2b906e610d94d9dfc
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Aaron-Tomlin/module-Move-all-into-module/20211229-063051
        git checkout dca0a654ac33ddd67bc916d2b906e610d94d9dfc
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 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:380:3: sparse: sparse: symbol 'mod_tree' was not declared. Should it be static?
kernel/module/kallsyms.c:178:23: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct mod_kallsyms [noderef] __rcu *kallsyms @@ got void * @@
kernel/module/kallsyms.c:178:23: sparse: expected struct mod_kallsyms [noderef] __rcu *kallsyms
kernel/module/kallsyms.c:178:23: sparse: got void *

>> kernel/module/kallsyms.c:486:52: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected struct mod_kallsyms *kallsyms @@     got struct mod_kallsyms [noderef] __rcu *kallsyms @@

kernel/module/kallsyms.c:486:52: sparse: expected struct mod_kallsyms *kallsyms
kernel/module/kallsyms.c:486:52: sparse: got struct mod_kallsyms [noderef] __rcu *kallsyms
kernel/module/kallsyms.c:180:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:181:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:183:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:184:12: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:193:18: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:194:35: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:195:20: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:200:32: sparse: sparse: dereference of noderef expression kernel/module/kallsyms.c:203:45: sparse: sparse: dereference of noderef expression

vim +486 kernel/module/kallsyms.c

473
474 #ifdef CONFIG_LIVEPATCH
475 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
476 struct module *, unsigned long),
477 void *data)
478 {
479 struct module *mod;
480 unsigned int i;
481 int ret = 0;
482
483 mutex_lock(&module_mutex);
484 list_for_each_entry(mod, &modules, list) {
485 /* We hold module_mutex: no need for rcu_dereference_sched */

 > 486			struct mod_kallsyms *kallsyms = mod->kallsyms;

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#21 lore raw

Re: [RFC PATCH 05/12] module: Move arch strict rwx support to a separate file

In reply to Aaron Tomlin
Quoted 15 lines · Aaron Tomlin
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 +0 -0
new file mode 100644
index 000000000000..68e970671ec5

kernel/module/arch_strict_rwx.c line 3

Quoted 3 lines
kernel/module/arch_strict_rwx.c new file +3 -0
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * kernel/module/arch_strict_rwx.c - module arch strict rwx

No need to repeat the name of the file, a simple:

+ * module arch strict rwx

Would do it.

Please get 0day to test your git tree as you work on it, and before posting patches ensure they get tested by 0day, so we run into less issues once merged into modules-next.

Luis

maintainer
#31 lore raw

Re: [RFC PATCH 11/12] module: Move sysfs support into a separate file

In reply to Aaron Tomlin
Quoted 14 lines · Aaron Tomlin
kernel/module/main.c +1 -1
index 2da580c7b069..354fb2697188 100644
@@ -1017,7 +1015,7 @@ static ssize_t show_taint(struct module_attribute *mattr,
 static struct module_attribute modinfo_taint =
 	__ATTR(taint, 0444, show_taint, NULL);
 
-static struct module_attribute *modinfo_attrs[] = {
+struct module_attribute *modinfo_attrs[] = {
 	&module_uevent,
 	&modinfo_version,
 	&modinfo_srcversion,

kernel/module/main.c static struct module_attribute *modinfo_attrs[] = { · line 1036

Quoted 8 lines
kernel/module/main.c +2 -0
@@ -1031,6 +1029,8 @@ static struct module_attribute *modinfo_attrs[] = {
 	NULL,
 };
 
+size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);
+
 static const char vermagic[] = VERMAGIC_STRING;
 
 static int try_to_force_load(struct module *mod, const char *reason)

Can't modinfo_attrs and modinfo_attrs_count be left static and moved to the new file?

Luis

maintainer
#34 lore raw

Re: [RFC PATCH 00/12] module: core code clean up

In reply to Aaron Tomlin
Quoted 7 lines · Aaron Tomlin

Hi Luis, Allen,

I had some free time so decided to make a quick start. There is more outstanding; albeit, I wanted to share what was accomplished thus far. Unfortunately, nothing has been thoroughly tested yet. Please let me know your thoughts.

This is looking good!

Luis