1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-10 16:58:28 +03:00

68047 Commits

Author SHA1 Message Date
Yu Watanabe
ffee7b97e3 macro: introduce u64_multiply_safe() to avoid overflow
Just a paranoia.
2023-10-19 18:31:44 +09:00
Yu Watanabe
b39907c712 sd-journal: use PAGE_ALIGN_U64() and friends
This also make constants declared with UINT64_C().
2023-10-19 18:31:44 +09:00
Yu Watanabe
2977904cad macro: introduce several helper functions for alignment
Some of them are not used in this commit, but will be used later.
2023-10-19 18:31:44 +09:00
Yu Watanabe
d54c0f37d8 macro: paranoia about overflow
E.g. Consider the case ALIGN_TO(SIZE_MAX - 3, 4). The overflow check
passes as the condition
```
SIZE_MAX - 3 > SIZE_MAX - (4 - 1)
```
is false.
However, the value
```
l + ali - 1
```
may overflow as it is equivalent to
```
SIZE_MAX - 3 + 4 - 1
```
2023-10-19 18:31:44 +09:00
Yu Watanabe
86cbbc6d05 tree-wide: check if return value of lseek() and friends is negative
We usually check return value of syscalls or glibc functions by it is
negative or not, something like that `if (stat(path, &st) < 0)`.
Let's also use the same style for lseek() and friends even the type of
their return value is off_t.

Note, fseeko() returns int, instead of off_t.
2023-10-19 18:31:44 +09:00
Frantisek Sumsal
4820c9d417 fuzz: unify logging setup
Make sure we don't log anything when running in "fuzzing" mode. Also,
when at it, unify the setup logic into a helper, pretty similar to
the test_setup_logging() one.

Addresses:
  - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607
  - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
2023-10-19 10:05:20 +01:00
Luca Boccassi
47174dc054
Merge pull request #29611 from mrc0mmand/execute-serialize-fuzz
test: add a fuzzer for exec_{serialize,deserialize}_invocation()
2023-10-18 23:33:00 +01:00
Frantisek Sumsal
892eb4d795 core: don't assert when serializing malformed state 2023-10-18 22:44:16 +02:00
Frantisek Sumsal
81c4be64da test: add a fuzzer for exec_{serialize,deserialize}_invocation() 2023-10-18 22:44:16 +02:00
Lennart Poettering
81c1c387fe
Merge pull request #29594 from poettering/cgroup-rename-ret-params
more pidfdification
2023-10-18 17:25:44 +02:00
Frantisek Sumsal
7e9c7d6f5b test: use Type=exec for the test unit
Make sure everything we need is set up before continuing further with
the test. This should, hopefully, help with a race where we check
a dynamic user before it's created by NFTSet= stuff.

Before:
$ journalctl -o short-monotonic --grep '(test-nft|NFT|testsuite-75)' --no-hostname
...
[ 3657.929223] testsuite-75.sh[48]: + systemd-run -u test-nft.service -p DynamicUser=yes -p 'NFTSet=cgroup:inet:sd_test:c user:inet:sd_test:u group:inet:sd_test:g' sleep 10000
...
[ 3657.977372] systemd[1]: test-nft.service: Changed dead -> running
[ 3657.977388] systemd[1]: test-nft.service: Job 376 test-nft.service/start finished, result=done
[ 3657.977407] testsuite-75.sh[853]: Running as unit: test-nft.service; invocation ID: 8776af2ec7864a60a058cb5d403d1ca6
[ 3657.982437] testsuite-75.sh[856]:                 elements = { "system.slice/test-nft.service" }
[ 3657.984570] testsuite-75.sh[48]: + grep -qF test-nft.service /tmp/tmp.uqXKfyzcpJ
[ 3657.985400] testsuite-75.sh[859]: ++ getent passwd test-nft
[ 3657.986434] systemd[1]: varlink-12: New incoming message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test-nft","service":"io.systemd.DynamicUser"}}
[ 3657.986503] systemd[1]: varlink-12: Sending message: {"error":"io.systemd.UserDatabase.NoRecordFound","parameters":{}}
[ 3657.986643] systemd[1]: testsuite-75.service: Child 48 belongs to testsuite-75.service.
[ 3657.986660] systemd[1]: testsuite-75.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
[ 3657.986681] systemd[1]: testsuite-75.service: Failed with result 'exit-code'.
...
[ 3657.989885] systemd[1]: test-nft.service: User lookup succeeded: uid=64568 gid=64568
[ 3657.989936] systemd[1]: Added NFT set: family inet, table sd_test, set u, ID 64568
[ 3657.989965] systemd[1]: Added NFT set: family inet, table sd_test, set g, ID 64568

