kernel: Add fallback if user didn't implement 'get_cred_rcu'

https://github.com/tiann/KernelSU/pull/2320

Signed-off-by: rsuntk <rissu.ntk@gmail.com>
This commit is contained in:
rsuntk
2024-12-29 16:14:00 +07:00
committed by Rifat Azad
parent b18c39e911
commit 95584df023

View File

@@ -110,7 +110,7 @@ static void setup_groups(struct root_profile *profile, struct cred *cred)
set_groups(cred, group_info);
}
static void disable_seccomp()
static void disable_seccomp(void)
{
assert_spin_locked(&current->sighand->siglock);
// disable seccomp
@@ -132,6 +132,7 @@ void escape_to_root(void)
{
struct cred *cred;
#ifdef KSU_GET_CRED_RCU
rcu_read_lock();
do {
@@ -144,6 +145,15 @@ void escape_to_root(void)
rcu_read_unlock();
return;
}
#else
cred = (struct cred *)__task_cred(current);
if (cred->euid.val == 0) {
pr_warn("Already root, don't escape!\n");
return;
}
#endif
struct root_profile *profile = ksu_get_root_profile(cred->uid.val);
cred->uid.val = profile->uid;
@@ -180,8 +190,10 @@ void escape_to_root(void)
sizeof(cred->cap_ambient));
setup_groups(profile, cred);
#ifdef KSU_GET_CRED_RCU
rcu_read_unlock();
#endif
// Refer to kernel/seccomp.c: seccomp_set_mode_strict
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.