Skip to contentSkip to conversation

module: allow arch overrides for .init section names

PATCH In review Vincent Whitchurch 2 participants 4 messages May 11, 2020 – May 14, 2020

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH v2 2/2 ARM: module: fix handling of unwind init sections

In reply to Vincent Whitchurch

Unwind information for init sections is placed in .ARM.exidx.init.text and .ARM.extab.init.text. The module core doesn't know that these are init sections so they are allocated along with the core sections, and if the core and init sections get allocated in different memory regions (which is possible with CONFIG_ARM_MODULE_PLTS=y) and they can't reach each other, relocation fails:

final section addresses:
...
0x7f800000 .init.text

	..
  	0xcbb54078 .ARM.exidx.init.text
	..

section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000)

Fix this by informing the module core that these sections are init sections, and by removing the init unwind tables before the module core frees the init sections.

---
v2: No changes.

 arch/arm/kernel/module.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
arch/arm/kernel/module.c +19 -3
index deef17f34bd2..af0a8500a24e 100644
@@ -55,6 +55,13 @@ void *module_alloc(unsigned long size)
 }
 #endif
 
+bool module_init_section(const char *name)
+{
+	return strstarts(name, ".init") ||
+		strstarts(name, ".ARM.extab.init") ||
+		strstarts(name, ".ARM.exidx.init");
+}
+
 bool module_exit_section(const char *name)
 {
 	return strstarts(name, ".exit") ||
@@ -409,8 +416,17 @@ module_arch_cleanup(struct module *mod)
 #ifdef CONFIG_ARM_UNWIND
 	int i;
 
-	for (i = 0; i < ARM_SEC_MAX; i++)
-		if (mod->arch.unwind[i])
-			unwind_table_del(mod->arch.unwind[i]);
+	for (i = 0; i < ARM_SEC_MAX; i++) {
+		unwind_table_del(mod->arch.unwind[i]);
+		mod->arch.unwind[i] = NULL;
+	}
+#endif
+}
+
+void __weak module_arch_freeing_init(struct module *mod)
+{
+#ifdef CONFIG_ARM_UNWIND
+	unwind_table_del(mod->arch.unwind[ARM_SEC_INIT]);
+	mod->arch.unwind[ARM_SEC_INIT] = NULL;
 #endif
 }
Signature · 1 line
2.25.1
#0 lore raw

PATCH v2 1/2 module: allow arch overrides for .init section names

ARM stores unwind information for .init.text in sections named .ARM.extab.init.text and .ARM.exidx.init.text. Since those aren't currently recognized as init sections, they're allocated along with the core section, and relocation fails if the core and the init section are allocated from different regions and can't reach other.

final section addresses:

        ...
        0x7f800000 .init.text
        ..
        0xcbb54078 .ARM.exidx.init.text
        ..

section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000)

Allow architectures to override the section name so that ARM can fix this.

---
v2: Add comment and move module_init_section() next to module_exit_section().

 include/linux/moduleloader.h | 5 +++++
 kernel/module.c              | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
include/linux/moduleloader.h +5 -0
index ca92aea8a6bd..4fa67a8b2265 100644
@@ -29,6 +29,11 @@ void *module_alloc(unsigned long size);
 /* Free memory returned from module_alloc. */
 void module_memfree(void *module_region);
 
+/* Determines if the section name is an init section (that is only used during
+ * module loading).
+ */
+bool module_init_section(const char *name);
+
 /* Determines if the section name is an exit section (that is only used during
  * module unloading)
  */
kernel/module.c +7 -2
index 33569a01d6e1..84d0c455fb44 100644
@@ -2400,7 +2400,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || strstarts(sname, ".init"))
+			    || module_init_section(sname))
 				continue;
 			s->sh_entsize = get_offset(mod, &mod->core_layout.size, s, i);
 			pr_debug("\t%s\n", sname);
@@ -2433,7 +2433,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || !strstarts(sname, ".init"))
+			    || !module_init_section(sname))
 				continue;
 			s->sh_entsize = (get_offset(mod, &mod->init_layout.size, s, i)
 					 | INIT_OFFSET_MASK);
@@ -2768,6 +2768,11 @@ void * __weak module_alloc(unsigned long size)
 	return vmalloc_exec(size);
 }
 
+bool __weak module_init_section(const char *name)
+{
+	return strstarts(name, ".init");
+}
+
 bool __weak module_exit_section(const char *name)
 {
 	return strstarts(name, ".exit");
Signature · 1 line
2.25.1
Acked-by on v2 1/2
#2 lore raw

+++ Vincent Whitchurch [11/05/20 13:48 +0200]:

Quoted 16 lines

ARM stores unwind information for .init.text in sections named .ARM.extab.init.text and .ARM.exidx.init.text. Since those aren't currently recognized as init sections, they're allocated along with the core section, and relocation fails if the core and the init section are allocated from different regions and can't reach other.

final section addresses:

       ...
       0x7f800000 .init.text
       ..
       0xcbb54078 .ARM.exidx.init.text
       ..

section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000)

Quoted 6 lines

Allow architectures to override the section name so that ARM can fix this.

---
v2: Add comment and move module_init_section() next to module_exit_section().

Thanks, this patch looks fine to me. You could add my:

Alternatively, I can take this through modules-next if the second patch gets a review and ack from an ARM maintainer.

#3 lore raw
Quoted 24 lines · Jessica Yu

+++ Vincent Whitchurch [11/05/20 13:48 +0200]:

Quoted 16 lines

ARM stores unwind information for .init.text in sections named .ARM.extab.init.text and .ARM.exidx.init.text. Since those aren't currently recognized as init sections, they're allocated along with the core section, and relocation fails if the core and the init section are allocated from different regions and can't reach other.

final section addresses:

       ...
       0x7f800000 .init.text
       ..
       0xcbb54078 .ARM.exidx.init.text
       ..

section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000)

Quoted 6 lines

Allow architectures to override the section name so that ARM can fix this.

---
v2: Add comment and move module_init_section() next to module_exit_section().

Quoted 6 lines

Thanks, this patch looks fine to me. You could add my:

Alternatively, I can take this through modules-next if the second patch gets a review and ack from an ARM maintainer.

Thanks! I've put the patches in Russell's patch system.