After:
$ journalctl -o short-monotonic --grep '(test-nft|NFT|testsuite-75)' --no-hostname
[ 1523.874408] testsuite-75.sh[49]: + systemd-run -u test-nft.service --service-type=exec -p DynamicUser=yes -p 'NFTSet=cgroup:inet:sd_test:c user:inet:sd_test:u group:inet:sd_test:g' sleep 10000
...
[ 1523.924091] systemd[1]: Starting test-nft.service...
[ 1523.928891] systemd[1]: test-nft.service: User lookup succeeded: uid=64568 gid=64568
[ 1523.929102] systemd[1]: Added NFT set: family inet, table sd_test, set u, ID 64568
[ 1523.929220] systemd[1]: Added NFT set: family inet, table sd_test, set g, ID 64568
...
[ 1523.933263] systemd[1]: Started test-nft.service.
[ 1523.933626] testsuite-75.sh[849]: Running as unit: test-nft.service; invocation ID: d1a5c3eacbc647a7a5fcbd46c7b2f863
[ 1523.940810] testsuite-75.sh[852]:                 elements = { "system.slice/test-nft.service" }
[ 1523.942880] testsuite-75.sh[49]: + grep -qF test-nft.service /tmp/tmp.gWka2x3mQq
[ 1523.944031] testsuite-75.sh[855]: ++ getent passwd test-nft
[ 1523.945496] systemd[1]: varlink-18: New incoming message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test-nft","service":"io.systemd.DynamicUser"}}
[ 1523.951593] systemd[1]: varlink-18: Sending message: {"parameters":{"record":{"userName":"test-nft","uid":64568,"gid":64568,"realName":"Dynamic User",...
2023-10-18 16:08:44 +01:00
Lennart Poettering
06044356de manager: move idle_pipe allocation to manager.c and make it atomic
Let's make sure it either fails or suceeds, but never fails half-way
leaving a half-initialized array around.
2023-10-18 16:07:41 +01:00
Luca Boccassi
668d60627e
Merge pull request #29583 from poettering/deserialize-fd-many
add serialize_fd_many() + deserialize_fd_many() helpers
2023-10-18 16:06:22 +01:00
Lennart Poettering
1158b06b47 update TODO 2023-10-18 14:49:40 +02:00
Lennart Poettering
d0547385d9 test-cgroup: make test case a bit more robust towards previous aborted runs 2023-10-18 14:49:40 +02:00
Lennart Poettering
2d79017564 killall: port killing spree loop over to PidRef 2023-10-18 14:49:40 +02:00
Lennart Poettering
957f84e950 test: port tests over to new /proc/ enumeration API 2023-10-18 14:49:40 +02:00
Lennart Poettering
eefb7d22ce process-util: add API for enumerating processes in /proc/ and pinning them via PidRef 2023-10-18 14:49:40 +02:00
Lennart Poettering
4d9f092b5e process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errors 2023-10-18 14:49:40 +02:00
Lennart Poettering
6774be4206 process-util: add pidref_is_my_child() 2023-10-18 14:49:40 +02:00
Lennart Poettering
becdfcb9f1 process-util: change pid_is_alive() to not eat up errors, and add pidref_is_alive()
Let's no eat up errors, but propagate unexpected ones.
2023-10-18 14:40:25 +02:00
Lennart Poettering
8b51341545 process-util: add pidref_get_uid() and rename get_process_uid() → pidref_get_uid() 2023-10-18 14:39:33 +02:00
Lennart Poettering
4d1b2df199 core: port unit/process kill logic to pidref 2023-10-18 14:39:33 +02:00
Lennart Poettering
a7a877697f pidref: add new pidref_is_self() helper
This simply checks if the specified PidRef refers to the process we are
running in.

(In case you wonder why this is not a static inline: to avoid cyclic
header inclusion problems between pidref.h + process-util.h)
2023-10-18 14:39:33 +02:00
Lennart Poettering
d7d748548b process-util: add pidref_get_comm() and rename get_process_comm() to pid_get_comm() 2023-10-18 14:39:33 +02:00
Lennart Poettering
d57d521cae dbus-unit: make sure GetProcesses() D-Bus call internally uses pidfd
This way we can be sure to provide an atomic view of the process tree of
a unit.
2023-10-18 14:39:33 +02:00
Lennart Poettering
fc87713bed process-util: add pidref_is_kernel_thread() 2023-10-18 14:39:33 +02:00
Lennart Poettering
a034620f1a process-util: add pidref_get_cmdline() 2023-10-18 14:39:33 +02:00
Lennart Poettering
6f25a110ad cgroup-show: use size_t for array sizes 2023-10-18 14:39:33 +02:00
Lennart Poettering
3d7ba61a7b pidref: we never have to verify PID 1
The process exists as long as the kernel/userns exists at all, hence we
don't have to verify a pidfd to it.
2023-10-18 14:39:33 +02:00
Lennart Poettering
f2a2e60be6 cgroup-util: make cg_pidref_get_path() PidRef parameter const 2023-10-18 14:39:33 +02:00
Lennart Poettering
44c55e5a3f pidref: make signal sending calls take const PidRef 2023-10-18 14:38:07 +02:00
Lennart Poettering
cf45db5598 fd-util: use close_many() where appropriate 2023-10-18 14:03:47 +02:00
Lennart Poettering
d3eb74f8f8 fd-util: add new helper close_many_unset() 2023-10-18 14:03:36 +02:00
Lennart Poettering
26f937e576 execute: use close_many_and_free() more 2023-10-18 13:52:17 +02:00
Lennart Poettering
3b444970e6 serialize: add serialize_fd_many() helper 2023-10-18 13:51:02 +02:00
Lennart Poettering
c2e42d4b88 serialize: change order of deserialize_strv() parameters
The other deserializers put value first, and return parameter second,
let's do so here too.
2023-10-18 12:54:20 +02:00
Lennart Poettering
af6321857d serialize: modernize deserialize_{usec|dual_timestamp}() a bit
Rename the return parameters "ret", and use compound initialization. Add
an assert() on input.
2023-10-18 12:54:20 +02:00
Lennart Poettering
dff9808a62 serialize: add new helper deserialize_fd()
Currently, when we deserialize an fd we do a lot of manual work. Add a
common helper that makes this more robust and uniform.

Note that this sometimes changes behaviour slightly, but in ways that
shouldn't really matter: if we fail to deserialize an fd correctly we'll
unset (i.e. set to -EBADF) the fd in the deserialized data structure.
Previously, we'd leave the old value in place.

This should not change effective result (as in either case we'll be in a
bad state afterwards, just once we mix old/invalidated state with new
state, while now we'll reset the state explicitly to invalidated state
on failure). In particular as deserialization starts from an empty
structure generally, hence the old value should be unset anyway.

Another slight change is that if we fail to deserialize some object half
way, and we already have taken out one fd from the serialized fdset
we'll now just close it instead of returning it to/leaving it in the
fdset. Given that such "orphaned" fds are blanket closed after
deserialization finishes this also shouldn't change behaviour IRL.

Also, the idle_pipe was previously incorrectly serialized: we'd
serialize invalidated fds, which would fail, but because parsing errors
on this were ignored on the deserializatin noone noticed. This is fixed.
2023-10-18 12:54:20 +02:00
Lennart Poettering
bd389293f0 pidref: make pidref_verify() parameter const 2023-10-18 10:32:03 +02:00
Lennart Poettering
820fe745c7 cgroup-util: rename all return parameters in cgroup-util to ret_xyz 2023-10-18 10:02:43 +02:00
Yu Watanabe
87a768b801 tree-wide: fix typo 2023-10-18 12:40:25 +09:00
Ronan Pigott
06960d1719 network: include SSID in ipv6 stable prefix address generation
The SSID fills the role of the optional Network_ID input parameter
suggested by RFC7217. Including the SSID allows networkd to generate a
different pseudorandom address for different wireless networks, which
should help to obscure the host's identity when roaming between multiple
networks.
2023-10-18 09:48:09 +09:00
Daniel P. Berrangé
a3ad5c3140 repart: avoid use of uninitialized TPM2B_PUBLIC data
The 'TPM2B public' struct is only initialized if the public key
is non-NULL, however, it is unconditionally passed to
tpm2_calculate_sealing_policy, resulting in use of uninitialized
data. If the uninitialized data is lucky enough to be all zeroes,
this results eventually results in an error message from
tpm2_calculate_name about an unsupported nameAlg field value.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-10-17 23:47:02 +01:00
Luca Boccassi
cdc022802c
Merge pull request #29441 from evelikov/no-input-delay
sd-boot: add "menu-disabled" option to "timeout", disabling the 100ms input polling
2023-10-17 23:45:44 +01:00
Lennart Poettering
a104481144 cgroup: turn device cgroup controller "rwm" strings into proper flags
We generally prefer dealing with parsed data instead of original
strings, do so for the "rwm" strings too. We have to convert this to
flags for the primary backend implementation (BPF) anyway, hence we
can do this early to have simpler, shorter and more normalized code.
2023-10-17 23:27:01 +01:00
Luca Boccassi
8e3fb774ae
Merge pull request #29586 from poettering/read-stripped-line
add read_stripped_line() as trivial read_line() + strstrip() combo
2023-10-17 19:54:14 +01:00
Franck Bui
6495361c7d meson: add build option for install path of main config files
This allows distros to install configuration file templates in /usr/lib/systemd
for example.

Currently we install "empty" config files in /etc/systemd/. They serve two
purposes:

- The file contains commented-out values that show the default settings.
- It is easier to edit the right file if it is already there, the user doesn't
  have to type in the path correctly, and the basic file structure is already in
  place so it's easier to edit.

Things that have happened since this approach was put in place:

- We started supporting drop-ins for config files, and drop-ins are the
  recommended way to create local configuration overrides.
- We have systemd-analyze cat-config which takes care of iterating over
  all possible locations (/etc, /run, /usr, /usr/local) and figuring out
  the right file.
- Because of the first two points, systemd-analyze cat-config is much better,
  because it takes care of finding all the drop-ins and figuring out the
  precedence. Looking at files manually is still possible of course, but not
  very convenient.

The disadvantages of the current approach with "empty" files in /etc:

- We clutter up /etc so it's harder to see what the local configuration actually is.
- If a user edits the file, package updates will not override the file (e.g.
  systemd.rpm uses %config(noreplace). This means that the "documented defaults"
  will become stale over time, if the user ever edits the main config file.

Thus, I think that it's reasonable to:

- Install the main config file to /usr/lib so that it serves as reference for
  syntax and option names and default values and is properly updated on package
  upgrades.
- Recommend to users to always use drop-ins for configuration and
  systemd-analyze cat-config to view the documentation.

This setting makes this change opt-in.

Fixes #18420.

[zjs: add more text to the description]
2023-10-17 18:57:45 +02:00
Zbigniew Jędrzejewski-Szmek
ee691c802b
Merge pull request #29242 from fbuihuu/update-main-config-file-headers
config files: update their header to reflect that they can be install…
2023-10-17 18:56:09 +02:00
Emil Velikov
6efdd7fec5 sd-boot: add way to disable the 100ms delay when timeout=0
Currently we have a 100ms delay which allows for people to enter/show
the boot menu even when timeout is set to zero.

In a handful of cases, that may not be needed - both in terms of access
policy, as well as latency.

For example: the option to provide the boot menu may be hidden behind an
"expert only" UX in the OS, to avoid end users from accidentally
entering it.

In addition, the current 100ms input polling may cause unexpected
additional delays in the boot. Some example numbers from my SteamDeck:

 - boot counting/rename/flush doubles 300us -> 600us
 - seed/hash setup doubles 900us -> 1800us
 - kernel/image load gets ~40% slower 107ms -> 167ms

It's not entirely clear why the UEFI calls gets slower, nevertheless the
information in itself proves useful.

This commit introduces a new option "menu-disabled", which omits the
100ms delay. The option is documented throughout the manual pages as
well as the Boot Loader Specification.

v2:
 - use STR_IN_SET

v3:
 - drop erroneous whitespace

v4:
 - add a new LoaderFeature bit,
 - don't change ABI keep TIMEOUT_* tokens the same
 - move new token in the 64bit range, update API and storage for it
 - change inc/dec behaviour to TIMEOUT_MIN : TIMEOUT_MENU_FORCE
 - user cannot opt-in from sd-boot itself, add assert_not_reached()

v5:
 - s/Menu disablement control/Menu can be disabled/
 - rewrap comments to 109
 - use SYNTHETIC_ERRNO(EOPNOTSUPP)

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2023-10-17 15:09:53 +01:00