linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Kees Cook <keescook@chromium.org>, linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
	Thadeu Lima de Souza Cascardo <cascardo@canonical.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Christian Brauner <christian@brauner.io>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org,
	linux-xtensa@linux-xtensa.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 13/15] selftests/seccomp: powerpc: Set syscall return during ptrace syscall exit
Date: Mon, 14 Sep 2020 15:47:13 +1000	[thread overview]
Message-ID: <87zh5sq59a.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <20200912110820.597135-14-keescook@chromium.org>

Kees Cook <keescook@chromium.org> writes:
> Some archs (like ppc) only support changing the return code during
> syscall exit when ptrace is used. As the syscall number might not
> be available anymore during syscall exit, it needs to be saved
> during syscall enter. Adjust the ptrace tests to do this.

I'm not that across all the fixture stuff, but if I'm reading it right
you're now calling change_syscall() on both entry and exit for all
arches.

That should work, but it no longer tests changing the return code on
entry on the arches that support it, which seems like a backward step?

cheers


> Reported-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> Suggested-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> Link: https://lore.kernel.org/linux-kselftest/20200911181012.171027-1-cascardo@canonical.com/
> Fixes: 58d0a862f573 ("seccomp: add tests for ptrace hole")
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  tools/testing/selftests/seccomp/seccomp_bpf.c | 34 +++++++++++--------
>  1 file changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index bbab2420d708..26c712c6a575 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -1949,12 +1949,19 @@ void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee,
>  
>  }
>  
> +FIXTURE(TRACE_syscall) {
> +	struct sock_fprog prog;
> +	pid_t tracer, mytid, mypid, parent;
> +	long syscall_nr;
> +};
> +
>  void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
>  		   int status, void *args)
>  {
> -	int ret, nr;
> +	int ret;
>  	unsigned long msg;
>  	static bool entry;
> +	FIXTURE_DATA(TRACE_syscall) *self = args;
>  
>  	/*
>  	 * The traditional way to tell PTRACE_SYSCALL entry/exit
> @@ -1968,24 +1975,23 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
>  	EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>  			: PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
>  
> -	if (!entry)
> -		return;
> -
> -	nr = get_syscall(_metadata, tracee);
> +	/*
> +	 * Some architectures only support setting return values during
> +	 * syscall exit under ptrace, and on exit the syscall number may
> +	 * no longer be available. Therefore, save it here, and call
> +	 * "change syscall and set return values" on both entry and exit.
> +	 */
> +	if (entry)
> +		self->syscall_nr = get_syscall(_metadata, tracee);
>  
> -	if (nr == __NR_getpid)
> +	if (self->syscall_nr == __NR_getpid)
>  		change_syscall(_metadata, tracee, __NR_getppid, 0);
> -	if (nr == __NR_gettid)
> +	if (self->syscall_nr == __NR_gettid)
>  		change_syscall(_metadata, tracee, -1, 45000);
> -	if (nr == __NR_openat)
> +	if (self->syscall_nr == __NR_openat)
>  		change_syscall(_metadata, tracee, -1, -ESRCH);
>  }
>  
> -FIXTURE(TRACE_syscall) {
> -	struct sock_fprog prog;
> -	pid_t tracer, mytid, mypid, parent;
> -};
> -
>  FIXTURE_VARIANT(TRACE_syscall) {
>  	/*
>  	 * All of the SECCOMP_RET_TRACE behaviors can be tested with either
> @@ -2044,7 +2050,7 @@ FIXTURE_SETUP(TRACE_syscall)
>  	self->tracer = setup_trace_fixture(_metadata,
>  					   variant->use_ptrace ? tracer_ptrace
>  							       : tracer_seccomp,
> -					   NULL, variant->use_ptrace);
> +					   self, variant->use_ptrace);
>  
>  	ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
>  	ASSERT_EQ(0, ret);
> -- 
> 2.25.1

  reply	other threads:[~2020-09-14  5:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-12 11:08 [PATCH 00/15] selftests/seccomp: Refactor change_syscall() Kees Cook
2020-09-12 11:08 ` [PATCH 01/15] selftests/seccomp: Refactor arch register macros to avoid xtensa special case Kees Cook
2020-09-15 15:51   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 02/15] selftests/seccomp: Provide generic syscall setting macro Kees Cook
2020-09-15 15:53   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 03/15] selftests/seccomp: mips: Define SYSCALL_NUM_SET macro Kees Cook
2020-09-15 15:55   ` Christian Brauner
2020-09-18 22:00     ` Kees Cook
2020-09-12 11:08 ` [PATCH 04/15] selftests/seccomp: arm: " Kees Cook
2020-09-15 15:56   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 05/15] selftests/seccomp: arm64: " Kees Cook
2020-09-15 15:58   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 06/15] selftests/seccomp: mips: Remove O32-specific macro Kees Cook
2020-09-15 16:00   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 07/15] selftests/seccomp: Remove syscall setting #ifdefs Kees Cook
2020-09-15 16:01   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 08/15] selftests/seccomp: Convert HAVE_GETREG into ARCH_GETREG/ARCH_SETREG Kees Cook
2020-09-15 16:03   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 09/15] selftests/seccomp: Convert REGSET calls " Kees Cook
2020-09-15 16:05   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 10/15] selftests/seccomp: Avoid redundant register flushes Kees Cook
2020-09-15 16:08   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 11/15] selftests/seccomp: Remove SYSCALL_NUM_RET_SHARE_REG in favor of SYSCALL_RET_SET Kees Cook
2020-09-15 16:11   ` Christian Brauner
2020-09-12 11:08 ` [PATCH 12/15] selftests/seccomp: powerpc: Fix seccomp return value testing Kees Cook
2020-09-14  3:38   ` Michael Ellerman
2020-09-12 11:08 ` [PATCH 13/15] selftests/seccomp: powerpc: Set syscall return during ptrace syscall exit Kees Cook
2020-09-14  5:47   ` Michael Ellerman [this message]
2020-09-14 20:20     ` Kees Cook
2020-09-12 11:08 ` [PATCH 14/15] selftests/clone3: Avoid OS-defined clone_args Kees Cook
2020-09-15 16:25   ` Christian Brauner
2020-09-18 22:00     ` Kees Cook
2020-09-12 11:08 ` [PATCH 15/15] selftests/seccomp: Use __NR_mknodat instead of __NR_mknod Kees Cook
2020-09-15 16:16   ` Christian Brauner
2020-09-14 12:15 ` [PATCH 00/15] selftests/seccomp: Refactor change_syscall() Michael Ellerman
2020-09-14 20:32   ` Kees Cook
2020-09-15 11:12     ` Max Filippov
2020-09-15 12:52     ` Michael Ellerman
2020-09-15  8:45 ` Max Filippov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zh5sq59a.fsf@mpe.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=cascardo@canonical.com \
    --cc=christian@brauner.io \
    --cc=jcmvbkbc@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@amacapital.net \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).