From nobody Mon Feb 9 16:13:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 375CDC88CB2 for ; Mon, 12 Jun 2023 20:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238180AbjFLUtU (ORCPT ); Mon, 12 Jun 2023 16:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237673AbjFLUrq (ORCPT ); Mon, 12 Jun 2023 16:47:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D52C1BE5 for ; Mon, 12 Jun 2023 13:46:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A99C062F16 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BDEBC43325; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=N9vHg92hQf/Gt8IdTsnnfWQj4zqBnDUs4128W6vih/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iBqkFKk36EhtaWtPZU3rgUuxmTtfv97JaYZTgokAM7xcRt/22Jd6rGrNGFPWOBG63 xO4W8Cww3Yh5hfTupDtDNm0birqBzS4PNmnAtJpZnPST7SAICqEIZPgQO6HIoAp0qG H2F2Yt6Ef/HxDEyry02VutbT0YRSKV1RnwldHrd+caLpGfUxGTULdxUZUtbDHZF0WU +Z7ltdnbFdZvH7aPjVONZJQVNBWSg1QqWspwR+//JJQSslcD1lklBs/5DpQ0ZNQ4G7 TjlsYXhWa3n0PN1oLzbza6wdU3Z8zjZVYgai71XbHhyAiUQUfyhAHYpeilM1hrOhSj uNLF9+M2qEsCA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 01E0ACE3A7D; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 34/53] tools/nolibc: add support for prctl() Date: Mon, 12 Jun 2023 13:44:55 -0700 Message-Id: <20230612204514.292087-34-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh It will be used to disable core dumps from the child spawned to validate the stack protector functionality. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- 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 d5792a5de70b..c688b410f9e4 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 =20 #include "arch.h" #include "errno.h" @@ -875,6 +876,32 @@ int open(const char *path, int flags, ...) } =20 =20 +/* + * 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 =3D sys_prctl(option, arg2, arg3, arg4, arg5); + + if (ret < 0) { + SET_ERRNO(-ret); + ret =3D -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/s= elftests/nolibc/nolibc-test.c index b50b5a8bcc90..6db788603a34 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 =3D {= 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, (unsign= ed long)NULL, 0, 0, 0), -1, EFAULT); break; CASE_TEST(read_badf); EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBA= DF); break; CASE_TEST(sched_yield); EXPECT_SYSZR(1, sched_yield()); break; CASE_TEST(select_null); EXPECT_SYSZR(1, ({ struct timeval tv =3D {= 0 }; select(0, NULL, NULL, NULL, &tv); })); break; --=20 2.40.1