Commit Graph
4888 Commits
Author SHA1 Message Date
Daan De Meyer 06da125ea1 dirent-util: Expose dirent_ensure_type() 2022-11-24 13:18:00 +01:00
Lennart Poettering 0c14c45e5c sd-event: reenable epoll_pwait2()
This reenables epoll_pwait2() use, i.e. undoes the effect of
39f756d3ae.

Instead of just reverting that, this PR will change things so that we
strictly rely on glibc's new epoll_pwait2() wrapper (which was added
earlier this year), and drop our own manual fallback syscall wrapper.
That should nicely side-step any issues with correct syscall wrapping
definitions (which on some arch seem not to be easy, given the sigset_t
size final argument), by making this a glibc problem, not ours.

Given that the only benefit this delivers are time-outs more granular
than msec, it shouldn't really matter that we'll miss out on support
for this on systems with older glibcs.
2022-11-23 00:54:23 +01:00
Yu Watanabe 6ad17c31fb Merge pull request #25470 from keszybz/strv-extendf-format
Improve check for strv_extendf() format string
2022-11-22 12:27:37 +09:00
Lennart Poettering 7d1e61cab6 tree-wide: make constant ratelimit compound actually const
The compiler should recognize that these are constant expressions, but
let's better make this explicit, so that the linker can safely share the
initializations all over the place.
2022-11-22 01:30:55 +01:00
Luca Boccassi a0c544ee09 Merge pull request #25379 from keszybz/update-doc-links
Update doc links
2022-11-22 01:07:13 +01:00
Zbigniew Jędrzejewski-Szmek 400102ec91 basic/strv: check printf arguments to strv_extendf()
The second argument to _printf_() specifies where the arguments start. We need to
use 0 in two cases: when the args in a va_list and can't be checked, and with journald
logging functions which accept multiple format strings with multiple argument sets,
which the _printf_ checker does not understand. But strv_extendf() can be checked.
2022-11-21 20:08:50 +01:00
Zbigniew Jędrzejewski-Szmek db81144428 tree-wide: BLS and DPS are now on uapi-group website 2022-11-21 12:26:35 +01:00
Lennart Poettering eb2a610210 Merge pull request #25410 from DaanDeMeyer/mkfs-xfs-fixes
Followups for #25400
2022-11-18 14:45:48 +01:00
Lennart Poettering 128a11ea99 signal-util: add common implementation for propagating a signal
i.e. let's add a common logic to be called from a signal handler to
raise the passed signal again.

Follow-up for: #25399
2022-11-17 22:38:14 +09:00
Daan De Meyer f9fbac8b1f log: Remove log_ratelimit_debug() macros
These don't make sense anymore since we disable log ratelimiting
when logging at debug level.
2022-11-17 22:16:18 +09:00
Daan De Meyer dd3c825294 tmpfile-util: Introduce fopen_temporary_child()
Instead of having fopen_temporary() create the file either next
to an existing file or in tmp/, let's split this up clearly into
two different functions, one for creating temporary files next to
existing files, and one for creating a temporary file in a directory.
2022-11-17 14:14:31 +01:00
Lennart Poettering c204cfb2e8 Merge pull request #25399 from DaanDeMeyer/siginfo-crash
crash-handler: Make sure we propagate the original siginfo
2022-11-16 18:42:07 +01:00
Daan De Meyer ffa8d1ba39 Merge pull request #25096 from DaanDeMeyer/journald-log-fixes
journal: Ratelimit more journald log messages
2022-11-16 16:40:00 +01:00
Daan De Meyer a0f95434c0 sigbus: Add fallback in case rt_tgsiqqueueinfo() fails 2022-11-16 16:07:31 +01:00
Luca Boccassi 39a306ba34 Merge pull request #25319 from zx2c4-forks/krngseed
boot: implement kernel EFI RNG seed protocol with proper hashing
2022-11-16 15:07:54 +01:00
Daan De Meyer ee69f2b414 sigbus: Make sure the signal is delivered to the same thread 2022-11-16 15:07:23 +01:00
Daan De Meyer a54219532d missing_syscall: Add rt_tgsigqueueinfo() 2022-11-16 15:03:41 +01:00
Daan De Meyer a423050e28 log: Disable log rate limiting if debug logging is enabled
When debugging, it makes sense to not do any rate limiting at all.
2022-11-16 11:37:14 +01:00
Jason A. Donenfeld 0be72218f1 boot: implement kernel EFI RNG seed protocol with proper hashing
Rather than passing seeds up to userspace via EFI variables, pass seeds
directly to the kernel's EFI stub loader, via LINUX_EFI_RANDOM_SEED_TABLE_GUID.
EFI variables can potentially leak and suffer from forward secrecy
issues, and processing these with userspace means that they are
initialized much too late in boot to be useful. In contrast,
LINUX_EFI_RANDOM_SEED_TABLE_GUID uses EFI configuration tables, and so
is hidden from userspace entirely, and is parsed extremely early on by
the kernel, so that every single call to get_random_bytes() by the
kernel is seeded.

