Skip to content

Commit 9d3666c

Browse files
committed
Add locking to protect cred modifications in escape_to_root
This commit introduces locking to ensure safe access and modification of the `cred` structure within the `escape_to_root` function. Signed-off-by: SsageParuders <[email protected]>"
1 parent f195fb8 commit 9d3666c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kernel/core_hook.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,16 @@ void escape_to_root(void)
128128
{
129129
struct cred *cred;
130130

131-
cred = (struct cred *)__task_cred(current);
131+
rcu_read_lock();
132+
133+
do {
134+
cred = (struct cred *)__task_cred((current));
135+
BUG_ON(!cred);
136+
} while (!get_cred_rcu(cred));
132137

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

174+
setup_groups(profile, cred);
175+
176+
rcu_read_unlock();
177+
168178
// Refer to kernel/seccomp.c: seccomp_set_mode_strict
169179
// When disabling Seccomp, ensure that current->sighand->siglock is held during the operation.
170180
spin_lock_irq(&current->sighand->siglock);
171181
disable_seccomp();
172182
spin_unlock_irq(&current->sighand->siglock);
173183

174-
setup_groups(profile, cred);
175-
176184
setup_selinux(profile->selinux_domain);
177185
}
178186

0 commit comments

Comments
 (0)