Commit Graph
3591 Commits
Author SHA1 Message Date
Yu Watanabe 474536c949 sd-journal: use FOREACH_ARRAY() at one more place 2023-12-22 01:28:44 +09:00
Yu Watanabe 43127aebc7 tree-wide: use hashmap_isempty() and friends 2023-12-22 01:27:09 +09:00
Daan De Meyer a412a1b92a test: Skip various tests when /sys is not mounted
When running tests in a container, /sys might not be mounted, so
let's make sure we skip tests that depend on /sys in this case.
2023-12-19 16:38:57 +01:00
Yu Watanabe 5f6ab79571 sd-netlink: the kernel ignores NLM_F_APPEND in RTM_NEWNEXTHOP message but uses NLM_F_REPLACE
See insert_nexthop() in net/ipv4/nexthop.c of the kernel.
2023-12-14 18:58:26 +09:00
Mike Yuan 55b8f8100c macro-fundamental: add U64_{K,M,G}B 2023-12-13 20:42:05 +08:00
Yu Watanabe ef8ba77576 test: update log message and use SYNTHETIC_ERRNO()
Follow-up for ce5a6d5307.

Addresses https://github.com/systemd/systemd/pull/30049#discussion_r1395453408.
2023-12-10 12:51:17 +00:00
Zbigniew Jędrzejewski-Szmek 26e82eef01 sd-journal/catalog: modernize write_catalog() 2023-12-05 19:20:25 +01:00
Zbigniew Jędrzejewski-Szmek f9568765d4 variuos: fwrite() does not set errno
The man page doesn't even mention errno. It just says that ferror() should
be used to check for errors. Those writes are unlikely to fail, but if they
do, errno might even be 0. Also, we have fflush_and_check() which does
additional paranoia around errno, because we apparently do not trust that
errno will always be set correctly.
2023-12-05 19:18:23 +01:00
Zbigniew Jędrzejewski-Szmek ac116f8c27 Merge pull request #30268 from yuwata/network-fix-too-many-waiting-replies
network: fix issue caused by too many waiting replies
2023-12-01 19:54:18 +01:00
Yu Watanabe 4256379d99 sd-netlink: introduce netlink_get_reply_callback_count() 2023-12-01 19:44:47 +09:00
Yu Watanabe 4db7cb37bd sd-netlink: change error code of the case that too many replies waiting
ERANGE should be used when setting or parsing a number.
2023-12-01 14:37:05 +09:00
Yu Watanabe f3714bd5a2 test: add tests for generic_array_bisect() 2023-12-01 10:08:49 +09:00
Yu Watanabe 1f21bc5811 test: make append_number() optionally return offset of the entry object
Preparation for later commits.
2023-12-01 10:08:49 +09:00
Yu Watanabe 76b7a346ed test: split out finalization task 2023-12-01 10:08:46 +09:00
Yu Watanabe a93be359ae sd-journal: fix corrupted journal handling of generic_array_bisect()
Let's consider the following case:
- the direction is down,
- no cached entry,
- the array has 5 entry objects,
- the function test_object() reutns TEST_LEFT for the 1st object,
- the 2nd, 3rd, and 4th objects are broken, so generic_array_bisect_step()
  returns TEST_RIGHT for the object.

Then, previously, generic_array_bisect_step() updated the values like the following:
  0th: (m = 5, left = 0, right = 4, i = 4) -> (m = 4, left = 0, right = 3, RIGHT)
  1st: (m = 4, left = 0, right = 3, i = 1) -> (m = 4, left = 2, right = 3, LEFT)
  2nd: (m = 4, left = 2, right = 3, i = 2) -> (m = 2, left = 2, right = 1, RIGHT) <- ouch!!
So, assert(left < right) in generic_array_bisect() was triggered.
See issue #30210.

In such situation, there is no matching entry in the array. By returning
TEST_GOTO_PREVIOUS, generic_array_bisect() handles the result so.

Fixes a bug introduced by ab8f553d1e.

Fixes #30210.
2023-12-01 09:56:10 +09:00
Yu Watanabe 5dca908a9a sd-journal: ignore failure in testing cached corrupted entry
Let's consider the case that the 1st entry in an array is broken, but
n-th entry is valid. Then, if generic_array_get() is called to read
n-th object, the offset of the broken entry is cached by the function.
If generic_array_bisect() is followed, even if the matching entry is
valid, it always fail with -EBADMSG or friends, as the function test the
cached entry at the beginnning. Let's ignore the failure in testing the
cached entry.
2023-12-01 09:27:38 +09:00
Yu Watanabe 2292d377a2 sd-journal: fix typo in function name 2023-11-30 15:22:24 +09:00
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