Skip to contentSkip to conversation

CONFIG_DEBUG_SET_MODULE_RONX fixups

PATCH In review Laura Abbott 5 participants 8 messages Feb 25, 2015 – Mar 24, 2015

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

cover CONFIG_DEBUG_SET_MODULE_RONX fixups

Hi,

CONFIG_DEBUG_SET_MODULE_RONX is currently non-functional on arm and arm64 because of changes in behavior of is_module_addr. This series fixes both arm and arm64 to work correctly and corrects a minor bug related to section alignment in modules.

Laura Abbott (3):
arm64: Don't use is_module_addr in setting page attributes
arm: Don't use is_module_addr in setting page attributes kernel/module.c: Update debug alignment after symtable generation

 arch/arm/mm/pageattr.c   | 5 ++++-
 arch/arm64/mm/pageattr.c | 5 ++++-
 kernel/module.c          | 2 ++
 3 files changed, 10 insertions(+), 2 deletions(-)
Signature · 2 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw

PATCH 1/3 arm64: Don't use is_module_addr in setting page attributes

The set_memory_* functions currently only support module addresses. The addresses are validated using is_module_addr. That function is special though and relies on internal state in the module subsystem to work properly. At the time of module initialization and calling set_memory_*, it's too early for is_module_addr to work properly so it always returns false. Rather than be subject to the whims of the module state, just bounds check against the module virtual address range.

---
 arch/arm64/mm/pageattr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/mm/pageattr.c +4 -1
index bb0ea94..1d3ec3d 100644
@@ -51,7 +51,10 @@ static int change_memory_common(unsigned long addr, int numpages,
 		WARN_ON_ONCE(1);
 	}
 
-	if (!is_module_address(start) || !is_module_address(end - 1))
+	if (start < MODULES_VADDR || start >= MODULES_END)
+		return -EINVAL;
+
+	if (end < MODULES_VADDR || end >= MODULES_END)
 		return -EINVAL;
 
 	data.set_mask = set_mask;
Signature · 2 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#3 lore raw

PATCH 2/3 arm: Don't use is_module_addr in setting page attributes

In reply to Laura Abbott

The set_memory_* functions currently only support module addresses. The addresses are validated using is_module_addr. That function is special though and relies on internal state in the module subsystem to work properly. At the time of module initialization and calling set_memory_*, it's too early for is_module_addr to work properly so it always returns false. Rather than be subject to the whims of the module state, just bounds check against the module virtual address range.

---
 arch/arm/mm/pageattr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/mm/pageattr.c +4 -1
index 004e35c..cf30daf 100644
@@ -49,7 +49,10 @@ static int change_memory_common(unsigned long addr, int numpages,
 		WARN_ON_ONCE(1);
 	}
 
-	if (!is_module_address(start) || !is_module_address(end - 1))
+	if (start < MODULES_VADDR || start >= MODULES_END)
+		return -EINVAL;
+
+	if (end < MODULES_VADDR || start >= MODULES_END)
 		return -EINVAL;
 
 	data.set_mask = set_mask;
Signature · 2 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#4 lore raw

PATCH 3/3 kernel/module.c: Update debug alignment after symtable generation

In reply to Laura Abbott

When CONFIG_DEBUG_SET_MODULE_RONX is enabled, the sizes of module sections are aligned up so appropriate permissions can be applied. Adjusting for the symbol table may cause them to become unaligned. Make sure to re-align the sizes afterward.

---
 kernel/module.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/module.c +2 -0
index b34813f..cc93cf6 100644
@@ -2313,11 +2313,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
 	info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
 	info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
 	mod->core_size += strtab_size;
+	mod->core_size = debug_align(mod->core_size);
 
 	/* Put string table section at end of init part of module. */
 	strsect->sh_flags |= SHF_ALLOC;
 	strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
 					 info->index.str) | INIT_OFFSET_MASK;
+	mod->init_size = debug_align(mod->init_size);
 	pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
 }
 
Signature · 2 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Reviewed-by on the v1 series
#6 lore raw
In reply to Laura Abbott
Quoted 12 lines · Laura Abbott

Hi,

CONFIG_DEBUG_SET_MODULE_RONX is currently non-functional on arm and arm64 because of changes in behavior of is_module_addr. This series fixes both arm and arm64 to work correctly and corrects a minor bug related to section alignment in modules.

Laura Abbott (3):
arm64: Don't use is_module_addr in setting page attributes
arm: Don't use is_module_addr in setting page attributes kernel/module.c: Update debug alignment after symtable generation

