Commit Graph

7297 Commits

Author SHA1 Message Date
Lennart Poettering
deb0d489ea core: consult credentials for machine ID to use for host
Let's hook up one more thing with credentials: the machine ID to use
when none is initialized yet.

This requires some reordering of initialization steps in PID 1: we need
to import credentials first, and only then initialize the machine ID.
2023-07-04 23:01:42 +02:00
Lennart Poettering
49e859b7c7 creds-util: add new helper read_credential_with_decryption()
This is just like read_credential() but also looks into the encrypted
credential directory, not just the regular one.

Normally, we decrypt credentials at the moment we pass them to services.
From service PoV all credentials are hence decrypted credentials.

However, when we want to access credentials in a generator this logic
does not apply: here we have the regular and the encrypted credentials
directory. So far we didn't attempt to make use of credentials in
generators hence.

Let's address and add helper that looks into both directories, and talks
to the TPM if necessary to decrypt the credentials.
2023-07-04 22:59:57 +02:00
Lennart Poettering
f76ce81b91 execute: fix credential dir handling for fs which support ACLs
When the credential dir is backed by an fs that supports ACLs we must be
more careful with adjusting the 'x' bit of the directory, as any chmod()
call on the dir will reset the mask entry of the ACL entirely which we
don't want. Hence, do a manual set of ACL changes, that only add/drop
the 'x' bit but otherwise leave the ACL as it is.

This matters if we use tmpfs rather than ramfs to store credentials.
2023-07-04 22:58:01 +02:00
Zbigniew Jędrzejewski-Szmek
da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Daan De Meyer
506c1bb594 stat-util: Make sure we trigger automounts when looking for ESP/XBOOTLDR
Fixes #25417
2023-06-30 12:25:07 +01:00
Ivan Vecera
88d2bda812 udev-builtin-net_id: align VF representor names with VF names
Certain cards support to set their eswitch to switchdev mode. In this
mode for each created VF there is also created so called VF representor.
This representor is helper network interface used for configuration of
mentioned eswitch and belongs to an appropriate PF.

VF representors are identified by the specific value of phys_port_name
attribute and the value has format "pfMvfN" where M is PF function
number and N is VF number inside this PF.

As the VF representor interfaces belong to PF PCI device the naming
scheme used for them is the same like for other PCI devices. In this
case name of PF interface is used and phys_port_name suffix is appended.

E.g.
 PF=enp65s0f0np0 # phys_port_name for PF interface is 'p0'
 VF=enp65s0f0np0v0 # v0 is appended for VF0 in case of NAMING_SR_IOV_V
REP=enp65s0f0np0pf0vf0 # phys_port_name for VF0 representor is 'pf0vf0'

First as the phys_port_name for representors is long (6+ chars) then the
generated name does not fit into IFNAMSIZ so this name is used only as
alternate interface name and for the primary one is used generic one
like eth<N>. Second 'f0' and 'pf0' in REP name is redundant.

This patch fixes this issue by introducing another naming scheme for VF
representors and appending 'rN' suffix to PF interface name for them.
N is VF number so the name used for representor interface is similar to
VF interface and differs only by the suffix.

For the example above we get:
 PF=enp65s0f0np0
 VF=enp65s0f0np0v0
REP=enp65s0f0np0r0

This eases for userspace to determine which representor interface
represents particular VF.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2023-06-29 22:18:05 +01:00
Lennart Poettering
f56f9c6b3e mount-util: tweak flags decoding in mount_verbose_full()
Fine-tune the decoding of mount options in mount_verbose_full() to
provide more helpful log output:

1. decode changing of propagation changes
2. discern changing of superblock flags/mount option string from mount
   flags
3. don't check secondary fields when deciding which mount op is
   executed, only the flags decide that.
