1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-07 05:57:46 +03:00

432 Commits

Author SHA1 Message Date
Yu Watanabe
77064620d7 Revert "coredumpctl: Don't treat no coredumps as failure"
This reverts commit dfe79b9ed21b0feeb5a120e8b994f46cff7cf5b0.
2024-12-11 11:14:37 +09:00
Daan De Meyer
dfe79b9ed2 coredumpctl: Don't treat no coredumps as failure
Having to deal with a process that fails or doesn't fail depending on
whether there are coredumps or not is incredibly annoying for users.
2024-12-10 21:03:20 +01:00
Lennart Poettering
00f7398049 coredump: rename gather_pid_mount_tree_fd() → acquire_pid_mount_tree_fd()
From my understanding of the english language "gather" imples there are
multiple things to gather. But here there's only one, hence use
"acquire"
2024-11-01 10:07:55 +01:00
Lennart Poettering
4c9c8b8d09 coredump: lock down EnterNamespace= mount even more
Let's disable symlink following if we attach a container's mount tree to
our own mount namespace. We afte rall mount the tree to a different
location in the mount tree than where it was inside the container, hence
symlinks (if they exist) will all point to the wrong places (even if
relative, some might point to other places). And since symlink attacks
are a thing, and we let libdw operate on the tree, let's lock this down
as much as we can and simply disable symlink traversal entirely.
2024-11-01 10:05:53 +01:00
Lennart Poettering
098c3975ac coredump: make check that all argv[] meta data fields are passed strict
Otherwise, if some field is not supplied we might end up parsing a NULL
string later. Let's catch that early.
2024-10-31 23:09:14 +01:00
Lennart Poettering
b1694040af coredump: use memory_startswith() when looking at a data blob 2024-10-31 23:08:11 +01:00
Lennart Poettering
2865561eaa coredump: move to _cleanup_ for destroying iovw object 2024-10-31 23:08:11 +01:00
Lennart Poettering
19455dd600 coredump: parse rlimit field at same place as other fields 2024-10-31 23:08:11 +01:00
Lennart Poettering
960b045875 coredump: parse signal number at the same time as parsing other fields 2024-10-31 23:08:11 +01:00
Lennart Poettering
32756e57ef coredump: rename save_context() → context_parse_iovw()
The function doesn't "save" anything, it just parses iovw into the
individual fields, hence name the function accordingly.
2024-10-31 23:08:11 +01:00
Lennart Poettering
1f485bc735 coredump: acquire some process fields via pidref
Use pidref to acquire some fields. This just makes use of the pidref
helpers we already have. We acquire a lot of other data via classic pids
still, but for that we first have to write race-free pidref getters,
hence leave that for another time.
2024-10-31 23:08:11 +01:00
Lennart Poettering
313537da6f coredump: rework protocol between coredump pattern handler and processing service
In 68511cebe58977ea68ae4f57c6462e979efd1cff the ability to pass the
coredump's mount namespace fd from the coredump patter handler was added
to systemd-coredump. For this the protocol was augmented, in attempt to
provide both forward and backward compatibility.

The protocol as of v256: one or more datagrams with journal log fields
about the coredump are sent via an SOCK_SEQPACKET connection. It is
finished with a zero length datagram which carries the coredump fd (this
last datagram is called "sentinel" sometimes).

The protocol after 68511cebe58977ea68ae4f57c6462e979efd1cff is extended
so that after the sentinal a 2nd sentinel is sent, with a pair of fds:
the coredump fd *again* and a mount fd (acquired via open_tree()) of the
container's mount tree. It's a bit ugly to send the coredump fd a 2nd
time, but what's more important the implementation didn't work: since on
SOCK_SEQPACKET a zero sized datagram cannot be distinguished from EOF
(which is a Linux API design mistake), an early EOF would be
misunderstood as a zero size datagram lacking any fd, which resulted in
protocol termination.

Moreover, I think if we touch the protocol we should make the move to
pidfs at the same time.

All of the above is what this protocol rework addresses.

1. A pidfd is now sent as well

2. The protocol is now payload, followed by the coredump fd datagram (as
   before).  But now followed by a second empty datagram with a pidfd,
   and a third empty datagram with the mount tree fd. Of this the latter
   two or last are optional. Thus, it's now a stream of payload
   datagrams with one, two or three fd-laden datagrams as sentinel. If
   we read the 2nd or 3rd sentinel without an attached fd we assume this
   is actually an EOF (whether it actually is one or not doesn't matter
   here). This should provide nice up and down compatibility.

