Commit fdbaa798 authored by Kees Cook's avatar Kees Cook

selftests/seccomp: Convert HAVE_GETREG into ARCH_GETREG/ARCH_SETREG

Instead of special-casing the get/set-registers routines, move the
HAVE_GETREG logic into the new ARCH_GETREG() and ARCH_SETREG() macros.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/lkml/20200912110820.597135-9-keescook@chromium.orgAcked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 78f26627
...@@ -1821,20 +1821,21 @@ TEST_F(TRACE_poke, getpid_runs_normally) ...@@ -1821,20 +1821,21 @@ TEST_F(TRACE_poke, getpid_runs_normally)
} while (0) } while (0)
#endif #endif
/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for /*
* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
* architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux). * architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux).
*/ */
#if defined(__x86_64__) || defined(__i386__) || defined(__mips__) #if defined(__x86_64__) || defined(__i386__) || defined(__mips__)
#define HAVE_GETREGS # define ARCH_GETREGS(_regs) ptrace(PTRACE_GETREGS, tracee, 0, &(_regs))
# define ARCH_SETREGS(_regs) ptrace(PTRACE_SETREGS, tracee, 0, &(_regs))
#endif #endif
/* Architecture-specific syscall fetching routine. */ /* Architecture-specific syscall fetching routine. */
int get_syscall(struct __test_metadata *_metadata, pid_t tracee) int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
{ {
ARCH_REGS regs; ARCH_REGS regs;
#ifdef HAVE_GETREGS #ifdef ARCH_GETREGS
EXPECT_EQ(0, ptrace(PTRACE_GETREGS, tracee, 0, &regs)) { EXPECT_EQ(0, ARCH_GETREGS(regs)) {
TH_LOG("PTRACE_GETREGS failed");
return -1; return -1;
} }
#else #else
...@@ -1855,17 +1856,19 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee) ...@@ -1855,17 +1856,19 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
void change_syscall(struct __test_metadata *_metadata, void change_syscall(struct __test_metadata *_metadata,
pid_t tracee, int syscall, int result) pid_t tracee, int syscall, int result)
{ {
int ret;
ARCH_REGS regs; ARCH_REGS regs;
#ifdef HAVE_GETREGS #ifdef ARCH_GETREGS
ret = ptrace(PTRACE_GETREGS, tracee, 0, &regs); EXPECT_EQ(0, ARCH_GETREGS(regs)) {
return;
}
#else #else
int ret;
struct iovec iov; struct iovec iov;
iov.iov_base = &regs; iov.iov_base = &regs;
iov.iov_len = sizeof(regs); iov.iov_len = sizeof(regs);
ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov); ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
#endif
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
#endif
SYSCALL_NUM_SET(regs, syscall); SYSCALL_NUM_SET(regs, syscall);
...@@ -1878,14 +1881,14 @@ void change_syscall(struct __test_metadata *_metadata, ...@@ -1878,14 +1881,14 @@ void change_syscall(struct __test_metadata *_metadata,
#endif #endif
/* Flush any register changes made. */ /* Flush any register changes made. */
#ifdef HAVE_GETREGS #ifdef ARCH_SETREGS
ret = ptrace(PTRACE_SETREGS, tracee, 0, &regs); EXPECT_EQ(0, ARCH_SETREGS(regs));
#else #else
iov.iov_base = &regs; iov.iov_base = &regs;
iov.iov_len = sizeof(regs); iov.iov_len = sizeof(regs);
ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov); ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov);
#endif
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
#endif
} }
void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee, void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment