Commit graph

43140 commits

Author SHA1 Message Date
Yu Watanabe b72fd2af86 sd-journal: check validity of object type more strictly
Otherwise, the object with invalid type may pass check_object_header()
when the requested type is OBJECT_UNUSED.
2023-05-01 14:25:38 +09:00
Yu Watanabe 3092eaa72e sd-journal: add _OBJECT_TYPE_INVALID as usual 2023-05-01 14:25:38 +09:00
Yu Watanabe deb87cc80e sd-journal: align table 2023-05-01 14:25:38 +09:00
Yu Watanabe 5b895f56c6 sd-journal: check that the journal file is not stored in .newest_by_boot_id on free 2023-05-01 14:24:55 +09:00
Yu Watanabe f11de491ca sd-journal: unset prioq index on failure
Otherwise, potentially, the assertion in
journal_file_unlink_newest_by_bood_id() will be triggered.
2023-05-01 14:24:55 +09:00
Yu Watanabe e28d825127 sd-journal: fix use-after-free
As commented in the code, we need to replace the pointer to the key,
hence, hashmap_replace() must be used, instead of hashmap_update().

Fixes #27459.
2023-05-01 14:24:55 +09:00
Dan Streetman 9589824158 tpm2: move openssl-required ifdef code out of policy-building function 2023-05-01 00:52:28 +01:00
Yu Watanabe 9857de4f1c libsystemd: add missing _public_ attributes 2023-04-29 21:25:12 +09:00
Yu Watanabe 9857bc4cea libsystemd: drop _public_ attribute for non-exported functions 2023-04-29 21:25:08 +09:00
Luca Boccassi 708d63c0e7
Merge pull request #27451 from yuwata/core-path-trigger-notify
core/path: do not install new job in .trigger_notify()
2023-04-29 12:35:24 +01:00
Yu Watanabe 8c59feed5e missing_fs: also define struct file_clone_range
Follow-up for b640e274a7.

Addresses b640e274a7 (r110996661).
2023-04-29 07:03:09 +02:00
Yu Watanabe bc6377762c core/path: do not enqueue new job in .trigger_notify callback
Otherwise,
1. X.path triggered X.service, and the service has waiting start job,
2. systemctl stop X.service
3. the waiting start job is cancelled to install new stop job,
4. path_trigger_notify() is called, and may reinstall new start job,
5. the stop job cannot be installed, and triggeres assertion.

So, instead, let's add a defer event source, then enqueue the new start
job after the stop (or any other type) job finished.

