Skip to content

Commit fdbaa79

Browse files
committed
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: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/lkml/20200912110820.597135-9-keescook@chromium.org Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent 78f2662 commit fdbaa79

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,20 +1821,21 @@ TEST_F(TRACE_poke, getpid_runs_normally)
18211821
} while (0)
18221822
#endif
18231823

1824-
/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
1824+
/*
1825+
* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
18251826
* architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux).
18261827
*/
18271828
#if defined(__x86_64__) || defined(__i386__) || defined(__mips__)
1828-
#define HAVE_GETREGS
1829+
# define ARCH_GETREGS(_regs) ptrace(PTRACE_GETREGS, tracee, 0, &(_regs))
1830+
# define ARCH_SETREGS(_regs) ptrace(PTRACE_SETREGS, tracee, 0, &(_regs))
18291831
#endif
18301832

18311833
/* Architecture-specific syscall fetching routine. */
18321834
int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
18331835
{
18341836
ARCH_REGS regs;
1835-
#ifdef HAVE_GETREGS
1836-
EXPECT_EQ(0, ptrace(PTRACE_GETREGS, tracee, 0, &regs)) {
1837-
TH_LOG("PTRACE_GETREGS failed");
1837+
#ifdef ARCH_GETREGS
1838+
EXPECT_EQ(0, ARCH_GETREGS(regs)) {
18381839
return -1;
18391840
}
18401841
#else
@@ -1855,17 +1856,19 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
18551856
void change_syscall(struct __test_metadata *_metadata,
18561857
pid_t tracee, int syscall, int result)
18571858
{
1858-
int ret;
18591859
ARCH_REGS regs;
1860-
#ifdef HAVE_GETREGS
1861-
ret = ptrace(PTRACE_GETREGS, tracee, 0, &regs);
1860+
#ifdef ARCH_GETREGS
1861+
EXPECT_EQ(0, ARCH_GETREGS(regs)) {
1862+
return;
1863+
}
18621864
#else
1865+
int ret;
18631866
struct iovec iov;
18641867
iov.iov_base = &regs;
18651868
iov.iov_len = sizeof(regs);
18661869
ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
1867-
#endif
18681870
EXPECT_EQ(0, ret);
1871+
#endif
18691872

18701873
SYSCALL_NUM_SET(regs, syscall);
18711874

@@ -1878,14 +1881,14 @@ void change_syscall(struct __test_metadata *_metadata,
18781881
#endif
18791882

18801883
/* Flush any register changes made. */
1881-
#ifdef HAVE_GETREGS
1882-
ret = ptrace(PTRACE_SETREGS, tracee, 0, &regs);
1884+
#ifdef ARCH_SETREGS
1885+
EXPECT_EQ(0, ARCH_SETREGS(regs));
18831886
#else
18841887
iov.iov_base = &regs;
18851888
iov.iov_len = sizeof(regs);
18861889
ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov);
1887-
#endif
18881890
EXPECT_EQ(0, ret);
1891+
#endif
18891892
}
18901893

18911894
void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee,

0 commit comments

Comments
 (0)