arm64: compat: Split the sigreturn trampolines and kuser helpers
Subsystems (2)
PATCH 1/2 arm64: compat: Split the sigreturn trampolines and kuser helpers
From: Kevin Brodsky <[email protected]>
AArch32 processes are currently installed a special [vectors] page that contains the sigreturn trampolines and the kuser helpers, at the fixed address mandated by the kuser helpers ABI.
Having both functionalities in the same page has become problematic, because:
* It makes it impossible to disable the kuser helpers (the sigreturn trampolines cannot be removed), which is possible on arm.
* A future 32-bit vDSO would provide the sigreturn trampolines itself, making those in [vectors] redundant.
This patch addresses the problem by moving the sigreturn trampolines to a separate [sigpage] page, mirroring [sigpage] on arm.
Even though [vectors] has always been a misnomer on arm64/compat, as there is no AArch32 vector there (and now only the kuser helpers), its name has been left unchanged, for compatibility with arm (there are reports of software relying on [vectors] being there as the last mapping in /proc/maps).
mm->context.vdso used to point to the [vectors] page, which is unnecessary (as its address is fixed). It now points to the [sigpage] page (whose address is randomized like a vDSO).
Finally aarch32_setup_vectors_page() has been renamed to the more generic aarch32_setup_additional_pages().
--- arch/arm64/include/asm/elf.h | 6 +- arch/arm64/include/asm/processor.h | 4 +- arch/arm64/include/asm/signal32.h | 2 - arch/arm64/kernel/signal32.c | 5 +- arch/arm64/kernel/vdso.c | 138 +++++++++++++++++++++++++++---------- 5 files changed, 107 insertions(+), 48 deletions(-)
arch/arm64/include/asm/elf.h +3 -3
@@ -199,10 +199,10 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];set_thread_flag (TIF_32BIT ); \ })#define COMPAT_ARCH_DLINFO -extern int aarch32_setup_vectors_page (struct linux_binprm *bprm, -int uses_interp); +extern int aarch32_setup_additional_pages (struct linux_binprm *bprm, +int uses_interp);#define compat_arch_setup_additional_pages \ - aarch32_setup_vectors_page + aarch32_setup_additional_pages#endif /* CONFIG_COMPAT */
arch/arm64/include/asm/processor.h +2 -2
@@ -39,9 +39,9 @@#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT -#define AARCH32_VECTORS_BASE 0xffff0000 +#define AARCH32_KUSER_HELPERS_BASE 0xffff0000#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ - AARCH32_VECTORS_BASE : STACK_TOP_MAX) + AARCH32_KUSER_HELPERS_BASE : STACK_TOP_MAX)#else #define STACK_TOP STACK_TOP_MAX#endif /* CONFIG_COMPAT */
arch/arm64/include/asm/signal32.h +0 -2
@@ -20,8 +20,6 @@#ifdef CONFIG_COMPAT #include <linux/compat.h> -#define AARCH32_KERN_SIGRET_CODE_OFFSET 0x500 -extern const compat_ulong_t aarch32_sigret_code[6 ]; int compat_setup_frame(int usig, struct ksignal *ksig, sigset_t *set,
arch/arm64/kernel/signal32.c +2 -3
@@ -484,14 +484,13 @@ static void compat_setup_return(struct pt_regs *regs, struct k_sigaction *ka, retcode =ptr_to_compat (ka->sa.sa_restorer); }else {/* Set up sigreturn pointer */ +void *sigreturn_base = current->mm->context.vdso;unsigned int idx = thumb <<1 ;if (ka->sa.sa_flags &SA_SIGINFO ) idx +=3 ; - retcode =AARCH32_VECTORS_BASE + -AARCH32_KERN_SIGRET_CODE_OFFSET + - (idx <<2 ) + thumb; + retcode =ptr_to_compat (sigreturn_base) + (idx <<2 ) + thumb; } regs->regs[0 ] = usig;
arch/arm64/kernel/vdso.c +100 -38
169 lines not on this page · raw message
Signature · 1 line
2.14.0.rc1.383.gd1ce394fe2-goog
I like the idea of this patch, but it's really churny for some reason. Any chance you could clean it up?
Some examples of what I mean inline.
Quoted 139 lines · Mark Salyzyn
From: Kevin Brodsky <[email protected]>
AArch32 processes are currently installed a special [vectors] page that contains the sigreturn trampolines and the kuser helpers, at the fixed address mandated by the kuser helpers ABI.
Having both functionalities in the same page has become problematic, because:
* It makes it impossible to disable the kuser helpers (the sigreturn trampolines cannot be removed), which is possible on arm.
* A future 32-bit vDSO would provide the sigreturn trampolines itself, making those in [vectors] redundant.
This patch addresses the problem by moving the sigreturn trampolines to a separate [sigpage] page, mirroring [sigpage] on arm.
Even though [vectors] has always been a misnomer on arm64/compat, as there is no AArch32 vector there (and now only the kuser helpers), its name has been left unchanged, for compatibility with arm (there are reports of software relying on [vectors] being there as the last mapping in
/proc/maps).
mm->context.vdsoused to point to the [vectors] page, which is unnecessary (as its address is fixed). It now points to the [sigpage] page (whose address is randomized like a vDSO).Finally
aarch32_setup_vectors_page()has been renamed to the more genericaarch32_setup_additional_pages().Signed-off-by Kevin Brodsky <[email protected]>Signed-off-by Mark Salyzyn <[email protected]>--- arch/arm64/include/asm/elf.h | 6 +- arch/arm64/include/asm/processor.h | 4 +- arch/arm64/include/asm/signal32.h | 2 - arch/arm64/kernel/signal32.c | 5 +- arch/arm64/kernel/vdso.c | 138 +++++++++++++++++++++++++++---------- 5 files changed, 107 insertions(+), 48 deletions(-)arch/arm64/include/asm/elf.h +3
-3@@ -199,10 +199,10 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];set_thread_flag (TIF_32BIT ); \ })#define COMPAT_ARCH_DLINFO -extern int aarch32_setup_vectors_page (struct linux_binprm *bprm, -int uses_interp); +extern int aarch32_setup_additional_pages (struct linux_binprm *bprm, +int uses_interp);#define compat_arch_setup_additional_pages \ - aarch32_setup_vectors_page + aarch32_setup_additional_pages#endif /* CONFIG_COMPAT */ arch/arm64/include/asm/processor.h +2
-2@@ -39,9 +39,9 @@#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT -#define AARCH32_VECTORS_BASE 0xffff0000 +#define AARCH32_KUSER_HELPERS_BASE 0xffff0000#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ - AARCH32_VECTORS_BASE : STACK_TOP_MAX) + AARCH32_KUSER_HELPERS_BASE : STACK_TOP_MAX)#else #define STACK_TOP STACK_TOP_MAX#endif /* CONFIG_COMPAT */ arch/arm64/include/asm/signal32.h +0
-2@@ -20,8 +20,6 @@#ifdef CONFIG_COMPAT #include <linux/compat.h> -#define AARCH32_KERN_SIGRET_CODE_OFFSET 0x500 -extern const compat_ulong_t aarch32_sigret_code[6 ]; int compat_setup_frame(int usig, struct ksignal *ksig, sigset_t *set,arch/arm64/kernel/signal32.c +2
-3@@ -484,14 +484,13 @@ static void compat_setup_return(struct pt_regs *regs, struct k_sigaction *ka, retcode =ptr_to_compat (ka->sa.sa_restorer); }else {/* Set up sigreturn pointer */ +void *sigreturn_base = current->mm->context.vdso;unsigned int idx = thumb <<1 ;if (ka->sa.sa_flags &SA_SIGINFO ) idx +=3 ; - retcode =AARCH32_VECTORS_BASE + -AARCH32_KERN_SIGRET_CODE_OFFSET + - (idx <<2 ) + thumb; + retcode =ptr_to_compat (sigreturn_base) + (idx <<2 ) + thumb; } regs->regs[0 ] = usig;arch/arm64/kernel/vdso.c +7
-9@@ -1,5 +1,7 @@/* -* VDSO implementation for AArch64 and vector page setup for AArch32. +* Additional userspace pages setup for AArch64 and AArch32. +* - AArch64: vDSO pages setup, vDSO data page update. +* - AArch32: sigreturn and kuser helpers pages setup. * * Copyright (C) 2012 ARM Limited * @@ -50,64 +52,124 @@ static union {struct vdso_data *vdso_data = &vdso_data_store.data;#ifdef CONFIG_COMPAT -/* -* Create and map the vectors page for AArch32 tasks. -*/ -static struct page *vectors_page[1 ]__ro_after_init ; -static int __init alloc_vectors_page (void ) -{ -extern char __kuser_helper_start[], __kuser_helper_end[]; -extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[]; +/* sigreturn trampolines page */ +static struct page *sigreturn_page__ro_after_init ; +static const struct vm_special_mapping sigreturn_spec = { + /* Must be named [sigpage] for compatibility with arm. */
arch/arm64/kernel/vdso.c static union { · line 66
Quoted 10 lines
arch/arm64/kernel/vdso.c +6
-3+ .name = "[sigpage]", + .pages = &sigreturn_page, +}; -int kuser_sz = __kuser_helper_end - __kuser_helper_start; -int sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start; -unsigned long vpage; +static int __init aarch32_sigreturn_init (void ) +{ +extern char __aarch32_sigret_code_start, __aarch32_sigret_code_end;
Why lose the [] suffixes from these?
arch/arm64/kernel/vdso.c static union { · line 69
Quoted 3 lines
arch/arm64/kernel/vdso.c +2
-1- vpage =get_zeroed_page (GFP_ATOMIC ); +size_t sigret_sz = + &__aarch32_sigret_code_end - &__aarch32_sigret_code_start;
Why not use the existing size calculation?
arch/arm64/kernel/vdso.c static union { · line 73
Quoted 5 lines
arch/arm64/kernel/vdso.c +3
-1+struct page *page; +unsigned long page_addr; -if (!vpage) + page =alloc_page (GFP_KERNEL | __GFP_ZERO);
Why not continue to use get_zeroed_page, rather than explicit alloc + page_address?
Quoted 13 lines
arch/arm64/kernel/vdso.c +3
-7+if (!page)return -ENOMEM ; + page_addr = (unsigned long )page_address (page); -/* kuser helpers */ -memcpy ((void *)vpage +0x1000 - kuser_sz, __kuser_helper_start, - kuser_sz); - -/* sigreturn code */ -memcpy ((void *)vpage +AARCH32_KERN_SIGRET_CODE_OFFSET , - __aarch32_sigret_code_start, sigret_sz); +memcpy ((void *)page_addr, &__aarch32_sigret_code_start, sigret_sz);
arch/arm64/kernel/vdso.c static union { · line 85
Quoted 10 lines
arch/arm64/kernel/vdso.c +3
-3-flush_icache_range (vpage, vpage +PAGE_SIZE ); - vectors_page[0 ] =virt_to_page (vpage); +flush_icache_range (page_addr, page_addr +PAGE_SIZE ); + sigreturn_page = page;return 0 ; } -arch_initcall (alloc_vectors_page); +arch_initcall (aarch32_sigreturn_init);
I think this would be much tidier if we kept the existing alloc_vectors_page and aarch32_setup_vectors_page functions, but extended the vectors_page to have two entries: one for the sigpage and one for the kuser helpers. That way we could avoid having two sets of functions that are really doing the same thing, just with different pages.
Will