Fixes https://github.com/systemd/systemd/issues/24577#issuecomment-1522628906.
2023-04-29 08:54:29 +09:00
Yu Watanabe 34a4e22e97 core/path: align table 2023-04-29 08:45:06 +09:00
Lennart Poettering c23e9b6a64 pid1: unify implemenation of /run/ disk space safety check a bit
reload/reexec currently used a separate implementation of the /run/ disk
space check, different from the one used for switch-root, even though
the code is mostly the same. The one difference is that the former
checks are authoritative, the latter are just informational (that's
because refusing a reload/reexec is relatively benign, but refusing a
switch-root quite troublesome, since this code is entered when it's
already "too late" to turn turn back, i.e. when the preparatory
transaction to initiate the switch root are already fully executed.

Let's share some code, and unify codepaths.

(This is preparation for later addition of a "userspace reboot" concept)

No change in behaviour, just refactoring.
2023-04-28 23:27:20 +01:00
Lennart Poettering 5ae89ef347 core/systemctl: when switching root default to /sysroot/
We hardcode the path the initrd uses to prepare the final mount point at
so many places, let's also imply it in "systemctl switch-root" if not
specified.

This adds the fallback both to systemctl and to PID 1 (this is because
both to — different – checks on the path).
2023-04-28 23:26:20 +01:00
Daan De Meyer 77b7026668 libsystemd: Add missing memory pressure functions to public symbols 2023-04-28 21:19:38 +02:00
Mike Yuan 0102857b52
Merge pull request #27445 from poettering/reflink-fix
remove duplication reflink ioctl invocation
2023-04-29 01:33:21 +08:00
Lennart Poettering 4b7fda8731 systemctl: rework 'if' to 'switch' statement 2023-04-29 01:23:24 +08:00
Luca Boccassi 398d858d1c
Merge pull request #27437 from mrc0mmand/pstore
test: add a couple of tests for systemd-pstore
2023-04-28 16:14:09 +01:00
Lennart Poettering 535358ad2e copy: shortcut reflink_range() to reflink() in some cases 2023-04-28 15:16:30 +02:00
Lennart Poettering 427ad121c2 copy: don't call clone ioctls twice
The btrfs name and the generic name have the same values, hence there's
no point in bothering with the former.
2023-04-28 15:10:24 +02:00
Luca Boccassi 91010bd6cc
Merge pull request #27440 from yuwata/reflink-follow-ups
copy: follow ups for reflink()
2023-04-28 11:34:41 +01:00
Frantisek Sumsal ad5980803a pstore: avoid opening the dmesg.txt file if not requested
Even with Storage=journal we would still attempt to open the final
dmesg.txt file which causes a lot of noise in the journal:

```
[    5.764111] H testsuite-82.sh[658]: + systemctl start systemd-pstore
[    5.806385] H systemd[1]: Starting modprobe@efi_pstore.service...
[    5.808656] H systemd[1]: modprobe@efi_pstore.service: Deactivated successfully.
[    5.808971] H systemd[1]: Finished modprobe@efi_pstore.service.
[    5.818845] H kernel: audit: type=1130 audit(1682630623.637:114): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel msg='unit=modprobe@efi_pstore comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? termin>
[    5.818865] H kernel: audit: type=1131 audit(1682630623.637:115): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel msg='unit=modprobe@efi_pstore comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? termin>
[    5.816052] H systemd[1]: Starting systemd-pstore.service...
[    5.840703] H systemd-pstore[806]: PStore dmesg-efi-168263062313014.
[    5.841239] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.841428] H systemd-pstore[806]: PStore dmesg-efi-168263062312014.
[    5.841575] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.841712] H systemd-pstore[806]: PStore dmesg-efi-168263062311014.
[    5.841839] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.841989] H systemd-pstore[806]: PStore dmesg-efi-168263062310014.
[    5.842141] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.842274] H systemd-pstore[806]: PStore dmesg-efi-168263062309014.
[    5.842423] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.842589] H systemd-pstore[806]: PStore dmesg-efi-168263062308014.
[    5.842722] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.842865] H systemd-pstore[806]: PStore dmesg-efi-168263062307014.
[    5.843003] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.843153] H systemd-pstore[806]: PStore dmesg-efi-168263062306014.
[    5.843280] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.843434] H systemd-pstore[806]: PStore dmesg-efi-168263062305014.
[    5.843570] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.843702] H systemd-pstore[806]: PStore dmesg-efi-168263062304014.
[    5.843831] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.843958] H systemd-pstore[806]: PStore dmesg-efi-168263062303014.
[    5.844093] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.844250] H systemd-pstore[806]: PStore dmesg-efi-168263062302014.
[    5.844412] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.844619] H systemd-pstore[806]: PStore dmesg-efi-168263062301014.
[    5.844781] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.844956] H systemd-pstore[806]: PStore dmesg-efi-168263062300014.
[    5.845168] H systemd-pstore[806]: Failed to open file /var/lib/systemd/pstore/1682630623/014/dmesg.txt: Operation not permitted
[    5.851101] H systemd[1]: Finished systemd-pstore.service.
```
2023-04-28 12:00:42 +02:00
Yu Watanabe 657152a459 network-generator: shorten code a bit 2023-04-28 18:50:47 +09:00
Yu Watanabe 75fd8ad008
Merge pull request #27424 from dtardon/auto-cleanup
More automatic cleanup
2023-04-28 18:46:36 +09:00
Frantisek Sumsal a95d96a243 pstore: explicitly set the base when converting record ID 2023-04-28 11:41:52 +02:00
David Tardon 360179ea46 logind-session-dbus: use _cleanup_ 2023-04-28 09:29:04 +02:00
David Tardon 80e52052db logind-session-device: modernize session_device_free() 2023-04-28 09:29:03 +02:00
David Tardon fc447921a8 homed-manager-bus: use _cleanup_ 2023-04-28 09:29:03 +02:00
David Tardon 7fb1cc85ab transaction: make transaction_free() static
... as it's not needed outside transaction.c anymore.
2023-04-28 09:28:25 +02:00
David Tardon 32620826cf manager: use _cleanup_ in manager_propagate_reload() 2023-04-28 09:27:37 +02:00
David Tardon c7e3eb5dd5 manager: use _cleanup_ in manager_add_job() 2023-04-28 09:27:37 +02:00
David Tardon 542fe40845 transaction: introduce transaction_abort_and_free()
Will be used in following commits.
2023-04-28 09:26:20 +02:00
Yu Watanabe d6f96778b1 missing_fs: mention commit hash and version of ioctl commands introduced 2023-04-28 14:18:48 +09:00
Yu Watanabe 71e84b4be6 copy: rename reflink_full() -> reflink_range()
The commit b640e274a7 introduced reflink()
and reflink_full(). We usually name function xyz_full() for fully
parameterized version of xyz(), and xyz() is typically a inline alias of
xyz_full(). But in this case, reflink() and reflink_full() call
different ioctl().
Moreover, reflink_full() does partial reflink, while reflink() does full
file reflink. That's super confusing.
Let's rename reflink_full() to reflink_range(), the new name is
consistent with ioctl name, and should be fine.
2023-04-28 14:06:00 +09:00
David Edmundson c63dde8099 xdg-autostart-service: handle gnome autostart phase better on other desktops
Autostart files which contain the line gnome-autostart-phase are currently
completely skipped by systemd. This is because these are handled internally by
gnome startup through other means.

The problem is a number of desktop files that need to run on KDE too have this
flag set. Ideally they should just create systemd user units, but we're not at
this point universally yet.

This patch changes the logic so if the flag is set, we set NotShowIn-gnome,
which in turn would just not load decided at runtime.

As an optimisation if we would get conflicting OnlyShowIn lines we still
skip the file completely.

Example:
  $ rg 'Exec|Autostart-Phase' /etc/xdg/autostart/gnome-keyring-pkcs11.desktop
  Exec=/usr/bin/gnome-keyring-daemon --start --components=pkcs11
  X-GNOME-Autostart-Phase=PreDisplayServer

  $ cat '/tmp/xxx/app-gnome\x2dkeyring\x2dpkcs11@autostart.service'
  # Automatically generated by systemd-xdg-autostart-generator
  [Unit]
  SourcePath=/etc/xdg/autostart/gnome-keyring-pkcs11.desktop
  ...
  [Service]
  ...
  ExecCondition=/usr/lib/systemd/systemd-xdg-autostart-condition "Unity:MATE" "GNOME"

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2023-04-28 12:32:53 +08:00
Daan De Meyer b640e274a7 copy: Introduce reflink() and reflink_full()
The kernel has had filesystem independent reflink ioctls for a
while now, let's try to use them and fall back to the btrfs specific
ones if they're not supported.
2023-04-28 00:57:03 +01:00
David Tardon 12da8805e7 transaction: modernize transaction_free() 2023-04-27 21:42:38 +02:00
David Tardon 0a956e8e02 initctl: use _cleanup_ 2023-04-27 21:42:38 +02:00
David Tardon 70bbf65942 initctl: add assert 2023-04-27 21:42:38 +02:00
David Tardon 1cc3a1302f specifier: use _cleanup_ 2023-04-27 21:42:38 +02:00
David Tardon 3cbbefc2a7 path-util: use _cleanup_ 2023-04-27 21:42:38 +02:00
David Tardon 5ce8ce908d logind: rename function to avoid confusion 2023-04-27 21:42:38 +02:00
David Tardon 3d01bfa7db logind-core: drop unneeded check for NULL 2023-04-27 21:42:38 +02:00
David Tardon 737e0f12d9 logind-core: modernize button_free() 2023-04-27 21:42:38 +02:00
David Tardon 93eceb59e6 env-util: use more _cleanup_ in replace_env_argv() 2023-04-27 21:42:38 +02:00
David Tardon cc09d8a5a1 env-util: use _cleanup_ in replace_env_argv() 2023-04-27 21:42:38 +02:00
David Tardon 5013d6def3 env-util: rename variable 2023-04-27 21:42:38 +02:00
David Tardon 480a7919bc env-util: use _cleanup_ in strv_env_delete() 2023-04-27 21:42:38 +02:00
Luca Boccassi fafded0ce0
Merge pull request #27346 from poettering/pam-fixes
pam-systemd: be more careful with sharing bus connections
2023-04-27 20:31:57 +01:00
Lennart Poettering dbecd3d6ee shutdown: paranoia – close all fds we might get passed in
We don't expect any fds (beyond 0…2) to be passed from the service
manager into systemd-shutdown, but let's better be safe then sorry.
2023-04-27 17:56:24 +01:00
Lennart Poettering ba8d00e859 pam-systemd: disconnect bus connection when leaving session hook, even on error
This adds support for systematically destroying connections in
pam_sm_session_open() even on failure, so that under no circumstances
unserved dbus connection are around while the invoking process waits for
the session to end.  Previously we'd only do this on success, now do it
in all cases.

This matters since so far we suggested people hook pam_systemd into
their pam stacks prefixed with "-", so that login proceeds even if
pam_systemd fails. This however means that in an error case our
cached connection doesn't get disconnected even if the session then is
invoked. This fixes that.
2023-04-27 17:04:05 +02:00
Lennart Poettering 402014086d pam-util: include PID in PAM data field id
Let's systematically avoid sharing cached busses between processes (i.e.
from parent and child after fork()), by including the PID in the field
name.

