Commit Graph

3538 Commits

Author SHA1 Message Date
Frantisek Sumsal
4820c9d417 fuzz: unify logging setup
Make sure we don't log anything when running in "fuzzing" mode. Also,
when at it, unify the setup logic into a helper, pretty similar to
the test_setup_logging() one.

Addresses:
  - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607
  - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
2023-10-19 10:05:20 +01:00
Lennart Poettering
4d9f092b5e process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errors 2023-10-18 14:49:40 +02:00
Lennart Poettering
becdfcb9f1 process-util: change pid_is_alive() to not eat up errors, and add pidref_is_alive()
Let's no eat up errors, but propagate unexpected ones.
2023-10-18 14:40:25 +02:00
Lennart Poettering
d7d748548b process-util: add pidref_get_comm() and rename get_process_comm() to pid_get_comm() 2023-10-18 14:39:33 +02:00
Lennart Poettering
0ff6ff2b29 tree-wide: port various parsers over to read_stripped_line() 2023-10-17 14:36:54 +02:00
Daan De Meyer
fe2a6dce6c sd-device: Support matching all properties
Let's support enumerating over devices that match all of the given
properties instead of any of the given properties by adding a new
function sd_device_enumerator_add_match_property_required() which
specifies properties that should all be matched instead of just one.

Fixes #28372
2023-10-11 19:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
f6210525cc fuzz-bus-match: drop unnecessary wrapper function
Same confusion as in previous commit.
2023-10-06 16:48:16 +02:00
Daan De Meyer
8aa59287c0 Merge pull request #29456 from yuwata/journal-replace-truncating-with-punching-holes
journal: replace truncating with punching holes
2023-10-06 09:18:06 +02:00
felixdoerre
3846d3aa29 journalctl: verify that old entries are not sealed with too recent key (#28885)
When verifying seals produced with forward secure sealing, the verification
currently does not check that old entries are only sealed with the key for
their epoch and not a more recent one. This missing check allows an attacker
to remove seals, and create new ones with the currently available key, and
verify will claim everything is in order, although all entries could have
been modified.

This resolves CVE-2023-31439.

Co-authored-by: Felix Dörre <felix.doerre@kit.edu>
2023-10-06 12:18:21 +09:00
Yu Watanabe
8af8f9e891 Merge pull request #29417 from yuwata/sd-journal-cleanups-for-generic-array-bisect-plus-one
sd-journal: cleanups for generic_array_bisect_plus_one()
2023-10-06 11:04:07 +09:00
Yu Watanabe
77db35bf10 sd-journal: make journal_file_next_entry() always return the nearest entry object
Previously, if the input offset 'p' does not point to an entry object,
the function returns the next of the nearest entry object on
DIRECTION_DOWN, as generic_array_bisect() already returns the nearest
entry object.
2023-10-06 09:57:27 +09:00
Yu Watanabe
80f96c0ce1 sd-journal: reduce number of calls generic_array_bisect_plus_one()
If the first call of generic_array_bisect_plus_one() provides the same
offset, then it is not necessary to call the next one, as we already
know the entry object is also liked to the input data object.

Also, this make the function reuse the object returned by
generic_array_bisect_plus_one().

No functional change, just optimization.
2023-10-06 09:55:04 +09:00
Yu Watanabe
20c45e5784 sd-journal: drop unnecessary re-read of data object
Follow-up for ec50313d4e.

The function generic_array_bisect_plus_one() does not read any new data
objects, so the data object is still valid, and not necessary to re-read it.
2023-10-06 09:55:04 +09:00
Yu Watanabe
d67078b4a3 sd-journal: rewrite conditions for test result and direction
No functional change, just refactoring. Hopefully the condition is more
descriptive now.
2023-10-06 09:55:00 +09:00
Yu Watanabe
3b0ae13bbf test: add reproducer for SIGBUS issue caused by journal truncation
The added code fails without the previous commit.

For issue #24320.
2023-10-06 09:24:55 +09:00
Yu Watanabe
ff95b60d1a test: modernize test-journal-flush 2023-10-05 19:15:55 +09:00
Yu Watanabe
0073f6c623 mmap-cache: each Window is owned by MMapFileDescriptor
And MMapFileDescriptor always references MMapCache, hence it is not
necessary Window to have a reference to MMapCache.

This also renames the list fields 'by_fd' -> 'windows', to make them
consistent with the name of the head.

No functional change, just refactoring.
2023-10-04 19:53:27 +09:00
Yu Watanabe
40f5e6a941 mmap-cache: merge mmap_cache_fd_get() with try_context() and find_mmap()
The post operations (attach the found or new window to a context, update
the keep_always flag, and calculate the address) in three steps are
equivalent, and the two searching logics are quite simple.
Let's merge them to decrease the total lines.

No functional change, just refactoring.
2023-10-04 19:53:27 +09:00
Yu Watanabe
81598f5ead mmap-cache: merge window_matches() and window_matches_fd()
Let's drop meaningless optimization, and always check if the window is
owned by the expected fd.
2023-10-04 19:53:27 +09:00
Yu Watanabe
1ed867d309 mmap-cache: merge mmap_try_harder() with make_room()
The function make_room() is short and only used by mmap_try_harder().
Let's merge them with short comments.

No functional change, just refactoring.
2023-10-04 19:53:27 +09:00
Yu Watanabe
0096914023 sd-journal: drop unused argument for generic_array_bisect_plus_one() 2023-10-04 17:36:14 +09:00
Daan De Meyer
9c56d79e1c Merge pull request #29386 from yuwata/mmap-cache-cleanups-part1
mmap-cache: several cleanups (part1)
2023-10-04 08:49:24 +02:00
Daan De Meyer
180d5aeaa7 Merge pull request #29403 from yuwata/journal-decouple-journald-and-journal-remote
journal: drop ManagedJournalFile and decouple journald and journal-remote
2023-10-04 07:55:52 +02:00
Yu Watanabe
0558c86c78 sd-netlink: use secure_getenv()
Follow-up for 52afaee74b.

Fixes CID#1522326.
2023-10-04 07:48:30 +02:00
Yu Watanabe
31438511e0 sd-journal: drop unnecessary re-read of object
This reverts the following commits.
- a1640191b4
- 231741d355

These were done by my misunderstanding of the mmap cache behavior.

Also, this updates the comments added by
df04b9ed86.
2023-10-03 22:17:34 +01:00
Luca Boccassi
8867122783 Merge pull request #29390 from yuwata/sd-netlink-make-default-timeout-configurable
sd-netlink: make the default timeout configurable
2023-10-02 22:59:07 +01:00
Yu Watanabe
1d3ef11dfe journal: move several tests to libsystemd/sd-journal
This also renames test-journal-xyz for journald (rather than sd-journal)
to test-journald-xyz.
2023-10-02 10:52:45 +09:00
Yu Watanabe
52afaee74b sd-netlink: make the default timeout configurable by environment variable
On normal systems, triggering a timeout should be a bug in code or
configuration error, so I do not think we should extend the default
timeout. Also, we should not introduce a 'first class' configuration
option about that. But, making it configurable may be useful for cases
such that "an extremely highly utilized system (lots of OOM kills,
very high CPU utilization, etc)".

