parisc: Fix random data corruption from exception handler
authorHelge Deller <deller@gmx.de>
Sat, 20 Jan 2024 14:29:27 +0000 (15:29 +0100)
committerHelge Deller <deller@gmx.de>
Tue, 30 Jan 2024 16:18:58 +0000 (17:18 +0100)
commit8b1d72395635af45410b66cc4c4ab37a12c4a831
treeb90475824e70fc33d4b97d2eb2eb81c4b520b7de
parent20e08a720cc526dacc0678067ffc81613aa738ca
parisc: Fix random data corruption from exception handler

The current exception handler implementation, which assists when accessing
user space memory, may exhibit random data corruption if the compiler decides
to use a different register than the specified register %r29 (defined in
ASM_EXCEPTIONTABLE_REG) for the error code. If the compiler choose another
register, the fault handler will nevertheless store -EFAULT into %r29 and thus
trash whatever this register is used for.
Looking at the assembly I found that this happens sometimes in emulate_ldd().

To solve the issue, the easiest solution would be if it somehow is
possible to tell the fault handler which register is used to hold the error
code. Using %0 or %1 in the inline assembly is not posssible as it will show
up as e.g. %r29 (with the "%r" prefix), which the GNU assembler can not
convert to an integer.

This patch takes another, better and more flexible approach:
We extend the __ex_table (which is out of the execution path) by one 32-word.
In this word we tell the compiler to insert the assembler instruction
"or %r0,%r0,%reg", where %reg references the register which the compiler
choosed for the error return code.
In case of an access failure, the fault handler finds the __ex_table entry and
can examine the opcode. The used register is encoded in the lowest 5 bits, and
the fault handler can then store -EFAULT into this register.

Since we extend the __ex_table to 3 words we can't use the BUILDTIME_TABLE_SORT
config option any longer.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: <stable@vger.kernel.org> # v6.0+
arch/parisc/Kconfig
arch/parisc/include/asm/assembly.h
arch/parisc/include/asm/extable.h [new file with mode: 0644]
arch/parisc/include/asm/special_insns.h
arch/parisc/include/asm/uaccess.h
arch/parisc/kernel/cache.c
arch/parisc/kernel/unaligned.c
arch/parisc/mm/fault.c