ARC: unwind: Serialize module unwind table updates
Subsystems (2)
PATCH 1/1 ARC: unwind: Serialize module unwind table updates
unwind_add_table() and unwind_remove_table() say they must be called with module_mutex held. Since commit 75676500f8298 ("module: make locking more fine-grained."), the module loader calls module_finalize() and module_arch_cleanup() without it. So the updates of root_table.link and last_table are not serialized.
Two module loads at the same time can link their tables to the same last table, so one table drops out of the list while last_table may still point to it. When that module is removed, its table is freed, and the next load writes through last_table into freed memory. Concurrent removals can likewise unlink a table through one that another removal has freed.
Serialize the list updates and the frees with a private mutex. Both callers run in process context.
This was found by an LLM-based audit that checks code against the rules stated in kernel comments.
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (arc haps_hs_smp_defconfig, GCC 14.2). checkpatch.pl is clean. Not runtime- tested, and there is no reproducer. I do not have this hardware.
arch/arc/kernel/unwind.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
arch/arc/kernel/unwind.c +8 -3
@@ -12,6 +12,7 @@#include <linux/sched.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/memblock.h> #include <linux/sort.h> #include <linux/slab.h>
@@ -354,8 +355,8 @@ static void *unw_hdr_alloc(unsigned long sz) }static struct unwind_table *last_table; +static DEFINE_MUTEX (unwind_mutex); -/* Must be called with module_mutex held. */ void *unwind_add_table (struct module *module,const void *table_start,unsigned long table_size) {
@@ -382,11 +383,13 @@ void *unwind_add_table(struct module *module, const void *table_start,unw_debug ("Table added for [%s] %lx %lx\n" , module->name, table->core.pc, table->core.range);#endif +mutex_lock (&unwind_mutex);if (last_table) last_table->link = table;else root_table.link = table; last_table = table; +mutex_unlock (&unwind_mutex);return table; }
@@ -421,7 +424,6 @@ static int unlink_table(void *arg)return 0 ; } -/* Must be called with module_mutex held. */ void unwind_remove_table (void *handle,int init_only) {struct unwind_table *table = handle;
@@ -430,18 +432,21 @@ void unwind_remove_table(void *handle, int init_only)if (!table || table == &root_table)return ; +mutex_lock (&unwind_mutex);if (init_only && table == last_table) { table->init.pc =0 ; table->init.range =0 ; +mutex_unlock (&unwind_mutex);return ; } info.table = table; info.init_only = init_only; -unlink_table (&info);/* XXX: SMP */ +unlink_table (&info);kfree (table->header);kfree (table); + mutex_unlock(&unwind_mutex); }#endif /* CONFIG_MODULES */
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
Signature · 1 line
2.25.1