| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Access to user system call parameters and results |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2008 Red Hat, Inc. All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This copyrighted material is made available to anyone wishing to use, |
|---|
| 7 | | - * modify, copy, or redistribute it subject to the terms and conditions |
|---|
| 8 | | - * of the GNU General Public License v.2. |
|---|
| 9 | 6 | * |
|---|
| 10 | 7 | * See asm-generic/syscall.h for descriptions of what we must do here. |
|---|
| 11 | 8 | */ |
|---|
| .. | .. |
|---|
| 18 | 15 | #include <linux/thread_info.h> |
|---|
| 19 | 16 | |
|---|
| 20 | 17 | /* ftrace syscalls requires exporting the sys_call_table */ |
|---|
| 21 | | -#ifdef CONFIG_FTRACE_SYSCALLS |
|---|
| 22 | 18 | extern const unsigned long sys_call_table[]; |
|---|
| 23 | | -#endif /* CONFIG_FTRACE_SYSCALLS */ |
|---|
| 19 | +extern const unsigned long compat_sys_call_table[]; |
|---|
| 24 | 20 | |
|---|
| 25 | 21 | static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) |
|---|
| 26 | 22 | { |
|---|
| .. | .. |
|---|
| 30 | 26 | * This is important for seccomp so that compat tasks can set r0 = -1 |
|---|
| 31 | 27 | * to reject the syscall. |
|---|
| 32 | 28 | */ |
|---|
| 33 | | - return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1; |
|---|
| 29 | + if (trap_is_syscall(regs)) |
|---|
| 30 | + return regs->gpr[0]; |
|---|
| 31 | + else |
|---|
| 32 | + return -1; |
|---|
| 34 | 33 | } |
|---|
| 35 | 34 | |
|---|
| 36 | 35 | static inline void syscall_rollback(struct task_struct *task, |
|---|
| 37 | 36 | struct pt_regs *regs) |
|---|
| 38 | 37 | { |
|---|
| 39 | 38 | regs->gpr[3] = regs->orig_gpr3; |
|---|
| 39 | +} |
|---|
| 40 | + |
|---|
| 41 | +static inline long syscall_get_error(struct task_struct *task, |
|---|
| 42 | + struct pt_regs *regs) |
|---|
| 43 | +{ |
|---|
| 44 | + if (trap_is_scv(regs)) { |
|---|
| 45 | + unsigned long error = regs->gpr[3]; |
|---|
| 46 | + |
|---|
| 47 | + return IS_ERR_VALUE(error) ? error : 0; |
|---|
| 48 | + } else { |
|---|
| 49 | + /* |
|---|
| 50 | + * If the system call failed, |
|---|
| 51 | + * regs->gpr[3] contains a positive ERRORCODE. |
|---|
| 52 | + */ |
|---|
| 53 | + return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0; |
|---|
| 54 | + } |
|---|
| 40 | 55 | } |
|---|
| 41 | 56 | |
|---|
| 42 | 57 | static inline long syscall_get_return_value(struct task_struct *task, |
|---|
| .. | .. |
|---|
| 49 | 64 | struct pt_regs *regs, |
|---|
| 50 | 65 | int error, long val) |
|---|
| 51 | 66 | { |
|---|
| 52 | | - /* |
|---|
| 53 | | - * In the general case it's not obvious that we must deal with CCR |
|---|
| 54 | | - * here, as the syscall exit path will also do that for us. However |
|---|
| 55 | | - * there are some places, eg. the signal code, which check ccr to |
|---|
| 56 | | - * decide if the value in r3 is actually an error. |
|---|
| 57 | | - */ |
|---|
| 58 | | - if (error) { |
|---|
| 59 | | - regs->ccr |= 0x10000000L; |
|---|
| 60 | | - regs->gpr[3] = error; |
|---|
| 67 | + if (trap_is_scv(regs)) { |
|---|
| 68 | + regs->gpr[3] = (long) error ?: val; |
|---|
| 61 | 69 | } else { |
|---|
| 62 | | - regs->ccr &= ~0x10000000L; |
|---|
| 63 | | - regs->gpr[3] = val; |
|---|
| 70 | + /* |
|---|
| 71 | + * In the general case it's not obvious that we must deal with |
|---|
| 72 | + * CCR here, as the syscall exit path will also do that for us. |
|---|
| 73 | + * However there are some places, eg. the signal code, which |
|---|
| 74 | + * check ccr to decide if the value in r3 is actually an error. |
|---|
| 75 | + */ |
|---|
| 76 | + if (error) { |
|---|
| 77 | + regs->ccr |= 0x10000000L; |
|---|
| 78 | + regs->gpr[3] = error; |
|---|
| 79 | + } else { |
|---|
| 80 | + regs->ccr &= ~0x10000000L; |
|---|
| 81 | + regs->gpr[3] = val; |
|---|
| 82 | + } |
|---|
| 64 | 83 | } |
|---|
| 65 | 84 | } |
|---|
| 66 | 85 | |
|---|
| 67 | 86 | static inline void syscall_get_arguments(struct task_struct *task, |
|---|
| 68 | 87 | struct pt_regs *regs, |
|---|
| 69 | | - unsigned int i, unsigned int n, |
|---|
| 70 | 88 | unsigned long *args) |
|---|
| 71 | 89 | { |
|---|
| 72 | 90 | unsigned long val, mask = -1UL; |
|---|
| 73 | | - |
|---|
| 74 | | - BUG_ON(i + n > 6); |
|---|
| 91 | + unsigned int n = 6; |
|---|
| 75 | 92 | |
|---|
| 76 | 93 | #ifdef CONFIG_COMPAT |
|---|
| 77 | 94 | if (test_tsk_thread_flag(task, TIF_32BIT)) |
|---|
| 78 | 95 | mask = 0xffffffff; |
|---|
| 79 | 96 | #endif |
|---|
| 80 | 97 | while (n--) { |
|---|
| 81 | | - if (n == 0 && i == 0) |
|---|
| 98 | + if (n == 0) |
|---|
| 82 | 99 | val = regs->orig_gpr3; |
|---|
| 83 | 100 | else |
|---|
| 84 | | - val = regs->gpr[3 + i + n]; |
|---|
| 101 | + val = regs->gpr[3 + n]; |
|---|
| 85 | 102 | |
|---|
| 86 | 103 | args[n] = val & mask; |
|---|
| 87 | 104 | } |
|---|
| .. | .. |
|---|
| 89 | 106 | |
|---|
| 90 | 107 | static inline void syscall_set_arguments(struct task_struct *task, |
|---|
| 91 | 108 | struct pt_regs *regs, |
|---|
| 92 | | - unsigned int i, unsigned int n, |
|---|
| 93 | 109 | const unsigned long *args) |
|---|
| 94 | 110 | { |
|---|
| 95 | | - BUG_ON(i + n > 6); |
|---|
| 96 | | - memcpy(®s->gpr[3 + i], args, n * sizeof(args[0])); |
|---|
| 111 | + memcpy(®s->gpr[3], args, 6 * sizeof(args[0])); |
|---|
| 97 | 112 | |
|---|
| 98 | 113 | /* Also copy the first argument into orig_gpr3 */ |
|---|
| 99 | | - if (i == 0 && n > 0) |
|---|
| 100 | | - regs->orig_gpr3 = args[0]; |
|---|
| 114 | + regs->orig_gpr3 = args[0]; |
|---|
| 101 | 115 | } |
|---|
| 102 | 116 | |
|---|
| 103 | | -static inline int syscall_get_arch(void) |
|---|
| 117 | +static inline int syscall_get_arch(struct task_struct *task) |
|---|
| 104 | 118 | { |
|---|
| 105 | | - int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64; |
|---|
| 119 | + int arch; |
|---|
| 120 | + |
|---|
| 121 | + if (IS_ENABLED(CONFIG_PPC64) && !test_tsk_thread_flag(task, TIF_32BIT)) |
|---|
| 122 | + arch = AUDIT_ARCH_PPC64; |
|---|
| 123 | + else |
|---|
| 124 | + arch = AUDIT_ARCH_PPC; |
|---|
| 125 | + |
|---|
| 106 | 126 | #ifdef __LITTLE_ENDIAN__ |
|---|
| 107 | 127 | arch |= __AUDIT_ARCH_LE; |
|---|
| 108 | 128 | #endif |
|---|