Commit Graph

41260 Commits

Author SHA1 Message Date
Daan De Meyer
cc232fa094 basic: Use statement expressions more in list.h
Let's use statement expressions to return values instead of passing
in return arguments to the LIST macros.
2023-01-08 16:31:15 +01:00
Daan De Meyer
d80463ea2f basic: Drop memory-util.h include from stdio-util.h
We want to include stdio-util.h in log.h in a future commit. To avoid
circular includes, we need to drop the memory-util.h include from
stdio-util.h
2023-01-08 16:31:15 +01:00
Daan De Meyer
3952290619 basic: Make snprintf_ok() a static inline function
This allows passing pre-allocated buffers via compound initializers
to snprint_ok(). If snprintf_ok() is a macro, the compound initializer
block will be scoped to the macro block, if snprint_ok() is a function,
the compound initializer block will be scoped to the block from which
snprintf_ok() is called.
2023-01-08 16:31:15 +01:00
Siddhesh Poyarekar
4f79f545b3 alloc-util: Disallow inlining of expand_to_usable
Explicitly set __attribute__ ((noinline)) so that the compiler does not
attempt to inline expand_to_usable, even with LTO.
2023-01-08 16:26:39 +01:00
Luca Boccassi
9907a7e00b Merge pull request #25915 from poettering/arm-timer-rel
pid1: rework service_arm_timer() to optionally take a relative time v…
2023-01-07 17:56:14 +01:00
Lennart Poettering
724f061db6 load-fragment: config_parse_emergency_action() doesn't ever get a Manager pointer passed in
In 'data' we get the location passed in we write stuff, and that's not
the Manager object.

And we neither get the Manager passed in via 'userdata', because at the
time we parse the emergency action for the manager the Manager is not
actually allocated yet.

hence, let's fix this differently, and pass in the user/system mode
descriptor via the 'ltype' argument.

Fixes: #25933
2023-01-06 16:15:46 +01:00
Lennart Poettering
2ae6917a1a load-fragment: remove EmergencyAction compat we were supposed to remove back in v241 2023-01-06 16:15:30 +01:00
Lennart Poettering
7122aee5ab Merge pull request #25918 from bluca/smbios_sd_notify
Support AF_VSOCK in sd_notify and pick up notify_socket from creds
2023-01-06 15:21:27 +01:00
Quentin Deslandes
48d8516043 journald: fix followup comments on regex feature
Fix followup comments on PR #24058:
- Use `mempcpy_safe()`.
- Remove unused `pcre2_code` variable.
- Use `static const` when relevant.
2023-01-06 14:59:31 +01:00
Lennart Poettering
34680637e8 nspawn: guard acl_free() with a NULL check
Inspired by #25957 there's one other place where we don't guard
acl_free() calls with a NULL check.

Fix that.
2023-01-06 14:59:09 +01:00
Sam James
9f804ab04d tmpfiles: avoid null free() for acl attributes
When built with ACL support, we might be processing a tmpfiles
entry where there's no cause for us to call parse_acls_from_arg,
then we get to the end of parse_line without having ever populated
i.{acl_access, acl_default}.

Then we pass a null pointer into acl_free().

