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 21, 2025
1 parent 16a4e32 commit d2fa963
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 @@ -179,7 +179,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 @@ -201,6 +201,7 @@ void ksu_escape_to_root(void)
{
struct cred *cred;

#ifdef KSU_GET_CRED_RCU
rcu_read_lock();

do {
Expand All @@ -213,6 +214,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 @@ -249,8 +259,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 d2fa963

Please sign in to comment.