1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-20 14:03:39 +03:00

60929 Commits

Author SHA1 Message Date
Jian Zhang
6d7b0dacc6 test-network: add test for bond mac address config
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
(cherry picked from commit 23b6bf274fc1a46d8778bfc979d3c803d61a1f5c)
2022-12-08 23:00:35 +01:00
Jian Zhang
6405eba4b6 network: Fix set bond device MAC address failed
Issue:
When device is in bond mode and booting up, there is a probability of
set bond MAC address failed due to `Device or resource busy` error.

In systemd-networkd, set MAC address steps are:
1. Try to set MAC address to device.
2. If failed with `Device or resource busy`, then `Down` the device.
3. Try to set MAC address to device again.

Currently, Even down the bond device, the bond device is still return
`Device or resource busy` error. So the MAC address set failed.

The root cause is that this not enough to down the bond device. We need
to down all the slaves of the bond device.
About this descprition, we could use those commands to check:
```shell
We have two network devices: eth0, bond1, eth0 is slave of bond1.
They are all up.

1. Down bond1, and set MAC address to bond1.
~# ip link set bond1 down
~# ip link set bond1 address 00:11:22:33:44:55
ip: SIOCSIFHWADDR: Device or resource busy

2. Down eth0, and set MAC address to bond1.
~# ip link set eth0 down
~# ip link set bond1 address 00:11:22:33:44:55
Set okay.
```

Fix:
When setting the mac for the second time, if the device kind is bond,
then we need to down the slave devices of bond device.

Tested: Verified in a long time test( reboot cycles ).

Fixes: #25627

Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
(cherry picked from commit f1a69d5accfd566c5af0210115f4b4a9743425ee)
2022-12-08 23:00:35 +01:00
Daan De Meyer
dbc59253ec test-fs-util: Add relative path chase_symlinks() tests
(cherry picked from commit 94799c305acad138ce62e562318fbe7936a50dce)
2022-12-08 23:00:35 +01:00
Lennart Poettering
6e99f9c8fb chase-symlink: when converting directory O_PATH fd to real fd, don't bother with /proc/
Replaces: #25581
(cherry picked from commit 2075b6dd394e09a0f203b9cc7e3253908397f933)
2022-12-08 23:00:35 +01:00
Yu Watanabe
bc6fc812fd test: add basic tests for octescape()
(cherry picked from commit 4f438c638b5335cd5d8f614804743a04311689f8)
2022-12-08 23:00:35 +01:00
Yu Watanabe
2ea5de7881 escape: fix wrong octescape of bad character
Fixes a bug introduced by 95052df3760523e1f3bb9705c918d85aae7fb431.

This also makes octescape() support NULL or zero length string.

