Skip to content

Commit c58e102

Browse files
aviraxprsuntk
authored andcommitted
kernel: core_hook: switch to prepare_creds
- Picked from tiann#2631 - Minor changes: NULL-ing creds after committing Signed-off-by: rsuntk <[email protected]>
1 parent 549daa3 commit c58e102

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

kernel/core_hook.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,15 @@ void escape_to_root(void)
139139
{
140140
struct cred *cred;
141141

142-
rcu_read_lock();
143-
144-
do {
145-
cred = (struct cred *)__task_cred((current));
146-
if (!cred) {
147-
pr_err("%s: cred is NULL! bailing out..\n", __func__);
148-
rcu_read_unlock();
149-
return;
150-
}
151-
} while (!get_cred_rcu(cred));
142+
cred = prepare_creds();
143+
if (!cred) {
144+
pr_err("%s: failed to allocate new cred.\n", __func__);
145+
return;
146+
}
152147

153148
if (cred->euid.val == 0) {
154149
pr_warn("Already root, don't escape!\n");
155-
rcu_read_unlock();
156-
put_cred(cred);
150+
abort_creds(cred);
157151
return;
158152
}
159153

@@ -187,8 +181,14 @@ void escape_to_root(void)
187181

188182
setup_groups(profile, cred);
189183

190-
rcu_read_unlock();
191-
put_cred(cred);
184+
commit_creds(cred);
185+
186+
// FIXME: Maybe need to remove? The tests were fine.
187+
// reference: https://elixir.bootlin.com/linux/v5.4/source/fs/exec.c#L1456
188+
if (cred) {
189+
pr_info("%s: NULL-ing creds after committing..\n", __func__);
190+
cred = NULL;
191+
}
192192

193193
// Refer to kernel/seccomp.c: seccomp_set_mode_strict
194194
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.
@@ -912,4 +912,4 @@ void __init ksu_core_init(void)
912912

913913
void ksu_core_exit(void)
914914
{
915-
}
915+
}

0 commit comments

Comments
 (0)