Skip to content

Commit 73d6eb4

Browse files
iii-ihcahca
authored andcommitted
s390: enable HAVE_FUNCTION_ERROR_INJECTION
This kernel feature is required for enabling BPF_KPROBE_OVERRIDE. Define override_function_with_return() and regs_set_return_value() functions, and fix compile errors in syscall_wrapper.h. Signed-off-by: Ilya Leoshkevich <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 4631f3c commit 73d6eb4

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ config S390
145145
select HAVE_EFFICIENT_UNALIGNED_ACCESS
146146
select HAVE_FENTRY
147147
select HAVE_FTRACE_MCOUNT_RECORD
148+
select HAVE_FUNCTION_ERROR_INJECTION
148149
select HAVE_FUNCTION_GRAPH_TRACER
149150
select HAVE_FUNCTION_TRACER
150151
select HAVE_FUTEX_CMPXCHG if FUTEX

arch/s390/include/asm/ptrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,10 @@ static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
184184
return regs->gprs[15];
185185
}
186186

187+
static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
188+
{
189+
regs->gprs[2] = rc;
190+
}
191+
187192
#endif /* __ASSEMBLY__ */
188193
#endif /* _S390_PTRACE_H */

arch/s390/include/asm/syscall_wrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
})
3131

3232
#define __S390_SYS_STUBx(x, name, ...) \
33-
asmlinkage long __s390_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
33+
asmlinkage long __s390_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
3434
ALLOW_ERROR_INJECTION(__s390_sys##name, ERRNO); \
3535
asmlinkage long __s390_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
3636
{ \
@@ -46,7 +46,7 @@
4646
#define COMPAT_SYSCALL_DEFINE0(sname) \
4747
SYSCALL_METADATA(_##sname, 0); \
4848
asmlinkage long __s390_compat_sys_##sname(void); \
49-
ALLOW_ERROR_INJECTION(__s390_compat__sys_##sname, ERRNO); \
49+
ALLOW_ERROR_INJECTION(__s390_compat_sys_##sname, ERRNO); \
5050
asmlinkage long __s390_compat_sys_##sname(void)
5151

5252
#define SYSCALL_DEFINE0(sname) \
@@ -72,7 +72,7 @@
7272
asmlinkage long __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
7373
asmlinkage long __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
7474
__attribute__((alias(__stringify(__se_compat_sys##name)))); \
75-
ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
75+
ALLOW_ERROR_INJECTION(__s390_compat_sys##name, ERRNO); \
7676
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
7777
asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
7878
asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \

arch/s390/lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ KASAN_SANITIZE_uaccess.o := n
1414

1515
obj-$(CONFIG_S390_UNWIND_SELFTEST) += test_unwind.o
1616
CFLAGS_test_unwind.o += -fno-optimize-sibling-calls
17+
18+
lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o

arch/s390/lib/error-inject.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
#include <asm/ptrace.h>
3+
#include <linux/error-injection.h>
4+
#include <linux/kprobes.h>
5+
6+
void override_function_with_return(struct pt_regs *regs)
7+
{
8+
/*
9+
* Emulate 'br 14'. 'regs' is captured by kprobes on entry to some
10+
* kernel function.
11+
*/
12+
regs->psw.addr = regs->gprs[14];
13+
}
14+
NOKPROBE_SYMBOL(override_function_with_return);

0 commit comments

Comments
 (0)