Commit graph

39021 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek e78bd91e55
Merge pull request #23596 from keszybz/bpf-messages-more
Silence messages from libbpf
2022-06-02 19:48:01 +02:00
Zbigniew Jędrzejewski-Szmek 4c989f89b6 core: rework variable initialization to avoid gcc warning
In file included from ../src/basic/siphash24.h:11,
                 from ../src/basic/hash-funcs.h:6,
                 from ../src/basic/hashmap.h:8,
                 from ../src/shared/fdset.h:6,
                 from ../src/shared/bpf-program.h:9,
                 from ../src/core/unit.h:11,
                 from ../src/core/all-units.h:4,
                 from ../src/core/manager.c:23:
../src/basic/time-util.h: In function 'manager_dispatch_jobs_in_progress':
../src/basic/time-util.h:140:38: error: 'x' may be used uninitialized [-Werror=maybe-uninitialized]
  140 | #define FORMAT_TIMESPAN(t, accuracy) format_timespan((char[FORMAT_TIMESPAN_MAX]){}, FORMAT_TIMESPAN_MAX, t, accuracy)
      |                                      ^~~~~~~~~~~~~~~
In function 'manager_print_jobs_in_progress',
    inlined from 'manager_dispatch_jobs_in_progress' at ../src/core/manager.c:3007:9:
../src/core/manager.c:219:18: note: 'x' was declared here
  219 |         uint64_t x;
      |                  ^
cc1: all warnings being treated as errors

For some reason this (false positive) warning starts appearing after
-ftrivial-auto-var-init is used.
2022-06-02 17:31:55 +02:00
Zbigniew Jędrzejewski-Szmek 6a9f3cef8c
Merge pull request #23576 from yuwata/network-erspan-version
network: support erspan version 0 and 2
2022-06-02 16:58:55 +02:00
Zbigniew Jędrzejewski-Szmek 7e5c7522e8
Merge pull request #23579 from yuwata/sha256-unaligned
sha256: use memcpy() to accept unaligned result buffer
2022-06-02 16:38:19 +02:00
Zbigniew Jędrzejewski-Szmek d7cf4ba6f3
Merge pull request #23582 from bnf/dns-proxy-stub-ifindex
resolved: define source address for proxy-only stub replies
2022-06-02 16:34:55 +02:00
Zbigniew Jędrzejewski-Szmek b1acbc08e2 core/bpf: prefix log messages from different bpf subsystems
When something goes awry, we would get identical log messages from all the
bpf subsystems. E.g. "Failed to load BPF object: %m" appeared 5 times in the
sources. But it is very important to know *which* object we failed to load.
This could be guessed, e.g. from surroudning messages or from filename/line
metadata, but when we get log messages in bug reports, this might not be
available. Let's make the messages distinguishable.

While at it, some messages were adjusted a bit. In particular, we shouldn't use
internal names like BPFProgram which have no meaning outside of the codebase.
2022-06-02 15:59:41 +02:00
Zbigniew Jędrzejewski-Szmek bb0b01ed20 core: define a helper function for basic bpf checks 2022-06-02 15:59:41 +02:00
Zbigniew Jędrzejewski-Szmek 62b045b45c test-socket-bind: fix comment 2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek b1fdcda876 tests: drop pointless checks for root
Testing the error paths is very important. If we are not root, we should
try and get a failure, which we should report nicely and mark the test
as skipped. After those checks are removed, this is what seems to happen.
This way we can see what will happen e.g. in the user manager when we try
to perform some bpf ops.
2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek 44005a5778 shared/bpf: install log callback and suppress most messages from libbpf
$ build/test-socket-bind
...
libbpf: load bpf program failed: Operation not permitted
libbpf: failed to load program 'sd_bind4'
libbpf: failed to load object 'socket_bind_bpf'
libbpf: failed to load BPF skeleton 'socket_bind_bpf': -1
Failed to load BPF object: Operation not permitted

Now all lines with "libbpf:" are at debug level and will be hidden by
default.

Partially fixes https://bugzilla.redhat.com/show_bug.cgi?id=2084955#c14
(i.e. the error that was exposed when the initial error was fixed.)
2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek 386b8026e5 meson: use files() for libcore_sources too
C.f. f1b98127ff.
2022-06-02 07:53:14 +02:00
Zbigniew Jędrzejewski-Szmek c6cb9d9074 userwork: use a better errno value
ESRCH is literally "No such process".
2022-06-02 07:53:14 +02:00
Zbigniew Jędrzejewski-Szmek 2e09b2235a various: add %m in messages
Sometimes we want to suppress strerror() message because the are providing
something better. But in those cases, it seems it was just forgotten.
2022-06-02 07:53:14 +02:00
Yu Watanabe 93d13a7dff test: fix indentation 2022-06-02 14:14:22 +09:00
Yu Watanabe 3bccc736c6 test: add test for sha256 2022-06-02 14:14:22 +09:00
Yu Watanabe c7a5eabeba sha256: use memcpy() when result buffer is unaligned
Fixes #23578.
2022-06-02 14:14:22 +09:00
Zbigniew Jędrzejewski-Szmek af72f975fe Move basic/recovery-key.* to shared/
No particular reason to have it in basic/. We should let homectl
and other users share the single copy through libsystemd-shared.
2022-06-02 13:09:09 +09:00
Zbigniew Jędrzejewski-Szmek 14c811ff4a
Merge pull request #23575 from keszybz/logind-wall-message-cleanup
Cleanup wall messages emitted by logind and systemctl
2022-06-01 16:26:29 +02:00
Zbigniew Jędrzejewski-Szmek d5254fa2f6
Merge pull request #23574 from keszybz/logind-pty-wall
Do not print logind wall message to local terminals
2022-06-01 16:26:03 +02:00
Benjamin Franzke de777ffae8 resolved: choose correct file descriptor for proxy stub replies
find_socket_fd() does not expect the sender address, but the
listen-address. This is in fact the destination of the DNS packet.
Matching via sender address caused a fallback to the default stub
listener in manager_dns_stub_fd() as the sender address can never
match the proxy stub listen address.

Note that manager_dns_stub_fd() is only used for the default
listener stub and the proxy stub, that means *extra* listeners
stubs (DNSStubListenerExtra=…) have not been affected as
`struct DnsStubListenerExtra` provides a direct link to the event
source.

By using the correct fd we ensure the correct socket options
(like TTL) are used and prevent issues like #23495 in case ifindex
could not be determined.
2022-06-01 15:08:33 +02:00
Li kunyu b278cf2efd src: The return value of server_vacuum () is not used and could be modified to void type 2022-06-01 09:32:22 +02:00
Christian Göttsche ea74f39c24 login: do not issue wall messages on local terminals for suspend and hibernate
Fixes: #23520

[zjs: I added the comment and tweaked the patch a bit.

The call to reset_scheduled_shutdown() is moved down a bit to allow the
callback to have access to information about the operation being cancelled.
This all happens within the same function, so there should be no observable
change in behaviour.]
2022-06-01 09:30:07 +02:00
Zbigniew Jędrzejewski-Szmek b622d2f789 shared/pager: print the name of the pager we'll try next in debug message
I had a strange failure where the pager was hanging on invocation (gdm crashed
and the kernel got into a strange state where it was hanging on some tasks).
Based on the logs from 'SYSTEMCTL_LOG_LEVEL=debug journalctl', I couldn't even
tell which pager binary we're executing. So let's shorten the function a bit and
provide a bit more detail.
2022-06-01 09:27:35 +02:00
Zbigniew Jędrzejewski-Szmek 5b69a7c540 man/systemctl: improve grammar in description of --check-inhibitors 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 1cc11a0951 systemctl: drop translation of method names to descriptions in error message
We had yet-another table of descriptive strings to use in error messages.
I started thinking how to synchronize them with the strings in logind, but
ultimately I think it's better to remove those altogether. Those strings
should almost never be used: normally if the call fails, logind will provide
an error message itself, which is probably more detailed than what we can
figure out on the client side. And the most important part that we want to
show here is what exactly we called, in particular RebootWithFlags vs. Reboot,
etc. By using the "descriptive strings" we were obfuscating this. So let's just
simplify our code and print the actual method name, since this is more useful
as an error statement that is googlable and unique.

While at it, let's print the correct method name ;)
2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 346840b159 systemctl: make function static 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek b280061314 logind: reduce scope of a few variables 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 3dbb9bc5eb logind: rework wall message about pending shutdown/halt/reboot/…
Those messages simply *feel* dated: "The system is going for suspend NOW!".
Let's say "The system will suspend|power off|hibernate|… now!" instead.
The exclamation mark is enough to show the urgency.

Also, the "the" seemed out of place. We're not talking about a specific reboot.
2022-06-01 09:23:05 +02:00
Yu Watanabe 9db25d01ef
Merge pull request #23531 from yuwata/sd-bus-drop-version-2
sd-bus: drop version 2 format support
2022-06-01 14:51:44 +09:00
Yu Watanabe cd25e17001
Merge pull request #23512 from medhefgo/efi-clang
boot: Add string functions
2022-06-01 06:16:48 +09:00
Benjamin Franzke dfa14e2859 resolved: define source address for proxy-only stub replies
DnsPacket.ifindex=1 (loopback) is normalized to 0 whenever a message is
received on the loopback iface, so for both listeners, 127.0.0.53 and
127.0.0.54, the ifindex will be set to 0 by manager_recv() for queries
that have a local origin.

Replies to such local messages need to set a proper ifindex in any
case, as the supplied source-address would otherwise be ignored in
manager_ipv4_send() (CMSG generation is skipped due to ifindex > 0 check).

Note that this change only forces `ifindex` to loopback if it was actually
normalized to `0` before (due to a loopback detection) in order to keep the
nat-to-127.0.0.54-from-another-interface usecase that was described in
a8d0906344 intact.
Also note that nat is not supported for the main stub 127.0.0.53 which is
why forcing LOOPBACK_IFINDEX was/is fine for that case.

Fixes #23495
2022-05-31 22:38:47 +02:00
Zbigniew Jędrzejewski-Szmek 51a2b575d7 logind: do not print wall messages to local pseudoterminals
Fixes #23520. Replaces #23555.

The problem started with cdf370626f and
90b1ec03b2 which together started printing the
wall message in more cases. The motivation for those change was reasonable, but
this clearly causes problems described in #23520: users are getting unexpected
wall messages. Xterm, urxvt, (anything using libutempter?), and tmux (in some
configurations), register local pty sessions in utmp.

So let's try to suppress the message for local pseudo-terminal logins. This
patch based on #23538, but instead of filtering just on /dev/pts, it uses the
.ut_addr_v6 to only filter out local entries.
2022-05-31 22:30:08 +02:00
Zbigniew Jędrzejewski-Szmek e31355bbc1 tests: add a helper that dumps /run/utmp in detail
utmpdump doesn't print all the details. Looking at the list if useful
when trying to tweak the wall filtering logic.

This doesn't do much, but at least it serves as a smoke test for the cleanup
functions.
2022-05-31 22:30:08 +02:00
Yu Watanabe 98406eda8a network/erspan: support erspan version 0 and 2
This also makes networkd accepts erspan index 0.

