ARM: allocate the signal page at boot
PATCH 1/1 ARM: allocate the signal page at boot
arch_setup_additional_pages() allocates the signal page on the first exec, without any locking:
if (!signal_page) signal_page = get_signal_page();
get_signal_page() also picks the random offset of the sigreturn code within the page and stores it in signal_return_offset.
If two tasks exec at the same time before the page exists, both allocate one. When the task that picked its offset first is the last one to set signal_page, signal_page points to that task's page while signal_return_offset holds the offset used in the other one. Every signal handler that returns through the signal page then lands in the wrong place, nearly always on the poison that fills the rest of the page, and the task gets a SIGILL.
Only handlers installed without SA_RESTORER return through the signal page. glibc always sets SA_RESTORER, klibc doesn't. With an initramfs that runs /init with klibc's sh, init dies on its first SIGCHLD:
Run /init as init process Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
On i.MX6Q SABRE Lite the first execs come in parallel on every boot:
the two SD hosts probe at the same time, each requests ledtrig:mmcN, and the two modprobe helpers exec together. KernelCI hits the panic in about 1 of 400 boots of that board with a klibc initramfs.
Allocate the page from an arch_initcall instead, which is what the other architectures do for their signal trampoline and vdso pages, arm64's sigpage for 32-bit tasks included.
---
arch/arm/kernel/process.c | 10 ++++++++-- arch/arm/kernel/signal.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-)
arch/arm/kernel/process.c +8 -2
@@ -379,6 +379,14 @@ static unsigned long sigpage_addr(const struct mm_struct *mm,static struct page *signal_page;extern struct page *get_signal_page (void ); +static int __init signal_page_init (void ) +{ + signal_page =get_signal_page (); + +return signal_page ?0 : -ENOMEM ; +} +arch_initcall (signal_page_init); +static int sigpage_mremap (const struct vm_special_mapping *sm,struct vm_area_struct *new_vma) {
@@ -401,8 +409,6 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)unsigned long hint;int ret =0 ; -if (!signal_page) - signal_page =get_signal_page ();if (!signal_page)return -ENOMEM ;
arch/arm/kernel/signal.c +1 -1
@@ -648,7 +648,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)return 0 ; } -struct page *get_signal_page (void ) +struct page *__init get_signal_page (void ) {unsigned long ptr;unsigned offset;
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.53.0