From 96b0607302500ed201a7816282efbaa8f990aa33 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Oct 2024 07:28:44 +0200 Subject: ash: cache more of uid/gid syscalls Testcase: setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?' should show that second "test -x" does not query ids again. function old new delta ash_main 1236 1256 +20 get_cached_euid - 19 +19 get_cached_egid - 19 +19 test_main 56 72 +16 test_exec 119 135 +16 is_in_supplementary_groups 52 57 +5 nexpr 718 702 -16 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16) Total: 79 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'shell/ash.c') diff --git a/shell/ash.c b/shell/ash.c index a6bb9894c..9173b8608 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -536,6 +536,8 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; curdir = nullstr; \ physdir = nullstr; \ trap_ptr = trap; \ + groupinfo.euid = -1; \ + groupinfo.egid = -1; \ } while (0) @@ -2319,7 +2321,7 @@ initvar(void) #if ENABLE_FEATURE_EDITING && ENABLE_FEATURE_EDITING_FANCY_PROMPT vps1.var_text = "PS1=\\w \\$ "; #else - if (!geteuid()) + if (!get_cached_euid(&groupinfo.euid)); vps1.var_text = "PS1=# "; #endif vp = varinit; @@ -13809,14 +13811,13 @@ static int test_exec(/*const char *fullname,*/ struct stat *statb) /* Executability depends on our euid/egid/supplementary groups */ stmode = S_IXOTH; - euid = geteuid(); -//TODO: cache euid? + euid = get_cached_euid(&groupinfo.euid); if (euid == 0) /* for root user, any X bit is good enough */ stmode = ANY_IX; else if (statb->st_uid == euid) stmode = S_IXUSR; - else if (statb->st_gid == getegid()) + else if (statb->st_gid == get_cached_egid(&groupinfo.egid)) stmode = S_IXGRP; else if (is_in_supplementary_groups(&groupinfo, statb->st_gid)) stmode = S_IXGRP; -- cgit v1.2.3-55-g6feb