tree-wide: port to prctl_safe()

This commit is contained in:
Lennart Poettering
2026-07-13 15:39:17 +02:00
parent 2d63905096
commit 3b38a4f240
15 changed files with 164 additions and 127 deletions
+8 -5
View File
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sys/ioctl.h>
#include <sys/prctl.h>
#include <sys/prctl.h> /* IWYU pragma: keep */
#include <sys/reboot.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -18,15 +18,18 @@
static int reset_environ(const char *new_environment, size_t length) {
unsigned long start, end;
int r;
start = (unsigned long) new_environment;
end = start + length;
if (prctl(PR_SET_MM, PR_SET_MM_ENV_START, start, 0, 0) < 0)
return -errno;
r = prctl_safe(PR_SET_MM, PR_SET_MM_ENV_START, start, 0, 0);
if (r < 0)
return r;
if (prctl(PR_SET_MM, PR_SET_MM_ENV_END, end, 0, 0) < 0)
return -errno;
r = prctl_safe(PR_SET_MM, PR_SET_MM_ENV_END, end, 0, 0);
if (r < 0)
return r;
return 0;
}
+11 -9
View File
@@ -8,7 +8,7 @@
#include <sys/keyctl.h>
#include <sys/mount.h>
#include <sys/personality.h>
#include <sys/prctl.h>
#include <sys/prctl.h> /* IWYU pragma: keep */
#include <sys/wait.h>
#include <unistd.h>
@@ -79,6 +79,7 @@
#include "namespace-util.h"
#include "netlink-internal.h"
#include "notify-recv.h"
#include "nspawn.h"
#include "nspawn-bind-user.h"
#include "nspawn-cgroup.h"
#include "nspawn-expose-ports.h"
@@ -90,14 +91,13 @@
#include "nspawn-settings.h"
#include "nspawn-setuid.h"
#include "nspawn-stub-pid1.h"
#include "nspawn.h"
#include "nsresource.h"
#include "os-util.h"
#include "parse-helpers.h"
#include "osc-context.h"
#include "options.h"
#include "os-util.h"
#include "osc-context.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-helpers.h"
#include "parse-util.h"
#include "path-lookup.h"
#include "path-util.h"
@@ -3579,8 +3579,9 @@ static int inner_child(
/* Make sure we keep the caps across the uid/gid dropping, so that we can retain some selected caps
* if we need to later on. */
if (prctl(PR_SET_KEEPCAPS, 1) < 0)
return log_error_errno(errno, "Failed to set PR_SET_KEEPCAPS: %m");
r = prctl_safe(PR_SET_KEEPCAPS, 1, 0, 0, 0);
if (r < 0)
return log_error_errno(r, "Failed to set PR_SET_KEEPCAPS: %m");
if (uid_is_valid(arg_uid) || gid_is_valid(arg_gid))
r = change_uid_gid_raw(arg_uid, arg_gid, arg_supplementary_gids, arg_n_supplementary_gids, arg_console_mode != CONSOLE_PIPE);
@@ -3963,8 +3964,9 @@ static int outer_child(
if (r < 0)
log_debug_errno(r, "Failed to read os-release from host for container, ignoring: %m");
if (prctl(PR_SET_PDEATHSIG, SIGKILL) < 0)
return log_error_errno(errno, "PR_SET_PDEATHSIG failed: %m");
r = prctl_safe(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
if (r < 0)
return log_error_errno(r, "PR_SET_PDEATHSIG failed: %m");
r = reset_audit_loginuid();
if (r < 0)