Yu Watanabe [Tue, 2 Jan 2024 19:19:33 +0000 (04:19 +0900)]
network/queue: fix potential double-free on oom
Currently, link_queue_request_safe(), which is a wrapper of
request_new(), is called with a free function at
- link_request_stacked_netdev() at netdev/netdev.c,
- link_request_address() at networkd-address.c,
- link_request_nexthop() at networkd-nexthop.c,
- link_request_neighbor() at networkd-networkd.c.
For the netdev case, the reference counter of the passed object is increased
only when the function returns 1. So, on failure (with -ENOMEM)
previously we unexpectedly dropped the reference of the NetDev object.
Similarly, for Address and friends, the ownership of the object is moved to the
Request object only when the function returns 1. And on failure, previously
the object was freed twice.
Also, netdev_queue_request(), which is another wrapper of request_new()
potentially leaks memory when the same NetDev object is queued twice.
Fortunately, that should not happen as the function is called only once
per object.
This fixes the above issue, and now the ownership or the reference
counter of the object is changed only when it is succeeded with 1.
Rewrite the test in bash and make it part of our integration test suite,
so it's actually executed in all our upstream CI environments.
The original test is flaky in environments where daemon-reload might
occur during the test runtime (e.g. when running the test in parallel
with the systemd-networkd test suite). Also, it was run only in CentOS
CI in limited way (i.e. without sanitizers), since it tests the host's
systemd, instead of the just built one.
Frantisek Sumsal [Thu, 28 Dec 2023 16:12:24 +0000 (17:12 +0100)]
coccinelle: drop a couple of FIXMEs
Turns out Coccinelle can handle compound literals just fine, the parsing
errors were caused by incorrectly parsed macros in code before the
literals, so let's just provide simplified versions for such macros.
The parsing error in `Type *foo[ELEMENTSOF(bar)] = {};` is actually
harmless; it occurs only when creating an array of pointers for a type
that's in an external header and it occurs only on the first parser's
pass, subsequent passes resolve the type correctly.
Also, unset ENABLE_DEBUG_HASHMAP, so Coccinelle doesn't expand the
hashmap debug macros.
As for the remaining FIXMEs, I opened a couple of issues in the
Coccinelle upstream to see if they can be fixed there (or at least
properly analyzed).
Yu Watanabe [Fri, 8 Dec 2023 07:01:06 +0000 (16:01 +0900)]
sd-journal: introduce cleanup function and hash ops for Directory
This makes the folloing:
- Each Directory object now has a reference to sd-journal.
- Hence, directory_free(), which is renamed from remove_directory(), can
be called without sd-journal as an argument.
- Introduces hash ops for Directory, so the finalization becomes
slightly simpler.
- Allocate hashmaps that store Directory objects when necessary.
- Split out add_directory_impl().
Mike Yuan [Mon, 1 Jan 2024 12:08:11 +0000 (20:08 +0800)]
logind: use handle_action_to_string where appropriate
Since 138224fc807091d31f19a3b22f066d6044626001, HandleActionData
records the corresponding HandleAction. Let's use it instead of
relying on inhibit_what when mapping to string.
Joakim Nohlgård [Fri, 29 Dec 2023 14:06:50 +0000 (15:06 +0100)]
udevadm: Propagate return code from verb result
udevadm lock did not propagate the return code from the child process
because all positive values were treated as success.
v2:
Now 'udevadm test-builtin' ignores all positive return values from the
builtin commands. Otherwise, as the hwdb builtin returns an positive value
when a matching entry found, 'udevadm test-builtin hwdb' will fail.
v3:
Initialize partition table before calling 'sfdisk --delete'.
Frantisek Sumsal [Thu, 28 Dec 2023 22:42:47 +0000 (23:42 +0100)]
test: avoid starting/stopping unwanted units during fuzzing
Skip calling start and stop methods on unit objects, as doing that is
not only time consuming, but it also starts/stops units that interfere
with the machine state. The actual code paths should be covered (to some
degree) by the respective method counterparts on the manager object.
Yu Watanabe [Thu, 28 Dec 2023 19:31:21 +0000 (04:31 +0900)]
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.
Ronan Pigott [Thu, 28 Dec 2023 01:27:00 +0000 (18:27 -0700)]
dns: update record type enum to match iana
Adds some new dns record types. Also, some types were inserted into the
middle of the enum — this corrects an error where the enum constants for
some of the record types previously held an incorrect value.
A S Alam [Thu, 28 Dec 2023 15:36:26 +0000 (16:36 +0100)]
po: Translated using Weblate (Punjabi)
Currently translated at 26.4% (60 of 227 strings)
Co-authored-by: A S Alam <aalam@users.noreply.translate.fedoraproject.org>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/master/pa/
Translation: systemd/main
Yu Watanabe [Tue, 26 Dec 2023 02:04:20 +0000 (11:04 +0900)]
network/address: unconditionally check if address is ready
Previously, we checked if the address is ready only when it is an IPv6
address. But, IPv4 address never enter tentative state, hence the check
for an IPv4 address is effectively equivalent to the one for IPv6.
So, let's unify the check. This does not change any effective behavior.
Luca Boccassi [Wed, 27 Dec 2023 16:48:05 +0000 (17:48 +0100)]
bash completion: make systemctl mount-image/bind autocomplete on active services
The verb works only on running service units, so complete on that as the first
parameter, and a local file as the second. The other parameters are inside the
service namespace so we can't autocomplete from the outside, return early.
Frantisek Sumsal [Tue, 26 Dec 2023 18:39:12 +0000 (19:39 +0100)]
coccinelle: dial back warnings about performance
Turns out I _really_ underestimated the impact of
--include-headers-for-types, as it significantly reduces both runtime
and storage penalties. For example, on my machine the runtime of
uncached run goes down from ~15 minutes to ~2 minutes, and similarly the
total storage needed by the cache goes from ~15 GiB down to ~3 GiB.
Frantisek Sumsal [Tue, 26 Dec 2023 17:55:31 +0000 (18:55 +0100)]
coccinelle: help Coccinelle with some more complex macros
Drop the original macro file, since it's not needed anymore thanks to
resolving includes properly, but introduce a similar file -
parsing_hacks.h - that helps Coccinelle in some specific corner cases.
This eliminates most of the outstanding parsing errors in source files.
The remaining ones are limitations of the parsing engine (see the FIXMEs
in pasing_hacks.h) and need further investigation.
Frantisek Sumsal [Tue, 26 Dec 2023 17:44:21 +0000 (18:44 +0100)]
coccinelle: search the system include path for header files as well
Since Coccinelle is originally a kernel tool, it doesn't search the
system include path by default for header files. Without this we're
missing a lot of types provides by stdlib (and other libraries we make
use of).