Commit Graph

6781 Commits

Author SHA1 Message Date
Yu Watanabe
b58c240312 build-path: make pin_callout_binary() optionally provides the path to the found executable 2025-04-04 21:02:18 +09:00
Yu Watanabe
2c31eda469 build-path: check if found path is executable binary
Otherwise, the path may point to a non-executable, e.g. a directory.
2025-04-04 20:56:11 +09:00
Lennart Poettering
2caa462504 build-path: make invoke_callout_binary() honour $PATH as last resort
If we cannot find the callout we need in the build dir let's look for it
in $PATH as last resort.

This makes invoke_callout_binary() usable for all binaries we install
into $PATH (as opposed to /usr/lib/systemd), but has no effect
on callout binaries specified with full path.

This is useful, since we soon want to invoke journalctl as a callout.
2025-04-03 19:40:30 +09:00
Yu Watanabe
9ec7d7ae90 tree-wide: replace unsigned int -> unsigned, long int -> long 2025-04-03 06:01:31 +09:00
Yu Watanabe
dba777cf26 memfd-util: make memfd_add/get_seals() static 2025-04-03 06:01:31 +09:00
Yu Watanabe
8f9737bf7e prioq: minor tweaks (#36963) 2025-04-03 04:10:10 +09:00
Lennart Poettering
39ce0324f9 prioq: add some minor overflow checking assert()s 2025-04-02 17:27:15 +02:00
Lennart Poettering
bbcfac20a6 prioq: invalidate index pointers on removal 2025-04-02 17:27:15 +02:00
Yu Watanabe
147f1d7b26 process-util: make wait_for_terminate() as trivial wrapper of its PidRef version 2025-04-03 00:11:27 +09:00
Lennart Poettering
4ecc87bf1c process-util: add pidref-based version of wait_for_terminate_and_check() 2025-04-03 00:11:27 +09:00
Yu Watanabe
451277707d validatefs: several follow-ups (#36910) 2025-04-01 05:35:21 +09:00
Yu Watanabe
9441880d83 socket-util: introduce socket_autobind() helper (#36893)
Prompted by https://github.com/systemd/systemd/pull/36858#discussion_r2017719305
and #36833.
2025-04-01 02:55:04 +09:00
Mike Yuan
05587cece5 xattr-util: add missing assertions
Follow-up for ed024abac6
and 9fbe26cfa8

Also, let's not get too tangled up in the style of defining variables
in between. The functions are short enough, and vars involved are still
effectively at the beginning... Put differently, the separation from
'int r' is too deliberate and brings no actual value in my eyes.
2025-03-31 19:23:49 +02:00
Yu Watanabe
30252c0ca4 introduce systemd-validatefs@.service that ensures file systems can only be used in the way they were intended (#36714)
If we have multiple trusted fs (i.e. luks or dm-verity) we generate via
repart at boot, we must make sure they cannot be "misappropriated", i.e.
used for a different mount they were intended for.

Hence, let's introduce "mount constraint" data (encoded in xattrs on the
root inode of the fs) that tells us where a file system has to be
mounted, and what the gpt partition metadata has to be for the fs to be
valid.

Inspired by this thread:
https://lists.freedesktop.org/archives/systemd-devel/2025-March/051244.html
2025-04-01 01:14:33 +09:00
Mike Yuan
1eeb4f9f47 socket-util: introduce socket_autobind() helper
Prompted by https://github.com/systemd/systemd/pull/36858#discussion_r2017719305
and #36833
2025-03-31 18:11:37 +02:00
Mike Yuan
ddbbc98bd5 socket-util: drop SO_BINDTODEVICE fallback in socket_bind_to_ifindex()
Our baseline is v5.4 now.
2025-03-31 18:00:09 +02:00
Yu Watanabe
4216018807 missing_socket: drop unnecessary definitions and update comments
- SO_PEERGROUPS is since kernel v4.13
  (28b5ba2aa0f55d80adb2624564ed2b170c19519e),
- SO_BINDTOIFINDEX is since kernel v5.1
  (f5dd3d0c9638a9d9a02b5964c4ad636f06cf7e2c).
2025-03-31 23:22:12 +09:00
Lennart Poettering
f872373a26 generators: hook in validatefs on gpt-auto and fstab generator mounts
Let's turn on validatefs automatically for all auto-discovered
partitions.

Let's add an x-systemd.validatefs option to optionally turn this on for
fstab listed file systems.
2025-03-31 15:14:28 +02:00
Lennart Poettering
9fbe26cfa8 xattr-util: add trivial xsetxattr_strv() wrapper 2025-03-31 15:13:55 +02:00
Lennart Poettering
ed024abac6 xattr-util: add trivial getxattr_at_strv() helper 2025-03-31 15:13:28 +02:00
Zbigniew Jędrzejewski-Szmek
55a8d118d6 basic/strv: return NULL from strv_skip
strv_skip was written to carefully return the original array, but this turns
out to be an unnecessary complication. After the previous patch, no caller
cares about the distinction between NULL and { NULL }, but various callers need
to wrap the process the returned value with strv_isempty(), sometimes more than
once. Let's always return NULL for an empty result to allow callers to be
simplified.
2025-03-27 12:04:23 +01:00
Luca Boccassi
5aee5bda1a tree-wide: introduce LOG_ITEM() macro for verifying format string (#36780)
This introduce `LOG_ITEM()` macro that checks format strings in
log_struct() and friends.

Hopefully, this silences false-positive warnings by Coverity.
2025-03-24 12:58:14 +00:00
Mike Yuan
b062cf19f4 memory-util: make mempcpy_typesafe nestable 2025-03-20 17:31:54 +01:00
Yu Watanabe
db4b4e0cd3 core: Make DelegateNamespaces= work for user managers with CAP_SYS_ADMIN (#36771)
Currently DelegateNamespaces= only works for services spawned by the
system manager. User managers will always unshare the user namespace
first even if they're running with CAP_SYS_ADMIN.

Let's add support for DelegateNamespaces= for user managers if they're
running with CAP_SYS_ADMIN. By default, we'll still delegate all
namespaces
for user managers, but this can now be overridden by explicitly passing
DelegateNamespaces=.

If a user manager is running without CAP_SYS_ADMIN, the user manager is
still always unshared first just like before.
2025-03-20 06:28:18 +09:00
Daan De Meyer
f49b7404b2 capability-util: Ignore unknown capabilities instead of aborting
capability_ambient_set_apply() can be called with capability sets
containing unknown capabilities. Let's not crash when this is the
case but instead ignore the unknown capabilities.

This fixes a crash when running the following command:

"systemd-run -p "AmbientCapabilities=~" --wait --pipe id"

Fixes d5e12dc75e
2025-03-19 10:01:19 +01:00
Yu Watanabe
4b4181f4ac io-util: add one more assertion for Coverity
Fixes CID#1548067.
2025-03-19 11:41:25 +09:00
Yu Watanabe
c995855266 bitfield: check if specified index is non-negative
Hopefully silences false-positive warnings by Coverity e.g. CID#1590746.
2025-03-19 09:56:04 +09:00
Yu Watanabe
3cf6a3a3d4 tree-wide: check more log message format in log_struct() and friends
This introduce LOG_ITEM() macro that checks arbitrary formats in
log_struct().
Then, drop _printf_ attribute from log_struct_internal(), as it does not
help so much, and compiler checked only the first format string.

Hopefully, this silences false-positive warnings by Coverity.
2025-03-19 01:56:48 +09:00
Lennart Poettering
2d47f43b43 cgroup-util: remove cg_get_xattr(), it's apparently unused 2025-03-18 07:17:10 +01:00
Lennart Poettering
33cbda04eb xattr-util: rework getxattr_at_malloc()
Let's return the size in a return parameter instead of the return value.
And if NULL is specified this tells us the caller doesn't care about the
size and expects a NUL terminated string. In that case look for an
embedded NUL byte, and refuse in that case.

This should lock things down a bit, as we'll systematically refuse
embedded NUL strings now when we expect strings.
2025-03-18 07:17:10 +01:00
Lennart Poettering
783b40bd73 namespace-util: introduce userns_acquire_self_root()
This is a simple helper for creating a userns that just maps the
callers user to UID 0 in the namespace. This can be acquired unpriv,
which makes it useful for various purposes, for example for the logic in
is_idmapping_supported(), hence port it over.

(is_idmapping_supported() used a different mapping before, with the
nobody users, but there's no real reason for that, and we'll use
userns_acquire_self_root() elsewhere soon, where the root mapping is
important).
2025-03-17 16:03:18 +01:00
Lennart Poettering
6431c34b8a namespace-util: make "setgroups" users property writable via userns_acquire()
Unprivileged namespaces are only allowed if the "setgroups" file is set
to "deny" for processes. And we need to write it before writing the
gidmap. Hence add a parameter for that.

Then, also patch all current users to actually enable this. The usecase
generally don't need it (because they don't care about unprivileged
userns), but it doesn't hurt to enable the concept anyway in all current
users (none of them actually runs complex userspace in them, but they
mostly use userns_acquire() for idmapped mounts and similar).

Let's anyway make this option explicit in the function call, to indicate
that the concept exists and is applied.
2025-03-17 16:03:18 +01:00
Luca Boccassi
3d278519fa build: add C23 support (#35085)
To support C23, this introduces UTF8() macro to define UTF-8 literals,
as C23 changed char8_t from char to unsigned char.
This also makes pointer signedness warning critical, and updates C
standards table for tests.
2025-03-17 11:29:33 +00:00
Mike Yuan
b66fd12135 cgroup-util: drop is_cgroup_fs()
No need to bother with any cgroup v1 stuff anymore.
2025-03-16 18:02:08 +01:00
Yu Watanabe
e193378d32 macro: Introduce UTF8() macro to define UTF-8 string literal
C23 changed char8_t from char to unsigned char, hence assigning a u8 literal
to const char* emits pointer sign warning, e.g.
========
../src/shared/qrcode-util.c: In function ‘print_border’:
../src/shared/qrcode-util.c:16:34: warning: pointer targets in passing argument 1 of ‘fputs’ differ in signedness [-Wpointer-sign]
   16 | #define UNICODE_FULL_BLOCK       u8"█"
      |                                  ^~~~~
      |                                  |
      |                                  const unsigned char *
../src/shared/qrcode-util.c:65:39: note: in expansion of macro ‘UNICODE_FULL_BLOCK’
   65 |                                 fputs(UNICODE_FULL_BLOCK, output);
      |                                       ^~~~~~~~~~~~~~~~~~
========

This introduces UTF8() macro, which define u8 literal and casts to consth char*,
then rewrites all u8 literal definitions with the macro.
With this change, we can build systemd with C23.
2025-03-16 10:15:24 +09:00
Zbigniew Jędrzejewski-Szmek
75d51d77da basic/glyph-util: introduce optional_glyph() to wrap emoji_enabled() 2025-03-15 14:40:52 +01:00
Zbigniew Jędrzejewski-Szmek
1ae9b0cfa8 basic/glyph-util: rename "special glyph" to just "glyph"
Admittedly, some of our glyphs _are_ special, e.g. "O=" for SPECIAL_GLYPH_TOUCH ;)
But we don't need this in the name. The very long names make some invocations
very wordy, e.g. special_glyph(SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY).
Also, I want to add GLYPH_SPACE, which is not special at all.
2025-03-15 14:40:39 +01:00
Lennart Poettering
d810815ed4 firstboot: welcome user with emoji in firstboot wizard 🧙 2025-03-15 05:12:12 +09:00
Lennart Poettering
da65941c3e coredump,analyze: use read_full_file() for reading various top-level /proc/ files
Kernel API file systems typically use either "raw" or "seq_file" to
implement their various interface files. The former are really simple
(to point I'd call them broken), in that they have no understanding of
file offsets, and return their contents again and again on every read(),
and thus EOF is indicated by a short read, not by a zero read. The
latter otoh works like a typical file: you read until you get a
zero-sized read back.

We have read_virtual_file() to read the "raw" files, and can use regular
read_full_file() to read the "seq_file" ones.

Apparently all files in the top-level /proc/ directory use 'seq_file'.
but we accidentally used read_virtual_file() for them. Fix that.

Also clarify in a comment what the rules are.

Fixes: #36131
2025-03-13 14:18:46 +01:00
Lennart Poettering
af9c45d5b6 hostname: support that /etc/hostname contains ??? as wildcards to be replaced by hash value from /etc/machine-id 2025-03-11 18:01:42 +01:00
Lennart Poettering
98b7c5e2f2 basic: move gethostname_full() from basic/hostname-util.c → shared/hostname-setup.c
In one of the next commits we'd like to introduce a concept of
optionally hashing the hostname from the machine ID. For that we we need
to optionally back gethostname_full() by code involving sd-id128, hence
let's move it from src/basic/ to src/shared/, since only there we are
allowed to use our public APIs.
2025-03-11 17:54:44 +01:00
Lennart Poettering
a9178dbdd9 cgroup-util: Handle capsule@ paths like user@ paths (#36664)
The capsule instances are related to user instances, so treat them
equally to user@.service when handling cgroup paths. This also saves us
from polluting public libsystemd API with variant for capsules too.

Fix: https://github.com/systemd/systemd/issues/36098
2025-03-11 12:03:57 +01:00
Michal Koutný
6c5703f9bc cgroup-util: Handle capsule@ paths like user@ paths
The capsule instances are related to user instances, so treat them
equally to user@.service when handling cgroup paths. This also saves us
from polluting public libsystemd API with variant for capsules too.

Fix: #36098
2025-03-11 10:37:19 +01:00
Michal Koutný
afffd9ee26 capsule-util: Move from shared/ to basic/
...so that other code in basic can use it too (basic ⊆ shared).
2025-03-07 18:07:51 +01:00
Lennart Poettering
600e135a0b virt: detect "linux,dummy-virt" devicetree VMs
So apparently "linux,dummy-virt" is a devicetree in popular use by
various hypervisors, including crosvm:

e5d7a64d37/aarch64/src/fdt.rs (L692)

and qemu:

98c7362b1e/hw/arm/virt.c (L283)

and that's because the kernel ships support for that natively:

https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/linux%2Cdummy-virt.yaml

It's explicitly for using in virtualization. Hence it's suitable for
detecting it as generic fallback.

This hence adds the check, similar to how we already look for one other
qemu-specific devicetree.

I ran into this while playing around with the new Pixel "Linux Terminal"
app from google which runs a Debian in a crosvm apparently. So far
systemd didn't recognize execution in it at all. Let's at least
recognize it as VM at all, even if this doesn't recognize it as
crosvm.
2025-03-07 15:18:08 +01:00
Lennart Poettering
4d53d76f5e virt: some modernizations
Reduce scope of certain allocations, add more debug logging, and improve
some log messages.
2025-03-07 15:11:09 +01:00
Lennart Poettering
4efd46c44b terminal-util: during terminal reset clear from beginning of line to end of screen
tianocore does some weird shit with its terminal emulation and regular
fills half the terminal with grey background and then invokes us with
this not cleared up. Hence let us clear this up for it: as part of the
ansi sequence based reset let's position the cursor explicitly at the
beginning of the current line, and erase everything till the end of the
screen. This makes boot output in tianocore vms much much cleaner.

Note that this does *not* erase any terminal output *before* the cursor
position where we take over, because that typically contains valuable
information still we should not erase.
2025-03-06 22:32:32 +00:00
Yu Watanabe
5c9feb2d6e tree-wide: drop unnecessary break in default branch 2025-03-06 11:42:20 +01:00
Mike Yuan
33db9f214b missing_syscall: drop raw_getpid()
This used to be relevant since in old versions of glibc an internal
cache is maintained, while we might sidestep their invalidation
with raw_clone(). After glibc 2.25 getpid() is a trivial wrapper
for the syscall, and hence there's no need to have a separate
raw_getpid().
2025-03-04 23:03:24 +01:00
Mike Yuan
c133fcd5c0 locale-util: modernize is_locale_utf8() a bit 2025-03-04 23:03:23 +01:00