Commit Graph

5755 Commits

Author SHA1 Message Date
Mike Yuan
7312c422f0 basic/uid-range: add uid_map_read_one helper 2023-12-15 21:22:51 +08:00
Mike Yuan
121b705426 cgroup-util: check ferror() first
Also, there's no need to set use errno_or_else(), since fscanf() is
documented to set errno on error.
2023-12-15 21:21:17 +08:00
Luca Boccassi
266e8d0eb6 Merge pull request #30417 from YHNdnzj/unit-log-resource
core/unit: clean up unit_log_resources
2023-12-14 08:45:26 +00:00
Lennart Poettering
21c43631d7 rlimit-util: add pid_getrlimit() helper
This is gets the resource limits off a specified process, and is very
similar to prlimit() with a NULL new_rlimit argument. In fact, it tries
that first. However, it then falls back to use /proc/$PID/limits. Why?
Simply because Linux prohibits access to prlimit() for processes with a
different UID, but /proc/$PID/limits still works.

This is preparation to allow nspawn to run unprivileged.
2023-12-14 08:31:29 +00:00
Lennart Poettering
a1796e9bd8 pidref: add pidref_set_parent() for race-freely getting pidref on ppid 2023-12-13 18:00:14 +01:00
Mike Yuan
ba354c164f iovec-util: add missing assertion 2023-12-13 20:42:05 +08:00
Yu Watanabe
a0460dfed6 parse-util: accept arbitrary MTU size when AF_UNSPEC
When [Link] MTU= is specified in a .network file, we have no idea about
that what kind of interface will be configured with the .network file.
The maximum and minimum MTU size depend on the kind of interface.
So, we should not filter MTU eagerly in the parser.

Closes #30140.
2023-12-08 10:47:42 +09:00
Lennart Poettering
cbc51d0cf4 Merge pull request #30101 from poettering/underline-rework
systemctl: "list-units" table tweaks
2023-12-06 22:13:12 +01:00
Lennart Poettering
4d56442755 recurse-dir: add new readdir_all_at() helper
This new helper combines open() with readdir_all() to simplify a few
callers.
2023-12-06 22:12:48 +01:00
Lennart Poettering
dc7a49ed25 Merge pull request #30183 from poettering/nlcr
NL → CRNL conversion fixes when logging at the same time as ptyfwd runs
2023-12-06 22:12:17 +01:00
Lennart Poettering
6498a0c2cc user-util: add new helper fully_set_uid_gid()
Usually when we do setresuid() we also do setesgid() and setgroups().
Let's add a common helper that does all three, and use it everywhere.
2023-12-06 22:11:38 +01:00
Luca Boccassi
d5401e36dc Merge pull request #30332 from bluca/softreboot_pivot_in_place
switch-root: also check that mount IDs are the same, not just inodes
2023-12-06 21:01:13 +00:00
Luca Boccassi
5134e54625 basic: add fds_are_same_mount() helper 2023-12-05 17:20:27 +00:00
Yu Watanabe
829732d40a basic: fix typo 2023-12-05 23:50:25 +09:00
Yu Watanabe
e521898d83 capability-util: avoid false-positive use-of-uninitialized-value error
fuzzers randomly fail with the following:
```
==172==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f41169cb39b in update_argv /work/build/../../src/systemd/src/basic/argv-util.c:96:13
    #1 0x7f41169cb39b in rename_process /work/build/../../src/systemd/src/basic/argv-util.c:210:16
    #2 0x7f4116b6824e in safe_fork_full /work/build/../../src/systemd/src/basic/process-util.c:1516:21
    #3 0x7f4116bffa36 in safe_fork /work/build/../../src/systemd/src/basic/process-util.h:191:16
    #4 0x7f4116bffa36 in parse_timestamp /work/build/../../src/systemd/src/basic/time-util.c:1047:13
    #5 0x4a61e6 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-time-util.c:16:16
    #6 0x4c4a13 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #7 0x4c41fa in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #8 0x4c58c9 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #9 0x4c6595 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #10 0x4b58ff in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #11 0x4def52 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #12 0x7f4115ea3082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: e678fe54a5d2c2092f8e47eb0b33105e380f7340)
    #13 0x41f5ad in _start (build-out/fuzz-time-util+0x41f5ad)

DEDUP_TOKEN: update_argv--rename_process--safe_fork_full
  Uninitialized value was created by an allocation of 'fv' in the stack frame of function 'have_effective_cap'
    #0 0x7f41169d3540 in have_effective_cap /work/build/../../src/systemd/src/basic/capability-util.c:21
```
2023-11-28 10:22:39 +01:00
Lennart Poettering
d19ddf91fd log: when writing a log message to a TTY always end line in CRNL
This should make sure our log lines look nice even if the tty we are
connected to is in raw mode. Normally, it's the TTY's job to turn an NL
we output into a CRNL and interpret it accordingly. However, if the tty
is in "raw" mode it won't do that. Specifically, this is controlled by
the ONLCR flag on the TTY. A TTY might be in raw mode if our "ptyfwd"
logic is used for example, where a 2nd tty is bi-directionally connected
to the primary tty, and duplicate processing is not desired.