Closes #23570.
2022-06-01 04:02:48 +09:00
Yu Watanabe a452cfd77b sd-bus: drop constant argument for message_extend_fields() 2022-06-01 03:41:16 +09:00
Yu Watanabe 0dd4876815 sd-bus: drop D-Bus version 2 format support
It seems the format is used only by kdbus.
2022-06-01 03:41:15 +09:00
Yu Watanabe c0f664ca89 sd-bus: merge message_peek_fields() and buffer_peek() 2022-06-01 03:41:15 +09:00
Yu Watanabe 75c85c3b25 sd-bus: make several functions static
And drop 'bus_' prefix from them.
2022-06-01 03:41:15 +09:00
Yu Watanabe 590a738562 sd-bus: use UINT32_MAX 2022-06-01 03:41:15 +09:00
Yu Watanabe b7096bd690 sd-bus: drop unnecessary cast 2022-06-01 03:41:15 +09:00
Yu Watanabe 30da99bd30 sd-bus: drop redundant condition
By the previous commit, ALIGN8() is always equal to or greater than the
argument.
2022-06-01 03:41:15 +09:00
Yu Watanabe dc7be33266 sd-bus: use ALIGN8() 2022-06-01 03:41:15 +09:00
Yu Watanabe b4e7df4a47 boot: use ALIGN4() 2022-06-01 03:41:15 +09:00
Yu Watanabe 4c8d7caf1a macro: make ALIGN4() and ALIGN8() also return SIZE_MAX on overflow
This also drops unused ALIGN4_PTR(), ALIGN8_PTR(), and ALIGN_TO_PTR().
2022-06-01 03:40:20 +09:00
Yu Watanabe 394129f88b tree-wide: use ALIGN_PTR() 2022-06-01 03:12:33 +09:00
Yu Watanabe a0f0cf0a6b portable: fix command option in comment
Follow-up for edea370222.
2022-05-31 16:32:09 +02:00
Zbigniew Jędrzejewski-Szmek 978af07f66 logind: use consistent casing in message
The other strings use "sentence capitalization". Let's do the
same here.
2022-05-31 15:59:40 +02:00
Zbigniew Jędrzejewski-Szmek 3c98bdce55 logind: align tables 2022-05-31 15:59:29 +02:00
Zbigniew Jędrzejewski-Szmek 1661833238 shared/utmp-wtmp: pass information if entry is local to filter function
This just adds an unused parameter for future use. No change in
behaviour.
2022-05-31 15:54:16 +02:00
Zbigniew Jędrzejewski-Szmek b5cb2d2847 tty-ask-password-agent: drop unnecessary code for non-absolute paths
utmp_wall() always prepends /dev/, so we don't need to do this a second
time here.
2022-05-31 15:54:03 +02:00
Jan Janssen 7783ab5df1 boot: Use xstrdup8/16
Note that xstrdup is now safe to call with a NULL pointer and will
just return NULL in that case.
2022-05-31 15:15:01 +02:00
Jan Janssen 101f68ff33 boot: Add xstrdup8/16 2022-05-31 15:15:01 +02:00
Jan Janssen bbc1f2eac5 boot: Use memcmp/memcpy/memset 2022-05-31 15:15:01 +02:00
Jan Janssen f7967716e3 boot: Add memcmp/memcpy/memset 2022-05-31 15:14:56 +02:00
Jan Janssen 60c2af56d6 boot: Use strsize8/16 2022-05-31 15:14:56 +02:00
Jan Janssen 96dc0dd387 boot: Add strsize8/16 2022-05-31 15:14:54 +02:00
Jan Janssen fb67588c62 boot: Use strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 5d7e0e8341 boot: Add strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 08ed842b56 boot: Use strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen ef4d71ad7f boot: Add strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen fc178cf1f8 boot: Use strtolower8/16 2022-05-31 15:10:48 +02:00
Jan Janssen 98850528bf boot: Add strtolower8/16 2022-05-31 15:10:45 +02:00
Jan Janssen 3d5127c68f boot: Use strcmp16 for cpio sorting 2022-05-31 15:09:10 +02:00
Jan Janssen ec436bdf16 boot: Use strcmp8/16
This also replaces streq and similar functions for consistency. Note
that streq16 is null pointer safe, so streq_ptr can be safely replaced
too.
2022-05-31 15:09:10 +02:00
Jan Janssen 0d933d024a boot: Add strcmp8/16 2022-05-31 15:09:06 +02:00
Jan Janssen 5f49747255 boot: Use strlen8/16
The casts in this and the next few commits are curently necessary
because CHAR8 is defined as uint8_t in gnu-efi, while char is signed.
Once we switch from gnu-efi typedefs to stdint types, the casts
will be dropped.
2022-05-31 14:18:43 +02:00
Jan Janssen 9080ffd4cd boot: Add strlen8/16 2022-05-31 14:18:43 +02:00
Jan Janssen 11f9a32de0 boot: Use stddef.h offsetof 2022-05-31 14:18:43 +02:00
Frantisek Sumsal a52765a550 seccomp: fix a typo in error message 2022-05-31 18:29:40 +09:00
Yu Watanabe 71891fb2de
Merge pull request #23558 from msekletar/issue-20329-followup
Actually delay running of mount start jobs when /p/s/mountinfo is rate limited
2022-05-31 17:38:25 +09:00
Jason A. Donenfeld 87cb1ab676 Simplify random number selection
We currently have a convoluted and complex selection of which random
numbers to use. We can simplify this down to two functions that cover
all of our use cases:

1) Randomness for crypto: this one needs to wait until the RNG is
   initialized. So it uses getrandom(0). If that's not available, it
   polls on /dev/random, and then reads from /dev/urandom. This function
   returns whether or not it was successful, as before.

2) Randomness for other things: this one uses getrandom(GRND_INSECURE).
   If it's not available it uses getrandom(GRND_NONBLOCK). And if that
   would block, then it falls back to /dev/urandom. And if /dev/urandom
   isn't available, it uses the fallback code. It never fails and
   doesn't return a value.

These two cases match all the uses of randomness inside of systemd.

I would prefer to make both of these return void, and get rid of the
fallback code, and simply assert in the incredibly unlikely case that
/dev/urandom doesn't exist. But Luca disagrees, so this commit attempts
to instead keep case (1) returning a return value, which all the callers
already check, and fix the fallback code in (2) to be less bad than
before.

For the less bad fallback code for (2), we now use auxval and some
timestamps, together with various counters representing the invocation,
hash it all together and provide the output. Provided that AT_RANDOM is
secure, this construction is probably okay too, though notably it
doesn't have any forward secrecy. Fortunately, it's only used by
random_bytes() and not by crypto_random_bytes().
2022-05-31 09:20:52 +02:00
Zbigniew Jędrzejewski-Szmek fada4bdcaa
Merge pull request #23533 from yuwata/portable-remove-drop-in-configs
portable: remove drop-in configs
2022-05-31 08:52:30 +02:00
Yu Watanabe 4282f39430
Merge pull request #23564 from yuwata/core-unit-add-dep
core: fix notification about unit dependency change
2022-05-31 14:07:34 +09:00
msizanoen1 37f0289bf5 cgroup-util: Properly handle conditions where cgroup.threads is empty after SIGKILL but processes still remain
After sending a SIGKILL to a process, the process might disappear from
`cgroup.threads` but still show up in `cgroup.procs` and still remains in the
cgroup and cause migrating new processes to `Delegate=yes` cgroups to fail with
`-EBUSY`. This is especially likely for heavyweight processes that consume more
kernel CPU time to clean up.

Fix this by only returning 0 when both `cgroup.threads` and
`cgroup.procs` are empty.
2022-05-31 05:03:31 +09:00
Yu Watanabe 9a18321058
Merge pull request #23560 from mrc0mmand/coccinelle
A couple of tweaks suggested by Coccinelle
2022-05-31 05:02:57 +09:00
Yu Watanabe a8c5a4c6c2 core: make unit_add_two_dependencies() or friends return 1 on changed
Follow-up for f971def3c2.
2022-05-31 01:53:11 +09:00
Yu Watanabe ac17080c04 core/unit: fix notification about unit dependency change
This also makes unit_add_dependency() return 1 only when a dependency
is added.
2022-05-31 01:53:11 +09:00
Yu Watanabe 5473bc61af esp: fix typo
Follow-up for 13d7c841a2.
2022-05-31 01:17:34 +09:00
Frantisek Sumsal 81aa8d4130 journal: return & log in one statement 2022-05-30 18:12:58 +02:00
Frantisek Sumsal 4c7f7f4b22 analyze: use IN_SET() in one more place 2022-05-30 18:12:55 +02:00
Yu Watanabe edea370222 portable: remove drop-in configs even if the main unit file does not exist
When we run `portablectl detach --enable --runtime`, then it triggers
`DisableUnitFilesWithFlags` DBus method and the main unit file is
removed, but its drop-ins are not. Hence, portable_detach() failed to
list existing portable units.

This makes the loop for listing portable units also accept drop-in
directories. So, all remaining drop-in directories are correctly
removed.

Before:
```
testsuite-29.sh[600]: + portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
portablectl[1391]: (Matching unit files with prefixes 'minimal-app0'.)
portablectl[1391]: Queued /org/freedesktop/systemd1/job/1812 to call StopUnit on portable service minimal-app0-foo.service.
portablectl[1391]: Removed "/run/systemd/system.attached/minimal-app0-foo.service".
portablectl[1391]: Queued /org/freedesktop/systemd1/job/1813 to call StopUnit on portable service minimal-app0.service.
portablectl[1391]: Removed "/run/systemd/system.attached/minimal-app0.service".
portablectl[1391]: Got result done/Success for job minimal-app0-foo.service
portablectl[1391]: Got result done/Success for job minimal-app0.service
portablectl[1391]: DetachImage failed: No unit files associated with '/tmp/rootdir' found attached to the system. Image not attached?
```

After:
```
testsuite-29.sh[508]: + portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
portablectl[1076]: (Matching unit files with prefixes 'minimal-app0'.)
portablectl[1076]: Queued /org/freedesktop/systemd1/job/1946 to call StopUnit on portable service minimal-app0-foo.service.
portablectl[1076]: Removed "/run/systemd/system.attached/minimal-app0-foo.service".
portablectl[1076]: Queued /org/freedesktop/systemd1/job/1947 to call StopUnit on portable service minimal-app0.service.
portablectl[1076]: Removed "/run/systemd/system.attached/minimal-app0.service".
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d/10-profile.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d/20-portable.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d/10-profile.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d/20-portable.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d.
portablectl[1076]: Removed /run/portables/rootdir.
portablectl[1076]: Removed /run/systemd/system.attached.
```
2022-05-31 01:09:29 +09:00
Yu Watanabe 8288382049
Merge pull request #23354 from DaanDeMeyer/mount-implicit-device-dep-trace
core: Add trace logging to mount_add_device_dependencies()
2022-05-31 01:00:56 +09:00
Michal Sekletar b161bc394b unit: check for mount rate limiting before checking active state
Having this check as part of mount_can_start() is too late because
UNIT(u)->can_start() virtual method is called after checking the active
state of unit in unit_start().

We need to hold off running mount start jobs when /p/s/mountinfo monitor
is rate limited even when given mount unit is already active.

Fixes #20329
2022-05-30 13:22:16 +02:00
Zbigniew Jędrzejewski-Szmek 02ece2fcb1
Merge pull request #23529 from nabijaczleweli/dollar-asterisk
Don't linebreak after each initrd in kernel-install verbose mode
2022-05-30 10:27:14 +02:00
Jan Janssen 5476cb988c meson: Build header tests with -pedantic
By using __extension__, we can silence pedantic errors we cannot or
do not want to fix.

This in particular silences:
 - enum values being outside of int range
 - variadic macros
 - long long being C99
 - type of bit-field ‘type’ is a GCC extension
 - use of C99 bool in public header functions