In order to do this properly, we use a bit more robust hashing scheme,
and make sure that each input is properly memzeroed out after use. The
scheme is:

    key = HASH(LABEL || sizeof(input1) || input1 || ... || sizeof(inputN) || inputN)
    new_disk_seed = HASH(key || 0)
    seed_for_linux = HASH(key || 1)

The various inputs are:
- LINUX_EFI_RANDOM_SEED_TABLE_GUID from prior bootloaders
- 256 bits of seed from EFI's RNG
- The (immutable) system token, from its EFI variable
- The prior on-disk seed
- The UEFI monotonic counter
- A timestamp

This also adjusts the secure boot semantics, so that the operation is
only aborted if it's not possible to get random bytes from EFI's RNG or
a prior boot stage. With the proper hashing scheme, this should make
boot seeds safe even on secure boot.

There is currently a bug in Linux's EFI stub in which if the EFI stub
manages to generate random bytes on its own using EFI's RNG, it will
ignore what the bootloader passes. That's annoying, but it means that
either way, via systemd-boot or via EFI stub's mechanism, the RNG *does*
get initialized in a good safe way. And this bug is now fixed in the
efi.git tree, and will hopefully be backported to older kernels.

As the kernel recommends, the resultant seeds are 256 bits and are
allocated using pool memory of type EfiACPIReclaimMemory, so that it
gets freed at the right moment in boot.
2022-11-14 15:21:58 +01:00
Yu Watanabe d6c817358c Merge pull request #25338 from DaanDeMeyer/at-fixes
Followups for #24813
2022-11-13 22:59:40 +09:00
Yu Watanabe 87172c3df6 Merge pull request #25360 from poettering/strv-fixes
nulstr fixes
2022-11-13 20:17:10 +09:00
Lennart Poettering d43e78b643 chase-symlinks: add new flag for prohibiting any following of symlinks
This is useful when operating in the ESP, which is untrusted territory,
and where under no circumstances we should be tricked by symlinks into
doing anything we don't want to.
2022-11-13 17:46:30 +09:00
Lennart Poettering 76078ad850 nulstr-util: fix corner cases of strv_make_nulstr()
Let's change the return semantics of strv_make_nulstr() so that we can
properly distuingish the case where we have a no entries in the nulstr
from the case where we have a single empty string in a nulstr.

Previously we couldn't distuingish those, we'd in both cases return a
size of zero, and a buffer with two NUL bytes.

With this change, we'll still return a buffer with two NULL bytes, but
for the case where no entries are defined we'll return a size of zero,
and where we have two a size of one.

This is a good idea, as it makes sure we can properly handle all corner
cases.

Nowadays the function is used by one place only: ask-password-api.c. The
corner case never mattered there, since it was used to serialize
passwords, and it was known that there was exactly one password, not
less. But let's clean this up. This means the subtraction of the final
NUL byte now happens in ask-password-api.c instead.
2022-11-13 17:40:59 +09:00
Lennart Poettering db645f936f nulstr-util: don't use 'r' for anything but integer return values 2022-11-13 17:39:08 +09:00
Lennart Poettering 1ef9703774 nulstr-util: use memdup_suffix0() where appropriate
if the nulstr is not nul-terminated, we shouldn't use strndup() but
memdup_suffix0(), to not trip up static analyzers which imply we are
duping a string here.
2022-11-13 17:39:08 +09:00
Lennart Poettering eecac5053b nulstr-util: use _cleanup_strv_free_() where appropriate 2022-11-13 17:39:08 +09:00
Lennart Poettering 8ba17a319b nulstr-util: rebreak comments 2022-11-13 17:39:08 +09:00
Lennart Poettering 7f0f540500 nulstr-util: modernize strv_from_nulstr() a bit 2022-11-13 17:39:08 +09:00
Lennart Poettering 08af3cc5a5 strv: move nulstr utilities to nulstr-util.[ch]
Let's move them out of the generic, already very long strv.[ch] module
into the more specific nulst-util.[ch]

