From patchwork Tue Apr 18 08:47:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 84685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2687851vqo; Tue, 18 Apr 2023 01:53:28 -0700 (PDT) X-Google-Smtp-Source: AKy350bmQJaUrWKUhI4k1vnzcg0iuqJn32l1qkjRN8NGuk+Rds2Kf58vvO/k7WDEDGQlZdRSaWHy X-Received: by 2002:a05:6a21:3393:b0:ec:5eb2:a2bb with SMTP id yy19-20020a056a21339300b000ec5eb2a2bbmr22931763pzb.61.1681808008227; Tue, 18 Apr 2023 01:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681808008; cv=none; d=google.com; s=arc-20160816; b=d66ds5YYArVU1vGKB+aPK4cHB1qIUAXRqnHvNaIvCWEzQJEPlFFaQ8FgSx/8B1DPR8 cNKgnPgVy7Pu+RzlHOUMnxKJnxMV9dhkqu71H9IbLGkGV9lMJakFqvgZ8ZhSph3txYqx 13LZYwtqqGjFublbK3jHlPn5dyJsrdtmXg3k063fDpzXVA/+iqbWS2xJ1A2ZGce4Lace 5sHFutPvLpTQpHI4YlIiY/NiDGhOhVcS3r081tTxDxj5I6xaJ62mlm13oQIPOA4/cZui tiYcxRisjlHXIlfBC8mkmGL87zCJb6ZfWLga53j3/ZTylJ6ZQk8lo2OW5oubD6KdbT8d t4aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=DW9A8g3/oAk3v/A00iyN2Xu69bbeEhnxtHkQPD6d1TY=; b=ZJD+yKp954+lf0SeV9D5M53z6jPzKUxitEAkkOYQal8EVxeQcqPx4IdzxtvfPEyzPI +6LFF+LiGw2sXnzU9fsRzF02iBdtgAzAQA6nDWLqzN1br7hFPW+H7iLDLldrFSEBQCvR IhGE0aiQaT1pldJGnvYVDgiwH1dNi8M6pcp26zRnOmHhoa+hTbQQ7zAbV3Iy5G6fisvb tbUdeETUgeyZgtt5m+1UvcFTJgRcmcsER/OzzHesiCQ89+kQynlHzqwHguz3JYq9eo6G J8MinaDm43Uu14uYokqb2I5koNuPX2vcIUmxsvptoJJi967sCOrrWbC+KqcN5KTlofWX 2VGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tIQfulbk; dkim=neutral (no key) header.i=@linutronix.de header.b=tIpsSkBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a63da0b000000b00513a68ca71asi14216793pgh.742.2023.04.18.01.53.13; Tue, 18 Apr 2023 01:53:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tIQfulbk; dkim=neutral (no key) header.i=@linutronix.de header.b=tIpsSkBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbjDRIrn (ORCPT + 99 others); Tue, 18 Apr 2023 04:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjDRIrl (ORCPT ); Tue, 18 Apr 2023 04:47:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE1EE3A9B; Tue, 18 Apr 2023 01:47:39 -0700 (PDT) Date: Tue, 18 Apr 2023 08:47:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681807658; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DW9A8g3/oAk3v/A00iyN2Xu69bbeEhnxtHkQPD6d1TY=; b=tIQfulbk5OvsQv11RPOjwQulcrjB3sr+BdVS62F38qTA2MJtxy1L2GTwiFcPm50l7YIn+C 7iAUY4/12LNcntzY8/6FyUQZ8zKNHtod1jDjPk3OSiNKw1k/RYURalQpqCSPIcuDaOXEcI zjtBCO5csr5QB38jMbOC9QDToE0wyV0OCPpMMjA340YkATC43JVgLoS7vVScsJrsorrLAi N5uxHYg8FYqfGhWFQTeDeqfu3VsmMKiCzuemCv+2xer/5m675rXv+YbvjFPSDmhPbWuZka iIlqLp/zUaM1Pfv08Rrgob//Z8anJy3g7q0Bj4rh6T8dZVXP4/6iw1sx9KcKkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681807658; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DW9A8g3/oAk3v/A00iyN2Xu69bbeEhnxtHkQPD6d1TY=; b=tIpsSkBlrvZkwjHVaiciq5x3LniBoOZ2yAi2qws5uvG9gkQNFRow+Of7fDavTSyVNs1sYu OiVuJ3z+SUZkBQDw== From: "tip-bot2 for Gregory Price" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/entry] selftest, ptrace: Add selftest for syscall user dispatch config api Cc: Gregory Price , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230407171834.3558-5-gregory.price@memverge.com> References: <20230407171834.3558-5-gregory.price@memverge.com> MIME-Version: 1.0 Message-ID: <168180765788.404.7470709952569487395.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762539798810576598?= X-GMAIL-MSGID: =?utf-8?q?1763503514496438893?= The following commit has been merged into the core/entry branch of tip: Commit-ID: 8c8fa605f7b8b6df3e6fb280a74cff8d7374a7b7 Gitweb: https://git.kernel.org/tip/8c8fa605f7b8b6df3e6fb280a74cff8d7374a7b7 Author: Gregory Price AuthorDate: Fri, 07 Apr 2023 13:18:34 -04:00 Committer: Thomas Gleixner CommitterDate: Sun, 16 Apr 2023 14:23:08 +02:00 selftest, ptrace: Add selftest for syscall user dispatch config api Validate that the following new ptrace requests work as expected * PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG returns the contents of task->syscall_dispatch * PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG sets the contents of task->syscall_dispatch Signed-off-by: Gregory Price Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20230407171834.3558-5-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 792318a..b7dde15 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 96ffa94..1c63174 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 -Wall $(KHDR_INCLUDES) -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 0000000..5297b10 --- /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 +#include +#include +#include +#include +#include + +#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