3. The mount_tree_fd is moved into the Context object. The pidfd is
   placed there too, as a PidRef. Thus the data we pass around is now
   the coredump fd plus the context, which is simpler and makes a lot
   more semantical sense I think.

4. The "first" boolean is replaced by an explicit state engine enum

Fixes: #34130
2024-10-31 23:08:11 +01:00
Lennart Poettering
ecfb4bb05e coredump: correct debug log message 2024-10-31 23:08:11 +01:00
Lennart Poettering
ea8eb370e7 coredump: minor modernizations 2024-10-31 23:08:11 +01:00
Lennart Poettering
393d0d2b69 coredump: rename pid → leader_pid
Let's rename this local variable, since we are not operating on the
coredump process here after all, but on the leader of the namespace the
coredump process in, which is quite different, hence let's make this
very clear via the name.
2024-10-31 23:08:11 +01:00
Michal Sekletar
d9fd1d3707 coredump: allow only empty messages after first "sentinel" 2024-10-30 19:45:31 +00:00
Michal Sekletár
13cd1db07f coredump: return correct error variable 2024-10-30 12:38:27 +00:00
Michal Sekletar
e26a7e08f5 coredump: rename AccessContainer= to EnterNamespace= 2024-10-30 12:38:27 +00:00
Michal Sekletar
b8fe1b1dc8 coredump: rework gather_pid_mount_tree_fd() 2024-10-30 12:38:27 +00:00
Michal Sekletar
c287f0f7e9 coredump: use FORK_WAIT 2024-10-30 12:38:26 +00:00
Michal Sekletar
84289ab90f coredump: store actual fd in appropriate variable 2024-10-30 12:20:40 +00:00
Michal Sekletar
e5bad3a7b9 coredump: use FORK_LOG to get more precise logging 2024-10-30 12:20:40 +00:00
Michal Sekletar
a88e72be2c coredump: fix coding style 2024-10-30 12:20:40 +00:00
Michal Sekletar
4698fd9769 coredump: get rid of redundant double space 2024-10-30 12:20:40 +00:00
Michal Sekletar
5e55410aca coredump: use more appropriate return code 2024-10-30 12:20:40 +00:00
Michal Sekletar
a65ad191cd coredump: check for and close unexpected FDs 2024-10-30 12:20:40 +00:00
Michal Sekletar
7bfce97666 coredump: fix line spacing 2024-10-30 11:47:34 +00:00
Michal Sekletar
d8a567dfc3 coredump: merge variable definitions 2024-10-30 11:47:34 +00:00
Michal Sekletar
0aea68721a coredump: rework attaching container mount trees 2024-10-30 11:47:34 +00:00
Mike Yuan
3f8999a76e
fs-util: rename laccess to access_nofollow
In order to distinguish it from libc function naming.
2024-10-05 01:30:43 +02:00
Mike Yuan
7c1dd9e288
various: correct laccess() error check
laccess is our own macro that uses RET_NERRNO.
2024-10-04 21:26:04 +02:00
Mike Yuan
eda6223942 basic/memory-util: introduce mempcpy_typesafe 2024-09-20 08:29:35 +09:00
Lennart Poettering
369b12375b coredump: use _cleanup_(iovec_done) where appropriate 2024-09-16 10:42:02 +09:00
Yu Watanabe
42efe5be1d tree-wide: drop msg argument for DEFINE_CONFIG_PARSE() macro and friends
This makes the macros use log_syntax_parse_error(), hopefully which provides
more informative log message in general, and reduces binary size.
2024-09-02 05:45:09 +09:00
Mike Yuan
fad3feec12
shared/logs-show: introduce journal_browse_prepare()
which combines sigbus_install() and bumping fd limit.
2024-08-22 20:33:22 +02:00
Michal Sekletar
68511cebe5 coredump: generate properly symbolized stacktrace for containerized processes 2024-08-06 18:32:42 +02:00
Luca Boccassi
e6b2508275 coredump: correctly take tmpfs size into account for compression
We calculate the amount of uncompressed data we can write by taking the limits
into account and halving it to ensure there's room for switching to compression
on the fly when storing cores on a tmpfs (eg: due read-only rootfs).

But the logic is flawed, as taking into account the size of the tmpfs storage
was applied after the halving, so in practice when an uncompressed core file
was larger than the tmpfs, we fill it and then fail.