2022-05-30 05:06:36 +09:00
Yu Watanabe 6a49fcdb3c portable: try to remove unit files even in a spurious state 2022-05-30 04:34:43 +09:00
Yu Watanabe 1b1e53d2a8 test: drop redundant log message 2022-05-30 04:17:54 +09:00
Yu Watanabe ba780ccd5f
Merge pull request #23542 from medhefgo/attributes
meson: Document why -Wimplicit-fallthrough is not used with clang
2022-05-30 04:07:41 +09:00
Evgeny Vereshchagin f232c83c72 tests: link tests using fabs against libm explicitly
Some compiler wrappers like honggfuzz pass -fno-builtin explicitly
and because of that the tests where fabs is used fail to compile
with something like
```
FAILED: test-bus-marshal
...
/usr/bin/ld: test-bus-marshal.p/src_libsystemd_sd-bus_test-bus-marshal.c.o: undefined reference to symbol 'fabs@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib64/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

Fun fact: it took honggfuzz less than a minute to discover
https://github.com/advisories/GHSA-gmc7-pqv9-966m used by
systemd to compress/descompress some stuff.
2022-05-29 19:05:58 +00:00
Zbigniew Jędrzejewski-Szmek 67f8ba714a
Merge pull request #23548 from tpgxyz/lua2
rpm: adjust lua trigger for udevadm
2022-05-29 20:08:05 +02:00
Tomasz Paweł Gajc 744984aa2d rpm: adjust lua trigger for udevadm 2022-05-28 21:38:33 +02:00
Tomasz Paweł Gajc 7bde8293a4 rpm: use rpm.execute() instead of fork() and execp() for trigger scriplets 2022-05-28 21:29:00 +02:00
Jan Janssen c0f5d58c9a meson: Document why -Wimplicit-fallthrough is not used with clang
This changes the macro to ensure proper fallthrough attributes are
used with clang in case this option is added in the future.
2022-05-28 12:44:08 +02:00
Jan Janssen b41ebe3d18 macro: Move attribute defintions to macro-fundamental
This also sorts them.
2022-05-28 11:34:16 +02:00
Yu Watanabe 89b6a3f13e sd-bus: fix buffer overflow
Fixes #23486.
2022-05-28 10:06:14 +02:00
Luca Boccassi 5ad69b04bf
Merge pull request #23518 from enr0n/sd-hwdb-from-path
Implement --root option for systemd-hwdb query
2022-05-27 22:51:36 +01:00
Zbigniew Jędrzejewski-Szmek 94b84a0703 Use descriptive name for nobody
This matches the changes pushed to Fedora [1,2].

[1] https://fedoraproject.org/wiki/Changes/RenameNobodyUser
[2] https://pagure.io/setup/c/f6fdb5ffc87fc8f1acc211867fef4e3f0856edfc
2022-05-27 22:09:24 +01:00
Nick Rosbrook beff73f94e hwdb: implement --root option for systemd-hwdb query
Currently, the systemd-hwdb --root flag only has an effect for the
'update' verb. It would be useful to be able to use the --root option
for the 'query' verb too (e.g. for testing a hwdb.bin created with
systemd-hwdb update --root <path>).

Use sd_hwdb_new_from_path to initialize the hwdb if --root is passed to
systemd-hwdb query.

Note that this functionality was not added to 'udevadm hwdb' since that
command is deprecated.
2022-05-27 09:40:54 -04:00
Nick Rosbrook 60f0ba7556 sd-hwdb: add sd_hwdb_new_from_path
The existing sd_hwdb_new function always initializes the hwdb from the
first successful hwdb.bin it finds from hwdb_bin_paths. This means there
is currently no way to initialize a hwdb from an explicit path, which
would be useful for systemd-hwdb query.

Add sd_hwdb_new_from_path to allow a sd_hwdb to be initialized from a
custom path outside of hwdb_bin_paths.
2022-05-27 09:40:54 -04:00
Nick Rosbrook 9745b51c73 sd-hwdb: include sys/stat.h in hwdb-internal.h
Include this header to fix errors when including hwdb-internal.h:
  ../src/libsystemd/sd-hwdb/hwdb-internal.h:16:21: error: field ‘st’ has incomplete type
     16 |         struct stat st;
2022-05-27 09:40:54 -04:00
Luca Boccassi e1a8917ae1
Merge pull request #23504 from keszybz/bls-reordering
Refactor the BLS and add a description of version sorts
2022-05-27 14:36:10 +01:00
Luca Boccassi df90d255fe
Merge pull request #23527 from keszybz/esp-detect-xbootldr
Fix xbootldr detection, fail early in kernel-install
2022-05-27 11:46:46 +01:00
Yu Watanabe 6d3bb9e7d1
Merge pull request #23517 from mrc0mmand/cryptsetup-switchroot-transition
test: cover initrd->sysroot transition in TEST-24
2022-05-27 07:36:17 +09:00
наб 2f9f8b96d4
kernel-install: don't log each initrd on its own line in verbose mode 2022-05-26 23:18:34 +02:00
наб c60ca42571
kernel-install: actually ignore the last two arguments 2022-05-26 23:16:13 +02:00
Zbigniew Jędrzejewski-Szmek 13d7c841a2 shared/find-esp: enhance logging
If something doesn't match, let's print the non-matching value.
If we can't query something, say what.
And make the messages in the udev and blkid paths different, so
we tell which approach failed from a log.
2022-05-26 21:50:18 +02:00
Zbigniew Jędrzejewski-Szmek 4e12442554 shared/find-esp: fix inverted check for XBOOTLDR type 2022-05-26 21:49:38 +02:00
Zbigniew Jędrzejewski-Szmek 5aa285b437 kernel-install: if a plugin fails, return error immediately
Since the first version in 81516adcb7,
kernel-install would "gather" a return value by summing the exit codes
of the plugins… This makes no sense, because those are not additive values.

Let's just break off immediately. We now implement cleanup via trap, so if we
break, we should leave no garbage behind.
2022-05-26 21:46:58 +02:00
Yu Watanabe 4fc69e8a09 core/device: do not downgrade device state if it is already enumerated
On switching root, a device may have a persistent databse. In that case,
Device.enumerated_found may have DEVICE_FOUND_UDEV flag, and it is not
necessary to downgrade the Device.deserialized_found and
Device.deserialized_state. Otherwise, the state of the device unit may
be changed plugged -> dead -> plugged, if the device has not been mounted.

Fixes #23429.

[mwilck: cherry-picked from #23437]
2022-05-26 17:07:59 +02:00
Martin Wilck cf1ac0cfe4 core/device: device_coldplug(): don't set DEVICE_DEAD
dm-crypt device units generated by systemd-cryptsetup-generator
habe BindsTo= dependencies on their backend devices. The dm-crypt
devices have the db_persist flag set, and thus survive the udev db
cleanup while switching root. But backend devices usually don't survive.
These devices are neither mounted nor used for swap, thus they will
seen as DEVICE_NOT_FOUND after switching root.

The BindsTo dependency will cause systemd to schedule a stop
job for the dm-crypt device, breaking boot:

[   68.929457] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Unit is stopped because bound to inactive unit dev-disk-by\x2duuid-3bf91f73\x2d1ee8\x2d4cfc\x2d9048\x2d93ba349b786d.device.
[   68.945660] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Trying to enqueue job systemd-cryptsetup@cr_root.service/stop/replace
[   69.473459] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Installed new job systemd-cryptsetup@cr_root.service/stop as 343

Avoid this by not setting the state of the backend devices to
DEVICE_DEAD.

Fixes the LUKS setup issue reported in #23429.
2022-05-26 15:06:41 +02:00
Zbigniew Jędrzejewski-Szmek a6e334649d systemctl: make show/status honour --state and --type
This makes the interface more flexible, by allowing the same filtering
for show and status as is done for list-units.

Fixes #23207.
2022-05-26 10:37:35 +09:00
Yu Watanabe c7a0c74c7f
Merge pull request #23513 from keszybz/bootctl-version-print
bootctl: print version comparison when updating
2022-05-26 10:30:16 +09:00
Zbigniew Jędrzejewski-Szmek 892fcb8955 bootctl: when comparing versions, show the result
In Fedora there was a mixup with versions (the version was prefixed with "v", and
"v251" < "250"). This makes this easier to debug.
2022-05-25 16:02:35 +02:00
Zbigniew Jędrzejewski-Szmek f90ee9ff66 basic: add helper function to print </==/> 2022-05-25 16:02:25 +02:00
Zbigniew Jędrzejewski-Szmek c20b2f2421 analyze: use '' instead of the empty string when showing versions
It looks like garbled output… I didn't use shell-escape, because the other
characters that are special for the shell that are used in versions should
not be escaped.
2022-05-25 16:01:14 +02:00
Zbigniew Jędrzejewski-Szmek 2367bdcfc9 docs/BLS: describe version comparisons
Fixes #23346.
2022-05-25 13:47:47 +02:00
Zbigniew Jędrzejewski-Szmek 46083ab321 basic/string-util: tweak strverscmp_improved() for some corner cases
So far we had the rule that '' == '', '0_' == '0', but '_' > ''. This means
that the general rule that strings are compared iteratively, and each
segment that compares equal can be dropped and the comparison resumes at
the following characters wasn't true in such cases. Similarly, '0~' < '0',
but after dropping the common segment, '~' > ''.

The special handling of empty strings is dropped, and '_' == '' and
'~' < ''.
2022-05-25 13:47:47 +02:00
Anita Zhang 7e46a5c093 test-seccomp: check for CAP_IPC_OWNER before calling shmat()
shmat() requires the CAP_IPC_OWNER capability. When running test-seccomp
in environments with root + CAP_SYS_ADMIN, but not CAP_IPC_OWNER,
memory_deny_write_execute_shmat would fail. This fixes it.
2022-05-25 08:03:23 +09:00
Zbigniew Jędrzejewski-Szmek 620ecc9c4b kernel-install: ignore extra args passed when invoked as installkernel
kernel's 'make install' invokes install.sh which calls /sbin/install-kernel.
Thus we are invoked as e.g.
  /sbin/installkernel 5.18.0 arch/x86/boot/bzImage System.map /boot
The last two arguments would be passed as "initrds".

Before , we would just quitely ignore
/boot, because it doesn't pass the 'test -f' test, and possibly try to do
something with System.map. 742561efbe tightened
the check, so we now throw an error.

It seems that the correct thing is to ignore those two arguments, because
our plugin syntax has no notion of System.map. And the installation directory
we can figure out ourselves better. Effectively, this makes things behave
like before, but less by accident.

Fixes #23490.
2022-05-24 23:31:43 +02:00
Zbigniew Jędrzejewski-Szmek 65df0ce39a Minor wording fixes
Some NEWS entries are tweaked a bit to address complaints about readability
from users.

"udev" is pronounced as /ˈjuːdɛv/, like in "user", hence "a" not "an".
2022-05-24 21:26:06 +02:00
Jan Janssen 2d5d72c62b boot: Fix bad CompareMem call 2022-05-24 16:53:36 +01:00
Daan De Meyer 794da5a1a5 portable: Fix memory leak in maybe_enable_disable()
Fixes #23481
2022-05-24 10:55:09 +09:00
Frantisek Sumsal 40bc68cf21
Merge pull request #23475 from nabijaczleweli/certified-lint.1-moment
Actually run shellcheck on CI
2022-05-23 19:16:22 +00:00
Daan De Meyer 75d7e04eb4 dissect-image: Explicitly remove partitions when done with image
When closing a loop device, the kernel will asynchronously remove
the probed partitions. This can lead to race conditions where we
try to reuse a partition device that still needs to be removed by
the kernel. To avoid such issues, let's explicitly try to remove
any partitions using BLKPG_DEL_PARTITION when we're done with an
image.

To make sure we don't try to remove partitions when we want them
to remain (e.g. systemd-dissect --mount), we add
dissected_image_relinquish() in a similar vein to loop_device_relinquish()
and decrypted_image_relinquish().
2022-05-23 18:15:16 +01:00
наб 35339eb88c
shellcheck-clean kernel-install again 2022-05-23 12:52:56 +02:00
Zbigniew Jędrzejewski-Szmek e133c79f9f
Merge pull request #23344 from medhefgo/boot-config-add
boot: Small config entry add changes
2022-05-23 09:26:19 +02:00
Zbigniew Jędrzejewski-Szmek 2f9b7186e3
Merge pull request #23414 from keszybz/analyze-vercmp
systemd-analyze compare-versions
2022-05-23 09:14:51 +02:00
Jan Janssen d17c93a72b test: Test STRLEN for C11 string literals 2022-05-22 20:21:04 +01:00
Daan De Meyer 08e86b15fc coredump: Fix format string type mismatch
Fixes #23471
2022-05-22 19:28:38 +02:00
Jan Janssen 9287b661c5 boot: Rename functions adding entries to match userspace 2022-05-22 12:48:10 +02:00
Jan Janssen 095a153d49 boot: Remove trivial config entry add helpers
These two functions have very limited use and are just fancy wrappers
around structured initializers.
2022-05-22 12:48:06 +02:00
Victor Westerhuis 87c7779599 Do not require a valid version when parsing sd-boot loader entries
This fixes #20820
2022-05-22 12:17:52 +02:00
Luca Boccassi a17ebc687b
Merge pull request #23465 from mrc0mmand/bump-actions-to-ubuntu-2204
ci: bump GH Actions to Ubuntu Jammy where applicable
2022-05-22 02:29:59 +01:00
Luca Boccassi ebd4571e31
Merge pull request #22550 from medhefgo/boot-mixed
boot: EFI mixed mode support
2022-05-21 22:38:56 +01:00
Frantisek Sumsal dfe7cfe4fb cryptsetup: fix build with -Db_ndebug=true
```
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c:33:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-pkcs11.c:34:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ninja: build stopped: subcommand failed.
 + fatal ''\''meson compile'\'' failed with -Db_ndebug=true'
