Skip to content

Commit 0bb605c

Browse files
Michael KarcherRich Felker
authored andcommitted
sh: Add SECCOMP_FILTER
Port sh to use the new SECCOMP_FILTER code. Signed-off-by: Michael Karcher <[email protected]> Tested-by: John Paul Adrian Glaubitz <[email protected]> Signed-off-by: Rich Felker <[email protected]>
1 parent 9d2ec8f commit 0bb605c

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

arch/sh/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ config SUPERH
2828
select GUP_GET_PTE_LOW_HIGH if X2TLB
2929
select HAVE_ARCH_AUDITSYSCALL
3030
select HAVE_ARCH_KGDB
31+
select HAVE_ARCH_SECCOMP_FILTER
3132
select HAVE_ARCH_TRACEHOOK
3233
select HAVE_COPY_THREAD_TLS
3334
select HAVE_DEBUG_BUGVERBOSE

arch/sh/kernel/entry-common.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ syscall_trace_entry:
368368
mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
369369
jsr @r11 ! superior (will chomp R[0-7])
370370
nop
371+
cmp/eq #-1, r0
372+
bt syscall_exit
371373
mov.l r0, @(OFF_R0,r15) ! Save return value
372374
! Reload R0-R4 from kernel stack, where the
373375
! parent may have modified them using

arch/sh/kernel/ptrace_32.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
485485
{
486486
long ret = 0;
487487

488-
secure_computing_strict(regs->regs[0]);
489-
490488
if (test_thread_flag(TIF_SYSCALL_TRACE) &&
491489
tracehook_report_syscall_entry(regs))
492490
/*
@@ -496,6 +494,9 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
496494
*/
497495
ret = -1L;
498496

497+
if (secure_computing() == -1)
498+
return -1;
499+
499500
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
500501
trace_sys_enter(regs, regs->regs[0]);
501502

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct seccomp_data {
122122
# define __NR_seccomp 358
123123
# elif defined(__s390__)
124124
# define __NR_seccomp 348
125+
# elif defined(__sh__)
126+
# define __NR_seccomp 372
125127
# else
126128
# warning "seccomp syscall number unknown for this architecture"
127129
# define __NR_seccomp 0xffff
@@ -1622,6 +1624,10 @@ TEST_F(TRACE_poke, getpid_runs_normally)
16221624
# define SYSCALL_SYSCALL_NUM regs[4]
16231625
# define SYSCALL_RET regs[2]
16241626
# define SYSCALL_NUM_RET_SHARE_REG
1627+
#elif defined(__sh__)
1628+
# define ARCH_REGS struct pt_regs
1629+
# define SYSCALL_NUM gpr[3]
1630+
# define SYSCALL_RET gpr[0]
16251631
#else
16261632
# error "Do not know how to find your architecture's registers and syscalls"
16271633
#endif
@@ -1693,7 +1699,7 @@ void change_syscall(struct __test_metadata *_metadata,
16931699
EXPECT_EQ(0, ret) {}
16941700

16951701
#if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
1696-
defined(__s390__) || defined(__hppa__) || defined(__riscv)
1702+
defined(__s390__) || defined(__hppa__) || defined(__riscv) || defined(__sh__)
16971703
{
16981704
regs.SYSCALL_NUM = syscall;
16991705
}

0 commit comments

Comments
 (0)