Rearrange the logic so that the halving is done after taking into account
the tmpfs size.
2024-07-03 01:15:03 +02:00
Lennart Poettering
309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Yu Watanabe
4e494e6aac tree-wise: several cleanups for logging
- drop unnecessary SYNTHETIC_ERRNO() when the logger does not propagate
  error code,
- drop unnecessary '%m' in error message when the error code is
  specified with SYNTHETIC_ERRNO(),
- add missing full stop at the end of log message,
- use RET_GATHER(),
- add missing ", ignoring.",
- upeercase the first letter, etc., etc...
2024-05-01 04:41:06 +09:00
Lennart Poettering
e1771c8ee6 sd-journal: make sure sd_journal_add_match() also accepts SIZE_MAX as size
In many of our internal functions that take a pointer + a size we have
introduced the rule that SIZE_MAX as size means: take strlen().

sd_journal_add_match() has something similar, but the special value is
0, not SIZE_MAX. This is a bit ugly, since a zero size data block is
theoretically fine. The only reason sd_journal_add_match() gets away
with using this special value is because valid matches must consist of
at least 2 chars, hence cannot be zero.

But let's make this more robust and less surprising when compared to the
rest of our code, and *also* accept SIZE_MAX to mean strlen().

No actual code changes, just some clean-up.
2024-04-10 16:54:03 +09:00
Yu Watanabe
8334b36653 coredumpctl: use strv_skip()
No functional change, just refactoring.
2024-03-25 21:39:37 +09:00
Yu Watanabe
5cacb0b645 coredumpctl: use journal_add_match_pair()
Also,
- use is_path(),
- drop unused pid.
2024-03-25 21:39:34 +09:00
Zbigniew Jędrzejewski-Szmek
f394876140 coredump: use free_and_strdup_warn() more 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
ec596fe34e
Merge pull request #30480 from keszybz/kernel-install-more-paths
Read kernel-install config from /run/kernel too
2024-03-08 08:25:07 +01:00
Zbigniew Jędrzejewski-Szmek
6378f257e7 various: use new config loader instead of config_parse_config_file()
This means the main config file is loaded also from /run and /usr.

We should load the main config file from all the places where we load drop-ins.

I realize I had a giant blind spot: I always assumed that we load config files
from /etc, /run, /usr/local/lib, /usr/lib. But it turns out that we only used
those paths for drop-ins. For the main config file, we only looked in /etc. The
docs actually partially described this behaviour, i.e. most SYNOPSIS sections
and some parts of the text, but not others.

This is strange, because 6495361c7d5e8bf640841d1292ef6cfe1ea244cf was completely
bogus with the behaviour before this patch. We had a huge discussion before it
was merged, and clearly nobody noticed this. Similarly, in the previous version
of the current pull request, we had a long discussion about the appropriate
order of directories, and apparently nobody noticed that there was no order,
because only looked in one directory. So the blind spot seems to have been
shared.

Also, systemd-analyze cat-config behaved incorrectly, i.e. its behaviour matches
the new behaviour.

Possibly, in the future it'll make it easier to add support for --root.
2024-03-07 19:14:36 +01:00
Zbigniew Jędrzejewski-Szmek
e5abff372d shared/conf-parser: collapse pkgdir and conf_file args into one
This essentially reverts 5656cdfeeabc16b5489f5ec7a0a36025a2ec1f23. I find it
much easier to understand what is going on when the
path-relative-to-the-search-path is passed in full, instead of being constructed
from two parts, with one of the parts being implicit in some places.

Also, we call 'systemd-analyze cat-config <path>' with <path> with the same
meaning, so this makes the internal and external APIs more consistent.
2024-03-07 18:49:44 +01:00
Matteo Croce
3fc72d5413 dynamically load compression libraries
Dynamically load liblz4, libzstd and liblzma with dlopen().
This helps to reduce the size of the initrd image when these libraries
are not really needed.
2024-03-05 12:37:21 +01:00
Lennart Poettering
f4a63ce25f dissect-image: add flag for explicitly enabling userspace verity signature checking
let's make userspace verity signature checking optional. This adds a
dissection flag to enable the logic and patches through all our users to
enable it by default, thus effectively not changing anything from the
status quo ante. However, know we have a knob to turn this off in
certain scenarios.
2024-02-28 16:17:40 +01:00
Yu Watanabe
f7f062bf9f tree-wide: set SD_JOURNAL_ASSUME_IMMUTABLE where appropriate
Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
2024-02-12 02:42:36 +09:00
Harald Brinkmann
2a9b1a76ee coredump: log minimal metadata early 2024-02-02 09:43:50 +09:00