int proc_set_comm(const char *comm) {
return prctl_safe(PR_SET_NAME, (unsigned long) comm, 0, 0, 0);
}
+
+int proc_set_nnp(void) {
+ return prctl_safe(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
+}
int prctl_safe(int op, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
int proc_set_comm(const char *comm);
+int proc_set_nnp(void);
}
}
- if (context_has_no_new_privileges(context))
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
+ if (context_has_no_new_privileges(context)) {
+ r = proc_set_nnp();
+ if (r < 0) {
*exit_status = EXIT_NO_NEW_PRIVILEGES;
- return log_error_errno(errno, "Failed to disable new privileges: %m");
+ return log_error_errno(r, "Failed to disable new privileges: %m");
}
+ }
#if HAVE_SECCOMP
r = apply_address_families(context, params);
}
if (arg_no_new_privs) {
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
+ r = proc_set_nnp();
+ if (r < 0) {
*ret_error_message = "Failed to disable new privileges";
- return log_struct_errno(LOG_EMERG, errno,
+ return log_struct_errno(LOG_EMERG, r,
LOG_MESSAGE("Failed to disable new privileges: %m"),
LOG_MESSAGE_ID(SD_MESSAGE_CORE_DISABLE_PRIVILEGES_STR));
}
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sched.h>
-#include <sys/prctl.h>
#include <unistd.h>
#include "sd-event.h"
if (r < 0)
log_debug_errno(r, "Failed to drop capabilities, ignoring: %m");
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
- log_warning_errno(errno, "Failed to enable PR_SET_NO_NEW_PRIVS, ignoring: %m");
+ r = proc_set_nnp();
+ if (r < 0)
+ log_warning_errno(r, "Failed to enable PR_SET_NO_NEW_PRIVS, ignoring: %m");
if (tar_x(pipefd[0], tree_fd, flags) < 0)
_exit(EXIT_FAILURE);
if (r < 0)
log_debug_errno(r, "Failed to drop capabilities, ignoring: %m");
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
- log_warning_errno(errno, "Failed to enable PR_SET_NO_NEW_PRIVS, ignoring: %m");
+ r = proc_set_nnp();
+ if (r < 0)
+ log_warning_errno(r, "Failed to enable PR_SET_NO_NEW_PRIVS, ignoring: %m");
if (tar_c(tree_fd, pipefd[1], /* filename= */ NULL, flags) < 0)
_exit(EXIT_FAILURE);
if (r < 0)
return log_error_errno(r, "Dropping capabilities failed: %m");
- if (arg_no_new_privileges)
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
- return log_error_errno(errno, "Failed to disable new privileges: %m");
+ if (arg_no_new_privileges) {
+ r = proc_set_nnp();
+ if (r < 0)
+ return log_error_errno(r, "Failed to disable new privileges: %m");
+ }
/* LXC sets container=lxc, so follow the scheme here */
envp[n_env++] = strjoina("container=", arg_container_service_name);