|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | +#ifndef __LINUX_ENTRYCOMMON_H |
| 3 | +#define __LINUX_ENTRYCOMMON_H |
| 4 | + |
| 5 | +#include <linux/tracehook.h> |
| 6 | +#include <linux/syscalls.h> |
| 7 | +#include <linux/seccomp.h> |
| 8 | +#include <linux/sched.h> |
| 9 | + |
| 10 | +#include <asm/entry-common.h> |
| 11 | + |
| 12 | +/* |
| 13 | + * Define dummy _TIF work flags if not defined by the architecture or for |
| 14 | + * disabled functionality. |
| 15 | + */ |
| 16 | +#ifndef _TIF_SYSCALL_EMU |
| 17 | +# define _TIF_SYSCALL_EMU (0) |
| 18 | +#endif |
| 19 | + |
| 20 | +#ifndef _TIF_SYSCALL_TRACEPOINT |
| 21 | +# define _TIF_SYSCALL_TRACEPOINT (0) |
| 22 | +#endif |
| 23 | + |
| 24 | +#ifndef _TIF_SECCOMP |
| 25 | +# define _TIF_SECCOMP (0) |
| 26 | +#endif |
| 27 | + |
| 28 | +#ifndef _TIF_SYSCALL_AUDIT |
| 29 | +# define _TIF_SYSCALL_AUDIT (0) |
| 30 | +#endif |
| 31 | + |
| 32 | +/* |
| 33 | + * TIF flags handled in syscall_enter_from_usermode() |
| 34 | + */ |
| 35 | +#ifndef ARCH_SYSCALL_ENTER_WORK |
| 36 | +# define ARCH_SYSCALL_ENTER_WORK (0) |
| 37 | +#endif |
| 38 | + |
| 39 | +#define SYSCALL_ENTER_WORK \ |
| 40 | + (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \ |
| 41 | + _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU | \ |
| 42 | + ARCH_SYSCALL_ENTER_WORK) |
| 43 | + |
| 44 | +/** |
| 45 | + * arch_check_user_regs - Architecture specific sanity check for user mode regs |
| 46 | + * @regs: Pointer to currents pt_regs |
| 47 | + * |
| 48 | + * Defaults to an empty implementation. Can be replaced by architecture |
| 49 | + * specific code. |
| 50 | + * |
| 51 | + * Invoked from syscall_enter_from_user_mode() in the non-instrumentable |
| 52 | + * section. Use __always_inline so the compiler cannot push it out of line |
| 53 | + * and make it instrumentable. |
| 54 | + */ |
| 55 | +static __always_inline void arch_check_user_regs(struct pt_regs *regs); |
| 56 | + |
| 57 | +#ifndef arch_check_user_regs |
| 58 | +static __always_inline void arch_check_user_regs(struct pt_regs *regs) {} |
| 59 | +#endif |
| 60 | + |
| 61 | +/** |
| 62 | + * arch_syscall_enter_tracehook - Wrapper around tracehook_report_syscall_entry() |
| 63 | + * @regs: Pointer to currents pt_regs |
| 64 | + * |
| 65 | + * Returns: 0 on success or an error code to skip the syscall. |
| 66 | + * |
| 67 | + * Defaults to tracehook_report_syscall_entry(). Can be replaced by |
| 68 | + * architecture specific code. |
| 69 | + * |
| 70 | + * Invoked from syscall_enter_from_user_mode() |
| 71 | + */ |
| 72 | +static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs); |
| 73 | + |
| 74 | +#ifndef arch_syscall_enter_tracehook |
| 75 | +static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs) |
| 76 | +{ |
| 77 | + return tracehook_report_syscall_entry(regs); |
| 78 | +} |
| 79 | +#endif |
| 80 | + |
| 81 | +/** |
| 82 | + * syscall_enter_from_user_mode - Check and handle work before invoking |
| 83 | + * a syscall |
| 84 | + * @regs: Pointer to currents pt_regs |
| 85 | + * @syscall: The syscall number |
| 86 | + * |
| 87 | + * Invoked from architecture specific syscall entry code with interrupts |
| 88 | + * disabled. The calling code has to be non-instrumentable. When the |
| 89 | + * function returns all state is correct and the subsequent functions can be |
| 90 | + * instrumented. |
| 91 | + * |
| 92 | + * Returns: The original or a modified syscall number |
| 93 | + * |
| 94 | + * If the returned syscall number is -1 then the syscall should be |
| 95 | + * skipped. In this case the caller may invoke syscall_set_error() or |
| 96 | + * syscall_set_return_value() first. If neither of those are called and -1 |
| 97 | + * is returned, then the syscall will fail with ENOSYS. |
| 98 | + * |
| 99 | + * The following functionality is handled here: |
| 100 | + * |
| 101 | + * 1) Establish state (lockdep, RCU (context tracking), tracing) |
| 102 | + * 2) TIF flag dependent invocations of arch_syscall_enter_tracehook(), |
| 103 | + * __secure_computing(), trace_sys_enter() |
| 104 | + * 3) Invocation of audit_syscall_entry() |
| 105 | + */ |
| 106 | +long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall); |
| 107 | + |
| 108 | +/** |
| 109 | + * irqentry_enter_from_user_mode - Establish state before invoking the irq handler |
| 110 | + * @regs: Pointer to currents pt_regs |
| 111 | + * |
| 112 | + * Invoked from architecture specific entry code with interrupts disabled. |
| 113 | + * Can only be called when the interrupt entry came from user mode. The |
| 114 | + * calling code must be non-instrumentable. When the function returns all |
| 115 | + * state is correct and the subsequent functions can be instrumented. |
| 116 | + * |
| 117 | + * The function establishes state (lockdep, RCU (context tracking), tracing) |
| 118 | + */ |
| 119 | +void irqentry_enter_from_user_mode(struct pt_regs *regs); |
| 120 | + |
| 121 | +#endif |
0 commit comments