Commit 97e1cd5d authored by Christian Brauner's avatar Christian Brauner Committed by Giuliano Procida
Browse files

UPSTREAM: coredump: hand a pidfd to the usermode coredump helper

commit b5325b2a upstream.

Give userspace a way to instruct the kernel to install a pidfd into the
usermode helper process. This makes coredump handling a lot more
reliable for userspace. In parallel with this commit we already have
systemd adding support for this in [1].

We create a pidfs file for the coredumping process when we process the
corename pattern. When the usermode helper process is forked we then
install the pidfs file as file descriptor three into the usermode
helpers 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 due to delay_group_leader() 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.

[brauner: This is a backport for the v6.12 series. The upstream kernel
has changed pidfs_alloc_file() to set O_RDWR implicitly instead of
forcing callers to set it. Let's minimize the churn and just let the
coredump umh handler raise O_RDWR.]

Link: https://github.com/systemd/systemd/pull/37125 [1]
Link: https://lore.kernel.org/20250414-work-coredump-v2-3-685bf231f828@kernel.org


Tested-by: default avatarLuca Boccassi <luca.boccassi@gmail.com>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Change-Id: I5c2020bdeec03e803eda6fbeb5a81cb204b3002e
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 510cf09f)
Bug: 437846539
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent c78656bd
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment