Commit graph

49636 commits

Author SHA1 Message Date
Mike Yuan 1d617b35fe
bus-unit-util: extend the bus call timeout for UnitFreezer
Might fix #33083

There's another report available on Mastodon:
https://m.otter.homes/@kaixin/112510783502516607
https://m.otter.homes/@kaixin/112510803023469180
2024-05-30 21:51:48 +08:00
Mike Yuan 61fbc58c46
sleep,home: clean up logs for session freezer a bit 2024-05-30 21:51:48 +08:00
Mike Yuan 12904d5387
bus-unit-util: rework UnitFreezer, explicitly thaw unit
Currently, we don't explicitly call unit_freezer_thaw(),
but rely on the destructor to thaw the frozen unit on
return. This has several problems though, one of them
being that we ignore the return value of ThawUnit(),
which is something we really shouldn't do here,
since such failure can easily leave the whole system
in unusable state. Moreover, the logging is kinda messy,
e.g. homed might log "Everything completed" yet immediately
followed by "Failed to thaw unit". Instead, we should log
consistently and at higher level, to make things more
debuggable.

Therefore, let's step away from the practice. Plus,
make UnitFreezer object heap-allocated, to match
with existing unit_freezer_new() and allow us to
use NULL to denote that the freezer is disabled.
2024-05-30 21:51:48 +08:00
Mike Yuan 759ac0dec3
core/dbus-unit: modernize bus_unit_method_freezer_generic a bit 2024-05-30 21:51:48 +08:00
Mike Yuan 47266ea224
core/dbus-manager: only allow Freeze/ThawUnit() if loaded 2024-05-30 21:51:47 +08:00
Lennart Poettering 43ad199802 homed: drop caches harder
echoing "2" is apparently not enough to erase inodes/dentrys from
memory, hence use "3", which seems to work.

Fixes: #32596
2024-05-30 14:50:40 +02:00
Daan De Meyer 381918edc9
Merge pull request #32866 from DaanDeMeyer/sanitizers
mkosi: Sanitizers
2024-05-30 14:49:13 +02:00
Daan De Meyer 0916532e4b
Merge pull request #33090 from poettering/tpm12-efi-check
efi-api: tighten check for TPM2 systems
2024-05-30 13:32:41 +02:00
Daan De Meyer 5837d0dced
Merge pull request #33084 from DaanDeMeyer/cgroup-log
cgroup-util: Don't try to open pidfd for pids from cgroup.threads
2024-05-30 12:49:37 +02:00
Daan De Meyer 51e26d2366 test-execute: Skip system call filter tests when sanitizers are used
System call filtering is incompatible with sanitizers so let's skip
these tests when we're built with sanitizers.
2024-05-30 12:47:45 +02:00
Daan De Meyer 4dc76eb770 test-execute: Skip test_exec_mount_apivfs() when running with sanitizers
The test fails when running under sanitizers due to missing sanitizer
libraries. For now, let's skip the test until we can make the necessary
changes to run it under sanitizers.
2024-05-30 12:47:45 +02:00
Zbigniew Jędrzejewski-Szmek 415bf4e01e sd-event: use consistent style for '*' in signatures 2024-05-30 12:15:11 +02:00
Zbigniew Jędrzejewski-Szmek 8ca77ee645 sd-event: emit a debug line if disabling unreffed source fails
We can only do a debug log from the library, so let's add that. Callers
probably want to provide some hint when that happens, but it's very unlikely so
not worth coding in every caller.

And drop the now-unnecessary handling in unit_dequeue_rewatch_pids().
2024-05-30 12:15:11 +02:00
Zbigniew Jędrzejewski-Szmek a3ada90a37 various: remove unnecessary check before sd_event_source_set_enabled()
sd_event_source_set_enabled() does the same check internally.
2024-05-30 12:11:58 +02:00
Zbigniew Jędrzejewski-Szmek 613b698eb4 basic/fd-util: drop report from fd_cloexec_many
fd_cloexec_many promised to report if work was done, but that code was
not effective, because it always reported true if any fds were open.
But no callers care about the return value, so let's just drop this.
2024-05-30 12:07:57 +02:00
Zbigniew Jędrzejewski-Szmek 4199866ac5 basic/fd-util: drop unnecessary {} 2024-05-30 12:07:57 +02:00
Zbigniew Jędrzejewski-Szmek 12080b1f7d shared/format-table: print BPS with part after point
Fixes https://github.com/systemd/systemd/issues/33076.
"2Gbps" → "2.5Gbps".
2024-05-30 11:38:30 +02:00
Zbigniew Jędrzejewski-Szmek 11226bf19b shared/format-table: do not print '.0'
This makes output a bit shorter and nicer. For us, shorter output is generally
better.

Also, drop unnecessary UINT64_C macros. The left operand is always uint64_t,
and C upcasting rules mean that it doesn't matter if the right operand is
narrower or signed, the operation is always done on the wider unsigned type.
2024-05-30 11:38:30 +02:00
Mike Yuan a6117106e4 blockdev-util: update comment for blockdev_partscan_enabled
Follow-up for aa6fe772e1

