Skip to content

Commit 3cfc096

Browse files
committed
xtensa: don't allow overflow/underflow on unaligned stack
Double exceptions that happen during register window overflow/underflow are handled in the topmost stack frame, as if it was the only exception that occured. However unaligned access exception handler is special because it needs to analyze instruction that caused the exception, but the userspace instruction that triggered window exception is completely irrelevant. Unaligned data access is rather normal in the generic userspace code, but stack pointer manipulation must always be done by architecture-aware code and thus unaligned stack means a serious problem anyway. Use the default unaligned access handler that raises SIGBUS in case of unaligned access in window overflow/underflow handler. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
1 parent d1b6ba8 commit 3cfc096

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎arch/xtensa/kernel/traps.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ static dispatch_init_table_t __initdata dispatch_init_table[] = {
101101
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
102102
#ifdef CONFIG_XTENSA_UNALIGNED_USER
103103
{ EXCCAUSE_UNALIGNED, USER, fast_unaligned },
104-
#else
105-
{ EXCCAUSE_UNALIGNED, 0, do_unaligned_user },
106104
#endif
105+
{ EXCCAUSE_UNALIGNED, 0, do_unaligned_user },
107106
{ EXCCAUSE_UNALIGNED, KRNL, fast_unaligned },
108107
#endif
109108
#ifdef CONFIG_MMU
@@ -264,7 +263,6 @@ do_illegal_instruction(struct pt_regs *regs)
264263
*/
265264

266265
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
267-
#ifndef CONFIG_XTENSA_UNALIGNED_USER
268266
void
269267
do_unaligned_user (struct pt_regs *regs)
270268
{
@@ -286,7 +284,6 @@ do_unaligned_user (struct pt_regs *regs)
286284

287285
}
288286
#endif
289-
#endif
290287

291288
void
292289
do_debug(struct pt_regs *regs)

‎arch/xtensa/kernel/vectors.S‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,14 @@ _DoubleExceptionVector_WindowOverflow:
454454
s32i a0, a2, PT_DEPC
455455

456456
_DoubleExceptionVector_handle_exception:
457+
addi a0, a0, -EXCCAUSE_UNALIGNED
458+
beqz a0, 2f
457459
addx4 a0, a0, a3
458-
l32i a0, a0, EXC_TABLE_FAST_USER
460+
l32i a0, a0, EXC_TABLE_FAST_USER + 4 * EXCCAUSE_UNALIGNED
461+
xsr a3, excsave1
462+
jx a0
463+
2:
464+
movi a0, user_exception
459465
xsr a3, excsave1
460466
jx a0
461467

‎arch/xtensa/kernel/vmlinux.lds.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ SECTIONS
269269
.UserExceptionVector.literal)
270270
SECTION_VECTOR (_DoubleExceptionVector_literal,
271271
.DoubleExceptionVector.literal,
272-
DOUBLEEXC_VECTOR_VADDR - 40,
272+
DOUBLEEXC_VECTOR_VADDR - 48,
273273
SIZEOF(.UserExceptionVector.text),
274274
.UserExceptionVector.text)
275275
SECTION_VECTOR (_DoubleExceptionVector_text,
276276
.DoubleExceptionVector.text,
277277
DOUBLEEXC_VECTOR_VADDR,
278-
40,
278+
48,
279279
.DoubleExceptionVector.literal)
280280

281281
. = (LOADADDR( .DoubleExceptionVector.text ) + SIZEOF( .DoubleExceptionVector.text ) + 3) & ~ 3;

0 commit comments

Comments
 (0)