From patchwork Fri May 26 07:51:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 99404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp303963vqr; Fri, 26 May 2023 01:12:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fyrCBtXb7sQkRE7yeTffDhStHlbvyfRKpQluB2NxGSqV/0Q98DdDbEiatph0mJPlhu8ds X-Received: by 2002:a17:902:e750:b0:1af:9b8a:9c7b with SMTP id p16-20020a170902e75000b001af9b8a9c7bmr1551561plf.47.1685088760969; Fri, 26 May 2023 01:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685088760; cv=none; d=google.com; s=arc-20160816; b=mTkRzBe+ESqbAAp0tCHCZupzn98NuDuWIWTnGYr8abpSpwbAogT4Hl4mvA6X4kx4JJ IY2faVSFL9YfPsjbRVlrJ00jnmaEKp3fOaBsm/4iF0FnX4NUG0zBJOdZMlXF5oKEFf+U AtzdAmr9Sd3nZqsg4ysEP4ljAAjBjwvYAlm5lmKSI3051+WQfQh3ydD3Ai//Z5VNH4DO c1tp6VTZIbfXzOykr3pM5o1jHoCnYOip2BUbtXRWiw6PhicppzFckCyVSJaVG0MRCT+7 KjercqgehYZeFWZfeSjI/hkdQpDSUyJjVu+c+m8Kr+bNO3rar/3rrXSx0BSS6xre9E5S KqzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:dkim-signature :from; bh=oFv0NzD4kalslzbXmvYwarlmkxpn25sB9CQcQYIO9WY=; b=1BdC+ZyYnx88tsrUsu0AUNbVhF60ppNNVA/IXz/dhfrGwphIn/pqvetiz9dQqkfthl +htLQj/mlT/SHb3BusY6hkVvh91LkW3A6lgLpaeTGdv9XAAGIpld+FadMs3ZYNBfoSWH uOPuuoGzj8470YolusTCaWpor5lbxWpIkHqwhkYU4d9uSqF+r/usmWALHAtOQFPsIBBR hEeqOWMqXO/S+08ezQcbJrfegwSST2eK0xInWnDPlwJDFP3ABwBs/4IaMVcV2ZQOicXt nvVetLu9Z6ToQhXSoADV6iwCQxKXyJ2aJQiZZCyFipteSr86UB3ZOWtiADhHDnT9pG4L 9yoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=lLn5Ra4U; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj20-20020a170903049400b001b017b563a0si292454plb.27.2023.05.26.01.12.28; Fri, 26 May 2023 01:12:40 -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=@weissschuh.net header.s=mail header.b=lLn5Ra4U; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242552AbjEZHvc (ORCPT + 99 others); Fri, 26 May 2023 03:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242512AbjEZHvY (ORCPT ); Fri, 26 May 2023 03:51:24 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F79E135; Fri, 26 May 2023 00:51:23 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1685087481; bh=DkJgAJcAvtdVnot+t7IOseLE6pLBA89qfDYOzqzRxr4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lLn5Ra4UT5W+7hPi/W7hyftOnWvQtbYt+RnnVvKlguWzQzyC0CwMO2hGXzu6ur9yH qfmUquarnq6NgvYS+xMiQ8MFmMW45qi4cvdFJu3NugZ30I2j+u6vl7Wz5c3sc1gHEz 6DY8wQXm+P5v9F77hDDwcSJsc8sUYdW2ttJUKJJQ= Date: Fri, 26 May 2023 09:51:19 +0200 Subject: [PATCH v2 1/2] tools/nolibc: add support for prctl() MIME-Version: 1.0 Message-Id: <20230526-nolibc-test-no-dump-v2-1-a66500bf73fc@weissschuh.net> References: <20230526-nolibc-test-no-dump-v2-0-a66500bf73fc@weissschuh.net> In-Reply-To: <20230526-nolibc-test-no-dump-v2-0-a66500bf73fc@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1685087479; l=2797; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=DkJgAJcAvtdVnot+t7IOseLE6pLBA89qfDYOzqzRxr4=; b=1qmpuRz+hs8ZGEviZzteWWt0ML8v4Ia8/JBkYrADdw2L0sSJWamEoTw3a3mzpd35T6OfV0d2/ uvz8xMz4/LmC5SqdGi/Jv4+cymN2dC0aC+H8ojsYN0kyrYw8n7SMt0n X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1766943632885682982?= X-GMAIL-MSGID: =?utf-8?q?1766943632885682982?= It will be used to disable core dumps from the child spawned to validate the stack protector functionality. Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/sys.h | 27 +++++++++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 29 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 7874062bea95..3d521feffad6 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -22,6 +22,7 @@ #include /* for O_* and AT_* */ #include /* for statx() */ #include /* for LINUX_REBOOT_* */ +#include #include "arch.h" #include "errno.h" @@ -894,6 +895,32 @@ int open(const char *path, int flags, ...) } +/* + * int prctl(int option, unsigned long arg2, unsigned long arg3, + * unsigned long arg4, unsigned long arg5); + */ + +static __attribute__((unused)) +int sys_prctl(int option, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5); +} + +static __attribute__((unused)) +int prctl(int option, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + int ret = sys_prctl(option, arg2, arg3, arg4, arg5); + + if (ret < 0) { + SET_ERRNO(-ret); + ret = -1; + } + return ret; +} + + /* * int pivot_root(const char *new, const char *old); */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 6e0a4dbe321e..95ff2867a91d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -580,6 +581,7 @@ int run_syscall(int min, int max) CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; CASE_TEST(poll_fault); EXPECT_SYSER(1, poll((void *)1, 1, 0), -1, EFAULT); break; + CASE_TEST(prctl); EXPECT_SYSER(1, prctl(PR_SET_NAME, (unsigned long)NULL, 0, 0, 0), -1, EFAULT); break; CASE_TEST(read_badf); EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBADF); break; CASE_TEST(sched_yield); EXPECT_SYSZR(1, sched_yield()); break; CASE_TEST(select_null); EXPECT_SYSZR(1, ({ struct timeval tv = { 0 }; select(0, NULL, NULL, NULL, &tv); })); break;