]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Merge tag 'vfs-6.17-rc1.coredump' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Jul 2025 18:50:36 +0000 (11:50 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Jul 2025 18:50:36 +0000 (11:50 -0700)
Pull coredump updates from Christian Brauner:
 "This contains an extension to the coredump socket and a proper rework
  of the coredump code.

   - This extends the coredump socket to allow the coredump server to
     tell the kernel how to process individual coredumps. This allows
     for fine-grained coredump management. Userspace can decide to just
     let the kernel write out the coredump, or generate the coredump
     itself, or just reject it.

     * COREDUMP_KERNEL
       The kernel will write the coredump data to the socket.

     * COREDUMP_USERSPACE
       The kernel will not write coredump data but will indicate to the
       parent that a coredump has been generated. This is used when
       userspace generates its own coredumps.

     * COREDUMP_REJECT
       The kernel will skip generating a coredump for this task.

     * COREDUMP_WAIT
       The kernel will prevent the task from exiting until the coredump
       server has shutdown the socket connection.

     The flexible coredump socket can be enabled by using the "@@"
     prefix instead of the single "@" prefix for the regular coredump
     socket:

       @@/run/systemd/coredump.socket

   - Cleanup the coredump code properly while we have to touch it
     anyway.

     Split out each coredump mode in a separate helper so it's easy to
     grasp what is going on and make the code easier to follow. The core
     coredump function should now be very trivial to follow"

* tag 'vfs-6.17-rc1.coredump' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (31 commits)
  cleanup: add a scoped version of CLASS()
  coredump: add coredump_skip() helper
  coredump: avoid pointless variable
  coredump: order auto cleanup variables at the top
  coredump: add coredump_cleanup()
  coredump: auto cleanup prepare_creds()
  cred: add auto cleanup method
  coredump: directly return
  coredump: auto cleanup argv
  coredump: add coredump_write()
  coredump: use a single helper for the socket
  coredump: move pipe specific file check into coredump_pipe()
  coredump: split pipe coredumping into coredump_pipe()
  coredump: move core_pipe_count to global variable
  coredump: prepare to simplify exit paths
  coredump: split file coredumping into coredump_file()
  coredump: rename do_coredump() to vfs_coredump()
  selftests/coredump: make sure invalid paths are rejected
  coredump: validate socket path in coredump_parse()
  coredump: don't allow ".." in coredump socket path
  ...

1  2 
include/linux/fs.h
tools/testing/selftests/coredump/stackdump_test.c

Simple merge
index 68f8e479ac3682d02011dc54089f1f37919b8eb8,a4ac80bb10038d7f9ab27b56da6a79f5cc59e8a6..5a5a7a5f7e1ddb3f58f6a3cfb8029abfde1ca198
@@@ -418,59 -430,31 +430,34 @@@ TEST_F(coredump, socket_detect_userspac
                close(ipc_sockets[1]);
  
                fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC);
-               if (fd_coredump < 0) {
-                       fprintf(stderr, "Failed to accept coredump socket connection\n");
-                       close(fd_server);
-                       _exit(EXIT_FAILURE);
-               }
+               if (fd_coredump < 0)
+                       goto out;
  
-               fd_peer_pidfd_len = sizeof(fd_peer_pidfd);
-               ret = getsockopt(fd_coredump, SOL_SOCKET, SO_PEERPIDFD,
-                                &fd_peer_pidfd, &fd_peer_pidfd_len);
-               if (ret < 0) {
-                       fprintf(stderr, "%m - Failed to retrieve peer pidfd for coredump socket connection\n");
-                       close(fd_coredump);
-                       close(fd_server);
-                       _exit(EXIT_FAILURE);
-               }
-               memset(&info, 0, sizeof(info));
-               info.mask = PIDFD_INFO_EXIT | PIDFD_INFO_COREDUMP;
-               ret = ioctl(fd_peer_pidfd, PIDFD_GET_INFO, &info);
-               if (ret < 0) {
-                       fprintf(stderr, "Failed to retrieve pidfd info from peer pidfd for coredump socket connection\n");
-                       close(fd_coredump);
-                       close(fd_server);
-                       close(fd_peer_pidfd);
-                       _exit(EXIT_FAILURE);
-               }
+               fd_peer_pidfd = get_peer_pidfd(fd_coredump);
+               if (fd_peer_pidfd < 0)
+                       goto out;
  
-               if (!(info.mask & PIDFD_INFO_COREDUMP)) {
-                       fprintf(stderr, "Missing coredump information from coredumping task\n");
-                       close(fd_coredump);
-                       close(fd_server);
-                       close(fd_peer_pidfd);
-                       _exit(EXIT_FAILURE);
-               }
+               if (!get_pidfd_info(fd_peer_pidfd, &info))
+                       goto out;
  
-               if (info.coredump_mask & PIDFD_COREDUMPED) {
-                       fprintf(stderr, "Received unexpected connection from coredumping task\n");
-                       close(fd_coredump);
-                       close(fd_server);
-                       close(fd_peer_pidfd);
-                       _exit(EXIT_FAILURE);
-               }
+               if (!(info.mask & PIDFD_INFO_COREDUMP))
+                       goto out;
  
-               ret = read(fd_coredump, &c, 1);
+               if (info.coredump_mask & PIDFD_COREDUMPED)
+                       goto out;
  
-               close(fd_coredump);
-               close(fd_server);
-               close(fd_peer_pidfd);
-               close(fd_core_file);
++              if (read(fd_coredump, &c, 1) < 1)
++                      goto out;
 +
-               if (ret < 1)
-                       _exit(EXIT_FAILURE);
-               _exit(EXIT_SUCCESS);
+               exit_code = EXIT_SUCCESS;
+ out:
+               if (fd_peer_pidfd >= 0)
+                       close(fd_peer_pidfd);
+               if (fd_coredump >= 0)
+                       close(fd_coredump);
+               if (fd_server >= 0)
+                       close(fd_server);
+               _exit(exit_code);
        }
        self->pid_coredump_server = pid_coredump_server;