Also, the 'partscan' sysattr has been backported to v6.6.
2024-05-30 10:57:30 +02:00
Daan De Meyer 8783355fd9 cgroup-util: Don't try to open pidfd for pids from cgroup.threads
Opening pidfds for non thread group leaders only works from 6.9 onwards with PIDFD_THREAD. On
older kernels or without PIDFD_THREAD pidfd_open() fails with EINVAL. Since we might read non
thread group leader IDs from cgroup.threads, we introduce and set CGROUP_NO_PIDFD to avoid
trying open pidfd's for them and instead use the pid as is.
2024-05-30 10:30:36 +02:00
Lennart Poettering 5005522412 pcrlock: tweak error messages when we are not looking at a TPM2 event log
If we are looking at a TPM1.2 event log the first log record will not be
the "EfiSpecIdEvent" but something else. Let's improve the log messages
about this, and say explicitly that this is likely not a TPM2.0 event
log.
2024-05-30 10:13:39 +02:00
Lennart Poettering aeaac9a289 efi-api: check /sys/class/tpm/tpm0/tpm_version_major, too
If the ceck for the ACPI TPM2 table did not work we currently check if
the EFI TPM table exists to check if the firmware supports TPM2.
Specifically we check if
/sys/kernel/security/tpm0/binary_bios_measurements exists. But that's
not enough, since that also exists on TPM1.2 systems. Hence, let's also
check /sys/class/tpm/tpm0/tpm_version_major which should exist under
similar conditions and tells us the kernel's idea of the TPM version in
use.

I originally intended to read the signature of the
/sys/kernel/security/tpm0/binary_bios_measurements contents for this,
but this is not ideal since that file has tight access mode, and our TPM
availability check would thus not work anymore if invoked unpriv.

Follow-up for 4b33911581

Fixes: #33077
2024-05-30 10:13:39 +02:00
Luca Boccassi 214013be83
Merge pull request #33079 from poettering/watchdog-no-disarm
watchdog: don't disarm on shutdown
2024-05-29 22:18:08 +02:00
Daan De Meyer 9ac8450e7f basic: Add debug logging for pidref_set_pid() 2024-05-29 21:04:13 +02:00
Daan De Meyer 330ecca853 cgroup-util: Add debug logging for cg_kill_recursive() 2024-05-29 21:04:09 +02:00
Lennart Poettering d46aab1374 main: add comment explaining parameter to watchdog_close 2024-05-29 17:42:02 +02:00
Lennart Poettering 79645d7376 shutdown: explicitly close watchdog with disarm=false before we destroy watchdog resources
Otherwise we'll close the device disarming it as side-effect of
watchdog_free_device(), which is not intended. Hence, let's close the fd
first explicitly leaving it armed.

Fixes: #33075
2024-05-29 17:42:02 +02:00
Lennart Poettering bbd3832e6b watchdog: reset last ping timestamp when opening watchdog
When we open a watchdog fresh we have never pinged it, hence reset the
ping timestamp explicitly, so that it is not only reset the first time
we open the device, but all times.
2024-05-29 17:42:02 +02:00
Lennart Poettering e7f0053787 watchdog: normalize how we name watchdog related calls
Let's put the "watchdog" always as prefix in the name, and not as suffix
or the middle. Just for reasons of naming hygiene
2024-05-29 17:42:02 +02:00
Zbigniew Jędrzejewski-Szmek 134bdba832 test-format-table: add test for TABLE_BPS formatting 2024-05-29 17:36:01 +02:00
Lennart Poettering a25acf70fe exec-util: make sure to close all fds for invoked generators
We should really have set O_CLOEXEC for all our fds, but better be safe
than sorry.
2024-05-29 14:43:40 +02:00
Lennart Poettering 6b90b04d3a exec-util: use the stdio array of safe_fork_full() where appropriate 2024-05-29 14:43:40 +02:00
Lennart Poettering 8971313336 generator-setup: use RET_GATHER() 2024-05-29 11:52:40 +02:00
Zbigniew Jędrzejewski-Szmek 1eb0009450 core/bpf-firewall: constify and reduce scope of variables 2024-05-29 11:06:04 +02:00
Luca Boccassi 8e495bf0b7 bpf: add helper to translate kernel error codes from libbpf
libbpf returns error codes from the kernel unmodified, and we don't understand
them so non-fatal ones are handled as hard errors.
Add a translation helper, and start by translating 524 to EOPNOTSUPP, which is
returned when nsresourced tries to use LSM BPF hooks that are not
implemented on a given arch (in this case, arm64 is misssing trampolines).

Fixes https://github.com/systemd/systemd/issues/32170
2024-05-29 08:29:47 +02:00
Luca Boccassi cbac9a3835
Merge pull request #33066 from YHNdnzj/logind-linger
logind-user: check linger file in user_wants_service_manager too
2024-05-28 22:41:57 +02:00
Christian Göttsche a424e4af6d tmpfiles: improve warning message and use O_NOCTTY
Mention in the warning message for a failed open on a to be removed file
why systemd-tmpfiles tried to open it.

Also open the file with the O_NOCTTY flag, since it should never become
the controlling terminal.
2024-05-28 21:58:30 +02:00
Mike Yuan e417415996
logind-user: check linger file in user_wants_service_manager too
Follow-up for 5099a50d43

