From: Gregory Price <gourry.memverge@gmail.com> To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, oleg@redhat.com, avagin@gmail.com, peterz@infradead.org, luto@kernel.org, krisman@collabora.com, tglx@linutronix.de, corbet@lwn.net, shuah@kernel.org, catalin.marinas@arm.com, arnd@arndb.de, will@kernel.org, mark.rutland@arm.com, tongtiangen@huawei.com, robin.murphy@arm.com, Gregory Price <gregory.price@memverge.com> Subject: [PATCH v14 4/4] selftest,ptrace: Add selftest for syscall user dispatch config api Date: Tue, 28 Mar 2023 12:48:13 -0400 [thread overview] Message-ID: <20230328164811.2451-5-gregory.price@memverge.com> (raw) In-Reply-To: <20230328164811.2451-1-gregory.price@memverge.com> Validate that the following new ptrace requests work as expected * PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG - returns the contents of task->syscall_dispatch if enabled * PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG - sets the contents of task->syscall_dispatch Signed-off-by: Gregory Price <gregory.price@memverge.com> --- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- tools/testing/selftests/ptrace/get_set_sud.c | 72 ++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/ptrace/get_set_sud.c diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index 792318aaa30c..b7dde152e75a 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only get_syscall_info +get_set_sud peeksiginfo vmaccess diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index 2f1f532c39db..33a36b73bcb9 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS += -std=c99 -pthread -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := get_syscall_info peeksiginfo vmaccess +TEST_GEN_PROGS := get_syscall_info peeksiginfo vmaccess get_set_sud include ../lib.mk diff --git a/tools/testing/selftests/ptrace/get_set_sud.c b/tools/testing/selftests/ptrace/get_set_sud.c new file mode 100644 index 000000000000..5297b10d25c3 --- /dev/null +++ b/tools/testing/selftests/ptrace/get_set_sud.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include "../kselftest_harness.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <sys/wait.h> +#include <sys/syscall.h> +#include <sys/prctl.h> + +#include "linux/ptrace.h" + +static int sys_ptrace(int request, pid_t pid, void *addr, void *data) +{ + return syscall(SYS_ptrace, request, pid, addr, data); +} + +TEST(get_set_sud) +{ + struct ptrace_sud_config config; + pid_t child; + int ret = 0; + int status; + + child = fork(); + ASSERT_GE(child, 0); + if (child == 0) { + ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { + TH_LOG("PTRACE_TRACEME: %m"); + } + kill(getpid(), SIGSTOP); + _exit(1); + } + + waitpid(child, &status, 0); + + memset(&config, 0xff, sizeof(config)); + config.mode = PR_SYS_DISPATCH_ON; + + ret = sys_ptrace(PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + ASSERT_EQ(config.mode, PR_SYS_DISPATCH_OFF); + ASSERT_EQ(config.selector, 0); + ASSERT_EQ(config.offset, 0); + ASSERT_EQ(config.len, 0); + + config.mode = PR_SYS_DISPATCH_ON; + config.selector = 0; + config.offset = 0x400000; + config.len = 0x1000; + + ret = sys_ptrace(PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + + memset(&config, 1, sizeof(config)); + ret = sys_ptrace(PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + ASSERT_EQ(config.mode, PR_SYS_DISPATCH_ON); + ASSERT_EQ(config.selector, 0); + ASSERT_EQ(config.offset, 0x400000); + ASSERT_EQ(config.len, 0x1000); + + kill(child, SIGKILL); +} + +TEST_HARNESS_MAIN -- 2.39.1
WARNING: multiple messages have this Message-ID (diff)
From: Gregory Price <gourry.memverge@gmail.com> To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, oleg@redhat.com, avagin@gmail.com, peterz@infradead.org, luto@kernel.org, krisman@collabora.com, tglx@linutronix.de, corbet@lwn.net, shuah@kernel.org, catalin.marinas@arm.com, arnd@arndb.de, will@kernel.org, mark.rutland@arm.com, tongtiangen@huawei.com, robin.murphy@arm.com, Gregory Price <gregory.price@memverge.com> Subject: [PATCH v14 4/4] selftest,ptrace: Add selftest for syscall user dispatch config api Date: Tue, 28 Mar 2023 12:48:13 -0400 [thread overview] Message-ID: <20230328164811.2451-5-gregory.price@memverge.com> (raw) In-Reply-To: <20230328164811.2451-1-gregory.price@memverge.com> Validate that the following new ptrace requests work as expected * PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG - returns the contents of task->syscall_dispatch if enabled * PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG - sets the contents of task->syscall_dispatch Signed-off-by: Gregory Price <gregory.price@memverge.com> --- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- tools/testing/selftests/ptrace/get_set_sud.c | 72 ++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/ptrace/get_set_sud.c diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index 792318aaa30c..b7dde152e75a 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only get_syscall_info +get_set_sud peeksiginfo vmaccess diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index 2f1f532c39db..33a36b73bcb9 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS += -std=c99 -pthread -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := get_syscall_info peeksiginfo vmaccess +TEST_GEN_PROGS := get_syscall_info peeksiginfo vmaccess get_set_sud include ../lib.mk diff --git a/tools/testing/selftests/ptrace/get_set_sud.c b/tools/testing/selftests/ptrace/get_set_sud.c new file mode 100644 index 000000000000..5297b10d25c3 --- /dev/null +++ b/tools/testing/selftests/ptrace/get_set_sud.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include "../kselftest_harness.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <sys/wait.h> +#include <sys/syscall.h> +#include <sys/prctl.h> + +#include "linux/ptrace.h" + +static int sys_ptrace(int request, pid_t pid, void *addr, void *data) +{ + return syscall(SYS_ptrace, request, pid, addr, data); +} + +TEST(get_set_sud) +{ + struct ptrace_sud_config config; + pid_t child; + int ret = 0; + int status; + + child = fork(); + ASSERT_GE(child, 0); + if (child == 0) { + ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { + TH_LOG("PTRACE_TRACEME: %m"); + } + kill(getpid(), SIGSTOP); + _exit(1); + } + + waitpid(child, &status, 0); + + memset(&config, 0xff, sizeof(config)); + config.mode = PR_SYS_DISPATCH_ON; + + ret = sys_ptrace(PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + ASSERT_EQ(config.mode, PR_SYS_DISPATCH_OFF); + ASSERT_EQ(config.selector, 0); + ASSERT_EQ(config.offset, 0); + ASSERT_EQ(config.len, 0); + + config.mode = PR_SYS_DISPATCH_ON; + config.selector = 0; + config.offset = 0x400000; + config.len = 0x1000; + + ret = sys_ptrace(PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + + memset(&config, 1, sizeof(config)); + ret = sys_ptrace(PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG, child, + (void *)sizeof(config), &config); + + ASSERT_EQ(ret, 0); + ASSERT_EQ(config.mode, PR_SYS_DISPATCH_ON); + ASSERT_EQ(config.selector, 0); + ASSERT_EQ(config.offset, 0x400000); + ASSERT_EQ(config.len, 0x1000); + + kill(child, SIGKILL); +} + +TEST_HARNESS_MAIN -- 2.39.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-03-28 16:49 UTC|newest] Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-28 16:48 [PATCH v14 0/4] Checkpoint Support for Syscall User Dispatch Gregory Price 2023-03-28 16:48 ` Gregory Price 2023-03-28 16:48 ` [PATCH v14 1/4] asm-generic,arm64: create task variant of access_ok Gregory Price 2023-03-28 16:48 ` Gregory Price 2023-03-28 18:46 ` Arnd Bergmann 2023-03-28 18:46 ` Arnd Bergmann 2023-03-29 15:15 ` Oleg Nesterov 2023-03-29 15:15 ` Oleg Nesterov 2023-03-29 15:41 ` Arnd Bergmann 2023-03-29 15:41 ` Arnd Bergmann 2023-03-29 16:03 ` Oleg Nesterov 2023-03-29 16:03 ` Oleg Nesterov 2023-03-29 3:56 ` Gregory Price 2023-03-29 3:56 ` Gregory Price 2023-03-29 17:13 ` Oleg Nesterov 2023-03-29 17:13 ` Oleg Nesterov 2023-03-29 5:37 ` Gregory Price 2023-03-29 5:37 ` Gregory Price 2023-03-29 17:58 ` Oleg Nesterov 2023-03-29 17:58 ` Oleg Nesterov 2023-03-29 5:54 ` Gregory Price 2023-03-29 5:54 ` Gregory Price 2023-03-29 18:13 ` Oleg Nesterov 2023-03-29 18:13 ` Oleg Nesterov 2023-03-29 10:02 ` Gregory Price 2023-03-29 10:02 ` Gregory Price 2023-03-29 23:54 ` Oleg Nesterov 2023-03-29 23:54 ` Oleg Nesterov 2023-03-29 18:29 ` Arnd Bergmann 2023-03-29 18:29 ` Arnd Bergmann 2023-03-29 16:22 ` Catalin Marinas 2023-03-29 16:22 ` Catalin Marinas 2023-03-29 4:34 ` Gregory Price 2023-03-29 4:34 ` Gregory Price 2023-03-30 14:05 ` Catalin Marinas 2023-03-30 14:05 ` Catalin Marinas 2023-03-30 4:18 ` Gregory Price 2023-03-30 4:18 ` Gregory Price 2023-03-28 16:48 ` [PATCH v14 2/4] syscall_user_dispatch: helper function to operate on given task Gregory Price 2023-03-28 16:48 ` Gregory Price 2023-03-28 16:48 ` [PATCH v14 3/4] ptrace,syscall_user_dispatch: checkpoint/restore support for SUD Gregory Price 2023-03-28 16:48 ` Gregory Price 2023-03-28 16:48 ` Gregory Price [this message] 2023-03-28 16:48 ` [PATCH v14 4/4] selftest,ptrace: Add selftest for syscall user dispatch config api Gregory Price
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=20230328164811.2451-5-gregory.price@memverge.com \ --to=gourry.memverge@gmail.com \ --cc=arnd@arndb.de \ --cc=avagin@gmail.com \ --cc=catalin.marinas@arm.com \ --cc=corbet@lwn.net \ --cc=gregory.price@memverge.com \ --cc=krisman@collabora.com \ --cc=linux-arch@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=luto@kernel.org \ --cc=mark.rutland@arm.com \ --cc=oleg@redhat.com \ --cc=peterz@infradead.org \ --cc=robin.murphy@arm.com \ --cc=shuah@kernel.org \ --cc=tglx@linutronix.de \ --cc=tongtiangen@huawei.com \ --cc=will@kernel.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.