kernel: core_hook: refactor escape_to_root
- Remove BUG_ON, bail out when failed - Add put_cred Signed-off-by: rsuntk <rissu.ntk@gmail.com>
This commit is contained in:
@@ -217,18 +217,23 @@ void ksu_escape_to_root(void)
|
|||||||
{
|
{
|
||||||
struct cred *cred;
|
struct cred *cred;
|
||||||
|
|
||||||
|
if (current_euid().val == 0) {
|
||||||
|
pr_warn("Already root, don't escape!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
cred = (struct cred *)__task_cred((current));
|
cred = (struct cred *)__task_cred((current));
|
||||||
BUG_ON(!cred);
|
if (!cred) {
|
||||||
|
pr_err("%s: cred is NULL! bailing out..\n", __func__);
|
||||||
|
rcu_read_unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} while (!get_cred_rcu(cred));
|
} while (!get_cred_rcu(cred));
|
||||||
|
|
||||||
if (cred->euid.val == 0) {
|
rcu_read_unlock();
|
||||||
pr_warn("Already root, don't escape!\n");
|
|
||||||
rcu_read_unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct root_profile *profile = ksu_get_root_profile(cred->uid.val);
|
struct root_profile *profile = ksu_get_root_profile(cred->uid.val);
|
||||||
|
|
||||||
@@ -260,7 +265,7 @@ void ksu_escape_to_root(void)
|
|||||||
|
|
||||||
setup_groups(profile, cred);
|
setup_groups(profile, cred);
|
||||||
|
|
||||||
rcu_read_unlock();
|
put_cred(cred); // - release here - include/linux/cred.h
|
||||||
|
|
||||||
// Refer to kernel/seccomp.c: seccomp_set_mode_strict
|
// Refer to kernel/seccomp.c: seccomp_set_mode_strict
|
||||||
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.
|
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.
|
||||||
|
|||||||
Reference in New Issue
Block a user