Commit Graph
8433 Commits
Author SHA1 Message Date
Yu Watanabe 93998559f8 Merge pull request #31789 from jsitnicki/socket-pass-fds-to-exec
Pass socket FDs to all ExecXYZ= commands in socket unit but ExecStartPre=
2024-03-27 10:18:13 +09:00
Zbigniew Jędrzejewski-Szmek 1e8c0c671e shared/logs-show: restore infinite loop avoidance for corrupted journals
Fixes a bug introduced in e44f06065b: it was
supposed to be a refactoring, but unfortunately FOREACH_ARRAY is implemented
using a for loop, so when the 'goto finish' was replaced by 'break', it only
broke the inner loop, leading to a infinite loop.
2024-03-27 10:16:16 +09:00
Jakub Sitnicki 97df75d7bd socket: pass socket FDs to all ExecXYZ= commands but ExecStartPre=
Today listen file descriptors created by socket unit don't get passed to
commands in Exec{Start,Stop}{Pre,Post}= socket options.

This prevents ExecXYZ= commands from accessing the created socket FDs to do
any kind of system setup which involves the socket but is not covered by
existing socket unit options.

One concrete example is to insert a socket FD into a BPF map capable of
holding socket references, such as BPF sockmap/sockhash [1] or
reuseport_sockarray [2]. Or, similarly, send the file descriptor with
SCM_RIGHTS to another process, which has access to a BPF map for storing
sockets.

To unblock this use case, pass ListenXYZ= file descriptors to ExecXYZ=
commands as listen FDs [4]. As an exception, ExecStartPre= command does not
inherit any file descriptors because it gets invoked before the listen FDs
are created.

This new behavior can potentially break existing configurations. Commands
invoked from ExecXYZ= might not expect to inherit file descriptors through
sd_listen_fds protocol.

To prevent breakage, add a new socket unit parameter,
PassFileDescriptorsToExec=, to control whether ExecXYZ= programs inherit
listen FDs.

[1] https://docs.kernel.org/bpf/map_sockmap.html
[2] https://lore.kernel.org/r/20180808075917.3009181-1-kafai@fb.com
[3] https://man.archlinux.org/man/socket.7#SO_INCOMING_CPU
[4] https://www.freedesktop.org/software/systemd/man/latest/sd_listen_fds.html
2024-03-27 01:41:26 +08:00
Mike Yuan 8e34fdb884 bus-util: dedup bus_set_address_capsule
Follow-up for ad963c3f56
2024-03-26 21:40:10 +08:00
Mike Yuan b377a7cce9 daemon-util: introduce notify_reloading helper
Prompted by #31951
2024-03-26 12:52:33 +00:00
Zbigniew Jędrzejewski-Szmek c38e4e2fda Merge pull request #29721 from poettering/systemd-project
New capsule@.service feature
2024-03-26 13:19:33 +01:00
Yu Watanabe 0ffcf398e5 Merge pull request #31899 from yuwata/sd-journal-add-match
sd-journal: introduce two helpers for adding journal filter
2024-03-26 02:56:58 +09:00
Yu Watanabe bcd558f12e logs-show: use journal_add_matchf() and journal_add_match_pair() 2024-03-25 21:39:37 +09:00
Gabríel Arthúr Pétursson 1923e21316 shared: Fix TPM2 unsealing when PCR values change
Recreate the encryption session on each retry. It's invalidated along
with the policy session when freed, failing subsequent retries.

	Unsealing HMAC key.
	WARNING:esys:src/tss2-esys/api/Esys_Unseal.c:295:Esys_Unseal_Finish() Received TPM Error
	ERROR:esys:src/tss2-esys/api/Esys_Unseal.c:98:Esys_Unseal() Esys Finish ErrorCode (0x00000128)
	A PCR value changed during the TPM2 policy session, restarting HMAC key unsealing (30 tries left).
	Missing encryption session
	Failed to unseal secret using TPM2: Invalid argument

Fixes #31881
2024-03-24 12:49:22 +00:00
Mike Yuan 8e1a1caa9c Merge pull request #31886 from DaanDeMeyer/logind
logind: Add fallback for when the PIDFDs= property is not available
2024-03-24 19:19:12 +08:00
Luca Boccassi 9c5b5d01f9 Merge pull request #31917 from keszybz/path-equal-ptr-drop
Drop unnecessary path_equal_ptr() wrapper
2024-03-24 11:10:58 +00:00
Zbigniew Jędrzejewski-Szmek acb27fba43 shared/install: use PATH_IN_SET() 2024-03-23 13:30:24 +01:00
Zbigniew Jędrzejewski-Szmek 1934242b72 Drop unnecessary path_equal_ptr() wrapper
path_equal already works with NULL pointers.
2024-03-23 13:21:06 +01:00
Adrian Vovk d0eff7a12d homework: Always upload volume key to keyring
This commit makes homework always upload the LUKS volume key into the
kernel keyring. This is different from previous behavior in three
notable ways:

