]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
3b176b8c91603052a240805c8f900e3484ed765a
[thirdparty/kernel/stable-queue.git] /
1 From 5665bc35c1ed917ac8fd06cb651317bb47a65b10 Mon Sep 17 00:00:00 2001
2 From: Nicholas Piggin <npiggin@gmail.com>
3 Date: Thu, 20 May 2021 21:19:30 +1000
4 Subject: powerpc/64s/syscall: Use pt_regs.trap to distinguish syscall ABI difference between sc and scv syscalls
5
6 From: Nicholas Piggin <npiggin@gmail.com>
7
8 commit 5665bc35c1ed917ac8fd06cb651317bb47a65b10 upstream.
9
10 The sc and scv 0 system calls have different ABI conventions, and
11 ptracers need to know which system call type is being used if they want
12 to look at the syscall registers.
13
14 Document that pt_regs.trap can be used for this, and fix one in-tree user
15 to work with scv 0 syscalls.
16
17 Fixes: 7fa95f9adaee ("powerpc/64s: system call support for scv/rfscv instructions")
18 Cc: stable@vger.kernel.org # v5.9+
19 Reported-by: "Dmitry V. Levin" <ldv@altlinux.org>
20 Suggested-by: "Dmitry V. Levin" <ldv@altlinux.org>
21 Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
22 Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
23 Link: https://lore.kernel.org/r/20210520111931.2597127-1-npiggin@gmail.com
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 Documentation/powerpc/syscall64-abi.rst | 10 +++++++++
27 tools/testing/selftests/seccomp/seccomp_bpf.c | 27 +++++++++++++++++---------
28 2 files changed, 28 insertions(+), 9 deletions(-)
29
30 --- a/Documentation/powerpc/syscall64-abi.rst
31 +++ b/Documentation/powerpc/syscall64-abi.rst
32 @@ -96,6 +96,16 @@ auxiliary vector.
33
34 scv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC.
35
36 +ptrace
37 +------
38 +When ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains
39 +the system call type that can be used to distinguish between sc and scv 0
40 +system calls, and the different register conventions can be accounted for.
41 +
42 +If the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was
43 +performed with the sc instruction, if it is 0x3000 then the system call was
44 +performed with the scv 0 instruction.
45 +
46 vsyscall
47 ========
48
49 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
50 +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
51 @@ -1753,16 +1753,25 @@ TEST_F(TRACE_poke, getpid_runs_normally)
52 # define SYSCALL_RET_SET(_regs, _val) \
53 do { \
54 typeof(_val) _result = (_val); \
55 - /* \
56 - * A syscall error is signaled by CR0 SO bit \
57 - * and the code is stored as a positive value. \
58 - */ \
59 - if (_result < 0) { \
60 - SYSCALL_RET(_regs) = -_result; \
61 - (_regs).ccr |= 0x10000000; \
62 - } else { \
63 + if ((_regs.trap & 0xfff0) == 0x3000) { \
64 + /* \
65 + * scv 0 system call uses -ve result \
66 + * for error, so no need to adjust. \
67 + */ \
68 SYSCALL_RET(_regs) = _result; \
69 - (_regs).ccr &= ~0x10000000; \
70 + } else { \
71 + /* \
72 + * A syscall error is signaled by the \
73 + * CR0 SO bit and the code is stored as \
74 + * a positive value. \
75 + */ \
76 + if (_result < 0) { \
77 + SYSCALL_RET(_regs) = -_result; \
78 + (_regs).ccr |= 0x10000000; \
79 + } else { \
80 + SYSCALL_RET(_regs) = _result; \
81 + (_regs).ccr &= ~0x10000000; \
82 + } \
83 } \
84 } while (0)
85 # define SYSCALL_RET_SET_ON_PTRACE_EXIT