No code changes.
2022-11-13 17:39:08 +09:00
Daan De Meyer 12e2b70f9b nulstr-util: Declare NULSTR_FOREACH() iterator inline 2022-11-11 16:31:32 +01:00
Daan De Meyer 5ea173a91b strv: Make sure strv_make_nulstr() always returns a valid nulstr
strv_make_nulstr() is documented to always return a valid nulstr,
but if the input is `NULL` we return a string terminated with only
a single NUL terminator, so let's fix that and always terminate the
resulting string with two NUL bytes.
2022-11-11 16:31:20 +01:00
Daan De Meyer 46fddd8eb6 Merge pull request #24803 from DaanDeMeyer/repart-copy-deny-list
repart: Don't descend into directories assigned to other partitions
2022-11-11 13:19:58 +01:00
Daan De Meyer 7d000133c2 fs-util: Add missing assert to chmod_and_chown_at() 2022-11-11 10:19:18 +01:00
Daan De Meyer c2fc5890e3 chase-symlinks: Drop unnecessary if 2022-11-11 09:52:12 +01:00
Daan De Meyer 8c39e28191 path-util: Drop path_make_relative_cwd()
Function is unused
2022-11-11 09:50:50 +01:00
Daan De Meyer 8b9c56ba3e tmpfile-util: Add missing assert 2022-11-11 09:50:19 +01:00
Daan De Meyer 2199ff9018 log: Add shorthands for log_ratelimit_full() 2022-11-10 17:51:05 +01:00
Daan De Meyer 0f06e64c3d log: Add ratelimit argument to ratelimit log macros
Allows configuring the ratelimit per logging statement.
2022-11-10 17:51:03 +01:00
Daan De Meyer 7a2ec6d0bf log: Add log_ratelimit_full() 2022-11-10 17:49:34 +01:00
Daan De Meyer fa83506d50 log: Use ##__VA_ARGS__ in ratelimit log macros
This allows us to call these without formatting arguments.
2022-11-10 17:49:34 +01:00
Lennart Poettering 71ea84369e locale: honour new env var $SYSTEMD_UTF8=
This is useful to force off fancy unicode glyph use (i.e. use "->"
instead of "→"), which is useful in tests where locales might be
missing, and thus control via $LC_CTYPE is not reliable.

Use this in TEST-58, to ensure the output checks we do aren't confused
by missing these glyphs being unicode or not.
2022-11-10 17:20:36 +01:00
Daan De Meyer ddfdf86f81 stat-util: Move inode_hash_ops to stat-util
TO make it usable in other code.
2022-11-10 15:59:18 +01:00
Luca Boccassi 741504aa17 Merge pull request #24813 from DaanDeMeyer/at-all-the-things
Add more openat() style variants for existing stuff
2022-11-10 10:57:14 +01:00
Luca Boccassi 84fe5182d5 Merge pull request #25315 from poettering/dissect-mtree
dissect: add new --mtree switch to generate BSD comaptible mtree manifests of DDIs
2022-11-10 10:44:27 +01:00
Frantisek Sumsal a92401d558 Merge pull request #25280 from keszybz/initrd-with-overlayfs
Initrd with overlayfs
2022-11-10 08:22:15 +00:00
Zbigniew Jędrzejewski-Szmek a940f507fb pid1: skip cleanup if root is not tmpfs/ramfs
in_initrd() was really doing two things: checking if we're in the initrd, and
also verifying that the initrd is set up correctly. But this second check is
complicated, in particular it would return false for overlayfs, even with an
upper tmpfs layer. It also doesn't support the use case of having an initial
initrd with tmpfs, and then transitioning into an intermediate initrd that is
e.g. a DDI, i.e. a filesystem possibly with verity arranged as a disk image.

We don't need to check if we're in initrd in every program. Instead, concerns
are separated:
- in_initrd() just does a simple check for /etc/initrd-release.
- When doing cleanup, pid1 checks if it's on a tmpfs before starting to wipe
  the old root. The only case where we want to remove the old root is when
  we're on a plain tempory filesystem. With an overlay, we'd be creating
  whiteout files, which is not very useful. (*)

This should resolve https://bugzilla.redhat.com/show_bug.cgi?id=2137631
which is caused by systemd refusing to treat the system as an initrd because
overlayfs is used.

(*) I think the idea of keeping the initrd fs around for shutdown is outdated.
We should just have a completely separate exitrd that is unpacked when we want
to shut down. This way, we don't waste memory at runtime, and we also don't
transition to a potentially older version of systemd. But we don't have support
for this yet.

This replaces 0fef5b0f0bd9ded1ae7bcb3e4e4b2893e36c51a6.
2022-11-09 22:44:23 +01:00
Lennart Poettering b21ec07b54 recurse-dir: optionally, call callback when entering/leaving toplevel dir, too
So far recurse_dir() will call the callback whenever we enter a
directory, and then pass the struct dirent for that directory, and an fd
for the directory the dirent is part of (i.e. the parent of the
directory we call things for). For the top-level dir the function is
invoked for we will not call the callback however, because we have no
dirent for that, and not fd for the directory the top-level dir is part
of. Let's add a flag to call it anyway, and in that case pass a NULL
dirent and -1 as directory fd.

This is useful when we want to treat the top-level dir the same as any
dir further down.

This is done opt-in since the callback must be ablet to handle a NULL
dirent and a -1 directory fd.
2022-11-09 18:55:58 +01:00
Daan De Meyer 0ab5e2a4b4 fileio: Add openat() like helpers 2022-11-09 11:14:10 +01:00
Daan De Meyer 92dae2bd23 mkdir: Add mkdirat_parents() 2022-11-09 11:14:10 +01:00
Daan De Meyer 8df60ed768 mkdir: Add mkdirat_safe() 2022-11-09 11:14:10 +01:00