core/execute: stop looking at ExecSharedRuntime to determine PrivateTmp= state
The only reason why ExecSharedRuntime.(var_)tmp_dir might be suppressed is when (/var)/tmp/ is listed in InaccessiblePaths=, in which case mount namespace is needed anyways. Moreover, the current logic imposes a chicken-and-egg problem: at various places in pid1 we'd need to check whether the unit runs in a mountns, but the ExecSharedRuntime may not be allocated for it just yet.
This commit is contained in:
@@ -4833,7 +4833,7 @@ static int setup_delegated_namespaces(
|
||||
|
||||
/* If PrivatePIDs= yes is configured, we're now running as pid 1 in a pid namespace! */
|
||||
|
||||
if (exec_needs_mount_namespace(context, params, runtime) &&
|
||||
if (exec_needs_mount_namespace(context, params) &&
|
||||
exec_namespace_is_delegated(context, params, have_cap_sys_admin, CLONE_NEWNS) == delegate) {
|
||||
_cleanup_free_ char *error_path = NULL;
|
||||
|
||||
@@ -5829,7 +5829,7 @@ int exec_invoke(
|
||||
return log_error_errno(r, "Failed to connect to nsresourced: %m");
|
||||
}
|
||||
|
||||
needs_mount_namespace = exec_needs_mount_namespace(context, params, runtime);
|
||||
needs_mount_namespace = exec_needs_mount_namespace(context, params);
|
||||
|
||||
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
|
||||
r = setup_exec_directory(context, params, uid, gid, dt, needs_mount_namespace, exit_status);
|
||||
|
||||
+2
-11
@@ -256,11 +256,7 @@ bool exec_needs_pid_namespace(const ExecContext *context, const ExecParameters *
|
||||
return context->private_pids != PRIVATE_PIDS_NO && namespace_type_supported(NAMESPACE_PID);
|
||||
}
|
||||
|
||||
bool exec_needs_mount_namespace(
|
||||
const ExecContext *context,
|
||||
const ExecParameters *params,
|
||||
const ExecRuntime *runtime) {
|
||||
|
||||
bool exec_needs_mount_namespace(const ExecContext *context, const ExecParameters *params) {
|
||||
assert(context);
|
||||
|
||||
if (context->root_image ||
|
||||
@@ -295,13 +291,8 @@ bool exec_needs_mount_namespace(
|
||||
if (!IN_SET(context->mount_propagation_flag, 0, MS_SHARED))
|
||||
return true;
|
||||
|
||||
if (context->private_tmp == PRIVATE_TMP_DISCONNECTED)
|
||||
return true;
|
||||
|
||||
if (context->private_tmp == PRIVATE_TMP_CONNECTED && runtime && runtime->shared && (runtime->shared->tmp_dir || runtime->shared->var_tmp_dir))
|
||||
return true;
|
||||
|
||||
if (context->private_devices ||
|
||||
context->private_tmp != PRIVATE_TMP_NO || /* no need to check for private_var_tmp here, private_tmp is never demoted to "no" */
|
||||
context->private_mounts > 0 ||
|
||||
(context->private_mounts < 0 && exec_needs_network_namespace(context)) ||
|
||||
context->protect_system != PROTECT_SYSTEM_NO ||
|
||||
|
||||
+1
-1
@@ -638,7 +638,7 @@ DECLARE_STRING_TABLE_LOOKUP(exec_resource_type, ExecDirectoryType);
|
||||
|
||||
DECLARE_STRING_TABLE_LOOKUP(memory_thp, MemoryTHP);
|
||||
|
||||
bool exec_needs_mount_namespace(const ExecContext *context, const ExecParameters *params, const ExecRuntime *runtime);
|
||||
bool exec_needs_mount_namespace(const ExecContext *context, const ExecParameters *params);
|
||||
bool exec_needs_network_namespace(const ExecContext *context);
|
||||
bool exec_needs_ipc_namespace(const ExecContext *context);
|
||||
bool exec_needs_pid_namespace(const ExecContext *context, const ExecParameters *params);
|
||||
|
||||
+1
-1
@@ -5800,7 +5800,7 @@ static int service_can_live_mount(Unit *u, sd_bus_error *reterr_error) {
|
||||
Service *s = ASSERT_PTR(SERVICE(u));
|
||||
|
||||
/* Ensure that the unit runs in a private mount namespace */
|
||||
if (!exec_needs_mount_namespace(&s->exec_context, /* params= */ NULL, s->exec_runtime))
|
||||
if (!exec_needs_mount_namespace(&s->exec_context, /* params= */ NULL))
|
||||
return sd_bus_error_setf(
|
||||
reterr_error,
|
||||
SD_BUS_ERROR_INVALID_ARGS,
|
||||
|
||||
+1
-1
@@ -4323,7 +4323,7 @@ static int unit_verify_contexts(const Unit *u) {
|
||||
return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOEXEC), "WorkingDirectory=~ is not allowed under DynamicUser=yes. Refusing.");
|
||||
|
||||
if (ec->working_directory && path_below_api_vfs(ec->working_directory) &&
|
||||
exec_needs_mount_namespace(ec, /* params= */ NULL, /* runtime= */ NULL))
|
||||
exec_needs_mount_namespace(ec, /* params= */ NULL))
|
||||
return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOEXEC), "WorkingDirectory= may not be below /proc/, /sys/ or /dev/ when using mount namespacing. Refusing.");
|
||||
|
||||
if (exec_needs_pid_namespace(ec, /* params= */ NULL) && !UNIT_VTABLE(u)->notify_pidref)
|
||||
|
||||
Reference in New Issue
Block a user