Commit Graph
508 Commits
Author SHA1 Message Date
Daan De Meyer fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Daan De MeyerandMike Yuan 8c007f68ff process-util: Migrate namespace_fork() to PidRef
Co-authored-by: Mike Yuan <me@yhndnzj.com>
2025-12-20 13:45:22 +01:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Yu Watanabe 929ce35f8d meson: rework include_directories() and finding of tools (#39956)
This is a cleanup in preparation for later additions.
2025-12-02 20:07:37 +09:00
Zbigniew Jędrzejewski-Szmek 963bebd7b0 meson: add source dir to include_directories automatically
Quite often we need to specify include_directories('.'). Normally, meson
does this automatically, but we specify implicit_include_directories : false,
see 30d20907bd for an explanation.
Passing the include_directories argument through the template layers was rather
cumbersome. Let's simplify things by always including the directory of the
first source file. This makes the definitions simpler, at the cost of having an
unnecessary include directory in the list in some cases.

(Tests are excluded from this change, because they happen to not need this, but
also because some tests have source[0] which is a custom target, and we'd need
newer meson to support that.)
2025-12-01 15:35:22 +01:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Daan De Meyer 87fbd33372 clang-tidy: Fix all remaining misc-include-cleaner violations
- Remove unused includes
- Add common false positive headers to misc-include-cleaner.IgnoreHeaders
- Add IWYU pragma keep for uncommon false positive headers
2025-11-22 10:19:41 +01:00
Zbigniew Jędrzejewski-Szmek 5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Yu Watanabe d42db35a7c Drop remaining CGroup v1 specific code (#38969) 2025-11-17 23:48:29 +09:00
Lennart Poettering 1006b7e5ba coredumpctl: remove unnecessary line break 2025-11-17 22:35:03 +09:00
Yu Watanabe b525a72f7b cgroup-util: drop cgroup v1 support from cg_pid_get_path()
We have dropped cgroup v1 support in v258. Let's drop legacy code.
Then, we can drop 'controller' argument from cg_pid_get_path() and
cg_pidref_get_path().
2025-11-17 21:30:29 +09:00
Yu Watanabe e3ea1cfd5e tree-wide: add several missing includes
- test-reread-partition-table.c: sys/file.h for LOCK_EX
- coredump: unistd.h for STDIN_FILENO
2025-11-10 09:36:52 +09:00
Yu Watanabe a7807e66b7 coredump: several cleanups, modernizations, fixlets for corner cases (#39418) 2025-11-02 10:13:53 +09:00
Daan De Meyer 004b7f1f7e elf-util: Add support for parsing dlopen metadata
Then we can add support for showing dlopen metadata to systemd-analyze.
2025-10-30 08:41:43 +01:00
Yu Watanabe de438df275 coredump-send: do not forward when the service manager in container crashed
In that case, even if we forward coredump to the container namespace,
the socket unit will never triggered.
2025-10-28 14:31:41 +09:00
Yu Watanabe ab999c9280 coredump: enter mount namespace even when the crashed process is in the same PID namespace
Otherwise, we may not get stacktrace of the crashed process when it is
in running a mount namespace, especially when it is in a portable
service or service that uses RootImage=/RootDirectory=.
2025-10-28 14:31:41 +09:00
Yu Watanabe 91840f324e coredump-context: cache if the crashed process in the same PID namespace 2025-10-28 14:31:41 +09:00
Yu Watanabe 7df4841e94 coredump-context: several cleanups
- Renames Context to CoredumpContext.
- Renames enum meta_argv_t to MetadataField, and use the correct type at
  several pleaces, especially in loop.
- Parses argv (when invoked as kernel helper or with '--backtrace') or
  iov (when invoked through socket) and store values in the context.
  Previously we use the passed string as is, but let's make them in a
  type safe way.
- Stores received or built iovw in the context. Also store input fd and
  mountfs fd in the context.
- Introduces coredump_context_is_pid1() and _is_journald() helper
  functions.
- Adds COREDUMP_PIDFDID= field when the kernel passed pidfd of the
  crashed process.

No effective funtional change. Just refactoring.
2025-10-28 14:31:41 +09:00
Yu Watanabe d7755c9caf coredump: allow to control log level and so on via command line 2025-10-28 14:31:41 +09:00
Yu Watanabe 4d73712ef7 coredump: shortcut to start backtrace mode
When running as backtrace mode, it is not necessary to use kmsg, not
necessary to disable coredump from the command, and unexpectedly
passed file descriptors can be silently ignored.
2025-10-28 14:31:37 +09:00
Yu Watanabe e09543b87b coredump-config: several modernizations
- introduce CoredumpConfig object that stores all configuration
  parameters parsed from coredump.conf,
- use gperf to generate conf parser table,
- parse coredump.conf only when necessary: when systemd-coredump is
  invoked as kernel helper or by socket actiavation.
2025-10-28 14:29:22 +09:00
Michal Sekletar 28e62e684b coredump: handle ENOBUFS and EMSGSIZE the same way
Depending on the runtime configuration, e.g. sysctls
net.core.wmem_default= and net.core.rmem_default and on the actual
message size, sendmsg() can fail also with ENOBUFS. E.g. alloc_skb()
failure caused by net.core.[rw]mem_default=64MiB and huge fdinfo list
from process that has 90k opened FDs.

We should handle this case in the same way as EMSGSIZE and drop part of
the message.
2025-10-24 15:23:09 +01:00
Lennart Poettering b38dc56bab coredump: split coredump.c into small pieces (#39351) 2025-10-22 13:37:51 +02:00
Yu Watanabe 94a23e9c44 coredumpctl: fix condition for checking coredump journal entry
If one of PID, UID, GID, or SIGNAL is missing, then parse_uid() and
friends in the below will trigger assertion. This fixes that.

Also, only PID, UID, GID, SIGNAL, and COMM are mandatory fields, but
others are not, hence this drops others from the condition.

Moreover, this mekes 'coredumpctl --list' not fail even if there exists a
broken coredump entry in journal.
2025-10-20 20:43:45 +09:00
Yu Watanabe f8e7566cb2 coredump: drop unnecessary header inclusion 2025-10-19 10:01:38 +09:00
Yu Watanabe 4fcd5f8b4b coredump: split out process_kernel() to coredump-kernel-helper.[ch]
Then, rename to coredump_kernel_helper().
2025-10-19 10:01:38 +09:00
Yu Watanabe 4bae593612 coredump: split out functions for sending coredump to coredump-send.[ch] 2025-10-19 10:01:38 +09:00
Yu Watanabe ab2e98b43c coredump: split out process_socket() to coredump-receive.[ch]
Then, rename to coredump_receive().
2025-10-19 10:01:38 +09:00
Yu Watanabe 640b7c38f8 coredump: split out acquire_pid_mount_tree_fd() and submit_coredump() to coredump-submit.[ch]
Then this renames submit_coredump() to coredump_submit().
2025-10-19 10:01:38 +09:00
Yu Watanabe fa30374e15 coredump: split out process_backtrace() to coredump-backtrace.[ch]
Then, rename to coredump_backtrace().
2025-10-19 10:01:38 +09:00
Yu Watanabe 4131e3a816 coredump: split out metadata parsers to coredump-context.[ch] 2025-10-19 10:01:38 +09:00
Yu Watanabe 2568548560 coredump: split out conf parser to coredump-config.[ch] 2025-10-19 10:01:38 +09:00
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Lennart Poettering 015025cba2 cgroup-util: add pidref+full counter parts for cg_pid_get_user_unit()
This completes the set of functions for getting the user unit of a
process, mirroring the four functions we already have for the system
unit.
2025-09-25 14:09:55 +02:00
Lennart Poettering ab2b430487 tree-wide: drop deps on libacl
test-shift-uid.c doesn't actually use anything from libacl. It all goes
through shared/, and the dep there is enough.

Same for the coredump stuffi, logind and core/.

And pstore doesn't use it at all, neither directly or indirectly.
2025-09-24 09:47:30 +02:00
ZIHCO ad6e02e7b4 systemd-analyze: added the verb unit-gdb to spawn and attach gdb 2025-07-17 15:09:58 +01:00
Zbigniew Jędrzejewski-Szmek 8ec2e177b0 coredump: fix 0-passed-as-pointer warning 2025-06-06 22:15:03 +02:00
Michal Sekletar 8f8148cb08 Revert "coredump: lock down EnterNamespace= mount even more"
This reverts commit 4c9c8b8d09.

Reverted change broke EnterNamespace= completely. For example, libdw
tries to access libc in /lib64 which points to usr/lib64 and that fails.
Similarly for binaries, we need to be able to resolve /bin to usr/bin
and /sbin to usr/sbin at the very least.
2025-06-04 19:21:07 +09:00
Adrian Vovk 554130faf3 Define uid range for greeter
In multi-seat scenarios, a display manager might need to start multiple
greeter sessions. But systemd allows at most one graphical session per
user. So, display managers now have a range of UIDs to dynamically
allocate users for their greeter sessions.
2025-06-02 11:19:12 +02:00
Lennart Poettering 1105f8d20f tree-wide: only use .si_pid field in siginfo_t, if .si_code indicates that's safe
Fixes: #37498
2025-05-31 14:48:37 +02:00
Zbigniew Jędrzejewski-Szmek 9ce8e3e449 Define helper to call PR_SET_DUMPABLE 2025-05-29 00:19:24 +02:00
Zbigniew Jędrzejewski-Szmek 76e0ab49c4 coredump: introduce an enum to wrap dumpable constants
Two constants are described in the man page, but are not defined by a header.
The third constant is described in the kernel docs. Use explicit values to
show that those are values are defined externally.
2025-05-29 00:12:10 +02:00
Zbigniew Jędrzejewski-Szmek e6a8687b93 coredump: when %F/pidfd is used, again allow forwarding to containers 2025-05-29 00:10:55 +02:00
Luca Boccassi 868d95577e coredump: add support for new %F PIDFD specifier
A new core_pattern specifier was added, %F, to provide a PIDFD
to the usermode helper process referring to the crashed process.
This removes all possible race conditions, ensuring only the
crashed process gets inspected by systemd-coredump.
2025-05-29 00:10:55 +02:00
Zbigniew Jędrzejewski-Szmek 13902e0253 coredump: get rid of a bogus assertion
The check looks plausible, but when I started checking whether it needs
to be lowered for the recent changes, I realized that it doesn't make
much sense.

context_parse_iovw() is called from a few places, e.g.:
- process_socket(), where the other side controls the contents of the
  message. We already do other checks on the correctness of the message
  and this assert is not needed.
- gather_pid_metadata_from_argv(), which is called after
  inserting MESSAGE_ID= and PRIORITY= into the array, so there is no
  direct relation between _META_ARGV_MAX and the number of args in the
  iovw.
- gather_pid_metadata_from_procfs(), where we insert a bazillion fields,
  but without any relation to _META_ARGV_MAX.

Since we already separately check if the required stuff was set, drop this
misleading check.
2025-05-29 00:10:55 +02:00
Zbigniew Jędrzejewski-Szmek 8fc7b2a211 coredump: also stop forwarding non-dumpable processes
See the comment in the patch for details.

Suggested-by: Qualys Security Advisory <qsa@qualys.com>
2025-05-29 00:10:55 +02:00
Zbigniew Jędrzejewski-Szmek 0c49e0049b coredump: use %d in kernel core pattern
The kernel provides %d which is documented as
"dump mode—same as value returned by prctl(2) PR_GET_DUMPABLE".

We already query /proc/pid/auxv for this information, but unfortunately this
check is subject to a race, because the crashed process may be replaced by an
attacker before we read this data, for example replacing a SUID process that
was killed by a signal with another process that is not SUID, tricking us into
making the coredump of the original process readable by the attacker.

With this patch, we effectively add one more check to the list of conditions
that need be satisfied if we are to make the coredump accessible to the user.

Reportedy-by: Qualys Security Advisory <qsa@qualys.com>

In principle, %d might return a value other than 0, 1, or 2 in the future.
Thus, we accept those, but emit a notice.
2025-05-29 00:10:08 +02:00
Zbigniew Jędrzejewski-Szmek 49f1f2d4a7 coredump: get rid of _META_MANDATORY_MAX
No functional change. This change is done in preparation for future changes.
Currently, the list of fields which are received on the command line is a
strict subset of the fields which are always expected to be received on a
socket. But when we add new kernel args in the future, we'll have two
non-overlapping sets and this approach will not work. Get rid of the variable
and enumerate the required fields. This set will never change, so this is
actually more maintainable.

The message with the hint where to add new fields is switched with
_META_ARGV_MAX. The new order is more correct.
2025-05-26 15:33:08 +02:00
Zbigniew Jędrzejewski-Szmek 61d78f1788 Restore compatibility for coredump --backtrace (#37559) 2025-05-22 13:40:29 +02:00
Zbigniew Jędrzejewski-Szmek c673f1f67a coredump: wrap long lines, fix grammar in comments 2025-05-21 23:51:31 +02:00