Commit Graph

5726 Commits

Author SHA1 Message Date
Yu Watanabe
25ac30bdb8 log: rename variables to store function call results 2023-11-16 09:21:10 +00:00
Luca Boccassi
b1ef479d5a Update syscalls list 2023-11-14 20:17:48 +00:00
Lennart Poettering
aa25e19b47 util-lib: share plymouth client code
Let's add a new "plymouth-util.c" module with helpers for talking to
plymouth. We so far had three places for this, let's unify the code
doing this a bit.
2023-11-13 14:17:05 +00:00
Zbigniew Jędrzejewski-Szmek
fa5a025167 Rename {dual,triple}_timestamp_get to {dual,triple}_timestamp_now
Those functions take a pointer to a timestamp and return a timestamp pointer,
so the reader would be justified to think that those are just getters. Rename
them to avoid confusion.
2023-11-13 13:27:07 +01:00
Mike Yuan
4c8d5f0217 pidref: introduce hash ops that doesn't come with destructor 2023-11-11 17:21:10 +08:00
Mike Yuan
2c302e8919 cgroup-util: introduce cg_pidref_get_unit 2023-11-11 17:21:10 +08:00
Mike Yuan
6f9677bc7f basic/fileio: drop O_CREAT before passing flags to fd_reopen
Follow-up for 78c21009bf

Fixes #29938
2023-11-09 03:38:14 +08:00
Mike Yuan
05314c9c87 fd-util: refuse O_CREAT in fd_reopen
O_CREAT doesn't make sense for fd_reopen, since we're
working on an already opened fd. Also, in fd_reopen
we don't handle the mode parameter of open(2), which
means we may get runtime error like #29938.
2023-11-09 03:35:56 +08:00
Luca Boccassi
00666ec71f Merge pull request #6763 from kinvolk/iaguis/no-new-privs
core: allow using seccomp without no_new_privs when unprivileged
2023-11-07 21:34:49 +00:00
Lennart Poettering
6a20a9d286 string-util: add strdup_or_null() helper 2023-11-07 12:23:27 +01:00
Iago López Galeiras
24832d10b6 core: allow using seccomp without no_new_privs when unprivileged
Until now, using any form of seccomp while being unprivileged (User=)
resulted in systemd enabling no_new_privs.

There's no need for doing this because:

* We trust the filters we apply
* If User= is set and a process wants to apply a new seccomp filter, it
will need to set no_new_privs itself

An example of application that might want seccomp + !no_new_privs is a
program that wants to run as an unprivileged user but uses file
capabilities to start a web server on a privileged port while
benefitting from a restrictive seccomp profile.

We now keep the privileges needed to do seccomp before calling
enforce_user() and drop them after the seccomp filters are applied.

If the syscall filter doesn't allow the needed syscalls to drop the
privileges, we keep the previous behavior by enabling no_new_privs.
2023-11-07 11:31:53 +01:00
Luca Boccassi
775c005026 Merge pull request #29848 from poettering/base64url-too
hexdecoct: implicitly parse URL-safe base64 format, too
2023-11-03 23:26:33 +00:00
Lennart Poettering
a5559e0622 hexdecoct: implicitly parse URL-safe base64 format, too
JSON-I (RFC 7493) suggests to use the URL safe base64 alphabet, rather
than the regular one when encoding binary data in JSON strings. We
generally uses the regular alphabet though.

Let's be tolerant in what we parse however: simply accept both formats
when we parse base64.