From UBSAN w/ GCC 13.0.0_pre20230101:
```
$ systemd-tmpfiles --clean
/var/tmp/portage/sys-apps/acl-2.3.1-r1/work/acl-2.3.1/libacl/acl_free.c:44:14: runtime error: applying non-zero offset 18446744073709551608 to null pointer
    #0 0x7f65d868b482 in acl_free /var/tmp/portage/sys-apps/acl-2.3.1-r1/work/acl-2.3.1/libacl/acl_free.c:44
    #1 0x55fe7e592249 in item_free_contents ../systemd-9999/src/tmpfiles/tmpfiles.c:2855
    #2 0x55fe7e5a347a in parse_line ../systemd-9999/src/tmpfiles/tmpfiles.c:3158
    #3 0x55fe7e5a347a in read_config_file ../systemd-9999/src/tmpfiles/tmpfiles.c:3897
    #4 0x55fe7e590c61 in read_config_files ../systemd-9999/src/tmpfiles/tmpfiles.c:3985
    #5 0x55fe7e590c61 in run ../systemd-9999/src/tmpfiles/tmpfiles.c:4157
    #6 0x55fe7e590c61 in main ../systemd-9999/src/tmpfiles/tmpfiles.c:4218
    #7 0x7f65d7ebe289  (/usr/lib64/libc.so.6+0x23289)
    #8 0x7f65d7ebe344 in __libc_start_main (/usr/lib64/libc.so.6+0x23344)
    #9 0x55fe7e591900 in _start (/usr/bin/systemd-tmpfiles+0x11900)
```
2023-01-06 14:58:46 +01:00
Daan De Meyer
e0ff0ee8f9 Merge pull request #25947 from poettering/resolved-dns-creds
resolved: add support for reading DNS config from kernel cmdline + service credentials
2023-01-06 14:11:57 +01:00
Lennart Poettering
2d935bbd22 gpt-auto-generator: improve log messages a bit
Fixes: #20331
2023-01-06 14:04:46 +01:00
Lennart Poettering
e5d6dcce7f pid1: rework service_arm_timer() to optionally take a relative time value
In most cases this is actually what we want, hence simplify this case.
2023-01-06 11:29:09 +01:00
Lennart Poettering
ef8591951a sd-event: don't mistake USEC_INFINITY passed in for overflow
Let's pass USEC_INFINITY from sd_event_source_set_time_relative() to
sd_event_source_set_time() instead of raising EOVERFLOW.

We should raise EOVERFLOW only if your addition fails, but not if the
input already is USEC_INFINITY, since it's an entirely valid operation
to have an infinite time-out, and we should support that.
2023-01-06 11:29:09 +01:00
Jan Janssen
6e689dc6ee bootctl: Fix NULL pointer dereference
Fixes: #25952
2023-01-06 10:39:41 +01:00
Lennart Poettering
4a6c6d35e4 bootspec: show default/selected entry info in JSON output
Fixes: #25889
2023-01-06 10:38:03 +01:00
Lennart Poettering
5f9041afec resolved: disable SO_BINDTOIFINDEX hack for localhost IP addresses
Fixes: #23010
2023-01-06 10:37:37 +01:00
Luca Boccassi
4a91ace5bc creds: import 'vmm.notify_socket' and use it to set
This is intended to be used with VSOCK, to notify the hypervisor/VMM, eg on the host:

qemu <...> -smbios type=11,value=io.systemd.credential:vmm.notify_socket=vsock:2:1234 -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=42

(vsock:2:1234 -> send to host on vsock port 1234, default is to send to 0 which is
the hypervisor itself)

Also on the host:

$ socat - VSOCK-LISTEN:1234,socktype=5
READY=1
STATUS=Ready.
2023-01-05 23:07:16 +01:00
Luca Boccassi
6c94cfcda5 sd_notify: support AF_VSOCK
Allow sending notifications via AF_VSOCK, so that VMs can communicate
to the hypervisor/VMM that they are finished booting.

Note that if the hypervisor does not support SOCK_DGRAM over AF_VSOCK
(ie: qemu at the time of writing), SOCK_SEQPACKET will be used instead.
2023-01-05 23:07:16 +01:00
Ludwig Nussel
dd003f1621 kernel-install: run depmod only if writeable 2023-01-05 21:46:09 +01:00
Benjamin Tissoires
a91078bc57 virt: fix container detection
Commit 1b86c7c59e ("virt: make virtualization enum a named type")
made the conversion from `if (!r)` to `if (v != VIRTUALIZATION_NONE)`.

However, the initial test was meaning "if r is null", IOW "if r IS
`VIRTUALIZATION_NONE`).

The test is wrong and this can lead to false detection of the container
environment (when calling `systemctl exit`).

For example, https://gitlab.freedesktop.org/whot/libevdev/-/jobs/34207974
is calling `systemctl exit 0`, and systemd terminates with the exit code
`130`.

Fixing that typo makes `systemctl exit 0` returns `0`.

