Skip to content

Commit

Permalink
Add locking to protect cred modifications in escape_to_root
Browse files Browse the repository at this point in the history
This commit introduces locking to ensure safe access and modification of the `cred` structure within the `escape_to_root` function.

Signed-off-by: SsageParuders <qinqingqing1025@gmail.com>"
  • Loading branch information
SsageParuders committed Dec 26, 2024
1 parent f195fb8 commit 9d3666c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ void escape_to_root(void)
{
struct cred *cred;

cred = (struct cred *)__task_cred(current);
rcu_read_lock();

do {
cred = (struct cred *)__task_cred((current));
BUG_ON(!cred);
} while (!get_cred_rcu(cred));

if (cred->euid.val == 0) {
pr_warn("Already root, don't escape!\n");
rcu_read_unlock();
return;
}
struct root_profile *profile = ksu_get_root_profile(cred->uid.val);
Expand Down Expand Up @@ -165,14 +171,16 @@ void escape_to_root(void)
memcpy(&cred->cap_ambient, &profile->capabilities.effective,
sizeof(cred->cap_ambient));

setup_groups(profile, cred);

rcu_read_unlock();

// Refer to kernel/seccomp.c: seccomp_set_mode_strict
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.
spin_lock_irq(&current->sighand->siglock);
disable_seccomp();
spin_unlock_irq(&current->sighand->siglock);

setup_groups(profile, cred);

setup_selinux(profile->selinux_domain);
}

Expand Down

0 comments on commit 9d3666c

Please sign in to comment.