Quoted 4 lines
 arch/arm/mm/pageattr.c   | 5 ++++-
 arch/arm64/mm/pageattr.c | 5 ++++-
 kernel/module.c          | 2 ++
 3 files changed, 10 insertions(+), 2 deletions(-)

Thanks for fixing this!

Out of curiosity, which change broke DEBUG_SET_MODULE_RONX ? (i.e. does this need a CC: stable, and if so, through which release?)

Regardless, consider them:

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
Acked-by on v1 3/3
#5 lore raw

Re: [PATCH 3/3] kernel/module.c: Update debug alignment after symtable generation

In reply to Laura Abbott
Quoted 6 lines · Laura Abbott

When CONFIG_DEBUG_SET_MODULE_RONX is enabled, the sizes of module sections are aligned up so appropriate permissions can be applied. Adjusting for the symbol table may cause them to become unaligned. Make sure to re-align the sizes afterward.

This won't clash with anything I'm planning, so happy for this to go in through the arm trees. CC:stable should be fine if you want too.

Thanks,
Rusty.

Quoted 31 lines
---
 kernel/module.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/module.c +2 -0
index b34813f..cc93cf6 100644
@@ -2313,11 +2313,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
 	info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
 	info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
 	mod->core_size += strtab_size;
+	mod->core_size = debug_align(mod->core_size);
 
 	/* Put string table section at end of init part of module. */
 	strsect->sh_flags |= SHF_ALLOC;
 	strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
 					 info->index.str) | INIT_OFFSET_MASK;
+	mod->init_size = debug_align(mod->init_size);
 	pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
 }
 
Signature · 8 lines
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] arm64: Don't use is_module_addr in setting page attributes

In reply to Laura Abbott
Quoted 11 lines · Laura Abbott

The set_memory_* functions currently only support module addresses. The addresses are validated using is_module_addr. That function is special though and relies on internal state in the module subsystem to work properly. At the time of module initialization and calling set_memory_*, it's too early for is_module_addr to work properly so it always returns false. Rather than be subject to the whims of the module state, just bounds check against the module virtual address range.

Not sure which tree this would be merged through, so:

I can pick up the arm64 patch and the module.c one with Rusty's ack (as for the arm one, I think it could go in via rmk's patch system).

Signature · 1 line
Catalin
#7 lore raw
In reply to Kees Cook
Quoted 18 lines · Kees Cook
Quoted 12 lines · Laura Abbott

Hi,

CONFIG_DEBUG_SET_MODULE_RONX is currently non-functional on arm and arm64 because of changes in behavior of is_module_addr. This series fixes both arm and arm64 to work correctly and corrects a minor bug related to section alignment in modules.

Laura Abbott (3):
arm64: Don't use is_module_addr in setting page attributes
arm: Don't use is_module_addr in setting page attributes kernel/module.c: Update debug alignment after symtable generation

Quoted 4 lines
 arch/arm/mm/pageattr.c   | 5 ++++-
 arch/arm64/mm/pageattr.c | 5 ++++-
 kernel/module.c          | 2 ++
 3 files changed, 10 insertions(+), 2 deletions(-)
Quoted 4 lines

Thanks for fixing this!

Out of curiosity, which change broke DEBUG_SET_MODULE_RONX ? (i.e. does this need a CC: stable, and if so, through which release?)

we need it for 3.19.x too:

without your patches:

root at beaglebone:~# cat /sys/module/bridge/sections/.text
0xbf199000
root at beaglebone:~# cat /sys/module/bridge/sections/.data
0xbf1ae000
root at beaglebone:~# grep -e 0xbf199000 -e 0xbf1ae000 /sys/kernel/debug/kernel_page_tables
0xbf199000-0xbf1b6000 116K RW x MEM/CACHED/WBRA

with you patches:

root at beaglebone:~# cat /sys/module/bridge/sections/.text
0xbf191000
root at beaglebone:~# cat /sys/module/bridge/sections/.data
0xbf1a6000
root at beaglebone:~# grep -e 0xbf191000 -e 0xbf1a6000 /sys/kernel/debug/kernel_page_tables

0xbf191000-0xbf1a2000          68K     ro x      MEM/CACHED/WBRA
0xbf1a2000-0xbf1a6000          16K     ro NX     MEM/CACHED/WBRA
0xbf1a6000-0xbf1ae000          32K     RW NX     MEM/CACHED/WBRA

root at beaglebone:~# uname -a
Linux beaglebone 3.19.0-9-generic #9~RONXFIX SMP Tue Mar 24 10:34:39 UTC 2015 armv7l armv7l armv7l GNU/Linux
root at beaglebone:~#

can you cc: stable@ ?

Signature · 2 lines
bye,
p.