Fixes [oss-fuzz#54059](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54059).

Fixes #25643.

(cherry picked from commit 76519cecc749a3d0e2054fd6db8a99143666e123)
2022-12-08 23:00:20 +01:00
Yu Watanabe
8999727a82 network: drop REMOVING flag when a netlink message is sent to kernel
When an interface goes to down, the kernel drops several routes
automatically, and at the same time networkd requests to remove
them, but the kernel sometimes does not respond the requests. Hence,
the routes cannot drop the REMOVING flag, and networkd will never try
to configure other routes which depend on the previously removed
routes even if they are already reconfigured.

With this patch, when networkd sends a request to configure a route
(or any other network settings), REMOVING flag for the route is dropped
without waiting for the reply about the previous remove request, as we
can expect it will appear even if it is already removed or under removing.

Fixes #24999.

(cherry picked from commit f4ee7b98c434bc9a0f436c29fd32225acd73e183)
2022-12-08 21:29:56 +01:00
Lennart Poettering
a064abff76 dissect: show color in log output
(cherry picked from commit 5acb31a6830e3c9c35b64754802f8214780c96cb)
2022-12-08 21:29:56 +01:00
Richard Phibel
278a97708b log: Switch logging to runtime when FS becomes read-only
The journal has a mechanism to log to the runtime journal if it fails to
log to the system journal. This mechanism is not triggered when the file
system becomes read-only. We enable it here.

When appending an entry fails if shall_try_append_again returns true,
the journal is rotated. If the FS is read-only, rotation will fail and
s->system_journal will be set to NULL. After that, when find_journal
will try to open the journal since s->system_journal will be NULL, it
will open the runtime journal.

(cherry picked from commit 379864f89079a92ff09917e25b3aea0fadd228ac)
2022-12-08 21:29:56 +01:00
Evgeny Vereshchagin
44984e15bb resolve: format zero-length RDATA according to rfc3597
If the RDATA is of zero length, the text representation contains only
the \# token and the single zero representing the length.

(cherry picked from commit 84f788d6699f289160d7cb3823c1bf9a3826f11f)
2022-12-08 21:29:56 +01:00
Zbigniew Jędrzejewski-Szmek
d59009dc1d manager: do not append '\n' when writing sysctl settings
When booting with debug logs, we print:

   Setting '/proc/sys/fs/file-max' to '9223372036854775807
   '
   Setting '/proc/sys/fs/nr_open' to '2147483640
   '
   Couldn't write fs.nr_open as 2147483640, halving it.
   Setting '/proc/sys/fs/nr_open' to '1073741816
   '
   Successfully bumped fs.nr_open to 1073741816

The strange formatting is because we explicitly appended a newline in those two
places. It seems that the kernel doesn't care. In fact, we have a few dozen other
writes to sysctl where we don't append a newline. So let's just drop those here
too, to make the code a bit simpler and avoid strange output in the logs.

(cherry picked from commit b47e0fac0356308cf34aa235ba9328c0c9de51bd)
2022-12-08 21:29:56 +01:00
Frantisek Sumsal
2a66b4c894 test: check if we can use SHA1 MD for signing before using it
Some distributions have started phasing out SHA1, which breaks
the systemd-measure test case in its current form. Let's make sure we
can use SHA1 for signing beforehand to mitigate this.

Spotted on RHEL 9, where SHA1 signatures are disallowed by [0]:
```
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "/tmp/pcrsign-private.pem"
...
openssl rsa -pubout -in "/tmp/pcrsign-private.pem" -out "/tmp/pcrsign-public.pem"
writing RSA key
/usr/lib/systemd/systemd-measure sign --current --bank=sha1 --private-key="/tmp/pcrsign-private.pem" --public-key="/tmp/pcrsign-public.pem"
Failed to initialize signature context.
```

[0] https://gitlab.com/redhat/centos-stream/rpms/openssl/-/blob/c9s/0049-Selectively-disallow-SHA1-signatures.patch

(cherry picked from commit d19e5540f20c78caa949ff33050b4a530cae1982)
2022-12-08 21:29:56 +01:00
Yu Watanabe
d0b80bf81e dissect-image: log expected UUID for /var
Closes #25443.

(cherry picked from commit a52efa813df9614b98069976b73fe63a68983ee7)
2022-12-08 21:29:56 +01:00
Yu Watanabe
b0b97848e8 bootspec: fix null-dereference-read
Fixes [oss-fuzz#53578](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53578).
Fixes #25450.

(cherry picked from commit 46dc071985ff487f5ccf20808531168a6add73d3)
2022-12-08 21:29:56 +01:00
Neil Moore
0ba8e9ecff virt: Support detection of LMHS SRE guests
(cherry picked from commit d833ed781f61b820e7abb17caa85c3c37c7ea807)
2022-12-08 21:29:56 +01:00
Ray Strode
787b2c32f3 terminal-util: Set OPOST when setting ONLCR
reset_terminal_fd sets certain minimum required terminal attributes
that systemd relies on.

One of those attributes is `ONLCR` which ensures that when a new line
is sent to the terminal, that the cursor not only moves to the next
line, but also moves to the very beginning of that line.

In order for `ONLCR` to work, the terminal needs to perform output
post-processing. That requires an additional attribute, `OPOST`,
which reset_terminal_fd currently fails to ensure is set.

In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
it's not an issue, but it could be a problem if, e.g., the terminal was
put in raw mode by a program and the program unexpectedly died before
restoring settings.

This commit ensures when `ONLCR` is set `OPOST` is set too, which is
the only thing that really makes sense to do.

(cherry picked from commit 9fe26523a189435d75b9d745188e09c17928d89e)
2022-12-08 21:29:56 +01:00
Lennart Poettering
c7bf13b2d9 units: change Requires=systemd-networkd.service → BindsTo= one more time
Follow-up for da15f8406e9aeb7908e1d92c02d2ff5147c7788a which did the
change for systemd-networkd-wait-online.service, let's also do this for
systemd-networkd-wait-online@.service

(cherry picked from commit 51f3dc2234082c1ca9bdda403e4f355cab6be03b)
2022-12-08 21:29:56 +01:00
Yu Watanabe
e3d9376692 core/device: verify device syspath on switching root
Otherwise, if a device is removed while switching root, then the
corresponding .device unit will never go to inactive state.

This replaces the code dropped by cf1ac0cfe44997747b0f857a1d0b67cea1298272.

Fixes #25106.

(cherry picked from commit b6c86ae28149c4abb2f0bd6acab13153382da9e7)
2022-12-08 21:29:56 +01:00
Yu Watanabe
9523f85b2e core/device: also serialize/deserialize device syspath
The field will be used in later commits.

(cherry picked from commit 1ea74fca3a3c737f3901bc10d879b7830b3528bf)
2022-12-08 21:29:56 +01:00
Yu Watanabe
10b3ce781b core/device: update comment
(cherry picked from commit 54a4d71509c0f3401aa576346754a0781795214a)
2022-12-08 21:29:56 +01:00
Yu Watanabe
2505010178 sd-netlink: fix segfault
(cherry picked from commit 766417bd763db913efdd9c48442b1094c23d7042)
2022-12-08 21:29:56 +01:00
Michal Koutný
4b885f3591 test: Add tests for systemd-cgtop args parsing
(cherry picked from commit d4e32838e875539ad6991b75b083c9563eddc3ed)
2022-12-08 21:29:56 +01:00
Michal Koutný
b97c1c427c cgtop: Do not rewrite -P or -k options
--recursive=no will overwrite possible -P or -k option hence making the
recursive disabling impossible.

Check what counting types the system supports (encoded in the ordering
of our enum) of and pick whatever user requests but is also supported.

Fixes: #25248
(cherry picked from commit 48600b3524afe05d0faa8a5c88b5aaa53b801199)
2022-12-08 21:29:56 +01:00
Michal Koutný
6cbf72a8d9 logind: Properly unescape names of lingering users
Filenames to store user linger requests are created with C-escaping.
When we enumerate the files to acquire ligering users, we use the
filenames verbatim. In the case C-escaping is not an identity map (such
as "DOMAIN\User"), we won't be able to start user instances of
such mangled users.

Unescape filenames when we treat them as usernames again.

Fixes: #25448
(cherry picked from commit f38e89c23ce52efa27bb47f5c3dafecdb987492b)
2022-12-08 21:29:56 +01:00
Daan De Meyer
01a39e96b5 units: Use BindsTo=systemd-networkd in systemd-networkd-wait-online.service
We don't want systemd-networkd-wait-online to start if systemd-networkd
is skipped due to condition failures. This is only guaranteed by BindsTo=
and not Requires=, so let's use BindsTo=

(cherry picked from commit da15f8406e9aeb7908e1d92c02d2ff5147c7788a)
2022-12-08 21:29:56 +01:00
Lennart Poettering
b0c39ffc54 resolved: remove inappropriate assert()
A NULL Bitmap object is by all our code considered identical to an empty
bitmap. Hence let's remove the entirely unnecessary assert().

The assert() can be triggered if debug monitoring is used an an empty
NSEC or NSEC3 RR is included in an answer resolved returns.

it's not really a security issue since enabling debug monitoring is a
manual step requiring root privileges, that is off by default. Moreover,
it's a "clean" assert(), i.e. the worst that happens is tha a coredump
is generated and resolved restarted.

Fixes: #25449
(cherry picked from commit fb896517aeecc2a8ec16586a34a0249606eb9f66)
2022-12-08 21:29:56 +01:00
Jan Janssen
e0521346ec stub: Detect empty LoadOptions when run from EFI shell
The EFI shell will pass the entire command line to the application it
starts, which includes the file path of the stub binary. This prevents
us from using the built-in cmdline if the command line is otherwise
empty.

Fortunately, the EFI shell registers a protocol on any images it starts
this way. The protocol even lets us access the args individually, making
it easy to strip the stub path off.

Fixes: #25201
(cherry picked from commit b17f3b3d8077ab6827549a123ac636d655fe8d4d)
2022-12-02 14:17:12 +01:00
Jan Janssen
7ca40a8b08 stub: Fix cmdline handling
This fixes some bugs that could lead to garbage getting appended to the
command line passed to the kernel:
 1. The .cmdline section is not guaranteed to be NUL-terminated, but it
    was used as if it was.
 2. The conversion of the command line to ASCII that was passed to the
    stub ate the NUL at the end.
 3. LoadOptions is not guaranteed to be a NUL-terminated EFI string (it
    really should be and generally always is, though).

This also fixes the inconsistent mangling of the command line. If the
.cmdline section was used ASCII controls chars (new lines in particular)
would not be converted to spaces.

As part of this commit, we optimize conversion for the generic code
instead of the (deprecated) EFI handover protocol. Previously we would
convert to ASCII/UTF-8 and then back to EFI string for the (now) default
generic code path. Instead we now convert to EFI string and mangle that
back to ASCII in the EFI handover protocol path.

(cherry picked from commit 927ebebe588970fa2dd082a0daaef246229f009b)
2022-12-02 14:17:12 +01:00
Jan Janssen
b39f2ab98f boot: Use xstr8_to_16 for path conversion
(cherry picked from commit 7444e10611671abac35be3ab9fe9697cd4c90d62)
2022-12-02 14:17:12 +01:00
Jan Janssen
6387a74d2c boot: Use xstr8_to_16
(cherry picked from commit aee515bbb58496272a6d975858aa26a355c4fb90)
2022-12-02 14:17:12 +01:00
Jan Janssen
ff7469af96 boot: Add xstrn8_to_16
(cherry picked from commit 8ad7deffa95d33b5849ad6589dd52ab12e645edc)
2022-12-02 14:17:12 +01:00
Christian Göttsche
475c130003 core: update audit messages
Pass getuid() instead of literal `0` as auid, since user session
managers also issue audit messages on SELinux denials.

(cherry picked from commit c826b7ef3272157167a5c9d493e9672f00d84b98)
v252.2
2022-11-24 17:38:34 +01:00
Lennart Poettering
c74bc2cd49 dissect: fix fsck
Since f7725647bb41c3398a867f139efe526efe8aa1b3 when dissecting a disk
image we operate with fds to the device nodes in question wherever we
can. This includes when we fork off fsck, where we pass a /proc/self/fd/
path as argument. This only works if we keep that fd open however and
disable O_CLOEXEC on the fd. Hence do so, and fix fsck this way.

(Without this, all fsck will fail, since the fd path is invalid)

(cherry picked from commit f8ab781223bcb0330ee4499b879a62e84fee313e)
2022-11-24 17:38:34 +01:00
Lennart Poettering
ce55eb4ebd process-util: add new FORK_CLOEXEC_OFF flag for disabling O_CLOEXEC on remaining fds
Often the fds that shall stay around in the child shall be passed
to a process over execve(), hence add an option to explicitly disable
O_CLOEXEC on them in the child.

(cherry picked from commit 981cfbe046297a18f2cb115ef81202f3bd68d2a3)
2022-11-24 17:38:34 +01:00
Lennart Poettering
36c3c4172d fd-util: add new fd_cloexec_many() helper
(cherry picked from commit ed18c22c989495aab36512f03449222cfcf79aa7)
2022-11-24 17:38:34 +01:00
Lennart Poettering
57b4329b38 fd-util: make fd_in_set() (and thus close_all_fds()) handle invalidated fds in the array
let's handle gracefully if fds in the specified array are already
invalidated (i.e. negative). This is handy when putting together arrays
on the fly.

(cherry picked from commit d11c14a9817f6561a30d96d8faea126a4c811af8)
2022-11-24 17:38:34 +01:00
Luca Boccassi
12c41564cd tmpfiles: log at info level when some allowed failures occur
In provision.conf we ship:

d- /root :0700 root :root -
d- /root/.ssh :0700 root :root -

These are allowed to fail, for example on a read-only filesystem. But they still
log at error level, which is annoying and gets flagged. Tune those specific errors
down to info.

There are likely more that could be tuned down, but the important thing is to cover
the tmpfiles.d that we ship right now.

Before:

$ echo -e "d- /root :0700 root :root - \nd- /root/.ssh :0700 root :root -" | SYSTEMD_LOG_LEVEL=err build/systemd-tmpfiles --root=/tmp/img --create -
Failed to create directory or subvolume "/tmp/img/root": Read-only file system
Failed to open path '/tmp/img/root': No such file or directory
$

After:

$ echo -e "d- /root :0700 root :root - \nd- /root/.ssh :0700 root :root -" | SYSTEMD_LOG_LEVEL=err build/systemd-tmpfiles --root=/tmp/img --create -
$

(cherry picked from commit 244c2a8344c01e94cd9bdf835de998b89bc53179)
2022-11-24 17:38:34 +01:00
Yu Watanabe
77f524dda0 find-esp: include device sysname in the log message
(cherry picked from commit 388d14659d250545125f8e950e3abb6eb8682c61)
2022-11-24 17:38:34 +01:00
Yu Watanabe
8d23210a2e find-esp: downgrade and ignore error on retrieving PART_ENTRY_SCHEME when searching
Fixes #25332.

(cherry picked from commit 01f234c6f5672926d6cfe4fbfcdb48326ce06250)
2022-11-24 17:38:34 +01:00
Daan De Meyer
eea92b179d sd-bus: Use goto finish instead of return in bus_add_match_full
Fixes #25340

(cherry picked from commit 0f3c342903d1a09577378912717539b530af1fcf)
2022-11-24 17:38:34 +01:00
Daan De Meyer
0916514b8c strv: Make sure strv_make_nulstr() always returns a valid nulstr
strv_make_nulstr() is documented to always return a valid nulstr,
but if the input is `NULL` we return a string terminated with only
a single NUL terminator, so let's fix that and always terminate the
resulting string with two NUL bytes.

(cherry picked from commit 5ea173a91b2093664a9ebb9add678edd6f5d1efd)
2022-11-24 17:38:34 +01:00
Lennart Poettering
2ddd7b5def bootctl: rework how we handle referenced but absent EFI boot entries
Follow-up for #25368.

Let's consider ENOENT an expected error, and just debug log about it
(though, let's suffix it with `, ignoring.`). All other errors will log
loudly, as they are unexpected errors.

(cherry picked from commit af1bed8e83c3d380d1eb0b9147684b76d1ee4df0)
2022-11-24 17:38:34 +01:00
Yu Watanabe
2daecc7179 bootctl: downgrade log message when firmware reports non-existent or invalid boot entry
Fixes #25359.

(cherry picked from commit 78bfeeae508a554483de02b52aa2e5afdc341e1a)
2022-11-24 17:38:34 +01:00
Yu Watanabe
9a7186e92a bootctl: make boot entry id logged in hex
To make consistent with the printed boot id below and other tools e.g.
efibootmgr.

(cherry picked from commit a7dcb75c539dd5bb69b72e47c820fe79c794409a)
2022-11-24 17:38:34 +01:00
Yu Watanabe
62f58d94f8 dissect-image: do not try to close invalid fd
Fixes a bug introduced by f7725647bb41c3398a867f139efe526efe8aa1b3.

Hopefully fixes #25348.

(cherry picked from commit 088377e0920a3785e7926f2ed382810836480ae6)
2022-11-24 17:38:34 +01:00
Jan Janssen
c1dd021d16 boot: Silence driver reconnect errors
(cherry picked from commit 98ac5192d5feddae19f6f5ceb60aa3751a30676b)
2022-11-24 17:38:34 +01:00
Franck Bui
a09a41c2f7 meson: install test-kernel-install only when -Dkernel-install=true
This patch fixes the following build failure:

  meson.build:3853:8: ERROR: Unknown variable "test_kernel_install_sh".

Fixes #25432.

(cherry picked from commit cc77a56532ddb59770e8312fc1b9954b0b135e72)
2022-11-24 17:38:34 +01:00
Lennart Poettering
9b6f12262f udev: make sure auto-root logic also works in UKIs booted from XBOOTLDR
If no root= switch is specified on the kernel command line we'll use the
root disk on which the partition the LoaderDevicePartUUID efi var is
located – as long as that partition is an ESP. Let's slightly liberalize
that and also allow it if that partition is an XBOOTLDR partition. This
ensures that UKIs spawned directly from XBOOTLDR work the same as those
from the ESP.

(Note that this makes no difference if sd-boot is in the mix, as in that
case LoaderDevicePartUUID is always set to the ESP, as that's where
sd-boot is located, and sd-boot will set the var first, sd-stub will
only set it later if it#s not set yet.)

(cherry picked from commit e4cb147a2e230a4a0b804c3e70f2692a5e2fd698)
2022-11-24 17:38:34 +01:00
Luca Boccassi
d5e3625a61 repart: respect --discard=no also for block devices
It's only used to avoid BLKDISCARD on individual partitions at the moment.
It can take a lot of time to run on very slow devices, so avoid it for
them too.

(cherry picked from commit 0dce448bbc97c861520c287b01d632b887442925)
2022-11-24 17:38:34 +01:00
Luca Boccassi
79f161ac65 portable: add a few more useful debug log messages
When attaching and /etc/systemd/system.attached can't be created or used
(eg: dead symlink) the logs are pretty much useless as even at debug
level there's no indication of what is going wrong.
Add some debug logs, and return a more specific error string over D-Bus.

(cherry picked from commit 80d95fcd6e1947a7887b96b22a32dbca115baac9)
2022-11-24 17:38:34 +01:00