Commit Graph

3574 Commits

Author SHA1 Message Date
Yu Watanabe
2b43729bf9 sd-journal: warn about seals may not be continuous only when the file is sealed
Follow-up for e375bc5fcc.

Fixes #30118.
2023-11-22 10:48:21 +09:00
Yu Watanabe
965040d811 test: always call test_setup_logging() 2023-11-18 03:04:27 +09:00
Luca Boccassi
fd13d32ba7 Merge pull request #30047 from yuwata/sd-bus-assert-return
sd-bus: several fixlets found by making assert_return() critical
2023-11-16 09:34:31 +00:00
Yu Watanabe
69f1c33425 test: sd_bus_process() may assign NULL even if it returns positive
Let's not trigger assert_return() needlessly.

Prompted by #30029.
2023-11-16 09:35:44 +09:00
Yu Watanabe
ce5a6d5307 test: several cleanups for test-bus-chat
- use sd_bus_query_sender_creds() to retrieve credentials,
- read credentials only when we get credentials, to avoid triggering
  assert_return(),
- downgrade log level of expected failure, and update log message about
  unexpected success.

Prompted by #30029.
2023-11-16 09:35:44 +09:00
Yu Watanabe
02dd646b16 sd-bus: drop SD_BUS_CREDS_AUGMENT flag
On checking if the message has enough credentials, the special flag
needs to be dropped.

Fixes a bug introduced by 705a415f68.
2023-11-16 09:35:44 +09:00
Yu Watanabe
22185cb71e sd-bus: insert missing space 2023-11-16 09:35:44 +09:00
Frantisek Sumsal
9988043b6b sd-journal: don't assert on invalid field
Also, field_is_valid(field) already does isempty(field), so drop that as
well.

$ SYSTEMD_LOG_LEVEL=debug journalctl -o verbose -F foo-bar-baz
...
Assertion 'field_is_valid(field)' failed at src/libsystemd/sd-journal/sd-journal.c:2789, function sd_journal_query_unique(). Ignoring.
Failed to query unique data objects: Invalid argument
2023-11-15 22:31:02 +01:00
Yu Watanabe
aecedc48a6 sd-device: do not trigger assertion by a bad udev rules
The assertion can be triggered by bad `$attr{[<subsys>/<sysname>]<attribute>}`
formatting. That's not a programmer's error, but a runtime error.

Prompted by #30029.
2023-11-16 02:32:12 +09:00
Frantisek Sumsal
6565b9d0b1 sd-bus: don't treat invalid user/machine as a programming error
$ SYSTEMD_LOG_LEVEL=debug machinectl status --machine=@
Assertion 'r > 0' failed at src/libsystemd/sd-bus/sd-bus.c:1694, function sd_bus_open_system_machine(). Ignoring.
2023-11-15 13:56:50 +01:00
Frantisek Sumsal
17122c3de1 sd-journal: don't treat invalid match as a programming error
Don't use assert_runtime() when we get an invalid match string, since
that's a runtime error:

$ SYSTEMD_LOG_LEVEL=debug coredumpctl info =
...
Adding match: =
Assertion 'match_is_valid(data, size)' failed at src/libsystemd/sd-journal/sd-journal.c:240, function sd_journal_add_match(). Ignoring.
Failed to add match "=": Invalid argument
2023-11-15 13:38:02 +01:00
Lennart Poettering
0408d802db id128: add id128_digest() helper
This helper hashes some arbitrary data and turns it into a v4 UUID.
2023-11-13 17:39:53 +01:00
Zbigniew Jędrzejewski-Szmek
fa5a025167 Rename {dual,triple}_timestamp_get to {dual,triple}_timestamp_now
Those functions take a pointer to a timestamp and return a timestamp pointer,
so the reader would be justified to think that those are just getters. Rename
them to avoid confusion.
2023-11-13 13:27:07 +01:00
Felix Dörre
e375bc5fcc journalctl: verify sealed log epochs are continuous
Currently empty epochs are not sealed. This allows an attacker to truncate
a sealed log and continue it without any problems showing when verifying the
log.

This partially addresses CVE-2023-31438. One way to extend this change to
address CVE-2023-31438 completely, would be to verify that there is exactly
one seal per epoch (and not sealing when the epoch has not ended yet).

the change also adds a journal-file flag: HEADER_COMPATIBLE_SEALED_CONTINUOUS
this flag indicates that a journal file is sealed continuously and decides whether
any missing crypto epochs should trigger a warning or an error.
2023-11-09 05:13:27 +09:00
Yu Watanabe
eba449fa81 sd-device-monitor: unconditionally increase buffer size by sd_device_monitor_new()
As suggested at https://github.com/systemd/systemd/pull/29872#discussion_r1382932633:
> socket memory is these days accounted to the process that owns a socket,
> hence we shouldn't be too concerned that this might waste memory.
2023-11-06 20:39:51 +09:00
Luca Boccassi
00cf9b3b1d Merge pull request #29402 from yuwata/sd-journal-cleanups-for-generic-array-bisect
sd-journal: cleanups for generic_array_bisect()
2023-11-04 10:38:03 +00:00
Yu Watanabe
7682aedb4e sd-journal: make generic_array_bisect_plus_one() take data object
Then, rename it to generic_array_bisect_for_data().
No functional change, just refactoring.
2023-11-04 11:48:20 +09:00
Yu Watanabe
a1b8d21fab sd-journal: introduce journal_file_pin_object()
Previously, OBJECT_UNUSED was used for 'pinning' the mmap cache for an
object. But, OBJECT_UNUSED is also used for reading object when type
cannot be determined before read, e.g. when reading the tail object.

Let's introduce another category for pinning mmap cache, and use it when
we want to temporary pin an object.
2023-11-04 11:47:55 +09:00
Yu Watanabe
7a56f6b2b9 mmap-cache: introduce window_matches_by_addr()
It is similar to window_matches(), but checks the mapped address.
Mostly preparation for later commits.
2023-11-04 11:42:19 +09:00
Yu Watanabe
1a25ab663c mmap-cache: introduce enum MMapCacheCategory
Then rename context -> category.

No functional change, just refactoring and modernization.
2023-11-04 11:41:15 +09:00
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
Yu Watanabe
ab8f553d1e sd-journal: rework generic_array_bisect()
- Rename generic_array_bisect_one() -> generic_array_bisect_step(), as there
  is also generic_array_bisect_plus_one(), so the original name is confusing.
- Make generic_array_bisect_step() return TEST_GOTO_NEXT or TEST_GOTO_PREVIOUS
  when the current array does not contain any matching entries.
- Make generic_array_bisect_step() symmetric with respect to the direction
  we are going to, except for the journal corruption handling.
- Make generic_array_bisect_step() gracefully handle journal corruptions,
  so the corruption handling in the caller side can be mostly dropped.
- Especially, when the last entry in an array is corrupted, previously
  we tried to find a valid entry sequentially from the end of the array,
  but now we anyway bisect the array. That should improve performance of
  reading corrupted journal files.
- Return earlier when no entry linked to the chained array (n == 0).
- Add many comments.

No behavior change unless journal is corrupted.
2023-11-04 11:01:30 +09:00
Yu Watanabe
f6548f053d sd-journal: drop redundant re-reading of entry array object
This effectively reverts e562f13158.

In the loop of the generic_array_bisect(), the offset of the entry array
object is unchanged, the object is read at the beginning of the loop, and
we do not read any other entry array object. Hence, it is not necessary to
re-read the object every time we use the object.
2023-11-04 10:54:43 +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
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