kernel: micro-opt escape_to_root

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
This commit is contained in:
backslashxx
2025-08-26 23:17:57 +07:00
committed by ShirkNeko
parent f3f2089a13
commit 3ad2241722

View File

@@ -230,15 +230,16 @@ static void disable_seccomp(struct task_struct *tsk)
void escape_to_root(void) void escape_to_root(void)
{ {
struct cred *newcreds = prepare_creds(); struct cred *newcreds;
if (newcreds == NULL) {
pr_err("%s: failed to allocate new cred.\n", __func__); if (current_euid().val == 0) {
pr_warn("Already root, don't escape!\n");
return; return;
} }
if (newcreds->euid.val == 0) { newcreds = prepare_creds();
pr_warn("Already root, don't escape!\n"); if (newcreds == NULL) {
abort_creds(newcreds); pr_err("%s: failed to allocate new cred.\n", __func__);
return; return;
} }