- Previously, we'd only upload if auto-resize was on. In preparation for
upcoming changes, now we always upload

- Previously, we'd upload the user's actual password (or a password
obtained from a FIDO key or similar). Now, we upload the LUKS volume key
itself, to remove a layer of unnecessary indirection.

- Previously, Lock() wouldn't remove the key from the kernel keyring.
This, of course, defeats the purpose of Lock(), so now it removes the
key

This commit also allows the LUKS volume to be unlocked using the volume
key we obtained from the keyring.
2024-03-23 01:05:13 +00:00
Daan De Meyer 66b574b0a2 tree-wide: Add allow_pidfd argument to bus_append_scope_pidref() 2024-03-22 17:03:35 +01:00
Unique-Usman 5f0e4d2fb4 Added more ASSERT macro and also make some test file to use them 2024-03-22 12:31:14 +00:00
Daan De Meyer 12473f3a4a dissect-image: Improve error messages 2024-03-22 10:48:35 +01:00
Yu Watanabe 1015742878 varlink: use varlink_server_description() 2024-03-21 19:54:25 +09:00
Yu Watanabe 839dce5ecb Merge pull request #31862 from keszybz/add-strdup_to-helper
Add strdup_to() helper
2024-03-21 14:47:05 +09:00
Unique-Usman c0cd99eee6 Follow up with the PR #31819 2024-03-20 15:48:05 +00:00
Zbigniew Jędrzejewski-Szmek 3a08372d18 shared/password-quality: inline iterator variable 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek b41f88a23c shared/dissect-image: use strdup_to_full() in one more place 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek bef2c63a40 shared: use strdup_to() in specifier functions 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek 4f77ddca59 various: also use strdup_to() in cases where we don't return immediately 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek 454318d3e8 various: use strdup_to() in various obvious cases
strdup_to() returns 0 on success and here we convert obvious blocks
which either return -ENOMEM or 0.
2024-03-20 15:13:44 +01:00
Unique-Usman e19186359a Add a set of assertion macros to tests.h
(ASSERT_OK(), ASSERT_EQ(), ASSERT_GE(), ASSERT_LE()) that log the failed condition before crashing and convert test-gpt.c test file to use them
2024-03-19 11:37:45 +00:00
Luca Boccassi 399560aa30 Merge pull request #31747 from yuwata/ptyfwd
ptyfwd: do not erase line after NL
2024-03-18 14:10:45 +00:00
Ronan Pigott 88123aa21c dnssd: support service subtypes
A service subtype is used for selective enumeration of services.
2024-03-18 13:16:48 +00:00
Luca Boccassi 15d4bedf3d Merge pull request #31778 from yuwata/kbd-util
kbd-util: allow to override the default keymap directories
2024-03-18 12:20:36 +00:00
Nick Rosbrook 6fec0fed10 shared/install: correctly install alias for units outside search path
Currently, if a unit file is enabled from outside of the search path,
and that unit has an alias, then the symlink ends up pointing outside of
the search path too. For example:

 $ cat /tmp/a.service
 [Service]
 ExecStart=sleep infinity

 [Install]
 Alias=b.service
 WantedBy=multi-user.target

 $ systemctl enable /tmp/a.service
 Created symlink /etc/systemd/system/a.service → /tmp/a.service.
 Created symlink /etc/systemd/system/b.service → /tmp/a.service.
 Created symlink /etc/systemd/system/multi-user.target.wants/a.service → /tmp/a.service.

This then means the alias is treated as a separate unit:

 $ systemctl start a.service
 $ sudo systemctl status a
 ● a.service
  Loaded: loaded (/etc/systemd/system/a.service; enabled; preset: enabled)
  Active: active (running) since Fri 2024-03-15 15:17:49 EDT; 9s ago
 Main PID: 769593 (sleep)
   Tasks: 1 (limit: 18898)
  Memory: 220.0K
     CPU: 5ms
  CGroup: /system.slice/a.service
          └─769593 sleep infinity

 Mar 15 15:17:49 six systemd[1]: Started a.service.
 $ sudo systemctl status b
 ○ b.service
  Loaded: loaded (/etc/systemd/system/b.service; alias)
  Active: inactive (dead)

To fix this, make sure the alias uses a target that is inside the search
path. Since the unit file itself is outside of the search path, a
symlink inside the search path will have been created already. Hence,
just point the alias symlink to that recently created symlink.
2024-03-18 11:58:07 +00:00
Yu Watanabe 66c4be596e ptyfwd: drop redundant brackets 2024-03-15 03:47:26 +09:00
Yu Watanabe 0d1606df0b ptyfwd: do not erase line after NL
Otherwise, moving upwards in 'less' does not work.

Follow-up for d0aa368c85.
2024-03-15 03:47:04 +09:00
Yu Watanabe e852f10cb4 kbd-util: allow to override the default keymap directories
This introduces $SYSTEMD_KEYMAP_DIRECTORIES environment variable to
override the hardcoded keymap directories.