With that we're never tempted to use a bus object the parent created in
the child.

(Note this is about *use*, not about *destruction*. Destruction needs to
be checked by other means.)
2023-04-27 17:02:49 +02:00
Mike Yuan 82060b62c9
Merge pull request #25622 from YHNdnzj/tmpfiles-X-bit-support
tmpfiles: add conditionalized execute permission (X) support
2023-04-27 22:40:09 +08:00
Lennart Poettering 1a3704dcc3 nspawn: port over to /supervisor/ subcgroup being delegated to nspawn
Let's make use of the new DelegateSubgroup= feature and delegate the
/supervisor/ subcgroup already to nspawn, so that moving the supervisor
process there is unnecessary.
2023-04-27 12:18:32 +02:00
Lennart Poettering f8371dbd56 udev: port to DelegateSubgroup= 2023-04-27 12:18:32 +02:00
Lennart Poettering bcd9b98159 core: change ownership of subcgroup we create recursively, it shall be owned by the user delegated to
If we create a subcroup (regardless if the '.control' subgroup we
always created or one configured via DelegateSubgroup=) it's inside of
the delegated territory of the cgroup tree, hence it should be owned
fully by the unit's users. Hence do so.
2023-04-27 12:18:32 +02:00
Lennart Poettering 18c1e481b6 execute: don't apply journal + oomd xattrs to subcgroup
We don't need to apply the journal/oomd xattrs to the subcgroups we add,
since those daemons already look for the xattrs up the tree anyway.
Hence remove this.

This is in particular relevant as it means later changes to the xattr
don#t need to be replicated on the subcgroup either.
2023-04-27 12:18:32 +02:00
Lennart Poettering a8b993dc11 core: add DelegateSubgroup= setting
This implements a minimal subset of #24961, but in a lot more
restrictive way: we only allow one level of subcgroup (as that's enough
to address the no-processes in inner cgroups rule), and does not change
anything about threaded cgroup logic or similar, or make any of this new
behaviour mandatory.

