diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index b588eb232e..10a7b55006 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -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); diff --git a/src/core/execute.c b/src/core/execute.c index 439f4b7b41..a2d148fde5 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -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 || diff --git a/src/core/execute.h b/src/core/execute.h index c5f3988371..094b0a3a44 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -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); diff --git a/src/core/service.c b/src/core/service.c index b9efd9bdb9..51bba291e8 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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, diff --git a/src/core/unit.c b/src/core/unit.c index 5d3282e121..bf4542c080 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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)