Fixes #33005
2024-05-29 00:50:07 +08:00
Mike Yuan 194dba5ef5
logind-user: add missing assertion for user_check_linger_file
Also make the function take const User*
2024-05-29 00:50:07 +08:00
Luca Boccassi aa6fe772e1
Merge pull request #33057 from poettering/partscan-no-part
blockdev-util: for partition block devices partition scanning is always off
2024-05-28 16:39:15 +02:00
Luca Boccassi 78247be91d
Merge pull request #33063 from keszybz/wiki-links
Update wiki links
2024-05-28 16:21:45 +02:00
Zbigniew Jędrzejewski-Szmek 95a248c56f
Merge pull request #33008 from fbuihuu/optionally-link-ssh-dropins
Optionally link ssh dropins
2024-05-28 16:02:40 +02:00
Mike Yuan 1e1df05296 socket-util: use GREEDY_REALLOC_APPEND where appropriate
Also, previously GREEDY_REALLOC was used improperly,
causing the fds_array to be leaked when realloc() fails.
2024-05-28 15:42:14 +02:00
Lennart Poettering 7c1a1aa42c machined: downgrade warning if we cannot drop ref to systemd unit if disconnected from bus
if machined exits while a machine is still running, we'll issue the
UnrefUnit() call on the unit. This quite likely will fail if during
shutdown the bus connection is already down. But that's no reason to
warn at all, since the ref count will implicitly be dropped if our side
disappears from the bus. Hence, downgrade to LOG_DEBUG in case of
connection problems.
2024-05-28 15:05:11 +02:00
Luca Boccassi c7eb3ae308
Merge pull request #33052 from yuwata/missing-loop
Fixlets for missing_loop.h
2024-05-28 15:01:00 +02:00
Zbigniew Jędrzejewski-Szmek 75ced6d5ee various: update links to usr-merge 2024-05-28 14:48:56 +02:00
Lennart Poettering 3455bcb0df test: add superficial test for partscan test 2024-05-28 11:08:06 +02:00
Lennart Poettering fa65917623 blockdev-util: partition block devices never have partition scanning enabled 2024-05-28 11:08:06 +02:00
Yu Watanabe 36c5035f2a test: suppress logs generated by journal tests
Note, journal_file_dump() is only used by tests.

Closes #33035.
2024-05-28 10:38:53 +02:00
Yu Watanabe eb6d3a5917 missing_loop.h: fix LOOP_SET_STATUS_SETTABLE_FLAGS
See https://github.com/torvalds/linux/blob/v6.10-rc1/include/uapi/linux/loop.h

Fixes a bug in b3fe33ff52.
2024-05-28 12:27:04 +09:00
Yu Watanabe fb45ced368 missing_loop: fix potential compile-time assertion
Fixes a bug introduced by 4d6437d33c.
2024-05-28 12:25:53 +09:00
Daniel Winzen 983028cdc4
cryptsetup: mention correct action in log message 2024-05-27 17:05:23 +01:00
Franck Bui 50d80ec5ac meson: don't put a symlink pointing to '20-systemd-userdb.conf' in /etc in all cases
It's only needed on distros where sshd doesn't support drop-ins in /usr, which
is not the case on SUSE.
2024-05-27 17:20:55 +02:00
Franck Bui de0f11d790 meson: don't put a symlink pointing to '20-systemd-ssh-proxy.conf' in /etc in all cases
On distros like SUSE where ssh config dropins in /usr are supported, there's no
need for a symlink in /etc/ssh/ssh_config.d/ that points to the dropin
installed somewhere in /usr (that is not reachable by ssh).
2024-05-27 17:20:26 +02:00
Luca Boccassi 86b89c7309
Merge pull request #33028 from yuwata/blockdev-util
blockdev-util: also check loop/partscan sysattr
2024-05-27 12:44:38 +02:00
Luca Boccassi cafe40ec82 executor: check for all permission related errnos when setting up IPC namespace
Denials from AppArmor are raised as EACCES, so EPERM is not enough. Do
the same check as PrivateNetwork above.

Fixes https://github.com/systemd/systemd/issues/31037

Related to 06384eb3c5
2024-05-27 10:58:15 +02:00
Daan De Meyer 09a2585686
Merge pull request #33013 from yuwata/journal-flush
journal: several fixlets for flushing runtime journal
2024-05-27 08:56:46 +02:00
Yu Watanabe c7cd75b0bf
Merge pull request #33016 from YHNdnzj/transient-working-dir
core: several cleanups/fixes for WorkingDirectory= handling
2024-05-27 09:40:26 +09:00
Yu Watanabe bab8c851da blockdev-util: also check loop/partscan sysattr
With b9684a71fc (v5.19),
we cannot check partition scanning is enabled for a loopback block device
without checking the attribute.
2024-05-27 09:33:46 +09:00
Yu Watanabe f0c2668c99 blockdev-util: also check newer value of GENHD_FL_NO_PART flag
With 430cc5d3ab,
the value of GENHD_FL_NO_PART, previously named as GENHD_FL_NO_PART_SCAN,
is changed from 0x0200 to 0x0004. So, we need to check both flags.
2024-05-27 09:33:09 +09:00
Mike Yuan 7fbb637ac9 run: also show a pretty string for main exit status, if any
This brings output on par with unit_log_process_exit().
2024-05-27 04:31:33 +09:00
Mike Yuan 100bed702b blockdev-util: "partscan" sysattr now directly shows the enabled state
See also: https://lore.kernel.org/r/20240502130033.1958492-3-hch@lst.de
2024-05-26 13:52:31 +02:00
Mike Yuan 52d8ba71b6
core: introduce unit_verify_contexts
Refuse WorkingDirectory=~ both in that and exec_invoke()
when dynamic user is used.
2024-05-26 13:41:43 +08:00
Mike Yuan 4dd884af1b
core/unit: don't set missing_ok if WorkingDirectory=~ is explicitly requested 2024-05-26 13:40:49 +08:00
Mike Yuan 3a14167102
core/exec-invoke: add a comment that acquire_home uses result from get_fixed_user
Prompted by https://github.com/systemd/systemd/pull/33016#discussion_r1614848067
2024-05-26 13:40:48 +08:00
Mike Yuan c0afdec5cf
core/exec-invoke: drop unused param for acquire_home, prefix out param with ret_ 2024-05-26 13:40:48 +08:00
Mike Yuan 6f8ef80bb3
core/dbus-execute: don't trigger assertion if WorkingDirectory="" or "-"
Follow-up for 14631951ce

