Commit Graph
3552 Commits
Author SHA1 Message Date
Yu Watanabe 2ebc9cc867 mmap-cache: drop Context and boolean flags in Window
No functional change, just refactoring.
2023-11-04 11:12:12 +09:00
Lennart Poettering 0adb58c3f1 sd-netlink: add call to query sd_event object an sd_netlink object is attached to
This mimics a similar call sd_bus_get_event() that already exists for
sd-bus.
2023-11-02 14:19:32 +01:00
Lennart Poettering e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Yu Watanabe 4314abf6d4 sd-netlink: res_id is 16bit but serial is 32bit
The explicit value here is not so important.
Let's chop off the higher bits.

Fixes the issue reported at
https://github.com/systemd/systemd/pull/29802#issuecomment-1788637950.
2023-11-01 14:02:49 +00:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Luca Boccassi e5cd8bc060 Merge pull request #29601 from yuwata/mmap-check-overflow
mmap: check offset and size more carefully
2023-10-24 12:20:04 +01:00
Zbigniew Jędrzejewski-Szmek 7dc951ef91 basic/iovec-util: drop IOVEC_NULL
The macro isn't very useful, we can just use the direct setting to increase
readability.
2023-10-23 15:04:08 +02:00
Lennart Poettering 986235a99a iovec-util: make IOVEC_INCREMENT a regular function too
Even more than with the previous commit, this is not a trivial function
and there's no reason to believe this will actually be inlined nor that
it would be beneficial.
2023-10-20 10:43:50 +02:00
Lennart Poettering c24e0dbea1 iovec-util: make IOVEC_TOTAL_SIZE() a regular function
The function isn't necessarily fast (it's O(n)), and there's no reason
to have it defined as inline function, since it's neither fast, nor
entirely trivial.
2023-10-20 10:43:50 +02:00
Lennart Poettering bd1ae17833 io-util: split out "struct iovec" related calls into their own .c/.h files
This is preparation for #28891, which adds a bunch more helpers around
"struct iovec", at which point this really deserves its own .c/.h file.

The idea is that we sooner or later can consider "struct iovec" as an
entirely generic mechanism to reference some binary blob, and is the
go-to type for this purpose whenever we need one.
2023-10-20 10:34:33 +02:00
Yu Watanabe cbdac0c33a tree-wide: check results of PAGE_ALIGN()
Fixes CID#1491282, CID#1491283, CID#1491285, CID#1491288.
2023-10-19 18:31:44 +09:00
Yu Watanabe c886f2d26e mmap-cache: check offset and size more carefully
PAGE_ALIGN() and friends take size_t, while offset is uint64_t.
Let's use macros for uint64_t.

Also, mmap() takes size_t for size. So, let's also use size_t to
calculate a window size.

Prompted by CID#1491286.
2023-10-19 18:31:44 +09:00
Yu Watanabe ffee7b97e3 macro: introduce u64_multiply_safe() to avoid overflow
Just a paranoia.
2023-10-19 18:31:44 +09:00
Yu Watanabe b39907c712 sd-journal: use PAGE_ALIGN_U64() and friends
This also make constants declared with UINT64_C().
2023-10-19 18:31:44 +09:00
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
felixdoerreandFelix Dörre 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