This does nothing about base64 generation though, only about parsing.
2023-11-03 21:35:24 +01:00
Luca Boccassi
a39cba252e strv: add strv_free_many() to be used with CLEANUP_ARRAY() 2023-11-03 16:59:58 +00:00
Luca Boccassi
8d04721507 Merge pull request #28891 from poettering/pcrlock
new pcrlock tool for generating signed PCR policies for PCR 0, 1, 4, …
2023-11-03 16:07:43 +00:00
Yu Watanabe
7636caf5b3 virt: also check if PID1 is in chroot
In PID1, running_in_chroot() is called by safety_checks(), but without
this change, the check did nothing.
2023-11-03 16:05:52 +00:00
Lennart Poettering
981f76278f efivars: add UEFI 'database' variable uuid 2023-11-03 11:19:19 +01:00
Lennart Poettering
3b516db71d glyph-util: add computer disk + world emoji 2023-11-02 14:19:32 +01:00
Lennart Poettering
e5f1e8b894 lock-util: add a new lock_generic_with_timeout() helper
This is just like lock_generic(), but applies the lock with a timeout.
This requires jumping through some hoops by executing things in a child
process, so that we can abort if necessary via a timer. Linux after all
has no native way to take file locks with a timeout.
2023-11-02 14:19:32 +01:00
Lennart Poettering
e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Lennart Poettering
61c062f896 fd-util: add new FORMAT_PROC_PID_FD_PATH() helper
This is just like FORMAT_PROC_FD_PATH() but goes via the PID number
rather than the "self" symlink.

This is useful whenever we want to generate a path that is useful
outside of our local scope.
2023-11-02 14:09:23 +01:00
Luca Boccassi
79e1f7091f Merge pull request #29816 from bluca/rel
Busywork for RC1
2023-11-01 20:14:11 +00:00
Yu Watanabe
f5a0831c32 Merge pull request #29817 from YHNdnzj/fchmodat2
Add support for fchmodat2 and use it where appropriate
2023-11-02 04:56:29 +09:00
Lennart Poettering
b71a721fbc parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
2023-11-02 04:52:16 +09:00
Lennart Poettering
423e2400af sort-util: make bsearch_safe() actually typesafe, by returning the right type 2023-11-01 17:18:15 +00:00
Arseny Maslennikov
adecfb3bc0 basic/fs-util: prefer fchmodat2 in fchmod_opath
Co-authored-by: Mike Yuan <me@yhndnzj.com>
2023-11-02 00:26:22 +08:00
Arseny Maslennikov
c21566d90b basic/missing_syscall: add missing_fchmodat2()
Follow-up for 8b45281daa
and preparation for later commits.

Since libcs are more interested in the POSIX `fchmodat(3)`, they are
unlikely to provide a direct wrapper for this syscall. Thus, the headers
we examine to set `HAVE_*` are picked somewhat arbitrarily.

Also, hook up `try_fchmodat2()` in `test-seccomp.c`. (Also, correct that
function's prototype, despite the fact that mistake would not matter in
practice)

Co-authored-by: Mike Yuan <me@yhndnzj.com>
2023-11-02 00:23:12 +08:00
Lennart Poettering
9c21cfdd7d chase: fix corner case when using CHASE_PARENT with a path ending in ".."
If we use CHASE_PARENT on a path ending in ".." then things are a bit
weird, because we the last path we look at is actually the *parent* and not
the *child* of the preceeding path. Hence we cannot just return the 2nd
to last fd we look at. We have to correct it, by going *two* levels up,
to get to the actual parent, and make sure CHASE_PARENT does what it
should.

Example: for the path /a/b/c chase() with CHASE_PARENT will return
/a/b/c as path, and the fd returned points to /a/b. All good.  But now,
for the path /a/b/c/.. chase() with CHASE_PARENT would previously return
/a/b as path (which is OK) but the fd would point to /a/b/c, which is
*not* the parent of /a/b, after all! To get to the actual parent of
/a/b we have to go *two* levels up to get to /a.

Very confusing. But that's what we here for, no?

@mrc0mmand ran into this in https://github.com/systemd/systemd/pull/28891#issuecomment-1782833722
2023-11-01 14:43:24 +00:00
Lennart Poettering
943aca96f7 proc-cmdline: use read_virtual_file() for /proc/cmdline 2023-11-01 15:20:54 +01:00
Luca Boccassi
6636cc54e5 Update syscalls table 2023-11-01 14:07:54 +00:00
Yu Watanabe
0e7a7cd4e9 locale,firstboot: add headers to vconsole.conf
Closes #29717.
Replaces #29760.

