From 95584df023341f760c18f2314f9d0b60617c04e5 Mon Sep 17 00:00:00 2001 From: rsuntk Date: Sun, 29 Dec 2024 16:14:00 +0700 Subject: [PATCH] kernel: Add fallback if user didn't implement 'get_cred_rcu' https://github.com/tiann/KernelSU/pull/2320 Signed-off-by: rsuntk --- kernel/core_hook.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/core_hook.c b/kernel/core_hook.c index ec3b3ebd..13a54895 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -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(¤t->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.