```
2022-05-21 23:27:24 +02:00
Yu Watanabe 7d3f2499b8
Merge pull request #23464 from bnf/update-wiki-links
tree-wide: replace obsolete wiki links with systemd.io/manpages
2022-05-21 23:48:58 +09:00
Jan Janssen 6e9165397f bootctl: Add EFI arch detection support 2022-05-21 15:11:13 +01:00
Jan Janssen c43a282c29 boot: Support booting in EFI mixed mode
The kernel provides a ".compat" PE section that contains a list of
compat entry points with their respective arches. This entry point
does all the heavy lifting to support running 64bit kernels when
the UEFI firmware is 32bit.

Note that the EFI handover protocol code in linux_x86.c does not
need any adjustments as it already correctly calls the 32bit handover
code.

Fixes: #17056
2022-05-21 15:11:13 +01:00
Jan Janssen 46ce6cf774 boot: Add LINUX_INITRD_MEDIA support to boot.c 2022-05-21 15:11:13 +01:00
Jan Janssen acdf7d157b boot: Keep initrds separate from cmdline options
This is in preparation for LINUX_INITRD_MEDIA support in boot.c. One
downside is that adding or changing the used initrds by command line
editing is not possible anymore.
2022-05-21 15:11:13 +01:00
Jan Janssen 5c330b3682 boot: Edit config entry options inline
An edited entry command line should not be saved globally as it
should be tied to that one entry only.
2022-05-21 15:11:13 +01:00
Jan Janssen 7b19627697 fundamental: Move some helpers into string-util-fundamental 2022-05-21 15:11:13 +01:00
Jan Janssen f386daa054 boot: Use cleanup handler to unload image
This also moves the message about failed image execution into
image_start() as we would otherwise show two error messages if
any of the preparatory steps failed.
2022-05-21 15:11:13 +01:00
Yu Watanabe 93a72170bd network: drop support for old kernels which cannot set prefix route with non-main route table
Not sure when the issue was fixed.
- kernel-3.10 on CentOS 7 has the issue,
- kernel-4.18 on CentOS 8 works fine.

Note, the workaround dropped by the commit is not incomplete:
with an old kernel which has the issue, all non-prefix routes are
configured on the specified route table, but the prefix route is
configured on the main table. That should not work for most cases,
hence, the workaround is mostly meaningless.
2022-05-21 15:09:53 +01:00
Luca Boccassi 0168b91603
Merge pull request #23339 from poettering/sockaddr-size-limit
tree-wide: add support for connecting to AF_UNIX sockets in the file system beyond the 108ch limit
2022-05-21 15:09:04 +01:00
Luca Boccassi 051c4e5419
Merge pull request #23342 from poettering/efi-monotonic-counter-random-seed
sd-boot: include GetNextMonotonicCount() in random seed calculations
2022-05-21 15:08:21 +01:00
Jan Janssen 7d4953de13 boot: Build with -flto=auto if available
Without this, we may get the following warning with gcc-12:
    lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
2022-05-21 15:07:47 +01:00
Jan Janssen 351b30dae0 macro: Use C11 noreturn only
No need to provide a fallback as we compile with gnu11.
2022-05-21 15:01:47 +01:00
Yu Watanabe 1246d09705 networkctl: show error message provided through dbus
Prompted by #23416.
2022-05-21 15:01:09 +01:00
Luca Boccassi 6910d43af5
Merge pull request #23453 from keszybz/strv-parsing
Add strv methods with externally-supplied size argument and speed up parsing of /etc/hosts
2022-05-21 15:00:51 +01:00
Benjamin Franzke a25d9395ad tree-wide: streamline wiki links
* Avoid traling slash as most links are defined without.
* Always use https:// protocol and www. subdomain

Allows for easier tree-wide linkvalidation
for our migration to systemd.io.
2022-05-21 14:28:03 +02:00
Yu Watanabe 30e29edf4c sysext: refuse empty release ID to avoid triggering assertion
Otherwise, the assertion in extension_release_validate() will be
triggered.
2022-05-21 06:37:56 +09:00
Yu Watanabe f65dcad5b7
Merge pull request #23439 from keszybz/kernel-install-verbose
Make kernel-install --verbose more verbose and some autodetection logic fixups
2022-05-21 04:26:03 +09:00
Yu Watanabe 3833c3356b
Merge pull request #23451 from medhefgo/boot-static-assert
boot: C11/static_assert
2022-05-21 04:22:17 +09:00
Luca Boccassi 54cd2d6869 sd-bus: add comment and test in sd_bus_path_decode() for empty string
3970	        e = object_path_startswith(path, prefix);
(gdb) p path
$1 = 0x55c5a166f768 "/org/freedesktop/portable1/image"
(gdb) p prefix
$2 = 0x55c59ffc2928 "/org/freedesktop/portable1/image"
(gdb) p e
$1 = 0x5581a1675788 ""

This can be a bit confusing in certain cases, so add a comment and a
test to make the behaviour clearer and explicit.
2022-05-21 03:44:09 +09:00
Zbigniew Jędrzejewski-Szmek 1b43f86893 kernel-install: restore priority of check for /boot/loader/entries
Before 9e82a74cb0, we had a check like the
following:

if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
    ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
    ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
elif [[ -d /boot/efi/loader/entries ]] || [[ -d /boot/efi/$MACHINE_ID ]]; then
    ENTRY_DIR_ABS="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
…

In stock Fedora 34-, /efi isn't used, but grub creates /boot/loader/entries and
installs kernels and initrds directly in /boot. Thus the second arm of the
check wins, and we end up with BOOT_ROOT=/boot.

After 9e82a74cb0, we iterate over the inner
directory first and over the second directory later:

[ -d /efi/<machine-id> ]
[ -d /boot/efi/<machine-id> ]
[ -d /boot/<machine-id> ]
[ -d /efi/Default ]
[ -d /boot/efi/Default ]
[ -d /boot/Default ]
[ -d /efi/loader/entries ]
[ -d /boot/efi/loader/entries ]
[ -d /boot/loader/entries ]

This was partially reverted by 447a822f8e which
removed Default from the list, and a5307e173b,
which moved checks for /boot up, so we ended up with:

[ -d /efi/<machine-id> ]
[ -d /boot/<machine-id> ]
[ -d /boot/efi/<machine-id> ]
[ -d /efi/loader/entries ]
[ -d /boot/loader/entries ]
[ -d /boot/efi/loader/entries ]

6637cf9db6 added autodetection of an entry
token, so we end up checking the following suffixes:

<machine-id>, $IMAGE_ID, $ID, Default

But the important unchanged characteristic is that we iterate over the suffix
first. Sadly this breaks Fedora, because we find /boot/efi/<machine-id> before
we could find /boot/loader/entries. It seems that every possible aspect of
behaviour matters for somebody, so we need to keep the original order of
detection.

With the patch:

[ -d /efi/<machine-id> ]
...
[ -d /efi/loader/entries ]
[ -d /boot/<machine-id> ]
...
[ -d /boot/loader/entries ]
[ -d /boot/efi/<machine-id> ]
...
[ -d /boot/efi/loader/entries ]

Note that we need to check for "loader/entries" too, even though it is not
an entry-token candidate, so that we get the same detection priority as
before.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2071034.
2022-05-20 15:34:17 +02:00
Zbigniew Jędrzejewski-Szmek eb164c51ea resolved: use strv_extend_with_size() to avoid slow parsing of /etc/hosts
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=43942 is a simple case
where a repeated entry generates a timeout. I didn't import that case, but
generated a simpler one by hand.

$ time build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries
test/fuzz/fuzz-etc-hosts/timeout-many-entries... ok
build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries  3.17s (old)
  ↓
build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries  0.11s (new)

I considered simply disallowing too many aliases. E.g. microsoft appearently
sometimes ignores entries after the ninth [1], and other systems set stringent
limits [2,3], but the recommended way to get around that is to simply use more
lines (as is done in the sample), so this wouldn't change anything.

Even if we cannot put all those names in a reply packet, the resolution from
the alias to the address should work. I think cases where people define lots
and lots of aliases through some programmatic interface is realistic, for
example for a blocklist, and such a file shouldn't bring resolved down to its
knees.

[1] https://superuser.com/questions/932112/is-there-a-maximum-number-of-hostname-aliases-per-line-in-a-windows-hosts-file
[2] https://library.netapp.com/ecmdocs/ECMP1516135/html/GUID-C6F3B6D1-232D-44BB-A76C-3304C19607A3.html
[3] https://www.ibm.com/docs/en/zos/2.1.0?topic=optional-creating-etchosts
2022-05-20 15:18:28 +02:00
Zbigniew Jędrzejewski-Szmek 3ec3ae68d2 basic/strv: add optimizable version of strv_push/consume/extend
This will be helpful in cases where we are repeatedly adding entries
to a long strv and want to skip the iteration over old entries leading
to quadratic behaviour.

Note that we don't want to calculate the length if not necessary, so
the calculation is delayed until after we've checked that value is not
NULL.
2022-05-20 15:18:28 +02:00
Zbigniew Jędrzejewski-Szmek 5943d85f34 portabled: wrap long lines and fix typo in error message 2022-05-20 15:01:56 +02:00
Zbigniew Jędrzejewski-Szmek 4313e2b69f portabled: refuse queries for empty image name
I took inspiration from pid1:
bus_unit_find()
  → find_unit()
    → manager_load_unit_from_dbus_path()
      → unit_name_from_dbus_path()
        → !startswith(path, "/org/freedesktop/systemd1/unit/")
          → return -EINVAL
          ←
        ←
      ←
    ← if (r < 0) return 0
  ← 0
←

i.e. we return 0 when queried for "/org/freedesktop/systemd1/unit".

Fixes #23445.
2022-05-20 14:59:50 +02:00
Yu Watanabe d316426eee shared/extension-release: drop unnecessary strna() wrapper
These are not NULL.
2022-05-20 14:26:47 +02:00
Luca Boccassi 7b2e763242 portable: reject root directories without an ID field in os-release
We always require at least ID to be set in os-release, reject
and propagate error to the caller instead of asserting later
2022-05-20 13:08:45 +01:00
Luca Boccassi a2cf73f0b6 dissect: ID from os-release should be non-empty, not just non-NULL 2022-05-20 12:05:34 +01:00
Jan Janssen 6c405f20a3 macro: Use C11 static_assert
Now that we require C11 everywhere, we can always use static_assert.
2022-05-20 12:49:50 +02:00
Jan Janssen b1672234e0 boot: Build with C11 too 2022-05-20 12:47:43 +02:00
Zbigniew Jędrzejewski-Szmek eb45cf97a9 kernel-install: fix detection of entry-token if $BOOT_ROOT is configured
If $BOOT_ROOT is specified, but entry-token not, we'd skip the detection
altogether, effectively defaulting to entry-token=machine-id.
The case where $BOOT_ROOT was not specied, but entry-token was configured
was handled correctly.
This patch makes the handling of both symmetrical, i.e. will only set what
wasn't configured.
2022-05-20 09:44:22 +02:00
Zbigniew Jędrzejewski-Szmek 4db4c28dc6 kernel-install: debug the configuration detection if --verbose
No changes to behaviour, but let's print everything out as we discover it.

The docs say that BOOT_ROOT can be specified by the environment. I have
it locally in /etc/kernel/install.conf, and then the override doesn't work.
It'd be nice to handle such cases more reliably.
2022-05-20 09:44:22 +02:00
Khem Raj 29b7114c5d Add sys/stat.h for S_IFDIR
Fixes
../git/src/shared/mkdir-label.c:13:61: error: use of undeclared identifier 'S_IFDIR'
        r = mac_selinux_create_file_prepare_at(dirfd, path, S_IFDIR);

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-05-20 14:54:02 +09:00
Daan De Meyer dcb4e45ad8 sd-bus: Fix introspect memory leak
We have to free the contents of the set on top of the set itself.

Fixes #23443.
2022-05-20 14:53:28 +09:00
Zbigniew Jędrzejewski-Szmek b21ba8ac6b kernel-install: bail if machine id generation fails
The call is unlikely to fail, but systemd-id128 might not be installed.
We shouldn't continue with the empty string.
2022-05-19 15:38:25 +02:00
Zbigniew Jędrzejewski-Szmek 94cbddf439 kernel-install: actually export KERNEL_INSTALL_VERBOSE
:(
2022-05-19 15:38:25 +02:00
Zbigniew Jędrzejewski-Szmek 8d9156660d version comparisons: stop using locale-dependent isdigit()
The docs are not entirely clear what glyphs qualify as digits.
The function is supposed to be locale-dependent, but I couldn't
get it to return true on any non-ascii digits I tried.
But it's better to be safe than sorry, let's use our trivial
replacement instead.
2022-05-19 11:07:28 +02:00
Zbigniew Jędrzejewski-Szmek bc012a3e91 analyze: add compare-versions
The interface, output, and exit status convention are all taken directly from
rpmdev-vercmp and dpkg --compare-versions. The implementation is different
though. See test-string-util for a list of known cases where we compare
strings incompatibly.

The idea is that this string comparison function will be declared as "the"
method to use for boot entry ordering in the specification and similar
uses. Thus it's nice to allow users to compare strings.
2022-05-19 09:07:34 +02:00
Daan De Meyer 1751d8c80c portable: Remove unnecessary assert()
Fixes #23433

matches is plumbed through until it finally gets used in unit_match()
which can deal with NULL matches so the assert() is unnecessary and
can be removed.

The two call sites of extract_image_and_extensions() also don't
assert() on matches either.
2022-05-19 15:39:25 +09:00
Zbigniew Jędrzejewski-Szmek fddad5f4a6 analyze: allow verbs to return positive failure
No functional change is intended. The verbs where it wasn't immediately
clear if the success exit status is 0 or >= 0 are changed to explicitly
return 0. (I think it's better to be explicit than to rely on some call
stack always returning 0 on success.)

Some other functions are cleaned up to be more idiomatic.
2022-05-19 08:02:29 +02:00
Zbigniew Jędrzejewski-Szmek d5dcd00ba2 analyze: use automatic cleanup in one more place 2022-05-19 08:02:29 +02:00
Zbigniew Jędrzejewski-Szmek e2d999345e analyze: sort/fix header includes in one place 2022-05-19 08:02:29 +02:00
Tomasz Pala d1df0466d9 udev: fixed config_parse_ifalias() logic not to skip setting IFLA_IFALIAS
this flaw was introduced in 6a74900002
2022-05-19 05:04:26 +09:00
Luca Boccassi bd144c9643
Merge pull request #23412 from yuwata/network-bond-param
networkctl: bond param
2022-05-17 20:11:55 +01:00
Zbigniew Jędrzejewski-Szmek d970092fa5 test-string-util: include a copy of rpm's version comparison tests
We said that strverscmp_improved() is similar to rpm, so it's nice to include
their tests too so we can pin down the differences.

Our test is changed to print older<newer instead of newer>older.
(I know the computer doesn't care, but I find it much harder to think about
when newer is on the left…)

The rpm test strings are copied from
https://github.com/rpm-software-management/rpm/blob/master/tests/rpmvercmp.at.
rpmio is licensed GPL OR LGPL, so we can do that without any issue.
(I think it could be argued as "fair use" anyway, but that's not necessary
in this case.)
I kept the original form as much as possible so it'll be easy to copy things
back and forth in the future.
2022-05-17 17:15:16 +02:00
Zbigniew Jędrzejewski-Szmek 80c48dd3a2
Merge pull request #23114 from yuwata/resolve-dnssec
resolve: always request additional record to verify negative answer
2022-05-17 16:53:09 +02:00
Zbigniew Jędrzejewski-Szmek 776fabbc8b Add a "test" that prints the SBAT table
The SBAT section was included in a special section in the EFI code, but
the contents weren't directly visible in any way. Let's add a "test" that
prints them for visual inspection.

If there's some external linter for this format, we could hook it up in the
future.
2022-05-17 16:45:15 +02:00
Zbigniew Jędrzejewski-Szmek dbf43adce2 fundamental: make strverscmp_improved() return -1/0/+1 in all cases
We would return the result of strcmp(), i.e. some positive/negative value.
Now that we want to make this a documented interface for other people
to implement, let's make the implementation more contstrained, even if
we ourselves don't care about whether the specific values.
2022-05-17 16:33:43 +02:00
Zbigniew Jędrzejewski-Szmek e77a55c599 fundamental/string-util-fundamental: include appropriate headers
We were using CMP() without pulling the definition in directly.
2022-05-17 16:33:43 +02:00
Zbigniew Jędrzejewski-Szmek c3e4cbe0c5 basic: make macro-fundamental.h self-contained
When !SD_BOOT, it used size_t without including the appropriate header.
2022-05-17 16:33:43 +02:00
Zbigniew Jędrzejewski-Szmek 68df2df668 Clean up the text in description of strverscmp_improved() 2022-05-17 16:33:43 +02:00
Yu Watanabe 9ce14a75e7 test-boot-timestamp: use ERRNO_IS_PRIVILEGE() to also mask -EPERM
Fixes #23395.
2022-05-17 15:54:24 +02:00
Yu Watanabe 05e022a913 networkctl: fix units for bond parameters
Fixes RHBZ#2086166 (https://bugzilla.redhat.com/show_bug.cgi?id=2086166).
2022-05-17 22:35:18 +09:00
Yu Watanabe 1a8922ddec
Merge pull request #23407 from keszybz/bpf-cleanup-warning
Clean up bpf cleanup warning
2022-05-17 20:31:10 +09:00
Zbigniew Jędrzejewski-Szmek ba187c9c9c manager: skip BPF cleanup if we never initialized
This fixes a spurious warning from the manager running in user mode:

systemd[1668]: Reached target sockets.target.
systemd[1669]: Failed to create BPF map: Operation not permitted
systemd[1669]: Finished systemd-tmpfiles-setup.service.
systemd[1669]: Listening on dbus.socket.
systemd[1669]: Reached target sockets.target.
systemd[1669]: Reached target basic.target.
systemd[1]: Started user@6.service.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2084955.
2022-05-17 10:55:40 +02:00
Yu Watanabe bfd671061c test-execute: skip one more test when PID1 is not systemd
Fixes #23332.
2022-05-17 10:50:33 +02:00
Zbigniew Jędrzejewski-Szmek 389db516df core/bpf: lsm_bpf_supported() returns a boolean
The code was corret, but confusing, because it was treating the int
as a boolean.
2022-05-17 10:16:27 +02:00
Yu Watanabe 9b7c8253f9
Merge pull request #23403 from keszybz/docs-update
Say that we support recent version of major distros and other doc updates
2022-05-17 06:02:08 +09:00
Zbigniew Jędrzejewski-Szmek 2fd7ecd2da rpm: remove check if systemd is running in a few cases
rpms can be installed in two different modes: into a chroot, where the system
is not running, and onto a live system. In the first mode, where should create
all changes that are "permanent", and in the second mode, all changes which are
"permanent" but also those which only affect the running system. Thus, changes
like new modprobe rules, tmpfiles rules, binfmt rules, udev rules, etc., are
guarded by 'test -d "/run/systemd/system"' which is the official way to check
if systemd is running, so that they are *not* executed when installed into a
chroot. But the same logic does not apply to sysusers, hwdb, and the journal
catalog: all those files can and should result in changes being performed
immediately to the system. This makes the creation of immutable images possible
(because there are no permanent changes to executed after a reboot), and allows
other packages to depend on the the effect of those changes.

Thus, the guard to check if we're not in a chroot is dropped from triggers for
sysusers, hwdb, and the journal catalog. This means that those triggers will
execute, and no subsequent work is needed. systemd-sysusers.service,
systemd-journal-catalog-update.service, and systemd-hwdb-update.service.in all
have ConditionNeedsUpdate= so they they generally won't be invoked after a
reboot. (systemd.rpm does not touch /usr to trigger the condition, because the
%transfiletriggers make that unnecessary.)

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2085481
2022-05-16 21:27:34 +01:00
Zbigniew Jędrzejewski-Szmek 8458ca26c1 networkd: reword debug messages
"left from <something>" is not correct. "left <something>" would be the
usual form, but "left master interface" is not clear at all. So reword
those messages totally.

Follow-up for 3881fd406b.
2022-05-16 19:50:26 +02:00
Luca Boccassi 9d9310e5f0
Merge pull request #23383 from yuwata/meson-suppress-warning
meson: suppress warning
2022-05-16 17:57:13 +01:00
Yu Watanabe 27408ef878
Merge pull request #23377 from nabijaczleweli/shopt
Fix shopt in 90-loaderentry, don't not lint kernel-install, respect `$TMPDIR`
2022-05-16 18:17:14 +09:00
Yu Watanabe 08a7e5459f core: fix comment 2022-05-16 05:18:30 +09:00
Yu Watanabe 8fe37dbdcf meson: always get libbpf include directory from pkgconfig 2022-05-16 04:27:36 +09:00
Luca Boccassi 943fadde48
Merge pull request #23378 from floppym/install-tags
Add install tags for nss modules and pkgconfig files
2022-05-15 14:52:19 +01:00
Yu Watanabe 4f6ebd43b2 resolve: merge variable declaration with same type 2022-05-15 10:26:24 +09:00
Yu Watanabe a3f87e32b9 resolve/dnssd: make dnssd_render_instance_name() take Manager
As DnssdService object passed to dnssd_render_instance_name() may
not owned by Manager.

Fixes #23381.
2022-05-15 10:23:33 +09:00
Yu Watanabe cee6833943 network: do not update interface group by default
This fixes a minor bug introduced by 10af8bb24b.
Before the commit, the interface group was set only when Group= is explicitly
specified, otherwise the interface group was kept. However, after the commit,
we need to specify Group= with an empty string to keep the current interface
group.
2022-05-15 08:24:13 +09:00
Mike Gilbert 260c0a80ac meson: add 'devel' install_tag to libsystemd.pc and libudev.pc 2022-05-14 11:59:13 -04:00
наб b32217e8d0
Don't not lint kernel-install 2022-05-14 15:21:34 +02:00
наб b0bf2a802f
kernel-install: respect $TMPDIR 2022-05-14 15:14:33 +02:00
наб 003c81b26c
kernel-install: 90-loaderentry: remove shopt
Fixes: #23374
Fixes: 367165a406
2022-05-14 15:14:32 +02:00
Yu Watanabe 6530ca0d2b resolve: fix memleak
Fixes a bug introduced by 71aee23dba.

Fixes CID#1488763.
2022-05-14 10:52:29 +01:00
Yu Watanabe 618b3642e1 tree-wide: replace AF_LOCAL with AF_UNIX 2022-05-14 10:51:05 +01:00
Lennart Poettering 1861986a3b tree-wide: port various users over to connect_unix_path()
Let's make use of our new helper, and thus allow longer paths.
2022-05-14 05:01:38 +09:00
Lennart Poettering 28ae8da972 fileio: port read_file_full() to use connect_unix_path()
This way we can connect correctly to any AF_UNIX socket in the file
system, and even save some code. Yay!

This also adds some test code for this, that ensures read_file_full()
works correctly for AF_UNIX sockets that violate the 108 char limit.

Supporting sockets like this kinda matters I think, for the simple
reason that apps want to build socket paths via XDG_RUNTIME_DIR and
suchlike, and we should be able to connect to them, even via
non-normalized paths.
2022-05-14 05:01:38 +09:00
Lennart Poettering 2679aee440 socket-util: add new connect_unix_path() helper
This is a short helper for connecting to AF_UNIX sockets in the file
system. It works around the 108ch limit of sockaddr_un, and supports
"at" style fds.

This doesn't come with a test of its own, but the next patch will add
that.
2022-05-14 05:01:38 +09:00
Yu Watanabe bdaf5c3df6
Merge pull request #23369 from yuwata/error-handling-fixlets
Several fixlets
2022-05-14 04:59:56 +09:00
Yu Watanabe 3881fd406b tree-wide: fix typo 2022-05-14 04:58:47 +09:00
Yu Watanabe a98042e7a3 userdb: fix error handling 2022-05-13 21:49:53 +09:00
Lennart Poettering 2c032478fc fileio: fix error propagation 2022-05-13 21:48:27 +09:00
Lennart Poettering 28fe6a8072 fileio: propagate original error if we notice AF_UNIX connect() is not going to work
let's not make up new errors in these checks that validate if connect()
work at all. After all, we don't really know if the ENXIO we saw earlier
actually is really caused by the inode being an AF_UNIX socket, we just
have the suspicion...
2022-05-13 21:48:17 +09:00
Lennart Poettering dfa2b389a6 socket-util: change sockaddr_un_set_path() to return recognizable error on 108ch limit
This way we can implement nice fallbacks later on.

While we are at it, provide a test for this (one that is a bit over the
top, but then again, we can never have enough tests).
2022-05-13 21:47:58 +09:00
Luca Boccassi 7eeedcfcb1
Merge pull request #23337 from yuwata/sd-device-new-from-subsystem-sysname
sd-device: always translate sysname to sysfs filename
2022-05-13 00:10:24 +01:00
Yu Watanabe 75d7b5989f core/device: ignore DEVICE_FOUND_UDEV bit on switching root
The issue #12953 is caused by the following:
On switching root,
- deserialized_found == DEVICE_FOUND_UDEV | DEVICE_FOUND_MOUNT,
- deserialized_state == DEVICE_PLUGGED,
- enumerated_found == DEVICE_FOUND_MOUNT,
On switching root, most devices are not found by the enumeration process.
Hence, the device state is set to plugged by device_coldplug(), and then
changed to the dead state in device_catchup(). So the corresponding
mount point is unmounted. Later when the device is processed by udevd, it
will be changed to plugged state again.

The issue #23208 is caused by the fact that generated udev database in
initramfs and the main system are often different.

So, the two issues have the same root; we should not honor
DEVICE_FOUND_UDEV bit in the deserialized_found on switching root.

This partially reverts c6e892bc0e.

Fixes #12953 and #23208.
Replaces #23215.

Co-authored-by: Martin Wilck <mwilck@suse.com>
2022-05-13 03:04:31 +09:00
Yu Watanabe f33bc87989 core/device: drop unnecessary condition 2022-05-13 02:56:14 +09:00
Yu Watanabe fc0cbed2db test-sd-device: skip gpio subsystem
There exist /sys/class/gpio and /sys/bus/gpio, and both have gpiochip%N
device. However, these point to different devpaths.
2022-05-13 02:51:00 +09:00
Yu Watanabe 4d38294baf sd-device: always translate sysname to sysfs filename
Previously, in sd_device_new_from_subsystem_sysname(), '/' in sysname
was replaced '!' for several limited subsystems. This was based on a wrong
assumption that no sysname in e.g. driver subsystem does not contain '!'.
And the assumption is actually wrong, and trigger issue #23327.

In device_set_sysname_and_sysnum() we unconditionally replace '!' in the
filename. Hence, the translation in sd_device_new_from_subsystem_sysname()
must be also done unconditionally.

Fixes #23327.
2022-05-13 02:51:00 +09:00
Yu Watanabe 0ffffade03
Merge pull request #23361 from keszybz/resolved-helpers
Add some ref-unref helpers for resolved
2022-05-13 02:33:29 +09:00
Yu Watanabe 57ee137ff2
Merge pull request #23358 from keszybz/fuzzer-input-sizes
fuzzers: add input size limits, always configure limits in two ways
2022-05-13 01:04:20 +09:00
Zbigniew Jędrzejewski-Szmek 899e3cdada resolved: add DNS_PACKET_REPLACE 2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek 5731844157 resolved: add DNS_RESOURCE_KEY_REPLACE 2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek 7daeec3e6c resolved: add DNS_RR_REPLACE 2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek 1117a96087 resolved: add DNS_ANSWER_REPLACE
C.f. ce913e0ec4.
2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek 14b71de4e1 resolved: use saturate_add() 2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek 8b0c43475a Add saturate_add() that generalizes size_add() 2022-05-12 17:15:51 +02:00
Zbigniew Jędrzejewski-Szmek cd0cade1ad
Merge pull request #23289 from yuwata/resolve-answer-add-rrsig
resolve: place RRSIG after the corresponding entries
2022-05-12 16:15:12 +02:00
Zbigniew Jędrzejewski-Szmek c4f883b78e fuzzers: ignore size limits when compiled standalone
This way we can still call fuzzers on old samples, but oss-fuzz will not waste
its and our time finding overly large inputs.
2022-05-12 14:57:07 +02:00
Daan De Meyer 556b6f4e6f core: Add trace logging to mount_add_device_dependencies()
To help debug missing implicit device deps in
https://github.com/systemd/systemd/issues/13775#issuecomment-1122969810.
2022-05-12 14:56:16 +02:00
Daan De Meyer f971def3c2 core: Return 1 from unit_add_dependency() on success
To allow checking if adding dependency was skipped or not.
2022-05-12 14:56:12 +02:00
Yu Watanabe 7593691aad fuzzers: add input size limits, always configure limits in two ways
Without the size limits, oss-fuzz creates huge samples that time out. Usually
this is because some of our code has bad algorithmic complexity. For data like
configuration samples we don't need to care about this: non-rogue configs are
rarely more than a few items, and a bit of a slowdown with a few hundred items
is acceptable. This wouldn't be OK for processing of untrusted data though.

We need to set the limit in two ways: through .options and in the code. The
first because it nicely allows libFuzzer to avoid wasting time, and the second
because fuzzers like hongfuzz and afl don't support .options.

While at it, let's fix an off-by-one (65535 is the largest offset for a
power-of-two size, but we're checking the size here).

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2022-05-12 13:31:11 +02:00
Zbigniew Jędrzejewski-Szmek 96974ea4a8 fuzz-dhcp-server: remove limit on input size
It was added originally back in 2bd37c5be2,
but there doesn't seem to by any particular reason for it.
2022-05-12 13:30:44 +02:00
Yu Watanabe b692ad36b9 sd-device-enumerator: fix inverted return value of match_initialized()
Fixes a bug introduced by d8b50e5df7.

Fixes https://github.com/systemd/systemd/pull/22662#issuecomment-1124163773.
Fixes RHBZ#2083374 (https://bugzilla.redhat.com/show_bug.cgi?id=2083374).
2022-05-12 09:31:23 +02:00
Yu Watanabe 34f6ae24c5
Merge pull request #23351 from keszybz/logind-message
logind: fix crash in logind on bad message string
2022-05-12 05:25:21 +09:00
Zbigniew Jędrzejewski-Szmek 011a03a3fa meson: turn on log-message-verification by default in developer builds
I'm not _quite_ convinced that this a good idea… I'm at least keeping
it separate to make it easy to revert ;)
2022-05-11 18:18:59 +02:00
Zbigniew Jędrzejewski-Szmek 1ec7c15613 Do LOG_MESSAGE_VERIFICATION in coverity runs
This should be enough to get reports if we screw up anywhere, coverity does
analysis of printf format strings.
2022-05-11 16:47:40 +02:00
Zbigniew Jędrzejewski-Szmek b9ce5cf9ca Optionally call printf on LOG_MESSAGE() arguments
With an intentional mistake:

../src/login/logind-dbus.c: In function ‘bus_manager_log_shutdown’:
../src/login/logind-dbus.c:1542:39: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
 1542 |                           LOG_MESSAGE("%s %s", message),
      |                                       ^~~~~~~
2022-05-11 16:47:40 +02:00
Zbigniew Jędrzejewski-Szmek f66020ab7f core: use LOG_UNIT_MESSAGE() where appropriate 2022-05-11 16:47:40 +02:00
Zbigniew Jędrzejewski-Szmek 92663a5e5b tree-wide: use LOG_MESSAGE() where possible
Also break some long lines for more uniform formatting. No functional change.

I went over all log_struct, log_struct_errno, log_unit_struct,
log_unit_struct_errno calls, and they seem fine.
2022-05-11 16:47:40 +02:00
Zbigniew Jędrzejewski-Szmek 153d1579ef logind: rename "log_message" to "log_verb"
This field is used to log SHUTDOWN=. Calling it "something-message" is
confusing.
2022-05-11 16:47:40 +02:00
Zbigniew Jędrzejewski-Szmek 0cb09bcb82 logind: fix crash in logind on user-specified message string
This is trivially exploitable (in the sense of causing a crash from SEGV) e.g.
by 'shutdown now "Message %s %s %n"'. The message is settable through polkit,
but is limited to auth_admin:

<action id="org.freedesktop.login1.set-wall-message">
         <description gettext-domain="systemd">Set a wall message</description>
         <message gettext-domain="systemd">Authentication is required to set a wall message</message>
         <defaults>
                <allow_any>auth_admin_keep</allow_any>
                <allow_inactive>auth_admin_keep</allow_inactive>
                <allow_active>auth_admin_keep</allow_active>
        </defaults>
</action>

Bug introduced in 9ef15026c0
('logind/systemctl: introduce SetWallMessage and --message', 2015-09-15).
2022-05-11 16:43:31 +02:00
Lennart Poettering f183c4f75a efi: include UEFI monotonic boot counter in random seed
UEFI provides a "monotonic boot counter" which is supposed to increase on
each reboot. We can include this in our random seed hash logic, which
makes things more robust in case our changes to the ESP end up not
actually being as persistent as we assume. As long as the monotonic boot
counter increases we should be good, as each boot we'll anyway end up
with a new seed that way.

This in fact should also pave the way that we can eventually enable the
random seed logic even on SecureBoot enabled systems. Why that? With
this change the input for the random seed hash is now:

1. the old seed file contents
2. (optionally) some bits from the UEFI RNG
3. (optionally) a per system random "token" stored in an UEFI variable,
   initialized at OS install
4. the UEFI monotonic counter
5. a counter integer used by the random seed logic.

We can ignore #5 entirely for security considerations, it's always going
to be a constant series of values determined by the random seed logic.

The #1 file is under control of the attacker. (Since it resides in the
unprotected ESP)

The #2 data is possibly low quality. (it's hard enough to trust the
quality of the Linux RNG, let's not go as far as trusting the UEFI one)

The #3 data should not be under control of the attacker, and should only
exist if explicitly set. Unless you have privileged access to the system
you should not be able to read or set it. (well, within limits of flash
chip security and its connectivity to the firmware)

The #4 data is provided by the firmware, and should not be under control
of the attacker. If it works correctly then it might still be guessable
(i.e. a new system might have the counter close to zero).

Thus: 1+2+5 are guessable/under control of attacker, but 3+4 should not
be. Thus, if 3 is not known to attacker and not guessable, and 4
strictly monotonically increasing then it should be enough to guarantee
that every boot will get a different seed passed in, that should not be
known or guessable by the attacker.

That all said, this patch does not enable the random seed logic on
SecureBoot. That is left for a later patch.
2022-05-11 11:03:10 +02:00
Yu Watanabe 6bb8928205 meson: sort files 2022-05-11 02:13:15 +09:00
Yu Watanabe 97cda6e10f
Merge pull request #23335 from keszybz/fuzz-json-more-coverage
More coverage in fuzz-json
2022-05-11 02:12:57 +09:00
Zbigniew Jędrzejewski-Szmek 82544241ba fuzz-bootspec: limit input size
https://oss-fuzz.com/testcase-detail/5680508182331392 has the
first timeout with 811kb of input. As in the other cases, the code
is known to be slow with lots of repeated entries and we're fine with
that.
2022-05-11 02:12:35 +09:00
Yu Watanabe 01c99b29e9
Merge pull request #23336 from keszybz/fuzz-calendarspec-more-coverage
More coverage in fuzz-calendarspec
2022-05-11 02:12:11 +09:00
Zbigniew Jędrzejewski-Szmek 99b1145aae shared/json: fix memleak in sort 2022-05-10 17:08:37 +02:00
Zbigniew Jędrzejewski-Szmek 3b6ce05537 shared/json: fix another memleak in normalization 2022-05-10 17:08:37 +02:00
Zbigniew Jędrzejewski-Szmek dbd27c6d28 fuzz-json: also try self-merge operations
This might even work ;)
2022-05-10 17:08:37 +02:00
Zbigniew Jędrzejewski-Szmek 96d651a22b basic/alloc-util: remove unnecessary parens
Those symbols are not macros anymore, so we can drop parens.
2022-05-10 17:08:37 +02:00
Zbigniew Jędrzejewski-Szmek ce913e0ec4 shared/json: add helper to ref first, unref second
This normally wouldn't happen, but if some of those places were called
with lhs and rhs being the same object, we could unref the last ref first,
and then try to take the ref again. It's easier to be safe, and with the
helper we save some lines too.
2022-05-10 17:08:34 +02:00
Zbigniew Jędrzejewski-Szmek 8e1e59b9ad shared/calendarspec: fix formatting of entries which collapse to a star
We canonicalize repeats that cover the whole range: "0:0:0/1" → "0:0:*".  But
we'd also do "0:0:0/1,0" → "0:0:*,0", which we then refuse to parse.  Thus,
first go throug the whole chain, and print a '*' and nothing else if any of the
components covers the whole range.
2022-05-10 14:35:57 +02:00
Yu Watanabe 756491af39 core/timer: fix potential use-after-free 2022-05-10 13:50:50 +02:00
Yu Watanabe d3ab7b8078 core/timer: fix memleak
Fixes #23326.
2022-05-10 13:50:50 +02:00
Zbigniew Jędrzejewski-Szmek 3aff2ae9d5 shared/calendarspec: fix printing of second ranges which start with 0
0..3 is not the same as 0..infinity, we need to check both ends of the range.
This logic was added in 3215e35c40, and back then
the field was called .value. .stop was added later and apparently wasn't taken
into account here.
2022-05-10 13:06:32 +02:00
Zbigniew Jędrzejewski-Szmek 4f23345592 test-calendarspec: tighten tests and add more logging 2022-05-10 13:06:32 +02:00
Zbigniew Jędrzejewski-Szmek 8b105ec831 shared/calendarspec: wrap long comments and reduce scope of one var 2022-05-10 13:06:32 +02:00
Zbigniew Jędrzejewski-Szmek 8e6e3ac7d1 fuzz-calendarspec: increase coverage by calculating occurences
Coverage data shows that we didn't test calendar_spec_next_usec() and
associated functions at all.

The input samples so far were only used until the first NUL. We take advantage
of that by using the part until the second NUL as the starting timestamp,
retaining backwards compatibility for how the first part is used.
2022-05-10 13:06:32 +02:00
Zbigniew Jędrzejewski-Szmek b456b09b25 shared/calendarspec: make function static void
calendar_spec_from_string() already calls calendar_spec_normalize(), so
there is no point in calling it from the fuzzer. Once that's removed, there's
just one internal caller and it can be made static.
2022-05-10 13:06:32 +02:00
Zbigniew Jędrzejewski-Szmek 7e4be6a584 shared/json: fix memory leak on failed normalization
We need to increase the counter immediately after taking the ref,
otherwise we may not unref it properly if we fail before incrementing.
2022-05-10 12:58:49 +02:00
Zbigniew Jędrzejewski-Szmek bac06497fe shared/json: wrap long comments 2022-05-10 12:58:48 +02:00
Zbigniew Jędrzejewski-Szmek a2c5735dd8 fuzz-json: also do sorting and normalizing and other easy calls 2022-05-10 12:58:48 +02:00
Zbigniew Jędrzejewski-Szmek a4669764f7 shared/json: reduce scope of variables 2022-05-10 12:58:48 +02:00
Zbigniew Jędrzejewski-Szmek 9ad955ce40 fuzz-json: optionally allow logging and output
Similarly to other fuzzers… this makes development easier.
2022-05-10 12:58:48 +02:00
Zbigniew Jędrzejewski-Szmek 9674b089cf json: align table 2022-05-10 12:58:48 +02:00
Yu Watanabe 16f74783d8 resolve: reallocate DNS scope when DNSSEC and/or DNS-over-TLS settings are changed
Fixes #23227.
2022-05-10 09:44:45 +02:00
Yu Watanabe 81391854ec
Merge pull request #23300 from DaanDeMeyer/device-debug
core/device: Add more logging
2022-05-10 14:29:35 +09:00
Frantisek Sumsal 624f685fe8 core: annotate Reexecute() as NoReply
So we're able to tell from the introspection data that the method
doesn't reply.
2022-05-10 14:16:11 +09:00
Yu Watanabe 31090c17f4
Merge pull request #23321 from poettering/sockaddr-no-cast
tests: avoid sockaddr casts
2022-05-09 23:44:01 +09:00
Yu Watanabe d171e72e7a core/slice: make slice_freezer_action() return 0 if freezing state is unchanged
Fixes #23278.
2022-05-09 23:43:32 +09:00
Lennart Poettering f9a1fd2a3b test: JSON_BUILD_REAL nowadays expects 'double', not 'long double'
Follow-up for 337712e777, aka "the great
un-long-double-ification of 2021".
2022-05-09 14:32:31 +02:00
Lennart Poettering 3bf175f076 tests: avoid (struct sockaddr*) casts
We prefer using using union sockaddr_union instead of casting sockaddr
to the correct types.

Coding style, nothing else.

Follow-up for 0dd5ec58fa.
2022-05-09 13:56:39 +02:00
Lennart Poettering b501e42e71 socket-util: don't reference field by macro parameter name
Let's avoid ambigituies here. (Interesting that the current users
compiled at all, in fact)
2022-05-09 13:55:28 +02:00
Yu Watanabe a6b084234c network: set/unset enumerating flag before/after loop 2022-05-09 18:59:24 +09:00
Daan De Meyer 2aaf6d407e shared: Fix memory leak in bus_append_execute_property()
Fixes #23317
2022-05-09 18:58:55 +09:00
Yu Watanabe df423851fc
Merge pull request #23310 from keszybz/suppress-fuzzer-timeouts-and-errors
Suppress fuzzer timeouts and errors
2022-05-09 15:50:29 +09:00
Yu Watanabe b5be9dbebf
Merge pull request #23311 from keszybz/bootspec-fuzzer
Fuzzer for bootspec.c and associated fixes
2022-05-09 15:46:49 +09:00
Zbigniew Jędrzejewski-Szmek 3947432eb0 shared/calendarspec: reduce scope of variables 2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek 68ac5118e7 shared/dissect-image: apply standard indentation 2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek a9d178d28b basic/virt: use STRV_FOREACH instead of iteration with ELEMENTSOF
I think it's a bit simpler, we don't have two indexes.
2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek c9c3b81f12 libsystemd-network: constify casts
It is better to not drop the const-ness from the argument.
2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek 2034c8b883 tree-wide: drop de-constifying casts for strv iteration
When the the iterator variable is declared automatically, it "inherits" the
const/non-const status from the argument. We don't need to cast a const
table to non-const. If we had a programming error and tried to modify the
string, the compiler could now catch this.
2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek 40893cbfd5 fuzz-journal-remote: allow -ENODATA too
It seems that we try to create a new file, which fails with -ENOSPC, and we
later fail when reading a file with ENODATA.  journal_file_open() will return
-ENODATA if the file is too short or if journal_file_verify_header() fails.
We'll unlink a file we newly created if we fail to initialize it immediately
after creation. I'm not sure if the file we fail to open is the one we newly
created and e.g. failed to create the arena and such, or if it's the file we
were trying to rotate away from. Either way, I think we should be OK with
with a non-fully-initialized journal file.

Failed to create rotated journal: No space left on device
Failed to write entry of 2 bytes: No space left on device
sd_journal_open_files(["/tmp/fuzz-journal-remote.vELRpI.journal"]) failed: No data available
Assertion 'IN_SET(r, -ENOMEM, -EMFILE, -ENFILE)' failed at src/journal-remote/fuzz-journal-remote.c:70, function int LLVMFuzzerTestOneInput(const uint8_t *, size_t)(). Aborting.

oss-fuzz-39238: https://oss-fuzz.com/issue/4609851129462784
2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek 44468876c3 fuzz-systemctl-parse-argv: refuse commandlines above 1k entries
oss-fuzz reports timeouts which are created by appending to a very long strv.
The code is indeed not very efficient, but it's designed for normal
command-line use, where we don't expect more than a dozen of entries. The fact
that it is slow with ~100k entries is not particularly interesting.

In the future we could rework the code to have better algorithmic complexity.
But let's at least stop oss-fuzz from wasting more time on such examples.

(My first approach was to set max_len in .options, but apparently this doesn't
work for hongfuzz and and AFL.)

oss-fuzz-34527: https://oss-fuzz.com/issue/5722283944574976
2022-05-08 22:47:50 +02:00
Yu Watanabe 734582830b core/unit: fix use-after-free
Fixes #23312.
2022-05-08 22:45:07 +02:00
Zbigniew Jędrzejewski-Szmek d4f72d104f shared/bootspec: add missing terminator to table 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek a89dd095e1 fuzz-bootspec: also add loader autoentries 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek b6bd2562eb shared/bootspec: avoid crashing on config without a value 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek 1409ce6ed2 Add fuzzer for the bootspec parser 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek a847b539de shared/bootspec: also export boot_config_load_type1()
The reallocation of memory and counter incrementation is moved from
the only caller to the function. This way the callers can remain oblivious
of the BootConfig internals.
2022-05-08 17:57:57 +02:00
Zbigniew Jędrzejewski-Szmek 5ba1550fd8 shared/bootspec: expose more parts of the config parsing 2022-05-08 17:56:12 +02:00
Zbigniew Jędrzejewski-Szmek 432ce53737 Move printing of boot entries from bootctl.c to shared/
I want to use this for fuzzing, but also later to return jsonified
list of entries from logind.
2022-05-08 17:55:03 +02:00
Zbigniew Jędrzejewski-Szmek ec725c0c49 shared/bootspec: add one more assert
All callers assume that boot_entry_title() always returns something.
It will, as long as it's not called on an uninitialized entry.
2022-05-08 17:53:56 +02:00
Zbigniew Jędrzejewski-Szmek 91da36f195 meson: sort list of fuzzers 2022-05-08 17:53:56 +02:00
Zbigniew Jędrzejewski-Szmek 7f5b2615a7 dissect: drop unnecessary {} 2022-05-08 16:23:13 +02:00
Daan De Meyer c189f91f1f core/device: Add logging to device_is_ready() 2022-05-08 13:25:42 +02:00
Daan De Meyer f0fdcb8cfa core/device: Improve device_dispatch_io() logging messages 2022-05-08 13:25:42 +02:00
Daan De Meyer c34511086f core/device: Log when we can't retrieve SYSTEMD_ALIAS property 2022-05-08 13:25:42 +02:00
Daan De Meyer 2f82874558 core/device: Log when we skip device unit creation for symlink 2022-05-08 13:25:42 +02:00
Daan De Meyer e9222bfcfa core/device: Log if we fail to open a device
We also shorten the logic by getting rid of the validate_node()
function. An extra check is added to verify we're dealing with
a device before calling sd_device_new_from_devname() since that
will return -EINVAL if anything other than a device is passed.
2022-05-08 13:25:42 +02:00
Daan De Meyer 6cc4da5eb5 core/device: Log on every event received from udev
We already debug log on device unit state changes but additionally,
let's debug log for every event received from udev as well.
2022-05-08 13:25:39 +02:00
Daan De Meyer 20907e5d86 core/device: Add sysfs argument to device_process_new()
Instead of retrieving the new sysfs path in device_process_new(),
let's pass the syspath we retrieved earlier to device_process_new()
similar to how we do for other functions in core/device.c.
2022-05-07 22:16:41 +02:00
Daan De Meyer b1ba0ce800 core/device: Use DEVICE_NOT_FOUND instead of 0.
Use the enum name instead of the value zero. This is a noop change
as DEVICE_NOT_FOUND == 0.
2022-05-07 20:05:10 +01:00
Jan Janssen f7ae43795c boot: Fix null pointer dereference 2022-05-07 21:56:06 +09:00
Yu Watanabe d1b8e56a62 resolve: fix false maybe-uninitialized warning 2022-05-07 15:14:41 +09:00
Yu Watanabe 388c92ce09 resolve: move the RRSIG after the all corresponding entries
Fixes #22002.
2022-05-07 15:14:41 +09:00
Yu Watanabe 71aee23dba resolve: manage DnsAnswerItem with OrderedSet
Previously, we manage DnsAnswerItem by an array and Set,
The array was used for the order of the items, and the set is used to
dedup items.
Let's use OrderedSet, then we can simplify the logic.

This fixes dns_answer_remove_by_key() and dns_answer_remove_by_rr()
which makes the set in a broken state.
2022-05-07 15:14:41 +09:00
Yu Watanabe 0bb7324c11 ordered-set: introduce ordered_set_reserve() 2022-05-07 15:14:41 +09:00
Yu Watanabe 4ce30e4de0 resolve: first increment the reference counter
When `exist->rr` and `rr` point to the same object, then it may be freed by
the `dns_resource_record_unref()`.
2022-05-07 15:14:41 +09:00
Yu Watanabe 6edf21dba7 resolve: use dns_answer_isempty() at one more place 2022-05-07 15:14:41 +09:00
Yu Watanabe 87d3b4ef3b
Merge pull request #23292 from alexhenrie/dhcpv6
network: clarify relationship between RA flags and DHCPv6 modes
2022-05-07 11:42:45 +09:00
Zbigniew Jędrzejewski-Szmek 680f2fb39d shared/json: disentangle flag mixup
_DEBUG and _RELAX had the same value… I'm not sure what the effect
of this is.
2022-05-07 11:41:57 +09:00
Alex Henrie 0bcc6557fb network: clarify the relationship between RA flags and DHCPv6 modes
In the documentation, using the term "managed" for both the RA flag and
the DHCPv6 mode is confusing because the mode is referred to as
"solicit" both in the official DHCPv6 documentation (see RFC 8415) and
in the WithoutRA option.

Furthermore, calling the other RA flag "other information" or "other
address configuration" is confusing because its official name is simply
"other configuration" (see RFC 4861 and RFC 5175) and it isn't used to
assign IP addresses.

Rewrite the documentation for DHCPv6Client and WithoutRA to make it
clear that getting the "managed" RA flag triggers the same kind of DHCP
request as WithoutRA=solicit, whereas getting the "other configuration"
RA flag triggers the same kind of DHCP request as
WithoutRA=information-request.
2022-05-06 14:01:53 -06:00
Yu Watanabe 01af366ef9
Merge pull request #23291 from yuwata/udev-rule-fix-regression
udev: fix parent token handling
2022-05-07 04:58:20 +09:00
Yu Watanabe 0139026b3e
Merge pull request #23290 from keszybz/three-fixes
Three fixes
2022-05-07 04:57:36 +09:00
Yu Watanabe af2ff171e0
Merge pull request #23272 from keszybz/logind-man-and-rules
Logind man and rules
2022-05-07 04:23:02 +09:00
Yu Watanabe eba782d59b udev: fix parent token handling
This fixes a bug introduced by 03677889f0.

Fixes #23288.
2022-05-07 02:51:21 +09:00
Zbigniew Jędrzejewski-Szmek b38a9d2d77 basic/strv: fix splitting of strings with escape characters
Plain strv_split() should not care if the strings contains backslashes
or quote characters. But extract_first_word() interprets backslashes
unless EXTRACT_RETAIN_ESCAPE is given.

I wonder how it's possible that nobody noticed this before. I think this
code was introduced in 0645b83a40.
2022-05-06 18:26:30 +02:00
Zbigniew Jędrzejewski-Szmek 34c2d32cf9 shared/terminal-util: don't use $COLORTERM to force colors
Fixup for a5efbf468c: if $COLORTERM was set, we'd
unconditionally turn on colors, which is unexpected and wrong. It even breaks
our own tests when executed in gnome-terminal.
2022-05-06 18:26:26 +02:00
Khem Raj 0dd5ec58fa resolve: Use sockaddr pointer type for bind()
bind() expects sockaddr* but SERVER_ADDRESS is sockaddr_in type struct

Fixes errors with clang e.g.

../git/src/resolve/test-resolved-stream.c:112:32: error: incompatible pointer types passing 'struct sockaddr_in *' to parameter of type 'const struct sockaddr *' [-Werror,-Wincompatible-pointer-types]
        assert_se(bind(bindfd, &SERVER_ADDRESS, sizeof(SERVER_ADDRESS)) >= 0);
                               ^~~~~~~~~~~~~~~
../git/src/resolve/test-resolved-stream.c:251:39: error: incompatible pointer types passing 'struct sockaddr_in *' to parameter of type 'const struct sockaddr *' [-Werror,-Wincompatible-pointer-types]
                r = connect(clientfd, &SERVER_ADDRESS, sizeof(SERVER_ADDRESS));

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-05-06 17:29:59 +09:00
Thomas Weißschuh 15d4c239f4 userdbctl: initialize parameter n for uid_range_load_userns()
uid_range_load_userns() dereferences the n parameter.

Passing unitialized memory may lead to crashes, for example with version
251rc2-1 on ArchLinux.
2022-05-06 13:48:51 +09:00
Zbigniew Jędrzejewski-Szmek 9aa3d6b41e Revert "shared/install: create relative symlinks for enablement and aliasing"
This reverts commit d6c9411072.

I still think this is something that needs to be done, but we're hitting some
unexplained failures, e.g. https://github.com/systemd/systemd/issues/22920.
So let's revert this for now, so -rc2 can be released, with a plan to return
to this after a release.

Closes #22920.
2022-05-05 19:02:26 +02:00
Daan De Meyer 5517607ad7 journal: Make journal_default_metrics() static
Only caller resides in the same file as were it's defined so no
need to have it be public.
2022-05-05 16:32:24 +02:00
Zbigniew Jędrzejewski-Szmek 7000a8c3bc
Merge pull request #23273 from keszybz/bootctl-quiet
bootctl --quiet and --graceful
2022-05-05 16:30:53 +02:00
Andreas Rammhold 66c38cd053 core: handle lookup paths being symlinks
With a recent change paths leaving the statically known lookup paths would be
treated differently then those that remained within those. That was done
(AFAIK) to consistently handle alias names. Unfortunately that means that on
some distributions, especially those where /etc/ consists mostly of symlinks,
would trigger that new detection for every single unit in /etc/systemd/system.
The reason for that is that the units directory itself is already a symlink.

Rebased-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2022-05-05 14:46:52 +02:00
Zbigniew Jędrzejewski-Szmek 14e6e444dd bootctl: add --quiet
It's useful for installation scripts and suchlike.
Raised in https://bugzilla.redhat.com/show_bug.cgi?id=2079784#c9.
2022-05-05 12:30:06 +02:00
Zbigniew Jędrzejewski-Szmek 18eb56c3c0 bootctl: support --graceful in is-installed 2022-05-05 12:30:06 +02:00
Zbigniew Jędrzejewski-Szmek e8a5b13e45 meson: move vconsole rules to rules.d/ 2022-05-05 11:51:44 +02:00
Zbigniew Jędrzejewski-Szmek 155078c835 meson: move udev rules to rules.d/ 2022-05-05 11:51:44 +02:00
Sonali Srivastava a5efbf468c terminal-util: get_color_mode checks COLORTERM 2022-05-05 09:18:51 +02:00
Evgeny Vereshchagin 51cef2b56f
Merge pull request #23246 from medhefgo/check-compilation
meson: Improve public header tests
2022-05-05 01:53:28 +03:00
Daan De Meyer 746ea80b77 basic: Add some missing headers to compress.h 2022-05-04 22:47:58 +01:00
Matthijs van Duin b0221bb6a4 Fix placement of TTL TLV in LLDP transmit
The LLDP spec (IEEE 802.1AB) requires the three mandatory TLVs (Chassis
ID, Port ID, and TTL) to be the first three TLVs in the packet, in that
specific order, whereas systemd put the TTL near the end of the packet.

This violation caused the ethernet switch in our office to discard these
packets as malformed, and Wireshark's packet parser also chokes on them.
2022-05-05 01:19:02 +09:00
Evgeny Vereshchagin a2e37d5231 timedatectl: fix a memory leak
```
timedatectl list-timezones --no-pager
...
==164329==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8192 byte(s) in 1 object(s) allocated from:
    #0 0x7fe8a74b6f8c in reallocarray (/lib64/libasan.so.6+0xaef8c)
    #1 0x7fe8a63485dc in strv_push ../src/basic/strv.c:419
    #2 0x7fe8a6349419 in strv_consume ../src/basic/strv.c:490
    #3 0x7fe8a634958d in strv_extend ../src/basic/strv.c:542
    #4 0x7fe8a643d787 in bus_message_read_strv_extend ../src/libsystemd/sd-bus/bus-message.c:5606
    #5 0x7fe8a643db9d in sd_bus_message_read_strv ../src/libsystemd/sd-bus/bus-message.c:5628
    #6 0x4085fb in list_timezones ../src/timedate/timedatectl.c:314
    #7 0x7fe8a61ef3e1 in dispatch_verb ../src/shared/verbs.c:103
    #8 0x410f91 in timedatectl_main ../src/timedate/timedatectl.c:1025
    #9 0x41111c in run ../src/timedate/timedatectl.c:1043
    #10 0x411242 in main ../src/timedate/timedatectl.c:1046
    #11 0x7fe8a489df1f in __libc_start_call_main (/lib64/libc.so.6+0x40f1f)
