From 08884da4237225a45443c6f56a3865680b0f2a3c Mon Sep 17 00:00:00 2001 From: weishu Date: Thu, 22 Jun 2023 13:42:28 +0800 Subject: [PATCH] kernel: don't alloc groups for default groups --- kernel/core_hook.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/core_hook.c b/kernel/core_hook.c index 7a021a14..b0acb224 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -52,6 +52,8 @@ static inline bool is_isolated_uid(uid_t uid) appid <= LAST_APP_ZYGOTE_ISOLATED_UID); } +static struct group_info root_groups = { .usage = ATOMIC_INIT(2) }; + static void setup_groups(struct root_profile *profile, struct cred *cred) { if (profile->groups_count > KSU_MAX_GROUPS) { @@ -60,6 +62,14 @@ static void setup_groups(struct root_profile *profile, struct cred *cred) return; } + if (profile->groups_count == 1 && profile->groups[0] == 0) { + // setgroup to root and return early. + if (cred->group_info) + put_group_info(cred->group_info); + cred->group_info = get_group_info(&root_groups); + return; + } + u32 ngroups = profile->groups_count; struct group_info *group_info = groups_alloc(ngroups); if (!group_info) {