Fixes: 1b86c7c59e.
2023-01-05 21:45:53 +01:00
Ludwig Nussel
8109b2908d bootctl: print entry token as well 2023-01-05 21:45:18 +01:00
Lennart Poettering
218db3d9ef dns-domain: dns_name_is_empty() is redundant
dns_name_is_empty() was added later, but does the same thing as the more
accurately called dns_name_is_root(), hence drop the former.
2023-01-05 21:44:26 +01:00
Lennart Poettering
ef503f1cec resolvectl: remove duplicate ':' from output
The second argument to dump_list() actually ends up in a TABLE_FIELD
cell now, where we implicitly append a ":". Hence drop it from the
strings.

Follow-up for: 37a50123fa
2023-01-05 21:44:11 +01:00
Lennart Poettering
116687f267 resolved: read DNS conf also from creds and kernel cmdline
Note that this drops ProtectProc=invisible from
systemd-resolved.service.

This is done because othewise access to the booted "kernel" command line is not
necessarily available. That's because in containers we want to read
/proc/1/cmdline for that.

Fixes: #24103
2023-01-05 18:52:15 +01:00
Luca Boccassi
747b5d963e src/shared/: split AF_UNIX/AF_VSOCK address parsing into src/basic/
We'll use it from libsystemd0 later, but AF_INET/6 requires some
netlink calls and thus the additional library dependency
2023-01-05 18:43:47 +01:00
Lennart Poettering
ea575e176a vconsole: permit configuration of vconsole settings via credentials 2023-01-05 18:24:21 +01:00
Luca Boccassi
bc0b2d377f Merge pull request #25929 from poettering/resolvectl-loopback-fix
resolvectl: show 127.0.0.1 among global DNS servers again
2023-01-05 13:25:13 +01:00
Mike Yuan
c067e61b85 systemctl: enable: overwrite broken alias symlinks
When switching to an alternative alias provider,
the previous one might have been uninstalled or so.
It should be fine for us to overwrite them directly.

Closes #23694
2023-01-05 02:10:42 +01:00
Mike Yuan
44db9fbb39 systemctl: edit: rephrase edit markers to avoid misunderstanding
Closes #25856
2023-01-05 01:58:05 +01:00
Joshua Goins
0855ce6772 udev: Fix some tablet pads being classified as mouse or joysticks 2023-01-04 17:50:10 +01:00
Lennart Poettering
889a1b9f4e resolvectl: don't filter loopback DNS server from global DNS server list
"resolvectl status" shows per-link DNS servers separately from global
ones. When querying the global list, it will contain both per-link and
global servers however. Thus, to not show duplicate info we filter all
entries that actually have a non-zero ifindex set (under the assumption
that that's a per-link server).

This doesn't work if people configured 127.0.0.1 as global server
though, as we'll add ifindex 1 to it since
6e32414a66 unconditionally even for global
servers.

Let's address that by excluding entries with ifindex 1 from suppression.
This is safe as resolved ignores loopback ifaces, hence never will have
per-link servers on ifindex 1.

Note that this splits up the "with_ifindex" parameter into a second
parameter "only_global", since they semantically do two different
things. One controls whether we shall expect/parse an ifindex dbus
field. The other controls whether we shall filter all ifindex values set
!= 0. These are effectively always used in conjunction hence making them
the same actually worked. However this is utterly confusing I think,
which as I guess is resulting in the confusion around #25796 (which
removes the whole check)

Replaces: #25796
2023-01-04 16:47:40 +01:00
Lennart Poettering
5707fb1297 resolved: add some line-breaks/comments
Let's make this a bit more readable.
2023-01-04 16:32:53 +01:00
Lennart Poettering
a5e6c8498c resolvectl: fix type of ifindex D-Bus field, and make sure to initialize to zero in all code paths 2023-01-04 16:29:34 +01:00
Lennart Poettering
54978e3f3b bootctl: split out setting of system token into function of its own
Let's break a huge function in two. No code change, just some
refactoring.
2023-01-04 15:18:10 +01:00
Lennart Poettering
5019b0cb15 bootctl: downgrade graceful messages to LOG_NOTICE 2023-01-04 15:18:10 +01:00
Lennart Poettering
29d487adb4 random-seed: don't refresh EFI random seed from random-seed.c anymore
The ESP is simply not mounted early enough for this. We want that the
regular random seed handling runs as early as we possibly could, but we
don't want to delay this until the ESP is actually mounted.

