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 EF09AC678DB for ; Sat, 4 Mar 2023 14:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbjCDO3T (ORCPT ); Sat, 4 Mar 2023 09:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjCDO3M (ORCPT ); Sat, 4 Mar 2023 09:29:12 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5467975A for ; Sat, 4 Mar 2023 06:29:09 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 324ESto3006570; Sat, 4 Mar 2023 15:28:55 +0100 From: Willy Tarreau To: paulmck@kernel.org Cc: chenhuacai@loongson.cn, chenfeiyang@loongson.cn, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 1/5] tools/nolibc: add getuid() and geteuid() Date: Sat, 4 Mar 2023 15:28:40 +0100 Message-Id: <20230304142844.6522-2-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230304142844.6522-1-w@1wt.eu> References: <20230304142844.6522-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.17.5