Commit Graph
4910 Commits
Author SHA1 Message Date
Yu Watanabe 7d34567444 hexdecoct: fix NULL pointer dereferences in hexmem()
Fixes oss-fuzz#54090 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54090).

Fixes #25655.
2022-12-09 04:55:47 +09:00
Yu Watanabe 45655e776f hexdecoct: add missing NULL check
Fixes oss-fuzz#54065 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54065).

Fixes #25650.
2022-12-09 04:54:43 +09:00
Yu Watanabe c21b316964 hexdecoct: several cleanups for base64_append()
- add missing assertions,
- use size_t for buffser size or memory index,
- handle empty input more gracefully,
- return the length or the result string,
- fix off-by-one issue when the prefix is already long enough.
2022-12-09 04:53:50 +09:00
Lennart Poettering 93c1baa0c8 Merge pull request #25667 from poettering/sha256-align-fix
sha256 alignment fixes/rework
2022-12-08 17:24:17 +01:00
Yu Watanabe 340bc268c8 fs-util: make chmod_and_chown_at() work with empty path and AT_FDCWD
Follow-up for 7d000133c2.

Fixes CID#1500608.
2022-12-08 15:57:33 +01:00
Lennart Poettering d8007e7aac fundamental: split out unaligned_{read|write}_ne{16,32,64}() helpers into unaligned-fundamental.h
Let's allow using this in code shared between userspace and EFI mode.

Also, don't implement these functions via endianness conversions given
we don't actually want to convert endianess here.
2022-12-08 15:18:47 +01:00
Zbigniew Jędrzejewski-Szmek cc420ae52a Merge pull request #25616 from poettering/chase-symlinks-opendir
chase-symlinks/systemctl: let's handle cases without /proc/ better
2022-12-06 17:10:54 +01:00
Yu Watanabe 76519cecc7 escape: fix wrong octescape of bad character
Fixes a bug introduced by 95052df376.

This also makes octescape() support NULL or zero length string.

Fixes [oss-fuzz#54059](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54059).

Fixes #25643.
2022-12-06 12:18:10 +09:00
Daan De Meyer 2877b14720 chase-symlinks: Fix regression from 5bc244aaa9
Previously, chase_symlinks() always returned an absolute path, which
changed after 5bc244aaa9. This commit
fixes chase_symlinks() so it returns absolute paths all the time again.
2022-12-05 09:27:58 +01:00
Zbigniew Jędrzejewski-Szmek 27c8ca439f manager: write net/unix/max_dgram_qlen sysctl as fixed string 2022-12-03 11:59:03 +01:00
Lennart Poettering 2075b6dd39 chase-symlink: when converting directory O_PATH fd to real fd, don't bother with /proc/
Replaces: #25581
2022-12-02 23:55:44 +01:00
Lennart Poettering 03c16b9784 glyph-util: add warning sign special glyph 2022-12-02 23:54:50 +01:00
Lennart Poettering 1fe6e5c112 Revert "basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted"
This reverts commit 3e22dfc235.
2022-12-02 17:57:10 +01:00
Michal Sekletar 3e22dfc235 basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted
https://bugzilla.redhat.com/show_bug.cgi?id=2136916
2022-12-02 17:45:33 +01:00
Neil Moore d833ed781f virt: Support detection of LMHS SRE guests 2022-12-02 10:29:14 +09:00
Ray Strode 9fe26523a1 terminal-util: Set OPOST when setting ONLCR
reset_terminal_fd sets certain minimum required terminal attributes
that systemd relies on.

One of those attributes is `ONLCR` which ensures that when a new line
is sent to the terminal, that the cursor not only moves to the next
line, but also moves to the very beginning of that line.

In order for `ONLCR` to work, the terminal needs to perform output
post-processing. That requires an additional attribute, `OPOST`,
which reset_terminal_fd currently fails to ensure is set.

In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
it's not an issue, but it could be a problem if, e.g., the terminal was
put in raw mode by a program and the program unexpectedly died before
restoring settings.

This commit ensures when `ONLCR` is set `OPOST` is set too, which is
the only thing that really makes sense to do.
2022-12-01 11:29:21 +01:00
Lennart Poettering 5f5865f0ad fd-util: add new helper fd_reopen_conditional()
This is a wrapper around fd_reopen() that will reopen an fd if the
F_GETFL flags indicate this is necessary, and otherwise not.

This is useful for various utility calls that shall be able to operate
on O_PATH and without it, and might need to convert between the two
depending on what's passed in.
2022-11-29 15:32:47 +01:00
Lennart Poettering 17f244e8f9 resolved: introduce the _localdnsstub and _localdnsproxy special hostnames for 127.0.0.54 + 127.0.0.53
Let's give these special IP addresses names. After all name resolution
is our job here.

Fixes: #23623
2022-11-25 17:37:30 +01:00
Daan De Meyer 03288a3f28 Merge pull request #25500 from DaanDeMeyer/mcopy-skip-symlinks
mkfs-util: Skip symlinks when calling mcopy
2022-11-24 16:28:01 +01:00
Daan De Meyer a0a4c57818 recurse-dir: Handle RECURSE_DIR_ENSURE_TYPE in readdir_all() 2022-11-24 14:02:19 +01:00
Daan De Meyer 06da125ea1 dirent-util: Expose dirent_ensure_type() 2022-11-24 13:18:00 +01:00
Yu Watanabe 00a60eaf5f Merge pull request #25483 from poettering/ppoll-usec-eintr
ppoll() + EINTR fixes
2022-11-24 09:42:48 +09: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
Lennart Poettering ffbcc8d423 io-util: document EINTR situation a bit 2022-11-22 15:23:34 +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