linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] coredump: hand a pidfd to the usermode coredump helper
@ 2025-04-14 13:55 Christian Brauner
  2025-04-14 13:55 ` [PATCH v2 1/3] pidfs: move O_RDWR into pidfs_alloc_file() Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Christian Brauner @ 2025-04-14 13:55 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Oleg Nesterov, Luca Boccassi, Lennart Poettering, Daan De Meyer,
	Mike Yuan, Zbigniew Jędrzejewski-Szmek, linux-kernel,
	Christian Brauner

Give userspace a way to instruct the kernel to install a pidfd for the
crashing process into the process started as a usermode helper. There's
still tricky race-windows that cannot be easily or sometimes not closed
at all by userspace. There's various ways like looking at the start time
of a process to make sure that the usermode helper process is started
after the crashing process but it's all very very brittle and fraught
with peril.

The crashed-but-not-reaped process can be killed by userspace before
coredump processing programs like systemd-coredump have had time to
manually open a PIDFD from the PID the kernel provides them, which means
they can be tricked into reading from an arbitrary process, and they run
with full privileges as they are usermode helper processes.

Even if that specific race-window wouldn't exist it's still the safest
and cleanest way to let the kernel provide the pidfd directly instead of
requiring userspace to do it manually. In parallel with this commit we
already have systemd adding support for this in [1].

When the usermode helper process is forked we install a pidfd file
descriptor three into the usermode helper's file descriptor table so
it's available to the exec'd program.

Since usermode helpers are either children of the system_unbound_wq
workqueue or kthreadd we know that the file descriptor table is empty
and can thus always use three as the file descriptor number.

Note, that we'll install a pidfd for the thread-group leader even if a
subthread is calling do_coredump(). We know that task linkage hasn't
been removed yet and even if this @current isn't the actual thread-group
leader we know that the thread-group leader cannot be reaped until
@current has exited.

[1]: https://github.com/systemd/systemd/pull/37125

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Changes in v2:
- Store a pid in struct coredump_params instead of a file.
- Link to v1: https://lore.kernel.org/20250414-work-coredump-v1-0-6caebc807ff4@kernel.org

---
Christian Brauner (3):
      pidfs: move O_RDWR into pidfs_alloc_file()
      coredump: fix error handling for replace_fd()
      coredump: hand a pidfd to the usermode coredump helper

 fs/coredump.c            | 68 +++++++++++++++++++++++++++++++++++++++++++-----
 fs/pidfs.c               |  1 +
 include/linux/coredump.h |  1 +
 kernel/fork.c            |  2 +-
 4 files changed, 65 insertions(+), 7 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250413-work-coredump-0f7fa7e6414c


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-04-30 11:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 13:55 [PATCH v2 0/3] coredump: hand a pidfd to the usermode coredump helper Christian Brauner
2025-04-14 13:55 ` [PATCH v2 1/3] pidfs: move O_RDWR into pidfs_alloc_file() Christian Brauner
2025-04-14 13:55 ` [PATCH v2 2/3] coredump: fix error handling for replace_fd() Christian Brauner
2025-04-14 13:55 ` [PATCH v2 3/3] coredump: hand a pidfd to the usermode coredump helper Christian Brauner
2025-04-14 14:14   ` Oleg Nesterov
2025-04-14 14:26     ` Christian Brauner
2025-04-14 14:28     ` Oleg Nesterov
2025-04-14 14:41       ` Christian Brauner
2025-04-25 11:31   ` Benjamin Drung
2025-04-25 11:57     ` Christian Brauner
2025-04-25 12:03       ` Benjamin Drung
2025-04-25 16:49         ` Christian Brauner
2025-04-30 11:39           ` Benjamin Drung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).