2023-06-29 22:15:16 +01:00
Lennart Poettering
d5602c1632 execute: when recursively chowning StateDirectory= when spawning services, follow initial symlink
It should be OK to allow one level of symlink for the various types of
directories like StateDirectory=, LogsDirectory= and such.
2023-06-28 22:01:07 +02:00
Lennart Poettering
f70c90f5ca analyze: add new "pcrs" verb
It shows the PCRs we know about along with their name strings and
current values.
2023-06-28 16:50:50 +02:00
Dmitry V. Levin
51c425dc93 pwquality: remove old built-in cracklib dictionary workaround
The first version of libpwquality with the required change was 1.4.1
released in 2019.
2023-06-28 15:56:38 +02:00
cunshunxia
556c674d6e mute the memory recursiveprot log if version of kernel is low. 2023-06-28 10:59:00 +02:00
Lennart Poettering
a3e54ddf49 tpm2: make PcrIndex an anonymous enum
It just gives names for things generally just handled as numeric
indexes, hence drop the type name, and make the enum anonymous. Nothing
is using the type name anyway.
2023-06-27 22:14:09 +02:00
Lennart Poettering
11e2be3a19 mount-util: use inode_type_to_string() in mode_to_inaccessible_inode()
Let's reuse the inode type name table here and shorten/simplify the code
a bit.
2023-06-26 17:24:35 +02:00
Daan De Meyer
846f5acdf2 Merge pull request #28117 from yuwata/copy-follow-ups
copy: several follow ups
2023-06-25 12:35:15 +01:00
Lennart Poettering
d39cdbb3bf Merge pull request #27330 from YHNdnzj/hibernate-resume-auto
sleep/hibernate-resume: pass hibernate location through efivar for resume without kernel cmdline
2023-06-23 23:03:32 +02:00
Lennart Poettering
031d21bc45 Merge pull request #27843 from yuwata/usleep_safe
time-util: introduce usleep_safe()
2023-06-23 23:03:15 +02:00
Lennart Poettering
1b618bf141 mount-util: add helper that can bind mount submounts of one dir to another 2023-06-23 18:30:59 +02:00
Lennart Poettering
4a1dca795c mount-util: don't claim maybe-uninitialized was false that is valid 2023-06-23 18:30:16 +02:00
Mike Yuan
1923373a64 sleep: always write resume_offset if possible
There's no need to conditionalize this.
Setting resume_offset=0 doesn't harm, and can even help
by overriding potentially existing half-written settings.
2023-06-23 23:57:49 +08:00
Luca Boccassi
fc84ddda2f Merge pull request #28123 from poettering/threads-no-more
get rid of any threads in PID 1
2023-06-23 13:24:41 +01:00
Romain Geissler
3965f173ea elf-util: check for overflow when computing end of core's PT_LOAD segments 2023-06-23 12:35:34 +01:00
Lennart Poettering
530f6ada2e async: use FORK_DETACH for asynchronous syncs
To get proper "fire-and-forget" feeling we really want to make sure
noone has to reap the forked off process.
2023-06-23 10:05:16 +02:00
Lennart Poettering
e4687bb8a6 async: add explanatory comment 2023-06-23 10:05:16 +02:00
Lennart Poettering
78b680f99b async: drop the now unused asynchronous_job() 2023-06-23 10:05:16 +02:00
Lennart Poettering
437f3e35b4 async: add generic implementation of asynchronous_rm_rf()
This one doesn't use threads anymore. This is the last use of threads in
PID 1. Yay!

Fixes: #27287
2023-06-23 10:05:16 +02:00
Lennart Poettering
7e14a308cf shared: move async.[ch] from src/basic/ → src/shared/
That way we can later add an async wrapper for rm_rf() which is in
src/shared/, too.
2023-06-23 10:02:15 +02:00
Lennart Poettering
6270b2e67e tpm2-util: look for tpm2-pcr-signature.json directly in /.extra/
So far we relied on tmpfiles.d to copy tpm2-pcr-signature.json from
/.extra/ into /run/systemd/. This is racy however if cryptsetup runs too
early, and we cannot unconditionally run it after tmpfiles completed.

hence, let's teach cryptsetup to directly look for the file in /.extra/,
in order to simplify this, and remove the race. But do so only in the
initrd (as only there /.extra/ is a concept).

We generally prefer looking in /run/systemd/, since things are under
user control then. In the regular system we exclusively want that
userspace looks there.

Fixes: #26490
2023-06-23 09:32:33 +02:00
Yu Watanabe
b62e2891ef copy: propagate error in fd_copy_directory()
Follow-up for 01428141ba.

