Commit Graph

49469 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
75ced6d5ee various: update links to usr-merge 2024-05-28 14:48:56 +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
Daniel Winzen
983028cdc4 cryptsetup: mention correct action in log message 2024-05-27 17:05:23 +01: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
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
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
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