Skip to content

Commit 6baaade

Browse files
Michael Schmitzgeertu
authored andcommitted
m68k: Add kernel seccomp support
Add secure_computing() call to syscall_trace_enter to actually filter system calls. Add necessary arch Kconfig options, define TIF_SECCOMP trace flag and provide basic seccomp filter support in asm/syscall.h syscall_get_nr currently uses the syscall nr stored in orig_d0 because we change d0 to a default return code before starting a syscall trace. This may be inconsistent with syscall_rollback copying orig_d0 to d0 (which we never check upon return from trace). We use d0 for the return code from syscall_trace_enter in entry.S currently, and could perhaps expand that to store a new syscall number returned by the seccomp filter before executing the syscall. This clearly needs some discussion. seccomp_bpf self test on ARAnyM passes 81 out of 94 tests. Signed-off-by: Michael Schmitz <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 2ca8a1d commit 6baaade

File tree

7 files changed

+81
-2
lines changed

7 files changed

+81
-2
lines changed

Documentation/features/seccomp/seccomp-filter/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
| hexagon: | TODO |
1515
| ia64: | TODO |
1616
| loongarch: | ok |
17-
| m68k: | TODO |
17+
| m68k: | ok |
1818
| microblaze: | TODO |
1919
| mips: | ok |
2020
| nios2: | TODO |

arch/m68k/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ config M68K
1818
select GENERIC_CPU_DEVICES
1919
select GENERIC_IOMAP
2020
select GENERIC_IRQ_SHOW
21+
select HAVE_ARCH_SECCOMP
22+
select HAVE_ARCH_SECCOMP_FILTER
2123
select HAVE_ASM_MODVERSIONS
2224
select HAVE_DEBUG_BUGVERBOSE
2325
select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_HAS_NO_UNALIGNED

arch/m68k/include/asm/seccomp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef _ASM_SECCOMP_H
3+
#define _ASM_SECCOMP_H
4+
5+
#include <asm-generic/seccomp.h>
6+
7+
#define SECCOMP_ARCH_NATIVE AUDIT_ARCH_M68K
8+
#define SECCOMP_ARCH_NATIVE_NR NR_syscalls
9+
#define SECCOMP_ARCH_NATIVE_NAME "m68k"
10+
11+
#endif /* _ASM_SECCOMP_H */

arch/m68k/include/asm/syscall.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,63 @@
44

55
#include <uapi/linux/audit.h>
66

7+
#include <asm/unistd.h>
8+
9+
extern const unsigned long sys_call_table[];
10+
11+
static inline int syscall_get_nr(struct task_struct *task,
12+
struct pt_regs *regs)
13+
{
14+
return regs->orig_d0;
15+
}
16+
17+
static inline void syscall_rollback(struct task_struct *task,
18+
struct pt_regs *regs)
19+
{
20+
regs->d0 = regs->orig_d0;
21+
}
22+
23+
static inline long syscall_get_error(struct task_struct *task,
24+
struct pt_regs *regs)
25+
{
26+
unsigned long error = regs->d0;
27+
28+
return IS_ERR_VALUE(error) ? error : 0;
29+
}
30+
31+
static inline long syscall_get_return_value(struct task_struct *task,
32+
struct pt_regs *regs)
33+
{
34+
return regs->d0;
35+
}
36+
37+
static inline void syscall_set_return_value(struct task_struct *task,
38+
struct pt_regs *regs,
39+
int error, long val)
40+
{
41+
regs->d0 = (long)error ?: val;
42+
}
43+
44+
static inline void syscall_get_arguments(struct task_struct *task,
45+
struct pt_regs *regs,
46+
unsigned long *args)
47+
{
48+
args[0] = regs->orig_d0;
49+
args++;
50+
51+
memcpy(args, &regs->d1, 5 * sizeof(args[0]));
52+
}
53+
54+
static inline void syscall_set_arguments(struct task_struct *task,
55+
struct pt_regs *regs,
56+
unsigned long *args)
57+
{
58+
regs->orig_d0 = args[0];
59+
args++;
60+
61+
memcpy(&regs->d1, args, 5 * sizeof(args[0]));
62+
}
63+
764
static inline int syscall_get_arch(struct task_struct *task)
865
{
966
return AUDIT_ARCH_M68K;

arch/m68k/include/asm/thread_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static inline struct thread_info *current_thread_info(void)
6161
#define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6262
#define TIF_SIGPENDING 6 /* signal pending */
6363
#define TIF_NEED_RESCHED 7 /* rescheduling necessary */
64+
#define TIF_SECCOMP 13 /* seccomp syscall filtering active */
6465
#define TIF_DELAYED_TRACE 14 /* single step a syscall */
6566
#define TIF_SYSCALL_TRACE 15 /* syscall trace active */
6667
#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
@@ -69,6 +70,7 @@ static inline struct thread_info *current_thread_info(void)
6970
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
7071
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
7172
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
73+
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
7274
#define _TIF_DELAYED_TRACE (1 << TIF_DELAYED_TRACE)
7375
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
7476
#define _TIF_MEMDIE (1 << TIF_MEMDIE)

arch/m68k/kernel/entry.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ ENTRY(system_call)
214214
| syscall trace?
215215
tstb %a1@(TINFO_FLAGS+2)
216216
jmi do_trace_entry
217+
| seccomp filter active?
218+
btst #5,%a1@(TINFO_FLAGS+2)
219+
bnes do_trace_entry
217220
cmpl #NR_syscalls,%d0
218221
jcc badsys
219222
syscall:

arch/m68k/kernel/ptrace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <linux/signal.h>
2222
#include <linux/regset.h>
2323
#include <linux/elf.h>
24-
24+
#include <linux/seccomp.h>
2525
#include <linux/uaccess.h>
2626
#include <asm/page.h>
2727
#include <asm/processor.h>
@@ -278,6 +278,10 @@ asmlinkage int syscall_trace_enter(void)
278278

279279
if (test_thread_flag(TIF_SYSCALL_TRACE))
280280
ret = ptrace_report_syscall_entry(task_pt_regs(current));
281+
282+
if (secure_computing() == -1)
283+
return -1;
284+
281285
return ret;
282286
}
283287

0 commit comments

Comments
 (0)