Before this commit, if WorkingDirectory= is empty or literally "-",
'simplified' is not populated, resulting in the ASSERT_PTR
in unit_write_settingf() below getting triggered.

Also, do not accept "-", so that the parser is consistent
with load-fragment.c

Fixes #33015
2024-05-26 13:40:48 +08:00
Mike Yuan af87bdc6bc
core/dbus-execute: use correct char for representing WorkingDirectory=home 2024-05-26 13:40:48 +08:00
Mike Yuan f28a7e87f1
core/load-fragment: also clear missing_ok when WorkingDirectory="" 2024-05-26 13:40:48 +08:00
Yu Watanabe 41d45bd96c cryptenroll: upgrade log level of critical failure 2024-05-26 04:45:55 +09:00
Yu Watanabe 16f51e2909 cryptenroll: do not pass an empty pcrlock policy
Otherwise, tpm2_uneal() -> tpm2_build_sealing_policy() ->
tpm2_deserialize() will trigger assertion.

Prompted by #33017.
2024-05-26 04:42:19 +09:00
Yu Watanabe caebda361e cryptsetup: use TPM2_FLAGS_USE_PCRLOCK at one more place
Follow-up for 404aea7815.
2024-05-26 04:29:18 +09:00
Yu Watanabe 3148edb254 journald: always unset flushed flag when the runtime journal is opened
If the runtime journal is opened, we will anyway write journal entries
to the runtime journal, even if the persistent journal is writable.
Hence, we need to flush the runtime journal file later.
2024-05-26 03:11:24 +09:00
Yu Watanabe 349fa06134 journald: log removal of runtime journal directories 2024-05-26 03:11:24 +09:00
Yu Watanabe 672a9ac7d0 journald: close runtime journal earlier
Then, we can use SD_JOURNAL_ASSUME_IMMUTABLE flag, and the performance
of reading runtime journal should be improved.
2024-05-26 03:11:14 +09:00
Yu Watanabe d2a11fd3ff machine-id-setup: update comment
If an initrd has an empty or uninitialized /etc/machine-id file,
then PID1 write a valid machine ID. So, the logic is important only on
soft-reboot. Let's mention that explicitly.

Follow-up for 16718dcf78.
2024-05-25 02:13:22 +09:00
Yu Watanabe 9ab78ad109 machine-id-setup: use isempty() instead of empty_or_root()
This effectively reverts ba540e9f1c.

https://github.com/systemd/systemd/pull/32915#discussion_r1608258136
> In many cases we allow --root=/ as a mechanism for forcing an "offline" mode,
> while still operating on the root dir. if we do the getenv_for_pid() thing
> below I'd claim this is very much an "online" operation, and hence --root=/
> should really disable that.
2024-05-25 01:45:10 +09:00
Luca Boccassi e67129e5e4
Merge pull request #32994 from keszybz/kernel-install-parsing
Improve parsing of kernel/install.conf
2024-05-24 11:25:26 +02:00
Zbigniew Jędrzejewski-Szmek 600a7405a9 shared/conf-parser: do not print "(null)" as section name
Before:
/etc/kernel/install.conf:6: Unknown key name 'asdf' in section '(null)', ignoring.
After:
/etc/kernel/install.conf:6: Unknown key 'asdf', ignoring.

Also make the message a bit better.
2024-05-23 16:15:24 +02:00
Zbigniew Jędrzejewski-Szmek 3f5196ffb8 kernel-install,bootctl: unify the config parsing procedure
Fixes https://github.com/systemd/systemd/issues/32992.
2024-05-23 16:15:24 +02:00
Lennart Poettering b3efb67ddc tpm2-util: improve compat with older unlocking tools
Let's only generate the pin and pcrlock booleans if they are enabled, in
order to not unnecessarily confuse older unlocking tools.
2024-05-23 15:38:37 +02:00
Lennart Poettering 360198efc3 tpm2-util: do not serialize tpm2 bank if none is specified
If both literal and signed PCR bindings are not used then we won't
determine a PCR bank to use, and hence we shouldnt attempt to serialize
it either.

Hence, if the bank is zero, skip serialization.

(And while we are at it, also skip serialization of the primary
algorithm if not set, purely to make things systematic).