Fixes CID#1513190.
2023-06-23 10:11:17 +09:00
Yu Watanabe
440ccf0424 copy: fix fd leak
Follow-up for 01428141ba.
2023-06-23 10:11:06 +09:00
Yu Watanabe
dcd407b5e7 copy: add one more assertions about copy_flags
Follow-up for 01428141ba.
2023-06-23 10:07:38 +09:00
Lennart Poettering
f1a83e41ae tests: teach tests boilerplate to run selected tests only
sometimes its useful to only run a specific test (or multiple) instead
of all implemented in a test. Allow the test name(s) to be specified on the
in a $TESTFUNCS env var, separated by colons.
2023-06-22 16:07:57 +02:00
Daan De Meyer
4638e18593 hwdb: Don't generate hwdb if no hwdb files are found 2023-06-22 16:07:22 +02:00
Lennart Poettering
947c4d3952 core: restrict ImportCredential= globbing
Let's restrict how we apply credential globbing in ImportCredential=, so
that we have some flexibility in automatically extending the glob
expression with per-instance data eventually without getting into
conflict with the globbing parts.

In our current uses we only allow globbing at the end of the expression,
and this is a new, unreleased feature hence let's be restrictive on this
initially. We can still relax this later if we feel the need to after
all.

Fixes: #28022
2023-06-22 16:07:09 +02:00
Lennart Poettering
665ca08b6e sleep-util: mention that offset is in memory pages 2023-06-22 10:30:23 +02:00
Yu Watanabe
4251512ea9 time-util: introduce usleep_safe()
We use usec_t for storing time value, which is 64bit.
However, usleep() takes useconds_t that is (typically?) 32bit.
Also, usleep() may only support the range [0, 1000000].

This introduce usleep_safe() which takes usec_t.
2023-06-22 15:33:56 +09:00
Zbigniew Jędrzejewski-Szmek
27ccba2621 pam: add macro wrapper to make code shorter
The same pattern is repeated so many times that it seems worth making a
shorthand for it.

Follow-up for f71b55b510 and
2675747f3c.
2023-06-22 00:47:32 +01:00
Ronan Pigott
f24590df43 systemd-analyze: allow --quiet for condition checks
I figure these messages are rather unnecessary, so let the user quiet
them with the existing --quiet flag if desired. Makes systemd-analyze
condition a little more ergonomic in scripts.
2023-06-21 19:56:43 +01:00
Romain Geissler
21a2c735e2 elf-util: discard PT_LOAD segment early based on the start address.
Indeed when iterating over all the PT_LOAD segment of the core dump
while trying to look for the elf headers of a given module, we iterate
over them all and try to use the first one for which we can parse a
package metadata, but the start address is never taken into account,
so absolutely nothing guarantees we actually parse the right ELF header
of the right module we are currently iterating on.

This was tested like this:
 - Create a core dump using sleep on a fedora 37 container, with an
   explicit LD_PRELOAD of a library having a valid package metadata:

    podman run -t -i --rm -v $(pwd):$(pwd) -w $(pwd) fedora:37 bash -x -c \
        'LD_PRELOAD=libreadline.so.8 sleep 1000 & SLEEP_PID="$!" && sleep 1 && kill -11 "${SLEEP_PID}" && mv "core.${SLEEP_PID}" the-core'

 - Then from a fedora 38 container with systemd installed, the resulting
   core dump has been passed to systemd-coredump with and without this
   patch. Without this patch, we get:

       Module /usr/bin/sleep from rpm bash-5.2.15-3.fc38.x86_64
       Module /usr/lib64/libtinfo.so.6.3 from rpm coreutils-9.1-8.fc37.x86_64
       Module /usr/lib64/libc.so.6 from rpm coreutils-9.1-8.fc37.x86_64
       Module /usr/lib64/libreadline.so.8.2 from rpm coreutils-9.1-8.fc37.x86_64
       Module /usr/lib64/ld-linux-x86-64.so.2 from rpm coreutils-9.1-8.fc37.x86_64

   While with this patch we get:

       Module /usr/bin/sleep from rpm bash-5.2.15-3.fc38.x86_64
       Module /usr/lib64/libtinfo.so.6.3 from rpm ncurses-6.3-5.20220501.fc37.x86_64
       Module /usr/lib64/libreadline.so.8.2 from rpm readline-8.2-2.fc37.x86_64

