Skip to content

Commit

Permalink
Revert "Improve seccomp disable && Add locking to protect cred modifi…
Browse files Browse the repository at this point in the history
…cations in escape_to_root (tiann#2320)"

This reverts commit 58ed786.

Signed-off-by: mrsrimar22 <mrsrimar22@gmail.com>
  • Loading branch information
mrsrimar22 committed Dec 29, 2024
1 parent 7ff57a8 commit 8810854
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,14 @@ static void setup_groups(struct root_profile *profile, struct cred *cred)
set_groups(cred, group_info);
}

static void disable_seccomp()
{
assert_spin_locked(&current->sighand->siglock);
// disable seccomp
#if defined(CONFIG_GENERIC_ENTRY) && \
LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
current_thread_info()->syscall_work &= ~SYSCALL_WORK_SECCOMP;
#else
current_thread_info()->flags &= ~(TIF_SECCOMP | _TIF_SECCOMP);
#endif

#ifdef CONFIG_SECCOMP
current->seccomp.mode = 0;
current->seccomp.filter = NULL;
#else
#endif
}

void escape_to_root(void)
{
struct cred *cred;

rcu_read_lock();

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

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 @@ -175,15 +151,21 @@ void escape_to_root(void)
memcpy(&cred->cap_ambient, &profile->capabilities.effective,
sizeof(cred->cap_ambient));

setup_groups(profile, cred);
// disable seccomp
#if defined(CONFIG_GENERIC_ENTRY) && \
LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
current_thread_info()->syscall_work &= ~SYSCALL_WORK_SECCOMP;
#else
current_thread_info()->flags &= ~(TIF_SECCOMP | _TIF_SECCOMP);
#endif

rcu_read_unlock();
#ifdef CONFIG_SECCOMP
current->seccomp.mode = 0;
current->seccomp.filter = NULL;
#else
#endif

// 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

2 comments on commit 8810854

@backslashxx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrsrimar22
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks buddy

Please sign in to comment.