linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM)
@ 2019-06-07 10:49 Matthias Schiffer
  2019-06-07 10:49 ` [PATCH modules v2 1/2] module: allow arch overrides for .exit section names Matthias Schiffer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Matthias Schiffer @ 2019-06-07 10:49 UTC (permalink / raw)
  To: Russell King, Jessica Yu
  Cc: Matthias Schiffer, linux-ia64, linux-kernel, linux-arm-kernel

For some time (050d18d1c651 "ARM: 8650/1: module: handle negative
R_ARM_PREL31 addends correctly", v4.11+), building a kernel without
CONFIG_MODULE_UNLOAD would lead to module loads failing on ARM systems with
certain memory layouts, with messages like:

  imx_sdma: section 16 reloc 0 sym '': relocation 42 out of range
  (0x7f015260 -> 0xc0f5a5e8)

(0x7f015260 is in the module load area, 0xc0f5a5e8 a regular vmalloc
address; relocation 42 is R_ARM_PREL31)

This is caused by relocatiosn in the .ARM.extab.exit.text and
.ARM.exidx.exit.text sections referencing the .exit.text section. As the
module loader will omit loading .exit.text without CONFIG_MODULE_UNLOAD,
there will be relocations from loaded to unloaded sections; the resulting
huge offsets trigger the sanity checks added in 050d18d1c651.

IA64 might be affected by a similar issue - sections with names like
.IA_64.unwind.exit.text and .IA_64.unwind_info.exit.text appear in the ld
script - but I don't know much about that arch.

Also, I'm not sure if this is stable-worthy - just enabling
CONFIG_MODULE_UNLOAD should be a viable workaround on affected kernels.

v2: Use __weak function as suggested by Jessica


Matthias Schiffer (2):
  module: allow arch overrides for .exit section names
  ARM: module: recognize unwind exit sections

 arch/arm/kernel/module.c     | 7 +++++++
 include/linux/moduleloader.h | 5 +++++
 kernel/module.c              | 7 ++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH modules v2 1/2] module: allow arch overrides for .exit section names
  2019-06-07 10:49 [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
@ 2019-06-07 10:49 ` Matthias Schiffer
  2019-06-07 10:49 ` [PATCH modules v2 2/2] ARM: module: recognize unwind exit sections Matthias Schiffer
  2019-06-21 12:35 ` [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
  2 siblings, 0 replies; 5+ messages in thread
From: Matthias Schiffer @ 2019-06-07 10:49 UTC (permalink / raw)
  To: Russell King, Jessica Yu
  Cc: Matthias Schiffer, linux-ia64, linux-kernel, linux-arm-kernel

Some archs like ARM store unwind information for .exit.text in sections
with unusual names. As this unwind information refers to .exit.text, it
must not be loaded when .exit.text is not loaded (when CONFIG_MODULE_UNLOAD
is unset); otherwise, loading a module can fail due to relocation failures.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
v2: Use __weak function as suggested by Jessica

 include/linux/moduleloader.h | 5 +++++
 kernel/module.c              | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
index 31013c2effd3..5229c18025e9 100644
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -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 exit section (that is only used during
+ * module unloading)
+ */
+bool module_exit_section(const char *name);
+
 /*
  * Apply the given relocation to the (simplified) ELF.  Return -error
  * or 0.
diff --git a/kernel/module.c b/kernel/module.c
index 6e6712b3aaf5..043c0f965be2 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2735,6 +2735,11 @@ void * __weak module_alloc(unsigned long size)
 	return vmalloc_exec(size);
 }
 
+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)
@@ -2924,7 +2929,7 @@ static int rewrite_section_headers(struct load_info *info, int flags)
 
 #ifndef CONFIG_MODULE_UNLOAD
 		/* Don't load .exit sections */
-		if (strstarts(info->secstrings+shdr->sh_name, ".exit"))
+		if (module_exit_section(info->secstrings+shdr->sh_name))
 			shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
 #endif
 	}
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH modules v2 2/2] ARM: module: recognize unwind exit sections
  2019-06-07 10:49 [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
  2019-06-07 10:49 ` [PATCH modules v2 1/2] module: allow arch overrides for .exit section names Matthias Schiffer
@ 2019-06-07 10:49 ` Matthias Schiffer
  2019-06-21 12:35 ` [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
  2 siblings, 0 replies; 5+ messages in thread
From: Matthias Schiffer @ 2019-06-07 10:49 UTC (permalink / raw)
  To: Russell King, Jessica Yu
  Cc: Matthias Schiffer, linux-ia64, linux-kernel, linux-arm-kernel

In addition to the prefix ".exit", ".ARM.extab.exit" and ".ARM.exidx.exit"
must be recognized as exit sections as well. Otherwise, loading modules can
fail without CONFIG_MODULE_UNLOAD depending on the memory layout, when
relocations for the unwind sections refer to the .exit.text section:

  imx_sdma: section 16 reloc 0 sym '': relocation 42 out of range
  (0x7f015260 -> 0xc0f5a5e8)

where 0x7F000000 is the module load area and 0xC0000000 is the vmalloc
area. Relocation 42 refers to R_ARM_PREL31, which is limited to signed
31bit offsets.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
v2: Use __weak function as suggested by Jessica

 arch/arm/kernel/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index 3ff571c2c71c..692001aabb0f 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -58,6 +58,13 @@ void *module_alloc(unsigned long size)
 }
 #endif
 
+bool module_exit_section(const char *name)
+{
+	return strstarts(name, ".exit") ||
+		strstarts(name, ".ARM.extab.exit") ||
+		strstarts(name, ".ARM.exidx.exit");
+}
+
 int
 apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
 	       unsigned int relindex, struct module *module)
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM)
  2019-06-07 10:49 [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
  2019-06-07 10:49 ` [PATCH modules v2 1/2] module: allow arch overrides for .exit section names Matthias Schiffer
  2019-06-07 10:49 ` [PATCH modules v2 2/2] ARM: module: recognize unwind exit sections Matthias Schiffer
@ 2019-06-21 12:35 ` Matthias Schiffer
  2019-06-24 12:32   ` Jessica Yu
  2 siblings, 1 reply; 5+ messages in thread
From: Matthias Schiffer @ 2019-06-21 12:35 UTC (permalink / raw)
  To: Russell King; +Cc: linux-ia64, linux-kernel, linux-arm-kernel, Jessica Yu

On Fri, 2019-06-07 at 12:49 +0200, Matthias Schiffer wrote:
> For some time (050d18d1c651 "ARM: 8650/1: module: handle negative
> R_ARM_PREL31 addends correctly", v4.11+), building a kernel without
> CONFIG_MODULE_UNLOAD would lead to module loads failing on ARM
> systems with
> certain memory layouts, with messages like:
> 
>   imx_sdma: section 16 reloc 0 sym '': relocation 42 out of range
>   (0x7f015260 -> 0xc0f5a5e8)
> 
> (0x7f015260 is in the module load area, 0xc0f5a5e8 a regular vmalloc
> address; relocation 42 is R_ARM_PREL31)
> 
> This is caused by relocatiosn in the .ARM.extab.exit.text and
> .ARM.exidx.exit.text sections referencing the .exit.text section. As
> the
> module loader will omit loading .exit.text without
> CONFIG_MODULE_UNLOAD,
> there will be relocations from loaded to unloaded sections; the
> resulting
> huge offsets trigger the sanity checks added in 050d18d1c651.
> 
> IA64 might be affected by a similar issue - sections with names like
> .IA_64.unwind.exit.text and .IA_64.unwind_info.exit.text appear in
> the ld
> script - but I don't know much about that arch.
> 
> Also, I'm not sure if this is stable-worthy - just enabling
> CONFIG_MODULE_UNLOAD should be a viable workaround on affected
> kernels.
> 
> v2: Use __weak function as suggested by Jessica

Hi Russell,

this patch series is still waiting for your thoughts - in reponse to
v1, Jessica already offered to take it through her tree if you give
your Acked-by.

Thanks,

Matthias


> 
> 
> Matthias Schiffer (2):
>   module: allow arch overrides for .exit section names
>   ARM: module: recognize unwind exit sections
> 
>  arch/arm/kernel/module.c     | 7 +++++++
>  include/linux/moduleloader.h | 5 +++++
>  kernel/module.c              | 7 ++++++-
>  3 files changed, 18 insertions(+), 1 deletion(-)
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM)
  2019-06-21 12:35 ` [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
@ 2019-06-24 12:32   ` Jessica Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Jessica Yu @ 2019-06-24 12:32 UTC (permalink / raw)
  To: Matthias Schiffer
  Cc: linux-ia64, Russell King, linux-arm-kernel, linux-kernel

+++ Matthias Schiffer [21/06/19 14:35 +0200]:
>On Fri, 2019-06-07 at 12:49 +0200, Matthias Schiffer wrote:
>> For some time (050d18d1c651 "ARM: 8650/1: module: handle negative
>> R_ARM_PREL31 addends correctly", v4.11+), building a kernel without
>> CONFIG_MODULE_UNLOAD would lead to module loads failing on ARM
>> systems with
>> certain memory layouts, with messages like:
>>
>>   imx_sdma: section 16 reloc 0 sym '': relocation 42 out of range
>>   (0x7f015260 -> 0xc0f5a5e8)
>>
>> (0x7f015260 is in the module load area, 0xc0f5a5e8 a regular vmalloc
>> address; relocation 42 is R_ARM_PREL31)
>>
>> This is caused by relocatiosn in the .ARM.extab.exit.text and
>> .ARM.exidx.exit.text sections referencing the .exit.text section. As
>> the
>> module loader will omit loading .exit.text without
>> CONFIG_MODULE_UNLOAD,
>> there will be relocations from loaded to unloaded sections; the
>> resulting
>> huge offsets trigger the sanity checks added in 050d18d1c651.
>>
>> IA64 might be affected by a similar issue - sections with names like
>> .IA_64.unwind.exit.text and .IA_64.unwind_info.exit.text appear in
>> the ld
>> script - but I don't know much about that arch.
>>
>> Also, I'm not sure if this is stable-worthy - just enabling
>> CONFIG_MODULE_UNLOAD should be a viable workaround on affected
>> kernels.
>>
>> v2: Use __weak function as suggested by Jessica
>
>Hi Russell,
>
>this patch series is still waiting for your thoughts - in reponse to
>v1, Jessica already offered to take it through her tree if you give
>your Acked-by.
>
>Thanks,
>
>Matthias

Hi Matthias,

There doesn't seem to be any complaints and I think the patchset looks
good, so I've taken it up the modules-next tree. Thanks!

Jessica

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-24 12:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 10:49 [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
2019-06-07 10:49 ` [PATCH modules v2 1/2] module: allow arch overrides for .exit section names Matthias Schiffer
2019-06-07 10:49 ` [PATCH modules v2 2/2] ARM: module: recognize unwind exit sections Matthias Schiffer
2019-06-21 12:35 ` [PATCH modules v2 0/2] Fix handling of exit unwinding sections (on ARM) Matthias Schiffer
2019-06-24 12:32   ` Jessica Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).