All this does is this: all non-control processes we invoke for a unit
we'll invoke in a subgroup by the specified name.

We'll later port all our current services that use cgroup delegation
over to this, i.e. user@.service, systemd-nspawn@.service and
systemd-udevd.service.
2023-04-27 12:18:32 +02:00
Lennart Poettering 1a56b0c05d cgroup: rework how we validate/escape cgroups
Let's clean up validation/escaping of cgroup names. i.e. split out code
that tests if name needs escaping. Return proper error codes, and extend
test a bit.
2023-04-27 12:17:58 +02:00
Mike Yuan 26d98cdd78
tmpfiles: add conditionalized execute bit (X) support
According to setfacl(1), "the character X stands for
the execute permission if the file is a directory
or already has execute permission for some user."

After this commit, parse_acl() would return 3 acl
objects. The newly-added acl_exec object contains
entries that are subject to conditionalized execute
bit mangling. In tmpfiles, we would iterate the acl_exec
object, check the permission of the target files,
and remove the execute bit if necessary.

Here's an example entry:
A /tmp/test - - - - u:test:rwX

Closes #25114
2023-04-27 15:15:09 +08:00
Yu Watanabe 49c778e6bf
Merge pull request #27413 from yuwata/core-job-cleanups
core/job: cleanups for job ID
2023-04-27 12:29:29 +09:00
Yu Watanabe a02287eab3 core/service: make service_add_fd_store() always consume provided fd
No functional change, just refactoring.
2023-04-27 01:36:58 +01:00
Lennart Poettering 637d57ddfd image-policy: split out code that "extends" underspecified partition policy flags
When encoding partition policy flags we allow parts of the flags to be
"unspecified" (i.e. entirely zeros), which when actually checking the
policy we'll automatically consider equivalent to "any" (i.e. entirely
ones). This "extension" of the flags was so far done as part of
partition_policy_normalized_flags(). Let's split this logic out into a
new function partition_policy_flags_extend() that simply sets all bits
in a specific part of the flags field if they were entirely zeroes so
far.

When comparing policy objects for equivalence we so far used
partition_policy_normalized_flags() to compare the per-designator flags,
which thus meant that "underspecified" flags, and fully specified ones
that are set to "any" were considered equivalent. Which is great.
However, we forgot to do that for the fallback policy flags, the flags
that apply to all partitions for which no explicit policy flags are
specified.

Let's use the new partition_policy_flags_extend() call to compare them
in extended form, so that there two we can hide the difference between
"underspecified" and "any" flags.
2023-04-27 01:35:06 +01:00
Luca Boccassi 2df327f6f6
Merge pull request #26877 from yuwata/fuzz-journal-remote
fuzz-journal-remote: several cleanups
2023-04-27 00:05:01 +01:00
Luca Boccassi 66a0ee55d8
Merge pull request #27355 from fbuihuu/kbd-improve-vc2x11-conversion
locale: improve vc -> x11 keyboard conversion
2023-04-26 23:37:53 +01:00
Luca Boccassi 68b12e2d56
Merge pull request #27421 from bluca/coredump_filter
CoredumpFilter: fix stack overflow and invalid assignment with 'all'
2023-04-26 23:22:59 +01:00
Lennart Poettering 8c9f0d83c2 image-policy: correct two comments 2023-04-26 22:24:58 +02:00
Daan De Meyer fec81dedfd
Merge pull request #27415 from DaanDeMeyer/verity-minimize
repart: Add Minimize= support for verity hash partitions
2023-04-26 18:55:51 +02:00
Daan De Meyer c00f0634ad
Merge pull request #27419 from yuwata/sd-journal-entry-item
sd-journal: skip invalid entry item
2023-04-26 18:35:26 +02:00
Yu Watanabe aafb96d514 core/job: use new job ID when we failed to deserialize job ID
This is for the case when we fail to deserialize job ID.
In job_install_deserialized(), we also check the job type, and that is
for the case when we failed to deserialize the job.
Let's gracefully handle the failure in deserializing the job ID.
This is paranoia, and just for safety. Should not change any behavior.
2023-04-27 00:36:41 +09:00
Yu Watanabe 3e1aec3036 core/job: handle job ID overflow or conflict more sanely
This is paranoia, and just for safety. Should not change any behavior.
2023-04-27 00:36:24 +09:00
Yu Watanabe ace15701c1 core/job: fix indentation 2023-04-27 00:36:24 +09:00
Yu Watanabe 6ff134004d core/job: add one more assertion
In this stage, the unit should not have installed job of the type.
2023-04-27 00:36:24 +09:00
Yu Watanabe c49dfd8911 core/transaction: use hashmap_remove_value() to make not remove job with same ID
When we fail to deserialize job ID, or the current_job_id is overflowed,
we may have jobs with the same ID.
This is paranoia, and just for safety.
Note, we already use hashmap_remove_value() in job_uninstall().
2023-04-27 00:35:54 +09:00
Luca Boccassi 7f3bb8f20d coredump filter: add mask for 'all' using UINT32_MAX, not UINT64_MAX
The kernel returns ERANGE when UINT64_MAX is passed. Create a mask
and use UINT32_max, which is accepted, so that future bits will also
be set.
2023-04-26 16:12:00 +01:00
Luca Boccassi 00e5933f57 ukify: allow building PE addon
Make the kernel optional too, so that we can easily build and sign a PE addon,
that can be used to carry extra command line options.
2023-04-26 16:55:26 +02:00
Zbigniew Jędrzejewski-Szmek 1db4acbe5d
Merge pull request #27398 from yuwata/udev-rule-negative-match
udev-rule: fix negative match
2023-04-26 16:40:01 +02:00
Zbigniew Jędrzejewski-Szmek 0f56698079
Merge pull request #27411 from yuwata/udev-iocost-follow-ups
udev/iocost: several follow ups
2023-04-26 16:37:59 +02:00
Luca Boccassi 37232d55a7 coredump filter: fix stack overflow with =all
We translate 'all' to UNIT64_MAX, which has a lot more 'f's. Use the
helper macro, since a decimal uint64_t will always be >> than a hex
representation.

