Commit Graph
3605 Commits
Author SHA1 Message Date
Yu Watanabe 5b201ffb1e sd-journal: check sd-event state before setting up post change timer
The similar check already exists in schedule_post_change().

The function is currently called at two places.
- journal_file_open() in sd-journal:
  In this case, if the timer is not set up, then journal_file_post_change()
  will be called at the end of journal_file_append_entry(). So, the necessary
  task will be done sequentially when an journal entry is stored to the opened
  journal file. That is desired when the function is called at outside of the
  event loop.
- server_open_journal() in journald:
  This is not called after we exit the event loop.

So, we can safely do nothing in the function if the event loop is being
finished or already finished.

Fixes #30644.
2023-12-29 06:39:06 +09:00
Mike Yuan da6c52c57c various: don't use close_nointr if retval is not checked anyway 2023-12-28 20:44:01 +08:00
Yu Watanabe fe3fcb9492 Merge pull request #30633 from mrc0mmand/cocci-shenanigans
coccinelle: rework how we run the Coccinelle transformations
2023-12-26 05:45:58 +09:00
Frantisek Sumsal f2d0e2e5f5 sd-bus: drop unnecessary braces 2023-12-25 18:26:59 +01:00
Frantisek Sumsal 0a6a59650e tree-wide: drop !! casts to booleans 2023-12-25 18:26:59 +01:00
Mike Yuan 0a0f49556f Merge pull request #30622 from yuwata/space
tree-wide: drop unnecessary space or insert missing space
2023-12-25 17:52:48 +08:00
Yu Watanabe c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Yu Watanabe 1d03d970a1 tree-wide: insert space after for and switch 2023-12-25 01:29:38 +09:00
Yu Watanabe 54cbad304c sd-device: shorten code a big
Suggested by coccinelle.
2023-12-25 00:47:42 +09:00
Luca Boccassi 65e1e29e55 Merge pull request #30596 from yuwata/sd-device-db-cleanups
sd-device: several cleanups for udev database related functions
2023-12-24 00:23:35 +01:00
Yu Watanabe 8161f6086e test: make assert_return() critical by default on fuzzer and unit tests
Several test cases intentionally trigger assert_return(). So, to avoid
the entire test fails, this introduces several macros that tentatively
make assert_return() not critical.
2023-12-24 02:02:18 +09:00
Yu Watanabe 6e574ebd00 sd-device: introduce device_has_db() helper function 2023-12-23 04:45:13 +09:00
Yu Watanabe 91fd5e6bd2 sd-device: modernize device_update_db() and friends
- introduce device_should_have_db(),
- split out device_get_db_path(),
- update log messages, especially clarify which stage is failed,
- use _cleanup_(unlink_and_freep) attribute,
- clear existing database file also when failed to create database directory
  and when failed to create temporary file.
2023-12-23 04:45:03 +09:00
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