From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gnuweeb.org (Postfix) with ESMTPS id EF3B281410 for ; Tue, 21 Mar 2023 01:11:40 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mj3U2cHM; dkim-atps=neutral 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 696F461903; Tue, 21 Mar 2023 01:11:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 911A2C433A1; Tue, 21 Mar 2023 01:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679361099; bh=TtxwyZ2yyBdV44Bz3Oj230Ni7X2FI+pFx4BXXurJI4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mj3U2cHM9CdZOnyGRS+2vZ70cuWOXcFb7SjpFE5x/bitMYYONegiZpty1MCYenuHd aTtJ/eFoAL5naFO24Dq2q+gJA0A26POMqlCuLubkKpW8DOQ0Lc2XmnxJBGt1BncJSr w9F8u8BuKWo/9kl13ZquH412PM/JQBIzx3YdX9AC0LYHAWQnXlKRo+Pm1rvF9TUYhM aAcnLR7usFuQoYyEhnoX5gWsEOaXegRZAZXcXT0f7/HXqJKgo93YCUtBn1jJp5sVi1 y3ahVFvC9OXn0VeFStya0K/y4a1Ru1pgL8ozyKEYbvWtJroUM5MOn5SaBt8Eeq6wP/ GpiZMru7Uo0ug== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id E9670154039F; Mon, 20 Mar 2023 18:11:38 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 07/14] tools/nolibc: add getuid() and geteuid() Date: Mon, 20 Mar 2023 18:11:30 -0700 Message-Id: <20230321011137.51837-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.0.rc2 In-Reply-To: <6a3206d0-e5cd-4990-9604-444a24a8207c@paulmck-laptop> References: <6a3206d0-e5cd-4990-9604-444a24a8207c@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Willy Tarreau This can be useful to avoid attempting some privileged operations, starting from the nolibc-test tool that gets two failures when not privileged. We call getuid32() and geteuid32() when they are defined, and fall back to getuid() and geteuid() otherwise. Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index b5f8cd35c03b..115579e7f1db 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -410,6 +410,27 @@ int getdents64(int fd, struct linux_dirent64 *dirp, int count) } +/* + * uid_t geteuid(void); + */ + +static __attribute__((unused)) +uid_t sys_geteuid(void) +{ +#ifdef __NR_geteuid32 + return my_syscall0(__NR_geteuid32); +#else + return my_syscall0(__NR_geteuid); +#endif +} + +static __attribute__((unused)) +uid_t geteuid(void) +{ + return sys_geteuid(); +} + + /* * pid_t getpgid(pid_t pid); */ @@ -544,6 +565,27 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } +/* + * uid_t getuid(void); + */ + +static __attribute__((unused)) +uid_t sys_getuid(void) +{ +#ifdef __NR_getuid32 + return my_syscall0(__NR_getuid32); +#else + return my_syscall0(__NR_getuid); +#endif +} + +static __attribute__((unused)) +uid_t getuid(void) +{ + return sys_getuid(); +} + + /* * int ioctl(int fd, unsigned long req, void *value); */ -- 2.40.0.rc2