Skip to content

Commit a518180

Browse files
authored
core: Don't silently succeed on UserNamespacePath= join failures (systemd#42512)
These also need to set exit_status so that sd-executor returns the right thing to pid1.
2 parents 9f073ba + fb1e76c commit a518180

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/core/exec-invoke.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6012,8 +6012,10 @@ int exec_invoke(
60126012
* Users with CAP_SYS_ADMIN can set up user namespaces last because they will be able to
60136013
* set up all of the other namespaces (i.e. network, mount, UTS) without a user namespace. */
60146014

6015-
if (context->user_namespace_path && runtime->shared->userns_storage_socket[0] >= 0)
6015+
if (context->user_namespace_path && runtime->shared->userns_storage_socket[0] >= 0) {
6016+
*exit_status = EXIT_USER;
60166017
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "UserNamespacePath= is configured, but user namespace setup not permitted");
6018+
}
60176019

60186020
PrivateUsers pu = exec_context_get_effective_private_users(context, params);
60196021
if (pu == PRIVATE_USERS_NO)
@@ -6098,12 +6100,16 @@ int exec_invoke(
60986100
* case of mount namespaces being less privileged when the mount point list is copied from a
60996101
* different user namespace). */
61006102
if (needs_sandboxing && context->user_namespace_path && runtime->shared && runtime->shared->userns_storage_socket[0] >= 0) {
6101-
if (!namespace_type_supported(NAMESPACE_USER))
6103+
if (!namespace_type_supported(NAMESPACE_USER)) {
6104+
*exit_status = EXIT_USER;
61026105
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "UserNamespacePath= is not supported, refusing.");
6106+
}
61036107

61046108
r = setup_shareable_ns(runtime->shared->userns_storage_socket, CLONE_NEWUSER);
6105-
if (ERRNO_IS_NEG_PRIVILEGE(r))
6106-
return log_notice_errno(r, "PrivateUsers= is configured, but user namespace setup not permitted, refusing.");
6109+
if (ERRNO_IS_NEG_PRIVILEGE(r)) {
6110+
*exit_status = EXIT_USER;
6111+
return log_error_errno(r, "UserNamespacePath= is configured, but user namespace setup not permitted, refusing.");
6112+
}
61076113
if (r < 0) {
61086114
*exit_status = EXIT_USER;
61096115
return log_error_errno(r, "Failed to set up user namespacing: %m");

0 commit comments

Comments
 (0)