Commit Graph

7336 Commits

Author SHA1 Message Date
Lennart Poettering
c746488537 block dlopen() once we transition into some foreign namespace (#39824)
Let's make sure we never accidentally end up loading code from a foreign
namespace.
2025-11-24 14:14:16 +01:00
Yu Watanabe
f866ff3df8 tree-wide: replace tab with space, adjust missing or duplicated space 2025-11-24 12:45:06 +01:00
Lennart Poettering
a08f2ea02d process-util: also disable dlopen() in safe_fork() 2025-11-24 11:56:47 +01:00
Lennart Poettering
2c7bdaf9f1 dlfcn-util: let's make our dlopen() code fail if we enter a container namespace
Now that we dlopen() so many deps, it might happen by accident that we
end up dlopen()ening stuff when we entered a container, which we should
really avoid, to not mix host and container libraries.

Let's add a global variable we can set when we want to block dlopen() to
ever succeed. This is then checked primarily in
dlopen_many_sym_or_warn(), where we'll generate EPERM plus a log
message.

There are a couple of other places we invoke dlopen(), without going
through dlopen_many_sym_or_warn(). This adds the same check there.
2025-11-24 09:19:33 +01:00
Daan De Meyer
87fbd33372 clang-tidy: Fix all remaining misc-include-cleaner violations
- Remove unused includes
- Add common false positive headers to misc-include-cleaner.IgnoreHeaders
- Add IWYU pragma keep for uncommon false positive headers
2025-11-22 10:19:41 +01:00
Luca Boccassi
4902a7f18d virt: debug log when inode_same() fails
If this fails with an error there's no log messages and tests
typically don't log it either as they just check, so add a
message to aid in debugging
2025-11-20 20:02:06 +01:00
Zbigniew Jędrzejewski-Szmek
0f7d3e34e1 Avoid multiple evaluations in STRERROR_XYZ() macros (#39794) 2025-11-20 08:29:32 +01:00
Yu Watanabe
cb4b36928a socket-label: move prototype of socket_address_listen() and string table for SocketAddressBindIPv6Only
The function socket_address_listen() is declared at shared/socket-label.c,
however its prototype was in basic/socket-util.h. This moves the
prototype to shared/socket-label.h.

Also, enum SocketAddressBindIPv6Only is not used anymore in basic/*.[ch].
Let's move the definition and its string table to shared/socket-label.[ch].

Follow-up for b25a930f0e.
2025-11-20 09:58:53 +09:00
Yu Watanabe
5feb65c5b1 user-util: avoid double evaluation in STRERROR_USER/GROUP()
Follow-up for 6e6e96f628.
2025-11-20 09:07:57 +09:00
Yu Watanabe
459000e8c5 errno-util: avoid double evaluation in STRERROR_OR_EOF()
Follow-up for f69ae8585f.
2025-11-20 09:04:35 +09:00
Chris Down
592c57e586 fd-util: Add fd_is_writable() to check if FD is opened for writing
This checks whether a file descriptor is valid and opened in a mode that
allows writing (O_WRONLY or O_RDWR). This is useful when we want to
verify that inherited FDs can actually be used for output operations
before dup'ing them.

The helper explicitly handles O_PATH file descriptors, which cannot be
used for I/O operations and thus are never writable.
2025-11-20 02:02:21 +08:00
Daan De Meyer
4186aad374 libudev: Don't pull in libshared_static
- Move devices-nodes.c to src/basic as it's super trivial anyway
- Duplicate udev_queue_is_empty() in libudev-util.c as it's trivial
  anyway.
2025-11-19 13:14:15 +01:00
Zbigniew Jędrzejewski-Szmek
a50fdf611c core: improve messages about unknown users and groups
$ sudo build/systemd-run --uid=asdf whoami
$ journalctl -e
(whoami)[1007784]: run-p1007782-i5200512.service: Failed to determine user credentials: No such process
(whoami)[1007784]: run-p1007782-i5200512.service: Failed at step USER spawning /usr/sbin/whoami: No such process
systemd[1]: run-p1007782-i5200512.service: Main process exited, code=exited, status=217/USER
systemd[1]: run-p1007782-i5200512.service: Failed with result 'exit-code'.

Now:
(whoami)[1013204]: run-p1013202-i5205932.service: Failed to determine credentials for user 'asdf': Unknown user
(whoami)[1013204]: run-p1013202-i5205932.service: Failed at step USER spawning /usr/sbin/whoami: Invalid argument
systemd[1]: run-p1013202-i5205932.service: Main process exited, code=exited, status=217/USER
systemd[1]: run-p1013202-i5205932.service: Failed with result 'exit-code'.
2025-11-18 16:23:29 +01:00
Zbigniew Jędrzejewski-Szmek
6e6e96f628 udev: define a generic helper to print messages about unknown users and groups
We cannot just use %m, because strerror returns a confusing error message
for ESRCH or ENOEXEC. udev code was doing a good job, but the error handling
was very verbose. Let's encapsulate the customized error messages in a
helper.

No functional change, except that the error messages have a slightly different
form now. The old messages were a bit better, but we don't have as much
flexibility in the new scheme. "Failed to resolve user 'foo': Unknown user"
should be good enough.
2025-11-18 16:23:29 +01:00
Lennart Poettering
0712316e8e fs-util: enable automatic access mode logic in xopenat() 2025-11-18 01:31:49 +09:00
Yu Watanabe
07910c73b0 test: modernize test-log and add test cases for log_format_iovec() (#39750) 2025-11-18 01:31:02 +09:00
Lennart Poettering
1daf7b56bb tmpfile-util: make sure errno is left untouched by CLEANUP_TMPFILE_AT()
This mimics how rm_rf_physical_and_free() operate, and we should do the
same here, and make clean-up error paths not touch errno needlessly.
2025-11-17 16:53:31 +01:00
Yu Watanabe
d753c0c658 log: replace format string in LOG_ITEM() to a dummy one when analyzed by Coverity
Hopefully silence many false-positives.
2025-11-17 23:06:53 +09:00
Yu Watanabe
1f546ab779 log: make each string generated in log_format_iovec() NUL terminated
Nowadays, we append an extra NUL for each data if possible for safety.
We already do the same for example at write_to_kmsg(), log_do_context(),
write_to_journal(), log_struct_iovec_internal(), and so on.
This does not change any behavior, as the iov_len field is unchanged.
2025-11-17 22:38:38 +09:00
Yu Watanabe
44440ea658 cgroup-util: drop outdated comments 2025-11-17 21:31:51 +09:00
Yu Watanabe
4434fd76f1 cgroup-util: drop unused SYSTEMD_CGROUP_CONTROLLER_{LEGACY,HYBRID} 2025-11-17 21:31:51 +09:00
Yu Watanabe
b9e612e070 cgroup-util: do not check validity of controller in cg_split_spec()
Now the controller part is always ignored, hence let's skip check for
the controller part of the spec. This also make it acceppt unnormalized
path. Previously paths were checked by path_is_normalized(), but now
checked by path_is_safe(). Also, now this mapps an empty path to NULL.
2025-11-17 21:31:51 +09:00
Yu Watanabe
6a8ab5f062 cgroup-show: drop unnecessary call of cg_mangle_path()
As the caller already dropped controller part.
2025-11-17 21:31:51 +09:00
Yu Watanabe
a8156588fa cgroup-util: drop 'controller' argument from cg_get_path()
The argument is not used anymore. Let's drop it.
2025-11-17 21:31:50 +09:00
Yu Watanabe
5d397dc7f4 cgroup-util: drop 'controller' argument from cg_get_keyed_attribute() and cg_is_empty()
The argument is completely unused. Let's drop it.
2025-11-17 21:31:50 +09:00
Yu Watanabe
3454b160e4 cgroup-util: drop unused cg_unified() and friends 2025-11-17 21:31:50 +09:00
Yu Watanabe
2fe89e3b0f limits-util: drop cgroup v1 support from physical_memory() 2025-11-17 21:30:29 +09:00
Yu Watanabe
2d6dd692be cgroup-util: drop cgroup v1 support in cg_get_path()
We have dropped cgroup v1 support in v258. Let's assume we are running
on cgroup v2 and drop unused legacy code.
2025-11-17 21:30:29 +09:00
Yu Watanabe
f5a48af34b cgroup-util: use cg_is_available() in cg_kill_supported() 2025-11-17 21:30:29 +09:00
Yu Watanabe
57c16d344b cgroup-util: drop cgroup v1 support from cg_mask_supported_subtree()
We have dropped cgroup v1 support in v258. Let's drop unused legacy code.
2025-11-17 21:30:29 +09:00
Yu Watanabe
0ab90015e0 tree-wide: replace cg_get_path_and_check() with cg_get_path()
We have dropped cgroup v1 support in v258. When running on cgroup v2,
cg_get_path_and_check() with SYSTEMD_CGROUP_CONTROLLER as controller is
equivalent with checking if we are running on cgroup v2 and then
cg_get_path(). As we can assume we are running on cgroup v2, then the
check is not necessary anymore, thus we can replace
cg_get_path_and_check() with cg_get_path().
2025-11-17 21:30:29 +09:00
Yu Watanabe
b525a72f7b cgroup-util: drop cgroup v1 support from cg_pid_get_path()
We have dropped cgroup v1 support in v258. Let's drop legacy code.
Then, we can drop 'controller' argument from cg_pid_get_path() and
cg_pidref_get_path().
2025-11-17 21:30:29 +09:00
Yu Watanabe
6475926a59 cgroup-util: drop 'controller' argument from cg_path_open()
Nowadays it always takes SYSTEMD_CGROUP_CONTROLLER as controller.
Let's drop it.

No functional change, just refactoring.
2025-11-17 21:30:29 +09:00
Yu Watanabe
4dbf06bd85 cgroup-util: drop 'controller' argument from cg_set_attribute(), cg_get_attribute() and friends
Non-null controller arguments are always ignored when running on cgroup v2.
Let's drop the argument.

No functional change, just refactoring.
2025-11-17 21:30:29 +09:00
Yu Watanabe
4d1badbbc4 cgroup-util: drop 'controller' argument from cg_enumerate_subgroups()
Nowadays it always takes SYSTEMD_CGROUP_CONTROLLER as controller.
Let's drop it.

No functional change, just refactoring.
2025-11-17 21:30:29 +09:00
Yu Watanabe
f8de2107a7 cgroup-util: drop 'controller' argument from cg_enumerate_processes()
Nowadays it always takes SYSTEMD_CGROUP_CONTROLLER as controller.
Let's drop it.

No functional change, just refactoring.
2025-11-17 21:30:29 +09:00
Yu Watanabe
4365351b93 cgroup-util: introduce cg_is_available() and check it in tests
Now most of our code does not support cgroup v1. Let's skip test cases
if we are running on cgroup v1.
2025-11-17 21:29:51 +09:00
Yu Watanabe
07e437f569 musl: glob-util: filter out . and .. even if GLOB_ALTDIRFUNC is not supported
musl neither support GLOB_ALTDIRFUNC nor GLOB_BRACE.
Let's make safe_glob() work even when GLOB_ALTDIRFUNC is not supported.
Currently, GLOB_BRACE is simply ignored when it is not supported.
2025-11-17 12:19:22 +09:00
Yu Watanabe
e7254f9f4e efivars: fix typo
Follow-up for ab69a04600.
2025-11-16 11:12:10 +09:00
Yu Watanabe
6412e540bc path-util: add generic ignore extension to the hidden files (#39554) 2025-11-15 10:05:38 +09:00
Mike Yuan
0cb7dd5b96 fd-util: do not block O_TMPFILE with -EISDIR
Follow-up for 7cf4f07567
2025-11-14 21:51:28 +01:00
Mike Yuan
87ed096657 fs-util: simplify open_parent_at() a bit
Let's refrain from specifying any access mode when opening
a directory, which matches our usual style and allows us
to drop one condition.
2025-11-14 21:51:28 +01:00
Daan De Meyer
bc8aebdce9 log-context: Don't add log context if value is NULL
This avoids if conditions at the callsite which mess up stack based
lifetimes.
2025-11-14 11:38:59 +01:00
Daan De Meyer
5cf894ad58 basic-forward: Add WaitFlags forward decl 2025-11-14 11:38:59 +01:00
Mike Yuan
b0e7c6141f efivars: insert a newline below fstat() call 2025-11-13 21:17:32 +01:00
Yu Watanabe
1abe8dd9eb efivarfs readv() size fixes and more (#39715)
Fixes: #39695
2025-11-14 00:38:29 +09:00
Yu Watanabe
32d1bed50b tree-wide: assorted fixes/workarounds for supporting musl (#39687) 2025-11-14 00:16:50 +09:00
Lennart Poettering
dbc25d84ae efivars: seek back to beginning in each efi_get_variable() loop
We try to read again from the beginning, hence let's seek back.
Apparently efivarfs doesn't strictly require this, but it's really weird
that it doesn't.
2025-11-13 14:19:29 +01:00
Lennart Poettering
40cb2aa4f8 efivars: validate we are actually talking about a regular file
We already have the stat data, let's actually check if things are
alright before relying on .st_size
2025-11-13 14:19:29 +01:00
Lennart Poettering
ab69a04600 efivars: fix size checks in efi_get_variable()
writev() returns the full size, not just the payload size, hence always
add sizeof(attr) where necessary.

Let's also change a couple of "4" into sizeof(attr) all over the place,
to make clear what they are about.

Fixes: #39695
Follow-up for: 9db9d6806e
2025-11-13 14:19:29 +01:00