Hence, let's remove this from random-seed.c here. A follow-up commit
will then add this back in, in a separate service which just calls
"bootctl random-seed".

Effectively reverts: f913c784ad

Fixes: #25769
2023-01-04 15:18:10 +01:00
Lennart Poettering
a16c65f3c4 sha256: add helper than hashes a buffer *and* its size
We use this pattern all the time in order to thward extension attacks,
add a helper to make it shorter.
2023-01-04 15:18:10 +01:00
Lennart Poettering
114172fbe7 bootctl: when updating EFI random seed file, hash old seed with new one
Let's not regress in entropy in any case.

This does what f913c784ad also does.
2023-01-04 15:18:10 +01:00
Lennart Poettering
60315d5953 bootctl: properly sync fs before/after moving random seed file into place
Let's do a careful, focussed sync at the right places instead of a
blanket sync at the end. After all we want to run this on every boot
soon.
2023-01-04 15:18:10 +01:00
Lennart Poettering
6b97b267bf bootctl: rework random seed logic to use open_mkdir_at() and openat()
This doesn't really fix anything, but in general we should put stronger
emphasis on operating via dir fds rather than paths more (in particular
when writing files as opposed to consuming them).

No real change in behaviour.
2023-01-04 15:18:10 +01:00
Lennart Poettering
e425849e99 bootctl: fix errno logging 2023-01-04 15:15:58 +01:00
Lennart Poettering
fd1fec534e efi: skip Read() calls with zero sizes
Let's avoid calling Read() with zero-sized buffer, to avoid needless firmware
quirkiness.

See: #25911
2023-01-03 23:12:36 +01:00
Lennart Poettering
40557509be resolved: downgrade inability to send varlink reply error message
Previously, if a client disconnected after sending a lookup request but
before waiting for the reply we'd log at LOG_ERR level. That's
confusing, since it's entirely OK for the client to lose interest.

Hence, let's downgrade to debug level.

Fixes: #25892
2023-01-03 23:12:02 +01:00
Luca Boccassi
1d75a24323 Merge pull request #25910 from crrodriguez/wth_c2x
Fix FTBS when -std=gnu2x
2023-01-03 23:10:36 +01:00
msizanoen1
3102499039 udev: match device tags in rules using current device tags
This ensures that udev scripts using `TAG-="..."` and expecting later
udev rules to honor it will work properly. An use case is removing the
`uaccess` tag from a device without overriding the original file and
ensuring that `73-seat-uaccess.rules` won't run the uaccess builtin later.
2023-01-03 18:39:22 +01:00
Jia Zhang
4b33911581 efi-api: check the EFI_TCG2_FINAL_EVENTS_TABLE in efi_has_tpm2()
The EFI firmware may provide the TPM2 event log using
EFI_TCG2_FINAL_EVENTS_TABLE stored in EFI configuration table,
instead of the ACPI Table TPM2.

If the ACPI Table TPM2 doesn't exist, try to check whether
EFI_TCG2_FINAL_EVENTS_TABLE is available or not.

Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com>
2023-01-03 18:02:18 +01:00
Jan Janssen
f151abb0e5 Revert "boot: Use EFI_BOOT_MANAGER_POLICY_PROTOCOL to connect console devices"
This reverts commit b99bf58118.

It seems that using this protocol on some firmwares to forcibly
initialize console devices may break handles (already opened file
handles and the device handle itself) that we rely on to access the
boot filesystem, making it impossible to load the selected entry.

It might be possible to get a new handle by querying for the device
handle by using its device path after calling into this protocol, but
this is untested. The firmware might also be so buggy that accessing
devices after using this protocol is impossible.

It seems prudent to revert this for now until some reliable way is found
to initialize console devices without introducing huge boot delays. Any
users on firmware where console devices cannot be accessed would have to
rely on disabling fastboot.

Fixes: #25737, #25846
2023-01-03 17:12:33 +01:00
Cristian Rodríguez
2cc697d740 libsystemd-network: FTBS in c2x mode
cannot pass false as argument because function wants a pointer to bool
instead, use NULL instead
2023-01-03 15:58:55 +01:00