```
2022-05-05 00:05:57 +09:00
Jan Janssen ee8052c137 meson: Add -Wall and -Wextra to header checks
This should ensure public headers are free from any warnings.
2022-05-04 16:11:41 +02:00
Jan Janssen 14056a52c6 meson: Use meson test suite feature
This makes it easier to only test a subset of tests without having
to specify them all on the command line:
    meson test -C build --suite headers
2022-05-04 16:11:34 +02:00
Jan Janssen 911c15087c meson: Remove check-compilation.sh
No need to involve a trivial shell script for this.

We could call the compiler directly, but test() expects arguments
to be passed separately and cc.cmd_array() can contain arguments
itself. Using env is easier than manually slicing the array because
meson has no builtins for that.
2022-05-04 15:59:51 +02:00
Jan Janssen 3d35c6d47e meson: Exit early with subdir_done() 2022-05-04 15:59:03 +02:00
Lennart Poettering 0af6ce9ab3 stat-util: drop dir_is_populated() which is apparently not used 2022-05-04 13:29:14 +02:00
Lennart Poettering db55bbf29b stat-util: fix dir_is_empty() with hidden/backup files
This is a follow-up for f470cb6d13 which in
turn is a follow-up for a068aceafb.

The latter started to honour hidden files when deciding whether a
directory is empty. The former reverted to the old behaviour to fix
issue #23220.

It introduced a bug though: when a directory contains a larger number of
hidden entries the getdents64() buffer will not suffice to read them,
since we just allocate three entries for it (which is definitely enough
if we just ignore the . + .. entries, but not ig we ignore more).

I think it's a bit confusing that dir_is_empty() can return true even if
rmdir() on the dir would return ENOTEMPTY. Hence, let's rework the
function to make it optional whether hidden files are ignored or not.
After all, I looking at the users of this function I am pretty sure in
more cases we want to honour hidden files.
2022-05-04 13:29:14 +02:00
Yu Watanabe 34458dbbe7 udev: also make uevent blocked by events for the same device node
Even if the device node is the same, devnum (thus, device ID) and
syspath may be different. If a 'remove' and 'add' events for the same
device node but with different devnum and syspath are queued,
previously, we might process them in parallel. And, udev_watch_end() for
the 'remove' event and udev_watch_begin() for the 'add' event may
interfere each other.
2022-05-04 17:16:23 +09:00
Yu Watanabe a1af9668ec udev: make newer event also blocked by DEVPATH_OLD
Previously, a device has DEVPATH_OLD is blocked by a previous event
whose devpath is equivalent to the DEVPATH_OLD.

This extends the condtion.

1. an event has DEVPATH_OLD is blocked by a previous event whose
   devpath is a parent of, child of, or equivalent to the DEVPATH_OLD.

2. an event is blocked by a previous event whose DEVPATH_OLD is a
   parent of, child of, or equivalent to the devpath of the new event.

I am not sure such check is really necessary. But, the cost of the check
is expected to be extremely small, as device renaming does not occur so
frequently. Hence, it should not introduce any significant performance
regression.
2022-05-04 17:16:14 +09:00
Yu Watanabe 29d0245832 udev: use device ID to find blockers
If two devices have the same devnum and subsystem (more specifically,
if the device is block or not), or have the same ifindex, then IDs of
these devices are equivalent.
Hence, the previous conditions are covered by comparing device IDs.

Of course, events with a same ID should be already blocked by the
devpath check. So, this should not change anything.

However, udevd saves many kinds of data under /run/udev named with
the device ID. If multiple workers processes events for the same device
ID, then the database may become corrupted.

Let's explicitly check the device IDs for safety and simplicity.
2022-05-04 16:41:16 +09:00
Jonathan Lebon 93651582ae manager: optionally, do a full preset on first boot
A compile time option is added to select behaviour: by default
UNIT_FILE_PRESET_ENABLE_ONLY is still used, but the intent is to change to
UNIT_FILE_PRESET_FULL at some point in the future. Distros that want to
opt-in can use the config option to change the behaviour.

(The option is just a boolean: it would be possible to make it multi-valued,
and allow full, enable-only, disable-only, none. But so far nobody has asked
for this, and it's better not to complicate things needlessly.)

With the configuration option flipped, instead of only doing enablements,
perform a full preset on first boot. The reason is that although
`/etc/machine-id` might be missing, there may be other files provisioned in
`/etc` (in fact, this use case is mentioned in `log_execution_mode`). Some of
those possible files include enablement symlinks even if presets dictate it
should be disabled.

Such a seemingly contradictory situation occurs in {RHEL,Fedora} CoreOS,
where we ship `/etc` as if `preset-all` were called. However, we want to
allow users to disable default-enabled services via Ignition, which does
this by creating preset dropins before switchroot. (For why we do
`preset-all` at compose time, see:
https://github.com/coreos/fedora-coreos-config/pull/77).

For example, the composed FCOS image has a `enable zincati.service`
preset and an enablement for that in `/etc`, while at boot time when we
switch root, there may be a `disable zincati.service` preset with higher
precedence. In that case, we want systemd to disable the service.

This is essentially a revert of 304b3079a2. It seems like systemd
*used* to do this, but it was changed to try to make the container
workflow a bit faster.

Resolves: https://github.com/coreos/fedora-coreos-tracker/issues/392

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2022-05-04 09:10:54 +02:00
Zbigniew Jędrzejewski-Szmek c1e0dc9c88 systemctl: stop saying "vendor preset"
We have vendor presets, and local admin presets, and runtime presets
(under /usr/lib, /usr/local/lib and /etc, /run, respectively). When we
display preset state, it can be configured in any of those places, so
we shouldn't say anything about the origin.

(Another nice advantage is that it improves alignment:

[root@f36 ~]# systemctl list-unit-files multipathd.service
UNIT FILE          STATE   VENDOR PRESET
multipathd.service enabled enabled

^ this looks we have a "PRESET" column that is empty.)
2022-05-04 09:10:50 +02:00