root@image:~# systemd-run -t --property CoredumpFilter=all ls /tmp
Running as unit: run-u13.service
Press ^] three times within 1s to disconnect TTY.
*** stack smashing detected ***: terminated
[137256.320511] systemd[1]: run-u13.service: Main process exited, code=dumped, status=6/ABRT
[137256.320850] systemd[1]: run-u13.service: Failed with result 'core-dump'.
2023-04-26 15:04:06 +01:00
Zbigniew Jędrzejewski-Szmek 947579e5e2
Merge pull request #27408 from keszybz/creds-missing-message
Adjust messages when credentials are missing
2023-04-26 14:57:13 +02:00
Zbigniew Jędrzejewski-Szmek d21d71fb28
Merge pull request #26944 from aafeijoo-suse/systemd-network-generator-initrd-fix
network-generator: do not parse kernel command line more than once
2023-04-26 14:55:41 +02:00
Daan De Meyer 5eef704734 repart: Add Minimize= support for verity hash partitions
Fixes #27414
2023-04-26 14:15:16 +02:00
Daan De Meyer cf18d96f62 repart: Extend error logging for format_verity_hash/sig() 2023-04-26 14:15:14 +02:00
Yu Watanabe 85e38da2ec sd-journal: make journal_file_copy_entry() return earlier 2023-04-26 20:54:08 +09:00
Yu Watanabe bf9b7728e6 sd-journal: copy boot ID
The pointer to boot ID may be invalidate by journal_file_move_to_object()
calls in the later loop.
2023-04-26 20:51:12 +09:00
Yu Watanabe 265b1dc048 sd-journal: tighten variable scope 2023-04-26 20:50:53 +09:00
Daan De Meyer f81409f844 journal: Don't try to write garbage if journal entry is corrupted
If journal_file_data_payload() returns -EBADMSG or -EADDRNOTAVAIL,
we skip the entry and go to the next entry, but we never modify
the number of items that we pass to journal_file_append_entry_internal()
if that happens, which means we could try to append garbage to the
journal file.

Let's keep track of the number of fields we've appended to avoid this
problem.
2023-04-26 20:46:25 +09:00
Daan De Meyer 13bde177e4 repart: Allow passing target to format_verity_hash()
Let's allow specifying where the verity hash data should be written
as preparation for adding verity hash partition minimize support.
2023-04-26 10:16:21 +02:00
Daan De Meyer e463e257c7 repart: Move partition_defer() out of format_verity_hash/sig()
To allow re-using format_verity_hash() for minimizing verity hash
partitions.
2023-04-26 10:09:10 +02:00
Daan De Meyer deeae10e26 repart: Turn condition into assert
format_verity_hash() should only be called with VERITY_HASH type
partitions, so assert() if that's not the case.
2023-04-26 10:04:08 +02:00
Franck Bui b35f71ac1a locale: when no xvariant match select the entry with an empty xvariant
When doing a conversion and the specified 'xc->xvariant' has no match, select
the x11 layout entry with a matching layout and an empty xvariant if such entry
exists. It's still better than no conversion at all.
2023-04-26 08:15:17 +02:00
Yu Watanabe ede5e271b1 udev/iocost: fix log message 2023-04-26 14:50:25 +09:00
Yu Watanabe b2fccd0729 udev/iocost: query_named_solution() provides non-NULL model and qos on success 2023-04-26 14:50:25 +09:00
Yu Watanabe 934613bb88 udev/iocost: call get_known_solutions() in apply_solution_for_path()
Then, the solution name can be logged.
2023-04-26 14:50:09 +09:00
Yu Watanabe 22148897cf udev: use version()
Fixes #27382.
2023-04-26 07:44:39 +02:00
Yu Watanabe 9c271f4509 udev/iocost: merge get_known_solutions() and choose_solution()
As these are always called sequentially.
No functional change, just refactoring.
2023-04-26 11:49:58 +09:00
Yu Watanabe dcb379619f udev/iocost: drop unnecessary initializations 2023-04-26 11:36:28 +09:00
Yu Watanabe 878f3a4f09 udev/iocost: arg_target_solution is always non-NULL 2023-04-26 11:19:53 +09:00
Yu Watanabe 5cfe9715f5 udev/iocost: set default target in parse_config()
And make the failure in parsing config critical.
2023-04-26 11:18:46 +09:00
Yu Watanabe 2b43ab00b0 udev-rules: fix negative match rule for SYMLINK and TAG
Fixes #27396.
2023-04-26 09:51:08 +09:00
Frantisek Sumsal c74e13a5c3 creds: make --pretty behave in a slightly more expected manner 2023-04-25 18:34:49 +02:00
Frantisek Sumsal ee46e4d982 test: cover missed stuff from securebits-util.h 2023-04-25 18:34:49 +02:00
Zbigniew Jędrzejewski-Szmek 1c7ed99027 resolved: adjust message about credentials
"credential provided widget" would be better spelled as "credential-provided widget".
But let's adjust the message to name the bad credential explicitly: this
makes it easier to fix for the user.
2023-04-25 18:08:15 +02:00
Zbigniew Jędrzejewski-Szmek 55ace8e5c5 shared/creds-util: return 0 for missing creds in read_credential_strings_many
Realistically, the only thing that the caller can do is ignore failures related
to missing credentials. If the caller requires some credentials to be present,
they should just check which output variables are not NULL. One of the callers
was already doing that, and the other wanted to, but missed -ENOENT. By
suppressing -ENOENT and -ENXIO, both callers are simplified.