[This effectively results in little change, as previously we'd then
seralize a json "null", while now we simply won't genreate the field]
2024-05-23 15:38:37 +02:00
Lennart Poettering 96bf8aa051 cryptenroll: explicitly pick PCR bank if literal PCR binding is off, but signed PCR binding is on
We so far derived the PCR bank to use from the PCR values specified fr
literal PCR binding. However, when that's not used then we left the bank
uninitialized – which will break if signed PCR binds are used (where we
need to pick a bank too after all).

Hence, let's explicitly pick a bank to use if literal PCR values are not
used, to make things just work.

Fixes: #32946
2024-05-23 13:53:22 +02:00
Christian Göttsche 9fb2db89e3 sd-bus: close peer pidfd
Do not leak the pidfd of the peer.

Fixes: 71be64064c ("sd-bus: add pidfd to the sd_bus_creds structure")
2024-05-22 22:08:44 +02:00
Lennart Poettering f5faf4ec5b varlinkctl: when operating in --more mode, fail correcly on Varlink method error
In varlink.c we generally do not make failing callback functions fatal,
since that should be up to the app. Hence, in case of varlinkctl (where
we want failures to be fatal), make sure to propagate the error back
explicitly.

Before this change a failing call to "varlinkctl --more call …" would result in
a zero exit code. With this it will correctly exit with a non-zero exit
code.
2024-05-22 22:08:28 +02:00
Yu Watanabe a925620f5f sd-ndisc: do not print "(null)" in the log message
If we received RA with no flags set, or with an invalid preference,
previously "(null)" was printed.

Follow-up for 238ed432c3.

Fixes https://github.com/systemd/systemd/pull/32308#discussion_r1600940289.
2024-05-22 22:07:58 +02:00
Luca Boccassi 6ab21f20bd test: do not fail network namespace test with permission issues
When running in LXC with AppArmor we'll most likely get an error when creating
a network namespace due to a kernel regression in < v6.2 affecting AppArmor,
resulting in denials. Like other tests, avoid failing in case of permission
issues and handle it gracefully.
2024-05-22 16:51:38 +01:00
Luca Boccassi 06384eb3c5 lock-util: do not expect EACCES when it cannot happen
As per the documentation, EACCES is only returned when F_SETLK is
used, and only on some platforms, which doesn't seem to include
Linux:

https://github.com/torvalds/linux/blob/master/fs/locks.c

F_OFD_SETLK is documented to only return EAGAIN, and F_SETLKW/F_OFD_SETLKW
are blocking operations so this logic doesn't apply to them in the
first place.

Hence, only automatically convert EACCES into EAGAIN for F_SETLK
operations, and propagate the original error in the other cases.

This is important because in some cases we catch permission errors
and gracefully fallback, which is not possible if the original error
is lost.

This is an issue in practice because, due to a kernel bug present
before v6.2, AppArmor denies locking on file descriptors to LXC
containers. We support all currently maintained LTS kernels,
including v6.1, where despite a lot of effort and attempts over almost
a year, the bugfix still hasn't been backported, as it is complex and
requires large changes to AppArmor.
On affected kernels, all services running with PrivateNetwork=yes
fail and do not recover, instead of the normal behaviour of gracefully
downgrading to PrivateNetwork=no.

The integration tests in the Debian CI fail due to this issue:

https://ci.debian.net/packages/s/systemd/testing/arm64/46828037/
2024-05-22 13:25:44 +01:00
Zbigniew Jędrzejewski-Szmek ab0137b44a shared/btrfs-util: simplify return conditions
Coverity has trouble undertanding this function, so let's get rid of the
redundant return branch to simplify the code.
2024-05-22 13:55:45 +02:00
Mike Yuan f781292d6c
core/service: try to query for new main process's starttime
Currently, when service_set_main_pidref() is called
without specifying start_timestamp, exec_status_start()
always uses dual_timestamp_now(). This is not ideal,
though, as when the main pid changes halfway due to
e.g. sd_notify + MAINPID=, it's definitely spurious.
2024-05-22 19:03:13 +08:00
Mike Yuan 6fb97a85c7
process-util: make pid*_get_start_time return usec_t 2024-05-22 18:47:16 +08:00
Zbigniew Jędrzejewski-Szmek cbd8fc859a core: simplify variable declaration
It doesn't matter much, but right below there is a second declaration
which already uses this style, and the mismatch was grating.
2024-05-22 11:55:26 +02:00
Zbigniew Jędrzejewski-Szmek 4f43cbe66c nspawn: use FOREACH_ARRAY() in one more place 2024-05-22 11:55:26 +02:00
Luca Boccassi 5e30e6e281 btrfs-util: add assert to fix Coverity warning
Coverity gets confused since the iterator change, so add an
assert to indicate that this is allocated if n_old_groups is > 0

CID#1545922

Follow-up for 125cca1b51
2024-05-21 22:17:09 +02:00
Luca Boccassi 27b5ac39d1
Merge pull request #32954 from YHNdnzj/run-forwarder-exit
run: when disconnected from PTY forwarder, exit event loop if not --wait
2024-05-21 20:37:17 +02:00
Mike Yuan c675851d5f
fs-util: try AT_EMPTY_PATH for access_fd() first 2024-05-22 00:50:44 +08:00
Mike Yuan 94d94f0c0a
fs-util: if /proc/ is mounted, return -EBADF when appropriate for link_fd() 2024-05-22 00:50:44 +08:00
Mike Yuan d19b3c5d99
fd-util: introduce proc_fd_enoent_errno helper
Currently, if proc_mounted() != 0, some functions
propagate -ENOENT while others return -EBADF.
Let's make things consistent, by introducing
a static inline helper responsible for finding out
the appropriate errno.
2024-05-22 00:50:44 +08:00
Mike Yuan 69baf0cb91
fs-util: use RET_GATHER at one more place 2024-05-22 00:48:51 +08:00
Mike Yuan 6548f0dab1
fs-util: add missing assertions 2024-05-22 00:48:51 +08:00
Mike Yuan 88873231c8
mountpoint-util: add missing assertions, make mount_fd static 2024-05-22 00:48:51 +08:00
Zbigniew Jędrzejewski-Szmek 9280b08664 logind: use SD_BUS_ERROR_ACCESS_DENIED
As requested in post-merge review
https://github.com/systemd/systemd/pull/32869#pullrequestreview-2068161094:
> NotInControl error is really about session controllers, but this here really
> is different.
2024-05-21 18:32:36 +02:00
Mike Yuan 2b4a691c32
run: when disconnected from PTY forwarder, exit event loop if not --wait
Follow-up for ade0789fab

The change in behavior was partly intentional, as I think
if both --wait and --pty are used, manually disconnecting
from PTY forwarder should not result in systemd-run exiting
with "Finished with ..." log. But we should check for
--wait here.

Closes #32953
2024-05-21 21:30:32 +08:00
Mike Yuan d735753256
ptyfwd: add missing assertions for pty_forward_new 2024-05-21 21:30:32 +08:00
Zbigniew Jędrzejewski-Szmek 055b465a3f shared/mountpoint-util: for old kernels, assume "norecovery" is supported by btrfs
Fixup for e3828d7103, as requested in
https://github.com/systemd/systemd/pull/32892#issuecomment-2117903328.
2024-05-21 15:13:42 +02:00
Zbigniew Jędrzejewski-Szmek 72192b6cc9
Merge pull request #32869 from keszybz/dbus-release-session
Allow pam stack to call ReleaseSession
2024-05-21 09:01:17 +02:00
Mike Yuan f2c2fa87b6
shutdown: rename initrd to exitrd
Nowadays the tmpfs where the final shutdown phase
is initiated has got its own name.
Plus, "Returning to initrd" sounds spurious anyway,
as we're not returning to the initial root tmpfs
as seen by the kernel.
2024-05-21 11:39:57 +08:00
Mike Yuan a2d4451e64
shutdown: don't freeze() if not executed by pid1 2024-05-21 11:39:29 +08:00
Mike Yuan 2e4da5e08c
shutdown: use execl where appropriate 2024-05-21 11:39:28 +08:00
Mike Yuan 4fbe2bfc51
shutdown: downgrade log level of ignored errors to warning 2024-05-21 11:39:28 +08:00
Mike Yuan 942b2f3b84
shutdown: explicitly initialize static variables, make arg_verb const 2024-05-21 11:39:28 +08:00
Yu Watanabe f8ef1df3d1 test: extend timeout for DHCP/NDisc tests
Fixes https://github.com/systemd/systemd/pull/32932#issuecomment-2120424121.
2024-05-20 22:55:07 +02:00
Yu Watanabe 125cca1b51 btrfs-util: check current offset before read
Fixes #32936.
2024-05-20 22:53:14 +02:00
Zbigniew Jędrzejewski-Szmek fc0bb7ccc7 logind: make ReleaseSession "unprivileged" and allow closing of own session
Fixes https://github.com/systemd/systemd/issues/28514.

Quoting https://github.com/systemd/systemd/issues/28514#issuecomment-1831781486:
> Whenever PAM is enabled for a service, we set up the PAM session and then
> fork off a process whose only job is to eventually close the PAM session when
> the service dies. That services we run with service privileges, both to
> minimize attack surface and because we want to use PR_SET_DEATHSIG to be get
> a notification via signal whenever the main process dies. But that only works
> if we have the same credentials as that main process.
>
> Now, if pam_systemd runs inside the PAM stack (which it normally does) it's
> session close hook will ask logind to synchronously end the session via a bus
> call. Currently that call is not accessible to unprivileged clients. And
> that's the part we need to relax: allow users to end their own sessions.

The check is implemented in a way that allows the kill if the sender is in
the target session.

I found 'sudo systemctl --user -M "zbyszek@" is-system-running' to
be a convenient reproducer.

Before:
May 16 16:25:26 x1c systemd[1]: run-u24754.service: Deactivated successfully.
May 16 16:25:26 x1c dbus-broker[1489]: A security policy denied :1.24757 to send method call /org/freedesktop/login1:org.freedesktop.login1.Manager.ReleaseSession to org.freedesktop.login1.
May 16 16:25:26 x1c (sd-pam)[3036470]: pam_systemd(login:session): Failed to release session: Access denied
May 16 16:25:26 x1c systemd[1]: Stopping session-114.scope...
May 16 16:25:26 x1c systemd[1]: session-114.scope: Deactivated successfully.
May 16 16:25:26 x1c systemd[1]: Stopped session-114.scope.
May 16 16:25:26 x1c systemd[1]: session-c151.scope: Deactivated successfully.
May 16 16:25:26 x1c systemd-logind[1513]: Session c151 logged out. Waiting for processes to exit.
May 16 16:25:26 x1c systemd-logind[1513]: Removed session c151.
After:
May 16 17:02:15 x1c systemd[1]: run-u24770.service: Deactivated successfully.
May 16 17:02:15 x1c systemd[1]: Stopping session-115.scope...
May 16 17:02:15 x1c systemd[1]: session-c153.scope: Deactivated successfully.
May 16 17:02:15 x1c systemd[1]: session-115.scope: Deactivated successfully.
May 16 17:02:15 x1c systemd[1]: Stopped session-115.scope.
May 16 17:02:15 x1c systemd-logind[1513]: Session c153 logged out. Waiting for processes to exit.
May 16 17:02:15 x1c systemd-logind[1513]: Removed session c153.

Edit: this seems to also fix https://github.com/systemd/systemd/issues/8598.
It seems that with the call to ReleaseSession, we wait for the pam session
close hooks to finish. I inserted a 'sleep(10)' after the call to ReleaseSession
in pam_systemd, and things block on that, nothing is killed prematurely.
2024-05-20 20:59:15 +02:00
Zbigniew Jędrzejewski-Szmek 337f74d7c0 logind: group policy entries by interface 2024-05-20 20:59:15 +02:00
Zbigniew Jędrzejewski-Szmek 1d640a044f analyze: do not print timestamps before "start of userspace"
We have the following timestamp status:

  $ systemctl show systemd-fsck-root.service | grep InactiveExitTimestamp
  InactiveExitTimestamp=Thu 2023-11-02 12:27:24 CET
  InactiveExitTimestampMonotonic=15143158

  $ systemctl show | grep UserspaceTimestamp
  UserspaceTimestamp=Thu 2023-11-02 12:27:25 CET
  UserspaceTimestampMonotonic=15804273

i.e. UserspaceTimestamp is before InactiveExit of systemd-fsck-root.service.
This is fine, but on display, we'd subtract those values and print a huge
negative value bogusly:

  $ build/systemd-analyze critical-chain systemd-remount-fs.service
  The time when unit became active or started is printed after the "@" character.
  The time the unit took to start is printed after the "+" character.

  systemd-remount-fs.service +137ms
  └─systemd-fsck-root.service @584542y 2w 2d 20h 1min 48.890s +45ms
    └─systemd-journald.socket
      └─system.slice
        └─-.slice

In fact, list_dependencies_print() already had a branch where the check that
'times->activating > boot->userspace_time', but it didn't cover all cases. So
make it cover both branches, and also change to '>=', since it's fine if
something happened with the same timestamp.

With the patch:

  $ build/systemd-analyze critical-chain systemd-remount-fs.service
  The time when unit became active or started is printed after the "@" character.
  The time the unit took to start is printed after the "+" character.

  systemd-remount-fs.service +42ms
  └─systemd-fsck-root.service
    └─systemd-journald.socket
      └─system.slice
        └─-.slice

Fixes https://github.com/systemd/systemd/issues/17191.
2024-05-20 18:31:32 +02:00
Luca Boccassi eb56b564a0 logind: do not fail creating a session when request is not from a unit
When running inside an LXC container the 'su' process will not be part of
any unit or slice.

manager_get_user_by_pid() which was used until v255 (included) does not fail
if it cannot find a unit/slice, but simply returns 'not found'. Do the same
in manager_get_session_by_pidref().

This was not detected as Semaphore CI does not reboot the testbed before
the logind test, so the session is started by the old logind from the base
distro, instead of the one being tested.

Follow-up for 8494f562c8
Follow-up for 5099a50d43

Fixes https://github.com/systemd/systemd/issues/32929
2024-05-20 13:14:50 +01:00
Luca Boccassi c275e01d99 logind: add one more debug log
Helped track down issue with session tracking
2024-05-20 13:14:50 +01:00
Luca Boccassi eb0c2da89e
Merge pull request #32915 from yuwata/machine-id-setup
machine-id-setup: acquire machine ID from /run/machine-id if possible
2024-05-20 00:16:16 +02:00
Yu Watanabe 16718dcf78 machine-id-setup: acquire machine ID from /run/machine-id if possible
If machine ID is previously stored at /run/machine-id, then let's reuse
it. This is important on switching root and /etc/machine-id was previously
a mount point.

Fixes #32908.
2024-05-20 02:17:57 +09:00
Yu Watanabe ba540e9f1c machine-id-setup: use empty_or_root() 2024-05-20 01:05:23 +09:00
Yu Watanabe 3b1b2d4e3d machine: fix use-after-free in Rename() DBus method
Fixes a bug introduced by 1ddb263d21.

Note, this requires the previous two commits, and cannot backport without them.

Note, before the previous commit, the use-after-free could be triggered
only by Rename() DBus method, and could not by RenameImage(), as we did not
cache Image object when RenameImage() method is called. And machinectl
always uses RenameImage(). Hence, the issue could be triggered only when
Rename() DBus method is explicitly called by e.g. busctl.

With the previous commit, the Image object passed to the function is
always cached. Hence, the issue could be triggered even with machinectl
command, and this fix is important.
2024-05-20 01:03:14 +09:00
Yu Watanabe c6aeb9b596 machine: also acquire Image object from cache when a dbus method in the main interface is called
Previously, Image objects were only cached when reading properties or
methods in the org.freedesktop.machine1.Image interface are called.

This makes that, when a method in the main interface (org.freedesktop.machine1)
for an image is called, also acquire the Image object from the cache,
and if not cached, create Image object and put into the cache, like we
do for org.freedesktop.machine1.Image.

Otherwise, if some properties of an image are updated by methods in the main
interface, e.g. MarkImageReadOnly(), the changes do not applied to the cached
Image object, and subsequent read of proerties through the interface for the
image, e.g. ReadOnly property, may provide outdated values.

Follow-up for 1ddb263d21.

Fixes #32888.
2024-05-20 01:03:14 +09:00
Yu Watanabe 6d917da140 machine: split out manager_acquire_image() from image_object_find()
Preparation for the next commit. No functional change.
2024-05-20 01:03:14 +09:00
Yu Watanabe 96ac6d3fcc discover-image: also update Image.limit in image_set_limit()
Same as the previous commit, but for SetLimit DBus method vs Limit
property and friends.
2024-05-20 01:03:14 +09:00
Yu Watanabe 608c321f23 discover-image: update Image.read_only flag in image_read_only()
Otherwise, ReadOnly DBus property in org.freedesktop.machine1.Image or
org.freedesktop.portable1.Image will not be updated by MarkReadOnly DBus
method.
2024-05-20 01:03:14 +09:00
Mike Yuan 28459ba1f4
run: pass the pty slave fd to transient service
The rationale is similar to 40e1f4ea74.

Currently, we only pass TTYPath=/dev/pts/... to
the transient service spawned by systemd-run.
This is a bit problematic though, when ExecStartPre=
or ExecStopPost= is used. Since when these control
processes get to run, the main process is not yet
started/has already exited, hence the slave suffers
from the same vhangup problem as the mentioned commit.

By passing the slave fd in, the service manager will
hold the fd open as long as the service is alive.

Fixes #32916
2024-05-19 09:18:48 +08:00
Mike Yuan ade0789fab
run: do not log "Error on PTY forwarding logic" when disconnected due to user operation 2024-05-19 09:18:48 +08:00
Mike Yuan 6d2a26a136
vmspawn: use openpt_allocate where appropriate 2024-05-19 09:18:48 +08:00
Mike Yuan 2153899d96
ptyfwd: trivial coding style and log cleanups 2024-05-19 09:18:48 +08:00
Yu Watanabe 762412f2bb
Merge pull request #32902 from yuwata/emergency-action-fixes
several fixes for emergency actions and document update
2024-05-18 16:32:36 +09:00
Yu Watanabe f3c5ea7111 install-file: make fs_make_very_read_only() static 2024-05-17 23:06:48 +02:00
Yu Watanabe 2a2d9539f0 core: refuse invalid emergency actions for SuccessAction= and friends in user service manager
Especially, soft-reboot is not supported by user service manager.

Fixes a bug in 13ffc60749 and
3cf848f6cd.
2024-05-18 02:51:34 +09:00
Mike Yuan de12b8d163 core/execute: do not use format str for log_object_internal
This reverts part of 210ca71cb5.

Another fallout from that commit...

Fixes #32877
2024-05-17 15:15:21 +02:00
Daan De Meyer e3828d7103 mountpoint-util: Deal with kernel API breakage in "norecovery" mount option
"norecovery" was deprecated for btrfs in
74ef00185e
and removed in
a1912f7121.

Let's drop our assumption that btrfs supports "norecovery" and first query for the
new name of the option followed by querying for the old name.
2024-05-17 14:29:09 +02:00
Yu Watanabe d7769b4d8e network/route: fix unexpected removal of routes for wireguard
Fixes a bug introduced by 8d01e44c1f.

If a .netdev file for a wireguard interface requests to configure
routes for the interface, the routes were removed during configuring
another interface.

Fixes #32859.
2024-05-17 06:40:43 +09:00
Zbigniew Jędrzejewski-Szmek 1cd53a1f91 repart: remove duplicate word in --help
My bad; follow-up for 4955d2e367.
2024-05-16 20:01:08 +02:00
Luca Boccassi aa4644882e
Merge pull request #32863 from YHNdnzj/switch-root-followup
Two minor followups
2024-05-16 15:53:18 +02:00
Daan De Meyer 11b706178c
Merge pull request #32842 from DaanDeMeyer/cryptsetup
test: Enable TEST-24-CRYPTSETUP for mkosi
2024-05-16 15:50:55 +02:00
Daan De Meyer 2540036979 journal-importer: Consider ECONNRESET as EOF
Otherwise we log a noisy error when we get ECONNRESET.
2024-05-16 19:23:56 +08:00
Mike Yuan 4eec099db8
switch-root: update comment regarding dropped mounts
Follow-up for 07c5c2ab8b
2024-05-16 19:18:59 +08:00
Mike Yuan 2599b32e72
fd-util: check and log error properly for fd_reopen_propagate_append_and_position
Follow-up for b8e25bff38
2024-05-16 19:17:25 +08:00
Yu Watanabe 2e93331605 pe-binary: .initrd section is optional for UKI
.osrel is also optional, but sd-boot and bootctl requires it.
So, let's keep .osrel section at least now.

Fixes #32774.
2024-05-16 12:56:22 +02:00
Zbigniew Jędrzejewski-Szmek b3aa88a475
Merge pull request #32800 from YHNdnzj/preserve-cred-mounts
switch-root: preserve the whole cred mount tree (/run/credentials/)
2024-05-16 12:45:40 +02:00
Daan De Meyer 0b6891abf5 repart: Improve error message 2024-05-16 12:34:28 +02:00
Luca Boccassi b410d2dcab
Merge pull request #32857 from dtardon/drop-assert
Drop invalid asserts
2024-05-16 12:04:51 +02:00
Daan De Meyer 452f91d846 core: Skip private /tmp for generators in manager test runs
For manager test runs, the generator output paths are located in
/tmp, which means that if we mount a private /tmp for generators,
we lose all the generated units (actually the generators will just
fail because the directories don't exist, but if they did exist,
we'd still lose all the units).

Let's avoid the problem by skipping the private /tmp for manager
test runs. This also avoids any possible privilege issues with
mounting a private /tmp that might happen in this scenario.
2024-05-16 10:17:00 +02:00
David Tardon 119f22526e journald-server: drop another invalid assert()
config_parse_forward_to_socket() is not used for parsing unit files
either.

Follow-up-for: f31cff849d
2024-05-16 10:10:25 +02:00
David Tardon 2ef7cdc425 journald-server: drop invalid assert()
config_parse_compress() is not used for parsing unit files, hence unit
is always NULL.

Fixes #32856

Follow-up-for: 6813be2eba
2024-05-16 10:10:19 +02:00
Yu Watanabe 60dbecff27 systemctl: fix "applying zero offset to null pointer" UBSan error
Fixes #32837.
2024-05-15 20:24:03 +02:00