Hence, let's just write out the CR on our own. This will make sure that
whenever we output something subsequent output always continues on the
beginning of the next line again, regardless the mode the TTY is in. Of
course, if the TTY is *not* in raw mode, then the extra CR we now
generate is redundant, but it shouldn't hurt either, as it just moves
the cursor to the front of the line even though already is just there.

We only to that if we actually talk to a TTY though, since we don't want
the extra CRs if we are redirected to a pipe or file or so. We are not
on Windows after all.

Fixes: #30155
2023-11-24 11:09:24 +01:00
Lennart Poettering
6a7e015429 stat-util: make file name arguments optional in inode_same_at() 2023-11-24 11:00:52 +01:00
Yu Watanabe
19f0a71ba0 io-util: actually retry on failure
Follow-up for e22c60a9d5.

Fixes #30152.
2023-11-22 20:38:38 +00:00
Lennart Poettering
40e1100283 recurse-dir: correct comment
The RECURSE_DIR_ENSURE_TYPE flag is actually interpreted by
readdir_all() already, hence rearrange comments to say so.
2023-11-22 17:44:29 +00:00
Luca Boccassi
61c232dc8b Merge pull request #30145 from poettering/reset-terminal-line-editing
make terminal line editing work with systemd-firstboot
2023-11-22 17:43:51 +00:00
Luca Boccassi
7d4b61d287 Merge pull request #30149 from yuwata/setlocale
locale-util: do not call setlocale() when multi-threaded
2023-11-22 17:43:39 +00:00
Luca Boccassi
31897753fb Merge pull request #30024 from keszybz/one-doc-thingy
Serialize units ratelimits and document StartLimitIntervalSec=infinity
2023-11-22 17:42:51 +00:00
Lennart Poettering
9b85e90780 fs-util: add comment explaining what xopenat() is for 2023-11-23 02:29:37 +09:00
Yu Watanabe
d54a45ad5f locale-util: drop unused init_gettext()
The function has not been used since 96d9117ad2.
2023-11-23 00:50:46 +09:00
Yu Watanabe
ca13432d60 locale-util: do not call setlocale() when multi-threaded
Fixes #30141.
2023-11-23 00:50:42 +09:00
Zbigniew Jędrzejewski-Szmek
fed25720ef core: use uniform style for RateLimit initialization
RateLimit is designed so that we can always initialize only the first two
fields explicitly. All other call sites use a single line for this.
2023-11-22 12:32:31 +00:00
Lennart Poettering
d5b6c6e378 terminal-util: drop ECHOPRT flag from TTY settings when resetting
Let's disable ECHOPRT for terminals we reset.

The feature only really makes sense for hardcopy terminals and we sure
as shit don't talk to one of those. It has the effect that when line
editing is on and you hit backspace it outputs "\" followed by the
removed character. This never makes sense on a TTY that can just erase
the character.

Hence turn of this flag.

We have carried this flag along for about forever, but it doesn't really
make sense. I guess we mostly tested the terminal reset stuff for output
only, not for input.

This change is in particular useful for tools such as
"systemd-firstboot" which interactively ask questions on the console,
and where line editing should really work.
2023-11-22 13:27:53 +01:00
Lennart Poettering
68e4c637f8 terminal-util: trivial modernizations for reset_terminal_fd() 2023-11-22 13:27:53 +01:00
Lennart Poettering
6ad2049dd9 terminal-util: add macro for adding underline to existing formats
This is different from the existing macros that generate "underline"
ANSI sequences: these ones are additive, i.e. do not reset the font to
the default first. The idea is to combine these with other ansi
sequences.
2023-11-20 13:00:43 +01:00
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