Skip to content

Commit

Permalink
kernel: Add fallback if user didn't implement 'get_cred_rcu'
Browse files Browse the repository at this point in the history
tiann/KernelSU#2320

Signed-off-by: rsuntk <rissu.ntk@gmail.com>
  • Loading branch information
rsuntk authored and diphons committed Feb 22, 2025
1 parent ff15790 commit cf56cfd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions drivers/kernelsu/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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
Expand All @@ -204,6 +204,7 @@ void ksu_escape_to_root(void)
{
struct cred *cred;

#ifdef KSU_GET_CRED_RCU
rcu_read_lock();

do {
Expand All @@ -216,6 +217,15 @@ void ksu_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;
Expand Down Expand Up @@ -252,8 +262,10 @@ void ksu_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.
Expand Down

0 comments on commit cf56cfd

Please sign in to comment.