exec-invoke: Move KSM logic up

Let's move it up to be located together with other resource logic
instead of having it stuffed inbetween the sandboxing logic.
This commit is contained in:
Daan De Meyer
2025-02-18 12:25:16 +01:00
parent d9e41bfe02
commit 0ea00396fd

View File

@@ -4864,6 +4864,19 @@ int exec_invoke(
}
}
if (context->memory_ksm >= 0)
if (prctl(PR_SET_MEMORY_MERGE, context->memory_ksm, 0, 0, 0) < 0) {
if (ERRNO_IS_NOT_SUPPORTED(errno))
log_exec_debug_errno(context,
params,
errno,
"KSM support not available, ignoring.");
else {
*exit_status = EXIT_KSM;
return log_exec_error_errno(context, params, errno, "Failed to set KSM: %m");
}
}
#if ENABLE_UTMP
if (context->utmp_id) {
_cleanup_free_ char *username_alloc = NULL;
@@ -5247,19 +5260,6 @@ int exec_invoke(
return r;
}
if (context->memory_ksm >= 0)
if (prctl(PR_SET_MEMORY_MERGE, context->memory_ksm, 0, 0, 0) < 0) {
if (ERRNO_IS_NOT_SUPPORTED(errno))
log_exec_debug_errno(context,
params,
errno,
"KSM support not available, ignoring.");
else {
*exit_status = EXIT_KSM;
return log_exec_error_errno(context, params, errno, "Failed to set KSM: %m");
}
}
/* Drop groups as early as possible.
* This needs to be done after PrivateDevices=yes setup as device nodes should be owned by the host's root.
* For non-root in a userns, devices will be owned by the user/group before the group change, and nobody. */