aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 07:28:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 07:28:44 +0200
commit96b0607302500ed201a7816282efbaa8f990aa33 (patch)
tree06356b47fe5be44acad2e5b947e23e5411f9d33a /shell/ash.c
parentd26e9587252fdf4774a05e351b86d3a18c46384e (diff)
downloadbusybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.tar.gz
busybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.tar.bz2
busybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.zip
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 <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--shell/ash.c9
1 files changed, 5 insertions, 4 deletions
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;
536 curdir = nullstr; \ 536 curdir = nullstr; \
537 physdir = nullstr; \ 537 physdir = nullstr; \
538 trap_ptr = trap; \ 538 trap_ptr = trap; \
539 groupinfo.euid = -1; \
540 groupinfo.egid = -1; \
539} while (0) 541} while (0)
540 542
541 543
@@ -2319,7 +2321,7 @@ initvar(void)
2319#if ENABLE_FEATURE_EDITING && ENABLE_FEATURE_EDITING_FANCY_PROMPT 2321#if ENABLE_FEATURE_EDITING && ENABLE_FEATURE_EDITING_FANCY_PROMPT
2320 vps1.var_text = "PS1=\\w \\$ "; 2322 vps1.var_text = "PS1=\\w \\$ ";
2321#else 2323#else
2322 if (!geteuid()) 2324 if (!get_cached_euid(&groupinfo.euid));
2323 vps1.var_text = "PS1=# "; 2325 vps1.var_text = "PS1=# ";
2324#endif 2326#endif
2325 vp = varinit; 2327 vp = varinit;
@@ -13809,14 +13811,13 @@ static int test_exec(/*const char *fullname,*/ struct stat *statb)
13809 13811
13810 /* Executability depends on our euid/egid/supplementary groups */ 13812 /* Executability depends on our euid/egid/supplementary groups */
13811 stmode = S_IXOTH; 13813 stmode = S_IXOTH;
13812 euid = geteuid(); 13814 euid = get_cached_euid(&groupinfo.euid);
13813//TODO: cache euid?
13814 if (euid == 0) 13815 if (euid == 0)
13815 /* for root user, any X bit is good enough */ 13816 /* for root user, any X bit is good enough */
13816 stmode = ANY_IX; 13817 stmode = ANY_IX;
13817 else if (statb->st_uid == euid) 13818 else if (statb->st_uid == euid)
13818 stmode = S_IXUSR; 13819 stmode = S_IXUSR;
13819 else if (statb->st_gid == getegid()) 13820 else if (statb->st_gid == get_cached_egid(&groupinfo.egid))
13820 stmode = S_IXGRP; 13821 stmode = S_IXGRP;
13821 else if (is_in_supplementary_groups(&groupinfo, statb->st_gid)) 13822 else if (is_in_supplementary_groups(&groupinfo, statb->st_gid))
13822 stmode = S_IXGRP; 13823 stmode = S_IXGRP;