Skip to content

Commit a39caac

Browse files
committed
selftests/seccomp: powerpc: Set syscall return during ptrace syscall exit
Some archs (like powerpc) only support changing the return code during syscall exit when ptrace is used. Test entry vs exit phases for which portions of the syscall number and return values need to be set at which different phases. For non-powerpc, all changes are made during ptrace syscall entry, as before. For powerpc, the syscall number is changed at ptrace syscall entry and the syscall return value is changed on ptrace syscall exit. Reported-by: Thadeu Lima de Souza Cascardo <[email protected]> Suggested-by: Thadeu Lima de Souza Cascardo <[email protected]> Link: https://lore.kernel.org/linux-kselftest/[email protected]/ Fixes: 58d0a86 ("seccomp: add tests for ptrace hole") Acked-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/lkml/20200921075300.7iylzof2w5vrutah@wittgenstein/ Signed-off-by: Kees Cook <[email protected]>
1 parent bef71f8 commit a39caac

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,7 @@ TEST_F(TRACE_poke, getpid_runs_normally)
17651765
(_regs).ccr &= ~0x10000000; \
17661766
} \
17671767
} while (0)
1768+
# define SYSCALL_RET_SET_ON_PTRACE_EXIT
17681769
#elif defined(__s390__)
17691770
# define ARCH_REGS s390_regs
17701771
# define SYSCALL_NUM(_regs) (_regs).gprs[2]
@@ -1853,6 +1854,18 @@ TEST_F(TRACE_poke, getpid_runs_normally)
18531854
} while (0)
18541855
#endif
18551856

1857+
/*
1858+
* Some architectures (e.g. powerpc) can only set syscall
1859+
* return values on syscall exit during ptrace.
1860+
*/
1861+
const bool ptrace_entry_set_syscall_nr = true;
1862+
const bool ptrace_entry_set_syscall_ret =
1863+
#ifndef SYSCALL_RET_SET_ON_PTRACE_EXIT
1864+
true;
1865+
#else
1866+
false;
1867+
#endif
1868+
18561869
/*
18571870
* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
18581871
* architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux).
@@ -2006,11 +2019,15 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
20062019
*/
20072020
if (entry)
20082021
self->syscall_nr = get_syscall(_metadata, tracee);
2009-
else
2010-
return;
20112022

2012-
syscall_nr = &syscall_nr_val;
2013-
syscall_ret = &syscall_ret_val;
2023+
/*
2024+
* Depending on the architecture's syscall setting abilities, we
2025+
* pick which things to set during this phase (entry or exit).
2026+
*/
2027+
if (entry == ptrace_entry_set_syscall_nr)
2028+
syscall_nr = &syscall_nr_val;
2029+
if (entry == ptrace_entry_set_syscall_ret)
2030+
syscall_ret = &syscall_ret_val;
20142031

20152032
/* Now handle the actual rewriting cases. */
20162033
switch (self->syscall_nr) {

0 commit comments

Comments
 (0)