]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.163/arm-8781-1-fix-thumb-2-syscall-return-for-binutils-2.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.163 / arm-8781-1-fix-thumb-2-syscall-return-for-binutils-2.patch
1 From a828b79637a2608b9872e1a283ef12436dce0fc4 Mon Sep 17 00:00:00 2001
2 From: Vincent Whitchurch <vincent.whitchurch@axis.com>
3 Date: Fri, 13 Jul 2018 11:12:22 +0100
4 Subject: ARM: 8781/1: Fix Thumb-2 syscall return for binutils 2.29+
5
6 [ Upstream commit afc9f65e01cd114cb2cedf544d22239116ce0cc6 ]
7
8 When building the kernel as Thumb-2 with binutils 2.29 or newer, if the
9 assembler has seen the .type directive (via ENDPROC()) for a symbol, it
10 automatically handles the setting of the lowest bit when the symbol is
11 used with ADR. The badr macro on the other hand handles this lowest bit
12 manually. This leads to a jump to a wrong address in the wrong state
13 in the syscall return path:
14
15 Internal error: Oops - undefined instruction: 0 [#2] SMP THUMB2
16 Modules linked in:
17 CPU: 0 PID: 652 Comm: modprobe Tainted: G D 4.18.0-rc3+ #8
18 PC is at ret_fast_syscall+0x4/0x62
19 LR is at sys_brk+0x109/0x128
20 pc : [<80101004>] lr : [<801c8a35>] psr: 60000013
21 Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
22 Control: 50c5387d Table: 9e82006a DAC: 00000051
23 Process modprobe (pid: 652, stack limit = 0x(ptrval))
24
25 80101000 <ret_fast_syscall>:
26 80101000: b672 cpsid i
27 80101002: f8d9 2008 ldr.w r2, [r9, #8]
28 80101006: f1b2 4ffe cmp.w r2, #2130706432 ; 0x7f000000
29
30 80101184 <local_restart>:
31 80101184: f8d9 a000 ldr.w sl, [r9]
32 80101188: e92d 0030 stmdb sp!, {r4, r5}
33 8010118c: f01a 0ff0 tst.w sl, #240 ; 0xf0
34 80101190: d117 bne.n 801011c2 <__sys_trace>
35 80101192: 46ba mov sl, r7
36 80101194: f5ba 7fc8 cmp.w sl, #400 ; 0x190
37 80101198: bf28 it cs
38 8010119a: f04f 0a00 movcs.w sl, #0
39 8010119e: f3af 8014 nop.w {20}
40 801011a2: f2af 1ea2 subw lr, pc, #418 ; 0x1a2
41
42 To fix this, add a new symbol name which doesn't have ENDPROC used on it
43 and use that with badr. We can't remove the badr usage since that would
44 would cause breakage with older binutils.
45
46 Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
47 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
48 Signed-off-by: Sasha Levin <sashal@kernel.org>
49 ---
50 arch/arm/kernel/entry-common.S | 4 +++-
51 1 file changed, 3 insertions(+), 1 deletion(-)
52
53 --- a/arch/arm/kernel/entry-common.S
54 +++ b/arch/arm/kernel/entry-common.S
55 @@ -32,6 +32,7 @@
56 * features make this path too inefficient.
57 */
58 ret_fast_syscall:
59 +__ret_fast_syscall:
60 UNWIND(.fnstart )
61 UNWIND(.cantunwind )
62 disable_irq_notrace @ disable interrupts
63 @@ -57,6 +58,7 @@ fast_work_pending:
64 * r0 first to avoid needing to save registers around each C function call.
65 */
66 ret_fast_syscall:
67 +__ret_fast_syscall:
68 UNWIND(.fnstart )
69 UNWIND(.cantunwind )
70 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
71 @@ -223,7 +225,7 @@ local_restart:
72 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
73 bne __sys_trace
74
75 - invoke_syscall tbl, scno, r10, ret_fast_syscall
76 + invoke_syscall tbl, scno, r10, __ret_fast_syscall
77
78 add r1, sp, #S_OFF
79 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)