]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Define helper to call PR_SET_DUMPABLE
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 28 May 2025 16:31:13 +0000 (18:31 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 28 May 2025 22:19:24 +0000 (00:19 +0200)
src/coredump/coredump.c
src/shared/coredump-util.c
src/shared/coredump-util.h
src/shared/elf-util.c
src/shared/tests.c

index 2507e1b60300cc4da885e7f5d7e310ede66aeef2..55a0b704e3de2da31e6e428920b4a75889ec6f75 100644 (file)
@@ -3,7 +3,6 @@
 #include <elf.h>
 #include <stdio.h>
 #include <sys/mount.h>
-#include <sys/prctl.h>
 #include <sys/statvfs.h>
 #include <sys/xattr.h>
 #include <unistd.h>
@@ -2024,7 +2023,7 @@ static int run(int argc, char *argv[]) {
         log_set_target_and_open(LOG_TARGET_KMSG);
 
         /* Make sure we never enter a loop */
-        (void) prctl(PR_SET_DUMPABLE, SUID_DUMP_DISABLE);
+        (void) set_dumpable(SUID_DUMP_DISABLE);
 
         /* Ignore all parse errors */
         (void) parse_config();
index 9d18cf13010a97c40986529f3420f69148b99790..37dfb2c91a5f94de6cedbdee4583555f14f12321 100644 (file)
@@ -1,9 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <elf.h>
+#include <sys/prctl.h>
 
 #include "alloc-util.h"
 #include "coredump-util.h"
+#include "errno-util.h"
 #include "extract-word.h"
 #include "fileio.h"
 #include "log.h"
 #include "unaligned.h"
 #include "virt.h"
 
+int set_dumpable(SuidDumpMode mode) {
+        /* Cast mode explicitly to long, because prctl wants longs but is varargs. */
+        return RET_NERRNO(prctl(PR_SET_DUMPABLE, (long) mode));
+}
+
 static const char *const coredump_filter_table[_COREDUMP_FILTER_MAX] = {
         [COREDUMP_FILTER_PRIVATE_ANONYMOUS]   = "private-anonymous",
         [COREDUMP_FILTER_SHARED_ANONYMOUS]    = "shared-anonymous",
index f774425b293a82b597f5b07fcbb86915f6b798c9..76e37155371e1100d42cb940a0f569f1ae0f7afa 100644 (file)
@@ -35,6 +35,8 @@ typedef enum SuidDumpMode {
         _SUID_DUMP_MODE_MAX,
 } SuidDumpMode;
 
+int set_dumpable(SuidDumpMode mode);
+
 const char* coredump_filter_to_string(CoredumpFilter i) _const_;
 CoredumpFilter coredump_filter_from_string(const char *s) _pure_;
 int coredump_filter_mask_from_string(const char *s, uint64_t *ret);
index edc2e82d362db3f3c124f03587909625cea10ed4..fd06b55ab1dc3e1a0a6b774d0fac95a3fa4f1b56 100644 (file)
@@ -6,12 +6,12 @@
 #include <elfutils/libdwelf.h>
 #include <elfutils/libdwfl.h>
 #include <libelf.h>
-#include <sys/prctl.h>
 #include <sys/resource.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "coredump-util.h"
 #include "dlfcn-util.h"
 #include "elf-util.h"
 #include "errno-util.h"
@@ -826,7 +826,7 @@ int parse_elf_object(int fd, const char *executable, const char *root, bool fork
         if (r == 0) {
                 /* We want to avoid loops, given this can be called from systemd-coredump */
                 if (fork_disable_dump) {
-                        r = RET_NERRNO(prctl(PR_SET_DUMPABLE, 0));
+                        r = set_dumpable(SUID_DUMP_DISABLE);
                         if (r < 0)
                                 report_errno_and_exit(error_pipe[1], r);
                 }
index 66e1ae88cd64b4d222b1ad9ba65cf33f7b262ebd..7284d00e23e9d75e6653c66f37ffd3e87b08f199 100644 (file)
@@ -16,6 +16,7 @@
 #include "bus-wait-for-jobs.h"
 #include "cgroup-setup.h"
 #include "cgroup-util.h"
+#include "coredump-util.h"
 #include "env-file.h"
 #include "env-util.h"
 #include "fd-util.h"
@@ -433,7 +434,8 @@ int assert_signal_internal(void) {
 
         if (r == 0) {
                 /* Speed things up by never even attempting to generate a coredump */
-                (void) prctl(PR_SET_DUMPABLE, 0);
+                (void) set_dumpable(SUID_DUMP_DISABLE);
+
                 /* But still set an rlimit just in case */
                 (void) setrlimit(RLIMIT_CORE, &RLIMIT_MAKE_CONST(0));
                 return 0;