linux-brain/arch/parisc/kernel
Mikulas Patocka 1a2f728b03 parisc: fix crash with signals and alloca
commit 030f653078316a9cc9ca6bd1b0234dcf858be35d upstream.

I was debugging some crashes on parisc and I found out that there is a
crash possibility if a function using alloca is interrupted by a signal.
The reason for the crash is that the gcc alloca implementation leaves
garbage in the upper 32 bits of the sp register. This normally doesn't
matter (the upper bits are ignored because the PSW W-bit is clear),
however the signal delivery routine in the kernel uses full 64 bits of sp
and it fails with -EFAULT if the upper 32 bits are not zero.

I created this program that demonstrates the problem:

#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <alloca.h>

static __attribute__((noinline,noclone)) void aa(int *size)
{
	void * volatile p = alloca(-*size);
	while (1) ;
}

static void handler(int sig)
{
	write(1, "signal delivered\n", 17);
	_exit(0);
}

int main(void)
{
	int size = -0x100;
	signal(SIGALRM, handler);
	alarm(1);
	aa(&size);
}

If you compile it with optimizations, it will crash.
The "aa" function has this disassembly:

000106a0 <aa>:
   106a0:       08 03 02 41     copy r3,r1
   106a4:       08 1e 02 43     copy sp,r3
   106a8:       6f c1 00 80     stw,ma r1,40(sp)
   106ac:       37 dc 3f c1     ldo -20(sp),ret0
   106b0:       0c 7c 12 90     stw ret0,8(r3)
   106b4:       0f 40 10 9c     ldw 0(r26),ret0		; ret0 = 0x00000000FFFFFF00
   106b8:       97 9c 00 7e     subi 3f,ret0,ret0	; ret0 = 0xFFFFFFFF0000013F
   106bc:       d7 80 1c 1a     depwi 0,31,6,ret0	; ret0 = 0xFFFFFFFF00000100
   106c0:       0b 9e 0a 1e     add,l sp,ret0,sp	;   sp = 0xFFFFFFFFxxxxxxxx
   106c4:       e8 1f 1f f7     b,l,n 106c4 <aa+0x24>,r0

This patch fixes the bug by truncating the "usp" variable to 32 bits.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-09-22 12:26:37 +02:00
..
syscalls parisc: wire up kexec_file_load syscall 2019-09-08 15:37:37 +02:00
.gitignore parisc: add arch/parisc/kernel/.gitignore 2008-10-10 16:32:28 +00:00
Makefile parisc: fix compilation when KEXEC=n and KEXEC_FILE=y 2020-01-12 12:21:33 +01:00
alternative.c parisc: Add ALTERNATIVE_CODE() and ALT_COND_RUN_ON_QEMU 2019-08-12 19:17:39 +02:00
asm-offsets.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
audit.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.c parisc: Use __ro_after_init in cache.c 2019-05-10 21:00:44 +02:00
compat_audit.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
drivers.c parisc: Use proper printk format for resource_size_t 2020-02-05 21:22:46 +00:00
entry.S parisc: Do not use an ordered store in pa_tlb_lock() 2020-08-19 08:16:26 +02:00
firmware.c parisc: add __pdc_cpu_rendezvous() 2019-09-08 15:19:58 +02:00
ftrace.c parisc/ftrace: Add KPROBES_ON_FTRACE 2019-08-03 08:56:57 +02:00
hardware.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
head.S parisc: Use __ro_after_init in head.S 2019-05-10 21:00:44 +02:00
hpmc.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
inventory.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
irq.c parisc: Bump 64-bit IRQ stack size to 64 KB 2021-03-07 12:20:47 +01:00
jump_label.c parisc: Add static branch and JUMP_LABEL feature 2019-05-06 00:10:03 +02:00
kexec.c parisc: add support for kexec_file_load() syscall 2019-09-08 15:41:46 +02:00
kexec_file.c parisc: add support for kexec_file_load() syscall 2019-09-08 15:41:46 +02:00
kgdb.c parisc: add KGDB support 2019-05-03 23:47:38 +02:00
kprobes.c kprobes/parisc: remove arch_kprobe_on_func_entry() 2019-09-06 23:58:44 +02:00
module.c Merge branch 'parisc-5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux 2019-07-09 12:08:15 -07:00
module.lds parisc: add dynamic ftrace 2019-06-08 12:56:29 +02:00
pa7300lc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pacache.S parisc: speed up flush_tlb_all_local with qemu 2019-08-12 19:17:40 +02:00
parisc_ksyms.c Revert "parisc: Add assembly implementations for memset, strlen, strcpy, strncpy and strcat" 2021-09-03 10:08:16 +02:00
patch.c parisc: add spinlock to patch function 2019-06-08 12:56:26 +02:00
pci-dma.c dma-direct: handle DMA_ATTR_NON_CONSISTENT in common code 2019-06-25 14:27:58 +02:00
pci.c parisc: Drop comments which are already in pci.h 2019-09-05 16:41:11 +02:00
pdc_chassis.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pdc_cons.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
pdt.c mm/memory_failure: Remove unused trapno from memory_failure 2018-01-23 12:17:42 -06:00
perf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
perf_asm.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
perf_images.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
process.c parisc: Implement copy_thread_tls 2020-01-14 20:08:34 +01:00
processor.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
ptrace.c parisc: Ensure userspace privilege for ptraced processes in regset functions 2019-07-17 23:11:27 +02:00
real2.S parisc: Fix and improve kernel stack unwinding 2018-08-13 09:54:17 +02:00
relocate_kernel.S parisc: add kexec syscall support 2019-09-08 15:37:04 +02:00
setup.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
signal.c parisc: fix crash with signals and alloca 2021-09-22 12:26:37 +02:00
signal32.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
signal32.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
smp.c parisc: add __pdc_cpu_rendezvous() 2019-09-08 15:19:58 +02:00
stacktrace.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
sys_parisc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sys_parisc32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
syscall.S Revert "parisc: Revert "Release spinlocks using ordered store"" 2020-08-19 08:16:26 +02:00
time.c parisc: Use __ro_after_init in time.c 2019-05-10 21:00:45 +02:00
topology.c parisc: Add CPU topology support 2017-11-17 15:27:22 +01:00
traps.c parisc: trigger die notifier chain in parisc_terminate() 2019-08-03 08:56:57 +02:00
unaligned.c Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
unwind.c parisc: Use __ro_after_init in unwind.c 2019-05-10 21:00:45 +02:00
vmlinux.lds.S parisc: add dynamic ftrace 2019-06-08 12:56:29 +02:00