Fixes a warning at boot:
systemd-vconsole-setup[221]: Failed to import credentials, ignoring: No such file or directory
2023-04-25 18:08:15 +02:00
Eric Curtin b9dac41837 Support /etc/system-update for OSTree systems
This is required when / is immutable and cannot be written at runtime.

Co-authored-by: Richard Hughes <richard@hughsie.com>
2023-04-25 17:40:41 +02:00
Lennart Poettering d30d5a0374
Merge pull request #27347 from bluca/sd_bus_nonce
sd: avoid closing sd-bus in a fork, store module-global id for sd-bus/sd-session/sd-journal
2023-04-25 17:40:15 +02:00
Lennart Poettering 17b798d915 mount-util: split remount_idmap() in two
This will make things a bit longer for now, but more powerful as we can
reuse the userns fd between calls to remount_idmap() if we need to
adjust multiple mounts.

No change in behaviour, just some minor refactoring.
2023-04-25 17:39:16 +02:00
Lennart Poettering 4054d76151 sd-daemon: add sd_pid_notifyf_with_fds()
I guess it was only a question of time until we need to add the final
frontier of notification functions: one that combines the features of
all the others:

1. specifiying a source PID
2. taking a list of fds to send along
3. accepting a format string for the status string

Hence, let's add it.
2023-04-25 17:38:57 +02:00
Luca Boccassi 4a75704b16 pam: do not attempt to close sd-bus after fork in pam_end()
When pam_end() is called after a fork, and it cleans up caches, it sets
PAM_DATA_SILENT in error_status. FDs will be shared with the parent, so
we do not want to attempt to close them from a child process, or we'll
hit assertions. Complain loudly and skip.
2023-04-25 17:19:57 +02:00
Lennart Poettering 973527648b logind: always use 64bit session IDs
it's a bit confusing that on 32bit systems we'd risk session IDs
overruns like this. Let's expose the same behaviour everywhere and stick
to 64bit ids.

Since we format the ids as strings anyway this doesn't really change
anything performance-wise, it just pushes out collisions by overrun to
basically never happen.
2023-04-25 15:52:19 +01:00
Thorsten Kukuk 092e6cd19a sd-login: add SetTTY session object #26611 2023-04-25 14:33:09 +02:00
Lennart Poettering eb3641fc3c user-record-nss: make return values optional
If we only want to know if some user ID/user name is already allocated,
we don't care for the returned data.
2023-04-25 14:00:57 +02:00
Lennart Poettering c8ab89e569 mountpoint-util: make path_get_mnt_id_at() work with a NULL path 2023-04-25 14:00:38 +02:00
Luca Boccassi 2eeff0f4f1 sd-event: store and compare per-module static origin id
sd-event objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-event object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-event are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.
2023-04-25 12:24:25 +01:00
Luca Boccassi e046719b74 sd-journal: store and compare per-module static origin id
sd-journal objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-journal object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-journal are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.
2023-04-25 12:24:25 +01:00
Luca Boccassi bf876e3f3e sd-bus: store and compare per-module static origin id
sd-bus objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-bus object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-bus are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.
2023-04-25 12:24:25 +01:00
Luca Boccassi bf2d930fa1 macro: add helper for module origin id
These need to be redefined in every module that we need to guard, so add
a macro
2023-04-25 11:34:39 +01:00
Lennart Poettering 797f6cc514 fs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/' 2023-04-25 18:38:00 +09:00
Yu Watanabe 3d008416d6
Merge pull request #27380 from poettering/bpf-meson-tweaks
two bpf build system changes
2023-04-25 18:37:36 +09:00
Lennart Poettering 3cd60148b4
Merge pull request #27388 from poettering/assert-fd
add ASSERT_FD() similar to ASSERT_PTR(), but for fds
2023-04-25 09:54:20 +02:00
Daan De Meyer afc47ee2af Drop log level of header limits log message
Especially when using in-memory logging, these are too noisy so
let's drop them back to debug level.
2023-04-25 07:31:40 +02:00
Luca Boccassi 7556f29694
Merge pull request #27386 from dtardon/test-cleanup
More automatic cleanup in tests
2023-04-25 02:00:56 +01:00
Wolfgang Müller 38fc5e0314 cryptsetup-fido2: Depend on libcryptsetup
crypsetup-fido2 always depended on both libfido2 and libcryptsetup, but
0a8e026e82 forgot to make the then
implicit dependency on libcryptsetup explicit when moving it from
cryptsetup/ to shared/. This breaks builds when libfido2 is autodetected
but the system is missing libcryptsetup.