I think it is not necessary to provide the first class configuration
option for controlling the keymap directories, but it is not good to
hardcode the paths. So, let's introduce an environment variable to
override that.

Prompted by #31759.

Closes #31759.
2024-03-15 03:19:45 +09:00
Lennart Poettering e516c4d286 machine-id-setup: inform supervisor about chosen machine ID
Similar as the previous commit, it's useful for a supervisor to know
what machine ID we settlted on, in particular as various other things
are deterministically derived from it, for example MAC addresses and
such.
2024-03-14 17:23:02 +01:00
Lennart Poettering 2f3b55c4f1 hostname-setup: send chosen hostname to supervisor via sd_notify()
once we decided on a hostname, let's tell the supervisor about it. This
is useful for example in order to recognize the system via mDNS/LLMNR or
in a DHCP lease.
2024-03-14 17:22:58 +01:00
Lennart Poettering 5a515940e9 hostname-setup: various modernizations 2024-03-14 17:22:54 +01:00
Yu Watanabe 6b67cf808a json: introduce json_dispatch_int8() and json_dispatch_uint8() 2024-03-14 23:56:44 +08:00
Lennart Poettering ad963c3f56 bus-util: add ability to connect directly to capsule instances of systemd --user 2024-03-14 11:34:04 +01:00
Lennart Poettering 9367af8a29 util: add capsule-util.[ch] with helpers for capsules
For now, there's only a routine for validating capsule names. More will
be added later.
2024-03-14 11:34:04 +01:00
Lennart Poettering 837eda0522 Merge pull request #31770 from poettering/linkat-replace
introduce linkat_replace() helper, and port various things over to it
2024-03-14 11:03:59 +01:00
Yu Watanabe af02814a85 ptyfwd: fix typo
Follow-up for d0aa368c85.
2024-03-14 17:40:26 +09:00
Lennart Poettering 5655e5c955 creds-util: port make_credential_host_secret() over to link_tmpfile_at()
Let's simplify things by just reusing the primitives we already have.
2024-03-14 09:22:09 +01:00
Mike Yuan 1ea275f119 core/cgroup: introduce MemoryZSwapWriteback setting
Added in
https://github.com/torvalds/linux/commit/501a06fe8e4c185bbda371b8cedbdf1b23a633d8
2024-03-13 23:36:25 +00:00
Yu Watanabe cac8e820d6 network/varlink: return StorageReadOnly error
Addresses https://github.com/systemd/systemd/pull/30021#discussion_r1521595855.
2024-03-13 21:49:12 +09:00
Lennart Poettering 91180a1eec polkit: add another flag that controls how to treat the PK absent case
Typically if PK is not present we want to treat this as "denied". But
sometimes it makes sense to treat this case as "allowed".

In particular the combination POLKIT_ALWAYS_QUERY and
POLKIT_DEFAULT_ALLOW makes a lot of sense: it means we can enable PK
logic for actions where we so far bypassed the checks for root. With the
new combination we can have a default policy of allowing some operation
but still provide an effective hook to disable it.

Also add some debug logging about PK operations and results as they are ongoing.
2024-03-13 10:43:44 +01:00
Lennart Poettering f5a12ceaed polkit: add new POLKIT_ALWAYS_QUERY flag
When this flag is set we'll disable the local shortcut that skips polkit
checks for clients that are privileged, and assumes they are
authenticated.

Or in other words: if this flag is set, we'll query PK not matter what,
regardless if it's root we talk about or any other user.
2024-03-13 10:42:27 +01:00
Lennart Poettering b9632ec42f polkit: allow checking if we already acquired some action
This adds a new helper that basically just wraps
async_polkit_query_have_action() and allows calling this without
actually triggering a PK authentication operation: it just checks if we
aleady have acquired an action or not.
2024-03-13 10:42:13 +01:00
SidhuRupinder 7d08e23558 local-addresses: call 'assert_not_reached' where appropriate (#31728)
Added code for calling the 'assert_not_reached' function as the value of the 'family' parameter must be either 'AF_INET' or 'AF_INET6'.
2024-03-13 13:16:46 +08:00
Mike Yuan a793133963 Merge pull request #31727 from YHNdnzj/homed-followup
data-fd-util: some cleanups
2024-03-13 13:10:34 +08:00
Lars Ellenberg b8e25bff38 fs-utils: new wrapper fd_reopen_propagate_append_and_position()
We may want to propagate O_APPEND, or (try to) keep the current file position,
even if we use fd_reopen() to re-initialize (and "unshare") other file
description status.

For now, used only with --pty to keep/propagate O_APPEND (and/or) position
if set on stdin/stdout.

If we re-open stdout and "drop" the O_APPEND,
we get rather "unexpected" behavior,
for example with repeated "systemd-run --pty >> some-log".

If someone carefully pre-positioned the passed in original file descriptors,
we avoid surprises if we do not reset file postition to zero.

fcntl F_GETFL first, and propagate O_APPEND if present in the existing flags.

Then use lseek to propagate the file position.
2024-03-12 19:01:00 +01:00