Co-authored-by: cunshunxia <cunshunxia@tencent.com>
2023-10-31 17:15:21 +09:00
Yu Watanabe
f155cb6d75 env-util: make write_env_file() optionally take headers
This also makes write_env_file() and write_env_file_label() optionally
take dir_fd, and drop write_env_file_at().

Preparation for later commits.
2023-10-31 17:15:21 +09:00
Lennart Poettering
7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Lennart Poettering
6414203cfc cgroup-util: add cg_is_delegated_fd() helper
This is just like cg_is_delegate() but operates on an fd instead of a
cgroup path.

Sooner or later we should access cgroupfs mostly via fds rather than
paths, but we aren't there yet. But let's at least get started.
2023-10-26 09:27:27 +02:00
Lennart Poettering
f0b8ac9e0e tree-wide: port various users over to the new getxattr_at_bool() call 2023-10-26 09:27:18 +02:00
Lennart Poettering
70554f7ebc xattr-util: add new getxattr_at_bool() helper
This carefully combines getxattr_at_malloc() and parse_bool(), which is
something we use at multiple places.
2023-10-26 09:27:00 +02:00
Yu Watanabe
9e15e24bdb inotify-util: drop to use pointer outside of the buffer
Hopefully fixes many Coverity issues.
2023-10-26 09:08:28 +02:00
Luca Boccassi
e5cd8bc060 Merge pull request #29601 from yuwata/mmap-check-overflow
mmap: check offset and size more carefully
2023-10-24 12:20:04 +01:00
Zbigniew Jędrzejewski-Szmek
1dd33bf3e4 basic/iovec-util: use FOREACH_ARRAY in one more place 2023-10-23 22:30:37 +02:00
Zbigniew Jędrzejewski-Szmek
3c9783c7f4 basic/iovec-util: drop TAKE_IOVEC
As suggested in
https://github.com/systemd/systemd/pull/29679#discussion_r1368678932.
2023-10-23 22:23:13 +02:00
Zbigniew Jędrzejewski-Szmek
7dc951ef91 basic/iovec-util: drop IOVEC_NULL
The macro isn't very useful, we can just use the direct setting to increase
readability.
2023-10-23 15:04:08 +02:00
Zbigniew Jędrzejewski-Szmek
1ca0b482b6 basic/iovec-util: always call the iovec "iovec"
We were using "i", "iov", and "iovec" in variuos places. Let's be
consistent.
2023-10-23 15:04:08 +02:00
Lennart Poettering
24aeaf4e7f glyph-util: add 'full block' glyph 2023-10-23 11:24:35 +01:00
Lennart Poettering
4c4de97db8 sort-utils: add generic uint16_t comparison call 2023-10-20 15:57:58 +01:00
Luca Boccassi
055ca3cd0a Merge pull request #29644 from poettering/json-iovec
add iovec/base64 json helpers and other iovec tweaks
2023-10-20 15:54:29 +01:00
Daan De Meyer
26204e1a4a Merge pull request #29630 from DaanDeMeyer/manager-json
Various refactoring in preparation for adding JSON dump to pid 1
2023-10-20 16:42:12 +02:00
Luca Boccassi
f455365031 Merge pull request #29626 from bluca/auto_soft_reboot
systemctl: automatically softreboot/kexec if set up on reboot
2023-10-20 13:46:46 +01:00
Lennart Poettering
3a856171c2 iovec-util: add some useful helpers for dealing with iovecs that refer to dynamic memory 2023-10-20 14:38:16 +02:00
Daan De Meyer
b2e9d80956 hashmap: Add extra uncounted entry to returned array from hashmap_dump_sorted()
This allows using the returned array as a strv.
2023-10-20 14:09:32 +02:00
Daan De Meyer
1b17dd9099 Add unit_type_to_capitalized_string() 2023-10-20 13:30:11 +02:00