From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Date: Mon, 21 Dec 2015 01:03:27 +0100 Message-Id: <1450656209-2676-3-git-send-email-mic@digikod.net> In-Reply-To: <1450656209-2676-1-git-send-email-mic@digikod.net> References: <1450656209-2676-1-git-send-email-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: linux-kernel-owner@vger.kernel.org Subject: [PATCH v1 2/4] selftests/seccomp: Remove the need for HAVE_ARCH_TRACEHOOK To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Jonathan Corbet , Jeff Dike , Richard Weinberger , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , x86@kernel.org, Kees Cook , Andy Lutomirski , Will Drewry , Shuah Khan , Chris Metcalf , Michael Ellerman , Andrew Morton , James Hogan , Thomas Meyer , Nicolas Iooss , Anton Ivanov , linux-doc@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-api@vger.kernel.org, Meredydd Luff , David Drysdale List-ID: Some architectures do not implement PTRACE_GETREGSET nor PTRACE_SETREGSET (required by HAVE_ARCH_TRACEHOOK) but only implement PTRACE_GETREGS and PTRACE_SETREGS (e.g. User-mode Linux). This improve seccomp selftest portability for architectures without HAVE_ARCH_TRACEHOOK support by defining a new trigger HAVE_GETREGS. For now, this is only enabled for i386 and x86_64 architectures. This is required to be able to run this tests on User-mode Linux. Signed-off-by: Micka=C3=ABl Sala=C3=BCn Cc: Jeff Dike Cc: Richard Weinberger Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: Shuah Khan Cc: linux-kernel@vger.kernel.org Cc: user-mode-linux-devel@lists.sourceforge.net Cc: user-mode-linux-user@lists.sourceforge.net Cc: linux-api@vger.kernel.org Cc: Meredydd Luff Cc: David Drysdale --- tools/testing/selftests/seccomp/seccomp_bpf.c | 27 +++++++++++++++++++= +++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/test= ing/selftests/seccomp/seccomp_bpf.c index 882fe83..b9453b8 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -1246,11 +1246,24 @@ TEST_F(TRACE_poke, getpid_runs_normally) # error "Do not know how to find your architecture's registers and sys= calls" #endif =20 +/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is usefu= l for + * architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux). + */ +#if defined(__x86_64__) || defined(__i386__) +#define HAVE_GETREGS +#endif + /* Architecture-specific syscall fetching routine. */ int get_syscall(struct __test_metadata *_metadata, pid_t tracee) { - struct iovec iov; ARCH_REGS regs; +#ifdef HAVE_GETREGS + EXPECT_EQ(0, ptrace(PTRACE_GETREGS, tracee, 0, ®s)) { + TH_LOG("PTRACE_GETREGS failed"); + return -1; + } +#else + struct iovec iov; =20 iov.iov_base =3D ®s; iov.iov_len =3D sizeof(regs); @@ -1258,6 +1271,7 @@ int get_syscall(struct __test_metadata *_metadata= , pid_t tracee) TH_LOG("PTRACE_GETREGSET failed"); return -1; } +#endif =20 return regs.SYSCALL_NUM; } @@ -1266,13 +1280,16 @@ int get_syscall(struct __test_metadata *_metada= ta, pid_t tracee) void change_syscall(struct __test_metadata *_metadata, pid_t tracee, int syscall) { - struct iovec iov; int ret; ARCH_REGS regs; - +#ifdef HAVE_GETREGS + ret =3D ptrace(PTRACE_GETREGS, tracee, 0, ®s); +#else + struct iovec iov; iov.iov_base =3D ®s; iov.iov_len =3D sizeof(regs); ret =3D ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov); +#endif EXPECT_EQ(0, ret); =20 #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) |= | \ @@ -1312,9 +1329,13 @@ void change_syscall(struct __test_metadata *_met= adata, if (syscall =3D=3D -1) regs.SYSCALL_RET =3D 1; =20 +#ifdef HAVE_GETREGS + ret =3D ptrace(PTRACE_SETREGS, tracee, 0, ®s); +#else iov.iov_base =3D ®s; iov.iov_len =3D sizeof(regs); ret =3D ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov); +#endif EXPECT_EQ(0, ret); } =20 --=20 2.6.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel"= in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/