Closes #25441.
2023-10-01 12:41:10 +09:00
Yu Watanabe
f5c615889a sd-netlink: make calc_elapse() return USEC_INFINITY when no timeout is requested
Then, timout_compare() becomes simplar, the timeout value becomes
consistent with what sd_netlink_get_timeout() provides.

This also drop unnecessary assignment of reply_callback.timeout after
the slot is dropped from the prioq.
2023-10-01 12:41:10 +09:00
Yu Watanabe
8fc4d1be77 mmap-cache: rebreak lines 2023-10-01 06:35:02 +09:00
Yu Watanabe
b38977e5d3 mmap-cache: modernize free functions
No functional change, just refactoring.
2023-10-01 06:35:02 +09:00
Yu Watanabe
8ff0f36e00 mmap-cache: check if mmap protection mode is consistent when fd is already managed
Otherwise, MMapFileDescriptor with an unexpected protection mode may be
returned.
2023-10-01 06:35:02 +09:00
Yu Watanabe
8926a6a467 mmap-cache: modernize mmap_cache_add_fd()
- use hashmap_ensure_put(),
- use _cleanup_free_ attribute,
- use structured initializer.
2023-10-01 06:35:02 +09:00
Yu Watanabe
397caa8122 mmap-cache: use structured initializer 2023-10-01 06:35:02 +09:00
Yu Watanabe
d37eeabc4f sd-journal: merge journal_file_next_entry_for_data() with generic_array_get_plus_one()
Because journal_file_next_entry_for_data() provides the first entry, while
journal_file_next_entry() actually provides the next entry of the input,
this also renames it to journal_file_move_to_entry_for_data().

