]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: Connect stdout/stderr to /dev/null before doing anything
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 14 Jul 2022 23:49:25 +0000 (01:49 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 Jul 2022 09:06:18 +0000 (11:06 +0200)
When invoked as the coredump handler by the kernel, systemd-coredump's
stdout and stderr streams are closed. This is dangerous as this means
the fd's can get reallocated, leading to hard to debug errors such as
log messages ending up being appended to a compressed coredump file.

To avoid such issues in the future, let's bind stdout/stderr to
/dev/null so the file descriptors can't get used for anything else.

src/coredump/coredump.c

index 994d968d871b4946029947cfceb096a2f9fcdd9a..10a96ab568f1d251be9f532403cc0f0c326286aa 100644 (file)
@@ -1271,6 +1271,13 @@ static int process_kernel(int argc, char* argv[]) {
         struct iovec_wrapper *iovw;
         int r;
 
+        /* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds
+         * could get reallocated. To avoid hard to debug issues, let's instead bind stdout/stderr to
+         * /dev/null. */
+        r = rearrange_stdio(STDIN_FILENO, -1, -1);
+        if (r < 0)
+                return log_error_errno(r, "Failed to connect stdout/stderr to /dev/null: %m");
+
         log_debug("Processing coredump received from the kernel...");
 
         iovw = iovw_new();