Skip to content

Commit dc2ad16

Browse files
committed
selftests/seccomp: Convert REGSET calls into ARCH_GETREG/ARCH_SETREG
Consolidate the REGSET logic into the new ARCH_GETREG() and ARCH_SETREG() macros, avoiding more #ifdef code in function bodies. Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/lkml/20200912110820.597135-10-keescook@chromium.org Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent fdbaa79 commit dc2ad16

1 file changed

Lines changed: 15 additions & 27 deletions

File tree

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,26 +1828,29 @@ TEST_F(TRACE_poke, getpid_runs_normally)
18281828
#if defined(__x86_64__) || defined(__i386__) || defined(__mips__)
18291829
# define ARCH_GETREGS(_regs) ptrace(PTRACE_GETREGS, tracee, 0, &(_regs))
18301830
# define ARCH_SETREGS(_regs) ptrace(PTRACE_SETREGS, tracee, 0, &(_regs))
1831+
#else
1832+
# define ARCH_GETREGS(_regs) ({ \
1833+
struct iovec __v; \
1834+
__v.iov_base = &(_regs); \
1835+
__v.iov_len = sizeof(_regs); \
1836+
ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &__v); \
1837+
})
1838+
# define ARCH_SETREGS(_regs) ({ \
1839+
struct iovec __v; \
1840+
__v.iov_base = &(_regs); \
1841+
__v.iov_len = sizeof(_regs); \
1842+
ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &__v); \
1843+
})
18311844
#endif
18321845

18331846
/* Architecture-specific syscall fetching routine. */
18341847
int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
18351848
{
18361849
ARCH_REGS regs;
1837-
#ifdef ARCH_GETREGS
1838-
EXPECT_EQ(0, ARCH_GETREGS(regs)) {
1839-
return -1;
1840-
}
1841-
#else
1842-
struct iovec iov;
18431850

1844-
iov.iov_base = &regs;
1845-
iov.iov_len = sizeof(regs);
1846-
EXPECT_EQ(0, ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov)) {
1847-
TH_LOG("PTRACE_GETREGSET failed");
1851+
EXPECT_EQ(0, ARCH_GETREGS(regs)) {
18481852
return -1;
18491853
}
1850-
#endif
18511854

18521855
return SYSCALL_NUM(regs);
18531856
}
@@ -1857,18 +1860,10 @@ void change_syscall(struct __test_metadata *_metadata,
18571860
pid_t tracee, int syscall, int result)
18581861
{
18591862
ARCH_REGS regs;
1860-
#ifdef ARCH_GETREGS
1863+
18611864
EXPECT_EQ(0, ARCH_GETREGS(regs)) {
18621865
return;
18631866
}
1864-
#else
1865-
int ret;
1866-
struct iovec iov;
1867-
iov.iov_base = &regs;
1868-
iov.iov_len = sizeof(regs);
1869-
ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
1870-
EXPECT_EQ(0, ret);
1871-
#endif
18721867

18731868
SYSCALL_NUM_SET(regs, syscall);
18741869

@@ -1881,14 +1876,7 @@ void change_syscall(struct __test_metadata *_metadata,
18811876
#endif
18821877

18831878
/* Flush any register changes made. */
1884-
#ifdef ARCH_SETREGS
18851879
EXPECT_EQ(0, ARCH_SETREGS(regs));
1886-
#else
1887-
iov.iov_base = &regs;
1888-
iov.iov_len = sizeof(regs);
1889-
ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov);
1890-
EXPECT_EQ(0, ret);
1891-
#endif
18921880
}
18931881

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

0 commit comments

Comments
 (0)