So the parsed package metadata reported by systemd-coredump when the module
files are not found on the host (ie the case of crash inside a container) are
now correct. The inconsistency of the first module in the above example
(sleep is indeed not provided by the bash package) can be ignored as it
is a consequence of how this was tested.

In addition to this, this also fixes the performance issue of
systemd-coredump in case of the crashing process uses a large number of
shared libraries and having no package metadata, as reported in
https://sourceware.org/pipermail/elfutils-devel/2023q2/006225.html.
2023-06-21 19:07:20 +01:00
Daan De Meyer
33885343cf Merge pull request #27942 from DaanDeMeyer/root-ephemeral
core: Add RootEphemeral= setting
2023-06-21 17:24:39 +02:00
Daan De Meyer
9c0c670125 core: Add RootEphemeral= setting
This setting allows services to run in an ephemeral copy of the root
directory or root image. To make sure the ephemeral copies are always
cleaned up, we add a tmpfiles snippet to unconditionally clean up
/var/lib/systemd/ephemeral. To prevent in use ephemeral copies from
being cleaned up by tmpfiles, we use the newly added COPY_LOCK_BSD
and BTRFS_SNAPSHOT_LOCK_BSD flags to take a BSD lock on the ephemeral
copies which instruct tmpfiles to not touch those ephemeral copies as
long as the BSD lock is held.
2023-06-21 12:48:46 +02:00
Luca Boccassi
01a6510a62 Merge pull request #28082 from mrc0mmand/more-journal-remote-tests
test: add a couple of tests for systemd-journal-{remote,upload}
2023-06-20 23:38:24 +01:00
Lennart Poettering
d39d9348d3 Merge pull request #28089 from poettering/sleep-cleanups
sleep-config: various clean-ups
2023-06-20 18:39:49 +02:00
Daan De Meyer
d31f8e0cb8 dissect-image: Log if verity signature partition is too large 2023-06-20 15:22:47 +02:00
Daan De Meyer
1a5f67aba3 Merge pull request #27863 from DaanDeMeyer/copy-lock
Add helpers to lock a directory before copying into it
2023-06-20 15:22:24 +02:00
Lennart Poettering
4014172a8b sleep: rename sleep-config.[ch] → sleep-util.[ch]
The file long ceased to be exclusively about configuration of the sleep
operation. It contains many many calls for other purposes, hence give it
a more generic name.
2023-06-20 14:18:52 +02:00
Lennart Poettering
c1583ca16a sleep-config: reduce scope of DMI object path a bit
We need this in a single function only, hence move it there, and make it
a static field so that it has local scope.

While we are at it, rename s/readsize to buf/bufsize, to make
relationship clear. In particular as the data read is actually binary
and "s" hence a misnomer, since it suggests it was a string.
2023-06-20 14:16:28 +02:00
Daan De Meyer
d54f60c2af btrfs-util: Add BTRFS_SNAPSHOT_LOCK_BSD
When making ephemeral snapshots of subvolumes whose cleanup depends on
whether they're locked or not, it's necessary to have the lock from the
very beginning, so let's support that with a new BTRFS_SNAPSHOT_LOCK_BSD
flag.
2023-06-20 13:42:41 +02:00
Lennart Poettering
8601ecbc7c sleep-config: rename .device field to .path
This has been badly named given the path doesn't refer to a device quite
likely, but to a path to a regular file. Hence let's be more precise
with naming.

(.device kinda suggests this was an sd_device object of sorts, but it
really isn't.)
2023-06-20 13:21:28 +02:00
Lennart Poettering
3595a9b7b8 sleep-config: don't use 'device_id' moniker for a dev_t entity
We usually call dev_t entities "devnum" or "devno". That's redundant
enough, let's not call this "device_id". In particular as that's
something else (in udev context).
2023-06-20 13:14:38 +02:00
Lennart Poettering
98034eb0ea sleep-config: pin swap device while operating via O_PATH 2023-06-20 13:14:38 +02:00