Also, previously, on DIRECTION_UP the function did not fall back to the
'extra' entry when all entries linked in the chained array are broken.
This also fixes the issue, and now it fall back to the extra entry.
2023-09-30 20:10:15 +09:00
Yu Watanabe
3a23e41883 sd-journal: add/update comments 2023-09-30 20:10:15 +09:00
Yu Watanabe
f85e79d3e5 sd-journal: add missing 'error' handling
When we reach an empty array, there are at least two possibilities:
- journal file is corrupted,
- invalid index is requested.

We cannot distinguish them here, let's simply return earlier.
2023-09-30 20:10:15 +09:00
Yu Watanabe
fe6f2bd8a6 sd-journal: fix calculation of number of 'total' entries in the chained arrays
If there's corruption and we are going upwards, then the 'total'
must be decreased when we go to the previous array. However,
previously, we wrongly kept or increased the number. This fixes
the behavior.
2023-09-30 20:10:15 +09:00
Yu Watanabe
b63f09e4ee sd-journal: merge two bump_entry_array() calls
No functional changes, just refactoring.
2023-09-30 20:10:15 +09:00
Yu Watanabe
b7264911aa sd-journal: make bump_entry_array() return positive when a valid offset found
When it returns 0 offset, then the subsequent
journal_file_move_to_object() will fail. Let's return
generic_array_get() earlier in such situation.
2023-09-30 20:10:15 +09:00
Yu Watanabe
eb6ba87344 sd-journal: drop redundant re-read of entry array object
This effectively reverts d9b61db922.

In the do-while loop, we do not read any other entry array object, hence
the current object is always in the mmap cache and not necessary to re-read it.
2023-09-30 20:10:15 +09:00
Daan De Meyer
4444564a95 Merge pull request #29193 from keszybz/path-util-adjustment
Make unit mangling follow paths
2023-09-29 11:33:12 +02:00
Yu Watanabe
304cb08f84 sd-journal: always fallback to find entry by realtime
Consider the following situation:
- There are two journal files (x and y), that contains entries for two boots (X and Y).
- The journal file x contains entries of the boot X, and y contains
  entries of Y.
- Nevertheless x does not contains entries of boot Y, it contains
  the _BOOT_ID= data object of boot Y. Of course, the data object is not
  referenced by any entries in the journal file x.

In such situation, when the current location of sd_journal is the head
of journal y, that is, the first entry of the boot Y,
sd_journal_previous() failed without this change, and
'journalctl --boot -NUM' for boot X failed.

Fixes #29275.
2023-09-26 13:26:22 +09:00
Yu Watanabe
1eede15851 sd-journal: refuse to write entry without boot ID
To make journal entries always contain valid boot ID.
2023-09-26 13:26:22 +09:00
Yu Watanabe
b761ae0fca sd-journal: boot_id is always non-NULL
The two callers of journal_file_append_entry_internal() always pass
non-NULL boot ID.
2023-09-26 13:26:22 +09:00
Yu Watanabe
6ea51363c8 sd-journal: also verify tail_entry_boot_id and friends in journal_file_verify_header()
Then, we can drop the redundant check in journal_file_read_tail_timestamp().
2023-09-26 13:26:22 +09:00
Zbigniew Jędrzejewski-Szmek
660087dc9c tree-wide: add path_simplify_alloc() and use it
path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.

In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.

In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
2023-09-22 08:13:34 +02:00
Yu Watanabe
c650d4cdef sd-journal: refuse entry objects with an empty boot ID
Otherwise, e.g. sd_journal_get_monotonic_usec() return an empty boot ID
when called for such a broken entry object.

Such a broken object may be stored when the system was not cleanly shutdown.

Fixes #29167.
2023-09-22 08:05:53 +02:00
Yu Watanabe
afb81a0c05 sd-event: drop unnecessary call of sd_event_now() when requested relative time is zero 2023-09-21 11:03:37 +02:00
Yu Watanabe
d08ff4506c sd-device: include missing alloc-util.h
unref_and_replace_full() is defined in alloc-util.h.
2023-09-21 14:28:55 +08:00