Introduce an explicit check for HAVE_LIBCRYPTSETUP such that
cryptsetup-fido2 is only built when both libraries are available.

Fixes #27374.
2023-04-25 02:00:16 +01:00
Luca Boccassi 7d9f6034a9 sd-bus: check for pid change before closing
If we try to close after a fork, the FDs will have been cloned
too and we'll assert. This can happen for example in PAM modules.

Avoid the macro and define ref/unref by hand to do the same check.
2023-04-25 00:54:07 +01:00
Lennart Poettering 0593b34adc homed: rename make_userns() to avoid name conflict with mount-util.[ch]
This doesn't really matter too much as both are static functions. But
it's confusing as hell both when debugging and reading code, given that
homed actually uses mount-util.c

Hence, let's just rename one of the two, to minimize confusion.

No actual change in behaviour.

(and sooner or later we might want to export mount-util.c's version of
the function, since it's generically useful)
2023-04-24 22:29:47 +02:00
Zbigniew Jędrzejewski-Szmek 208a59c15f
Merge pull request #27113 from keszybz/variable-expansion-rework
Rework serialization of command lines in pid1 and make run not expand variables
2023-04-24 22:03:06 +02:00
Lennart Poettering 91ce42f008 parse-util: allow parse_pid() to work with NULL return parameter
That way the function becomes useful for validating pids formatted as
strings.
2023-04-25 03:16:33 +08:00
David Tardon 5b87bccc00 test-hashmap-plain: use _cleanup_ 2023-04-24 21:15:50 +02:00
David Tardon 8f25d740f1 test-set: use _cleanup_ 2023-04-24 21:15:50 +02:00
Lennart Poettering 8e398254ba loop-util: port some code over to ASSERT_FD() 2023-04-24 20:52:52 +02:00
Lennart Poettering 6f81bcef25 fd-util: add ASSERT_FD() that is similar to ASSERT_PTR() but for fds 2023-04-24 20:51:51 +02:00
David Tardon 7a9f8b9053 test-calendarspec: use _cleanup_ 2023-04-24 20:44:29 +02:00
Franck Bui c821ad7d60 locale: convert generated vconsole keymap to x11 layout automatically
When doing x11->console conversions, find_converted_keymap() searches
automatically for a candidate in the converted keymap directory for a given x11
layout.

However doing console->x11 conversions, this automatic search is not done hence
simple conversion in this direction can't be achieved without populating
kbd-model-map with entries for converted keymaps.

For example, let's consider "at" layout which is not part of kbd-model-map. The
"at" x11 layout has a generated keymap
"/usr/share/kbd/keymaps/xkb/at.map.gz". If we configure "at" for the x11
layout, localed is able to automatically find the "at" converted vc layout and
the conversion just works :

  $ localectl set-x11-keymap at
  $ localectl
  System Locale: LANG=en_US.UTF-8
      VC Keymap: at
     X11 Layout: at

However in the opposite direction, ie when setting the vc keymap to "at", no
conversion is done and the x11 layout is not defined:

  $ localectl set-keymap at
  $ localectl
  System Locale: LANG=en_US.UTF-8
      VC Keymap: at
     X11 Layout: (unset)

This patch fixes this limitation as the implemenation is relatively simple and
it removes the need to populate kbd-model-map with (many) entries for converted
keymaps. However the patch doesn't remove the existing entries in kbd-model-map
which became unneeded after this change to be on the safe side.

Note: by default the automatically generated x11 keyboard configs use keyboard
model "microsoftpro" which should be equivalent to "pc105" model but with the
internet/media key mapping added.
2023-04-24 18:44:57 +02:00
Daan De Meyer d404c8d887 nspawn: Don't follow /etc/resolv.conf symlinks
When we're checking if /etc/resolv.conf exists so we can bind mount
on top of it, we care about whether the symlink itself exists if
/etc/resolv.conf exists and not the file it points to, so add
CHASE_NOFOLLOW to make sure we check existence of the symlink and
not the file it points to.
2023-04-24 18:14:12 +02:00
Lennart Poettering 906dff812e pid1: simplify bpf meson import 2023-04-24 17:10:08 +02:00
Lennart Poettering 4d3ef2d1a2 meson: move bpf hookup into main meson build file
This way we can use it in systemd-userdbd later on, too.
2023-04-24 17:10:08 +02:00
Luca Boccassi a2dd39b4cb pam: cache sd-bus separately per module
sd-bus connection is cached by the two pam modules globally, but this
can lead to issues due to hashmaps (used by sd-bus) using a global
static variable for the shared hash key, which is different per module
as both modules are loaded in the same process.

This happens because the sd-bus object is create in one module, but
used in the other, so global state does not match.

Use a different pam cache identifier for the sd-bus pointer, so that
each module uses a different sd-bus connection as a workaround.

Fixes https://github.com/systemd/systemd/issues/27216
Fixes https://github.com/systemd/systemd/issues/17266
2023-04-24 14:18:50 +02:00
Luca Boccassi db0c0f5e00 pam_systemd_home: clean up sd-bus when called about something else's user
acquire_home() takes a reference to a sd-bus object, which the open_session
hook cleans on success. But only when handling a user actually owned by homed,
it did not clean it up when skipping because it is being invoked on a system
user.
We need to be careful with sd-bus here as pam_sm_open_session is the last
hook before forking, and we want to clean up sd-bus before that happens, or
we'll have a broken reference (FDs are cloexec) in the child process, which
will then assert when attempting to close them, or leak the bus connection
which causes dbus to complain loudly:

 dbus-daemon[62]: [system] Connection has not authenticated soon enough, closing it (auth_timeout=30000ms, elapsed: 30020ms)
2023-04-24 14:18:22 +02:00
Franck Bui 3c7012cdda localed-util: make use of strdupcspn() 2023-04-24 14:12:58 +02:00
Luca Boccassi 54e4b42fde stub: add comment on measurement of io.systemd.stub.kernel-cmdline-extra 2023-04-24 11:04:50 +01:00
Zbigniew Jędrzejewski-Szmek 2ed7a221fa run: expand variables also with --scope
This makes syntax be the same for commands which are started by the manager and
those which are spawned directly (when --scope is used).

Before:
$ systemd-run -q -t echo '$TERM'
xterm-256color

$ systemd-run -q --scope echo '$TERM'
$TERM

Now:
$ systemd-run -q --scope echo '$TERM'
xterm-256color

Previous behaviour can be restored via --expand-environment=no:
$ systemd-run -q --scope --expand-environment=no echo '$TERM'
$TERM

Fixes #22948.

At some level, this is a compat break. Fortunately --scope is not very widely
used, so I think we can get away with this. Having different syntax depending
on whether --scope was used or not was bad UX.

A NEWS entry will be required.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek f872ddd182 run: add --expand-environment=no to disable server-side envvar expansion
This uses StartExecEx to get the equivalent of ExecStart=:. StartExecEx was
added in b3d593673c, so this will not work with
older systemds.

A hint is emitted if we get an error indicating lack of support. PID1 returns
SD_BUS_ERROR_PROPERTY_READ_ONLY, but I'm checking for
SD_BUS_ERROR_UNKNOWN_PROPERTY too for safety.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek b58026bddc run: split out creation of unit creation messages
Just refactoring, in preparation for future changes.
(Though I think it'd be reasonable to do anyway, those functions were
awfully long.)

'git diff' displays this badly. The middle part of start_transient_service()
is moved to make_transient_service_unit(), and the middle part of
start_transient_trigger() is moved to make_transient_trigger_unit().
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek ac9a75d05e run: simplify returning of status
start_transient_service() would return two ints: one normally and one via
*retval. We can just return one int and propagate it directly, because we
use DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE().
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek 0a27d86a3f core: fix writing of ExecStartEx and friends
The property name is called ExecStartEx, but we have to write it as ExecStart=
in the unit file. :(
Bug introduced in b3d593673c when ex-properties
were initially added.

In addition, we cannot escape $ as $$, because when ":" is used, we wouldn't
unescape $$ back to $.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek 8c41640a71 core/unit: add UNIT_ESCAPE_EXEC_SYNTAX
Unfortunately we can't escape $ when ':' is used to prohibit variable expansion:
  ExecStart=:echo $$
is not the same as
  ExecStart=:echo $

This just adds the functionality and the unittests, without using it anywhere
for real yet.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek f3af629050 core/unit: rename UNIT_ESCAPE_EXEC_SYNTAX → *_ENV
In preparation for future changes.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek e7416db183 core/unit: fix shell-escaping of strings
Our escaping of '$' is '$$', not '\$'. We would write unit files that
were not valid:
  $ systemd-run --user bash -c 'echo $$; sleep 1000'
  Running as unit: run-r1c7c45b5b69f487c86ae205e12100808.service
  $ systemctl cat --user run-r1c7c45b5b69f487c86ae205e12100808
  # /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service
  ...
  ExecStart="/usr/bin/bash" "-c" "echo \$\$\; sleep 1000"

  $ systemd-analyze verify /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service
  /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service:7:
    Ignoring unknown escape sequences: "echo \$\$\; sleep 1000"

Similarly, ';' cannot be escaped as '\;'. Only a handful of characters
listed in "Supported escapes" is allowed.

Escaping of "'" can be done, but it's not useful because we use double quotes
around the string anyway whenever we do escaping.

unit_write_setting() is called all over the place. In a great majority of
places we write either fixed strings or something that we generate ourselves,
so no escaping or quoting is needed. (And it's not allowed, e.g.
'Type="oneshot"' would not work.)  But if we forgot to add escaping or quoting
for a free-style string, it would probably allow writing a unit file that would
be read completely wrong. I looked over various places where
unit_write_setting() is called, and I couldn't find any place where
quoting/escaping was forgotten. But trying to figure out the full
ramifications of this change is not easy.
2023-04-24 10:02:30 +02:00
Zbigniew Jędrzejewski-Szmek a12bc99ef0 basic/logarithm: add popcount() wrapper
__builtin_popcount() is a bit of a mouthful, so let's provide a helper.
Using _Generic has the advantage that if a type other then the ones on
the list is given, compilation will fail. This is nice, because if by any
change we pass a wider type, it is rejected immediately instead of being
truncated.

log.h is also needed. It is included transitively, but let's include it
directly.

macro.h is *not* needed.
2023-04-24 10:02:30 +02:00