systemd/.git
3 years agoman: various issues reported in #22432
Zbigniew Jędrzejewski-Szmek [Tue, 22 Feb 2022 21:54:23 +0000 (22:54 +0100)]
man: various issues reported in #22432

Fixes #22432.

(cherry picked from commit fe003f02dd19b9ae88af0384e5cf4f5934d1e9db)

3 years agoman/systemd-analyze: split out example to a separate section
Zbigniew Jędrzejewski-Szmek [Tue, 22 Feb 2022 21:55:42 +0000 (22:55 +0100)]
man/systemd-analyze: split out example to a separate section

It turns out we can't have an Example nested in a list, and every
combination of nesting I tried looked bad either in troff or in html.
The whole example is moved to a separate section.

(cherry picked from commit e6ce19516315138d983ed4b7776d9ebd2fb296d8)

3 years agoman: adjust command for Fedora installations
Zbigniew Jędrzejewski-Szmek [Thu, 17 Feb 2022 19:34:14 +0000 (20:34 +0100)]
man: adjust command for Fedora installations

glibc now has Suggests:glibc-minimal-langpack, so we don't
need to mention it ourselves.

--repo=… is a nicer alternative to --disablerepo=* --enablerepo=….
It also avoids the issue with quoting.

Let's exclude weak deps, but install systemd-networkd, so the container
can configure networking if necessary.

(cherry picked from commit 8c4db5629c877425b2f46e414a94a8f24280a9d3)

3 years agojournal-send: close fd on exit when running with valgrind
Yu Watanabe [Tue, 22 Feb 2022 17:03:54 +0000 (02:03 +0900)]
journal-send: close fd on exit when running with valgrind

Fixes an issue reported in #22576.

(cherry picked from commit eb9752d2be82d994cd6a17f271be27c4d56423d6)

3 years agotest-journal-send: close fd opend by syslog()
Yu Watanabe [Tue, 22 Feb 2022 16:52:29 +0000 (01:52 +0900)]
test-journal-send: close fd opend by syslog()

Fixes an issue reported in #22576.

(cherry picked from commit 9048a6ccf3bd4f6794fc1ac9a838e1a0bfbcabf1)

3 years agounit: escape %
Yu Watanabe [Tue, 22 Feb 2022 16:29:42 +0000 (01:29 +0900)]
unit: escape %

Fixes #22601.

(cherry picked from commit 6e4d122ad1db11ca898de183f898f731c4839d4a)

3 years agoclang-format: we actually typically use 16ch continuation indentation
Lennart Poettering [Tue, 22 Feb 2022 15:51:58 +0000 (16:51 +0100)]
clang-format: we actually typically use 16ch continuation indentation

We use 8 for blocks, and 16 for continuation in most cases afaics, hence
say so in .clang-format too

(cherry picked from commit 92148fb77766767fdb6ad6e52747317dae2aae85)

3 years agotest: fix file descriptor leak in test-psi-util
Yu Watanabe [Tue, 22 Feb 2022 12:46:41 +0000 (21:46 +0900)]
test: fix file descriptor leak in test-psi-util

Fixes an issue reported in #22576.

(cherry picked from commit be99883e131ef422f8278ec1d099520996a78bb0)

3 years agotest: fix file descriptor leak in test-tmpfiles.c
Yu Watanabe [Tue, 22 Feb 2022 12:44:58 +0000 (21:44 +0900)]
test: fix file descriptor leak in test-tmpfiles.c

Also fixes a typo in assertion.

Fixes an issure reported in #22576.

(cherry picked from commit 1da5325d19dee654326e5fa2f61262e5e0a40fff)

3 years agotest: fix file descriptor leak in test-fs-util
Yu Watanabe [Tue, 22 Feb 2022 12:42:22 +0000 (21:42 +0900)]
test: fix file descriptor leak in test-fs-util

Fixes an issue reported in #22576.

(cherry picked from commit 19962747ca86a25e7102c536380bb2e9d7cfee9a)

3 years agoboot: Handle shift and logo keys too
Jan Janssen [Mon, 21 Feb 2022 12:45:06 +0000 (13:45 +0100)]
boot: Handle shift and logo keys too

Some firmware supports sending input events for shift and logo keys.
Previously, we would suppress these with EFI_NOT_READY unless
some other key was pressed alongside, but it is really the job of the
caller to decide how to handle these.

Note that for keys that already have a printable shift representation
the reported input event will not have the shift key bits set
(Shift+a is reported as A). Should some firmware turn out to violate the
spec here we can always remove that part.

(cherry picked from commit 3f9973bf368475d1f2f7f587e7af728dd6d84e10)

3 years agoboot: Properly check status code of console_key_read
Jan Janssen [Mon, 21 Feb 2022 11:52:30 +0000 (12:52 +0100)]
boot: Properly check status code of console_key_read

In some cases there was a unlikely possibility that we would look
at an uninitialized key value.
Also, returning in case of unexpected input error cases should prevent
infinite looping.

(cherry picked from commit 1cb5d7857b205023a0473ec13df154ae2e254066)

3 years agotest: fix file descriptor leak in test-oomd-util
Yu Watanabe [Tue, 22 Feb 2022 12:38:15 +0000 (21:38 +0900)]
test: fix file descriptor leak in test-oomd-util

Fixes an issue reported in #22576.

(cherry picked from commit 282696ce52471f5e3c963b9d98dbc89fba3a1fba)

3 years agotest: fix file descriptor leak in test-catalog
Yu Watanabe [Tue, 22 Feb 2022 12:11:51 +0000 (21:11 +0900)]
test: fix file descriptor leak in test-catalog

Fixes an issue reported in #22576.

(cherry picked from commit 62d4b3b36e9aba9e605ba042a75c374155b6e18b)

3 years agotest-oomd-util: fix conditional jump on uninitialised value
Yu Watanabe [Tue, 22 Feb 2022 11:23:58 +0000 (20:23 +0900)]
test-oomd-util: fix conditional jump on uninitialised value

Fixes #22577.

(cherry picked from commit a6d6a51d83fae32212e1780e71b16517a4df9a57)

3 years agotest-oomd-util: style fixlets
Yu Watanabe [Tue, 22 Feb 2022 11:21:45 +0000 (20:21 +0900)]
test-oomd-util: style fixlets

(cherry picked from commit d9fe39b24a0a5464c83c7a754752ca21dbd2578f)

3 years agocore: really skip automatic restart when a JOB_STOP job is pending
Franck Bui [Fri, 18 Feb 2022 09:06:24 +0000 (10:06 +0100)]
core: really skip automatic restart when a JOB_STOP job is pending

It's not clear why we rescheduled a service auto restart while a stop job for
the unit was pending. The comment claims that the unit shouldn't be restarted
but the code did reschedule an auto restart meanwhile.

In practice that was rarely an issue because the service waited for the next
auto restart to be rescheduled, letting the queued stop job to be proceed and
service_stop() to be called preventing the next restart to complete.

However when RestartSec=0, the timer expired right away making PID1 to
reschedule the unit again, making the timer expired right away... and so
on. This busy loop prevented PID1 to handle any queued jobs (and hence giving
no chance to the start rate limiting to trigger), which made the busy loop last
forever.

This patch breaks this loop by skipping the reschedule of the unit auto restart
and hence not depending on the value of u->restart_usec anymore.

Fixes: #13667
(cherry picked from commit c972880640ee19e89ce9265d8eae1b3aae190332)

3 years agodocs: swap Name and Partition Type UUID in header
Matthias Lisin [Mon, 21 Feb 2022 01:46:57 +0000 (02:46 +0100)]
docs: swap Name and Partition Type UUID in header

(cherry picked from commit 7d5beae28ca75725a680b0ab3ef5728a252282e5)

3 years agotools: adjust re.match to recent gpt.h additions
Matthias Lisin [Mon, 21 Feb 2022 01:32:25 +0000 (02:32 +0100)]
tools: adjust re.match to recent gpt.h additions

with addition of SD_ID128_MAKE_UUID_STR entries to src/shared/gpt.h the tool
failed halfway due to falsly matching the new entries

(cherry picked from commit 5fa87e9651074e8b78f632e43f0c2001a27f5b60)

3 years agomkosi CI: mask isc-dhcp-server units
Luca Boccassi [Fri, 18 Feb 2022 22:56:56 +0000 (22:56 +0000)]
mkosi CI: mask isc-dhcp-server units

The packages are installed to provide the dhcpd binary, used by
test/test-network/systemd-networkd-tests.py, but we don't need the units
to run, and in fact in some cases the image fails to boot because of
them:

Spawning container image on /home/runner/work/systemd/systemd/image.raw.
Press ^] three times within 1s to kill container.
● isc-dhcp-server.service  loaded failed failed ISC DHCP IPv4 server
● isc-dhcp-server6.service loaded failed failed ISC DHCP IPv6 server
Container image failed with error code 1.
Error: Process completed with exit code 1.

Mask the units with an --extra-tree.

(cherry picked from commit 21838f36a64e71dd6439692e57d629f27e4954ea)

3 years agosystemctl: make `--timestamp=` affect the `show` verb as well
Frantisek Sumsal [Fri, 18 Feb 2022 22:09:18 +0000 (23:09 +0100)]
systemctl: make `--timestamp=` affect the `show` verb as well

Currently the `--timestamp=` option has no effect on timestamps shown by
`systemctl show`, let's fix that.

Spotted in #22567.

Before:
```
$ systemctl show --timestamp=us+utc systemd-journald | grep Timestamp=
ExecMainStartTimestamp=Sat 2021-12-11 15:25:57 CET
StateChangeTimestamp=Sat 2021-12-11 15:25:57 CET
InactiveExitTimestamp=Sat 2021-12-11 15:25:57 CET
ActiveEnterTimestamp=Sat 2021-12-11 15:25:57 CET
ActiveExitTimestamp=Sat 2021-12-11 15:25:57 CET
InactiveEnterTimestamp=Sat 2021-12-11 15:25:57 CET
ConditionTimestamp=Sat 2021-12-11 15:25:57 CET
AssertTimestamp=Sat 2021-12-11 15:25:57 CET
```

After:
```
$ systemctl show --timestamp=us+utc systemd-journald | grep Timestamp=
ExecMainStartTimestamp=Sat 2021-12-11 14:25:57.177848 UTC
StateChangeTimestamp=Sat 2021-12-11 14:25:57.196714 UTC
InactiveExitTimestamp=Sat 2021-12-11 14:25:57.177871 UTC
ActiveEnterTimestamp=Sat 2021-12-11 14:25:57.196714 UTC
ActiveExitTimestamp=Sat 2021-12-11 14:25:57.144677 UTC
InactiveEnterTimestamp=Sat 2021-12-11 14:25:57.176331 UTC
ConditionTimestamp=Sat 2021-12-11 14:25:57.176980 UTC
AssertTimestamp=Sat 2021-12-11 14:25:57.176980 UTC

```

(cherry picked from commit a59e5c625da5a6e0c46e493d55f2f4212e9457ca)

3 years agopid1: set SYSTEMD_NSS_DYNAMIC_BYPASS=1 env var for dbus-daemon
Lennart Poettering [Thu, 17 Feb 2022 13:49:54 +0000 (14:49 +0100)]
pid1: set SYSTEMD_NSS_DYNAMIC_BYPASS=1 env var for dbus-daemon

There's currently a deadlock between PID 1 and dbus-daemon: in some
cases dbus-daemon will do NSS lookups (which are blocking) at the same
time PID 1 synchronously blocks on some call to dbus-daemon. Let's break
that by setting SYSTEMD_NSS_DYNAMIC_BYPASS=1 env var for dbus-daemon,
which will disable synchronously blocking varlink calls from nss-systemd
to PID 1.

In the long run we should fix this differently: remove all synchronous
calls to dbus-daemon from PID 1. This is not trivial however: so far we
had the rule that synchronous calls from PID 1 to the dbus broker are OK
as long as they only go to interfaces implemented by the broke itself
rather than services reachable through it. Given that the relationship
between PID 1 and dbus is kinda special anyway, this was considered
acceptable for the sake of simplicity, since we quite often need
metadata about bus peers from the broker, and the asynchronous logic
would substantially complicate even the simplest method handlers.

This mostly reworks the existing code that sets SYSTEMD_NSS_BYPASS_BUS=
(which is a similar hack to deal with deadlocks between nss-systemd and
dbus-daemon itself) to set SYSTEMD_NSS_DYNAMIC_BYPASS=1 instead. No code
was checking SYSTEMD_NSS_BYPASS_BUS= anymore anyway, and it used to
solve a similar problem, hence it's an obvious piece of code to rework
like this.

Issue originally tracked down by Lukas Märdian. This patch is inspired
and closely based on his patch:

       https://github.com/systemd/systemd/pull/22038

Fixes: #15316
Co-authored-by: Lukas Märdian <slyon@ubuntu.com>
(cherry picked from commit de90700f36f2126528f7ce92df0b5b5d5e277558)

3 years agodocs: $SYSTEMD_NSS_BYPASS_BUS is not honoured anymore, don't document it
Lennart Poettering [Thu, 17 Feb 2022 13:47:34 +0000 (14:47 +0100)]
docs: $SYSTEMD_NSS_BYPASS_BUS is not honoured anymore, don't document it

It was removed back in 1684c56f40f020e685e70b3d1785d596ff16f892

Follow-up for: 1684c56f40f020e685e70b3d1785d596ff16f892

(cherry picked from commit cec16155e3dab4f123ba073223477a4ef2cf10f9)

3 years agopid1: lookup owning PID of BusName= name of services asynchronously
Lennart Poettering [Thu, 17 Feb 2022 13:40:25 +0000 (14:40 +0100)]
pid1: lookup owning PID of BusName= name of services asynchronously

A first step of removing blocking calls to the D-Bus broker from PID 1.
There's a lot more to got (i.e. grep src/core/ for sd_bus_creds
basically), but it's a start.

Removing blocking calls to D-Bus broker deals systematicallly with
deadlocks caused by dbus-daemon blocking on synchronous IPC calls back
to PID1 (e.g. Varlink calls through nss-systemd). Bugs such as #15316.

Also-see: https://github.com/systemd/systemd/pull/22038#issuecomment-1042958390
(cherry picked from commit e39eb045a502d599e6cd3fda7a46020dd438d018)

3 years agopid1: watch bus name always when we have it
Lennart Poettering [Thu, 17 Feb 2022 16:23:48 +0000 (17:23 +0100)]
pid1: watch bus name always when we have it

Previously we'd only watch configured service bus names if Type=dbus was
set. Let's also watch it for other types. This is useful to pick up the
main PID of such a service. In fact the code to pick it up was already
in place, alas it didn't do anything given the signal was never received
for it. Fix that.

(It's also useful for debugging)

(cherry picked from commit 1e8b312e5a22538f91defb89cf2997e09e106297)

3 years agoresolve: synthesize empty domain only when A and/or AAAA key is requested
Yu Watanabe [Fri, 4 Feb 2022 03:05:33 +0000 (12:05 +0900)]
resolve: synthesize empty domain only when A and/or AAAA key is requested

Follow-up for 3b2ac14ac45bef01cf489c3231b868936866444b (#22231).

Before this commit.
---
$ dig -t SRV '.'

; <<>> DiG 9.16.24-RH <<>> -t SRV .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16836
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;. IN SRV

;; Query time: 1 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Feb 04 12:01:09 JST 2022
;; MSG SIZE  rcvd: 28
---

After this commit.
---
$ dig -t SRV '.'

; <<>> DiG 9.16.24-RH <<>> -t SRV .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19861
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;. IN SRV

;; AUTHORITY SECTION:
. 86394 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2022020302 1800 900 604800 86400

;; Query time: 20 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Feb 04 12:00:12 JST 2022
;; MSG SIZE  rcvd: 103
---

Fixes #22401.

(cherry picked from commit 30fa3aa1fa56d9a1a4f3a26c0bc02253d44dfa0f)

3 years agoresolve: make dns_scope_good_domain() take DnsQuery*
Yu Watanabe [Tue, 22 Feb 2022 22:50:30 +0000 (07:50 +0900)]
resolve: make dns_scope_good_domain() take DnsQuery*

(cherry picked from commit 176a9a2cca47f7c1553d96f7dd51c2193a269dbc)

3 years agoresolve: drop never matched condition
Yu Watanabe [Tue, 22 Feb 2022 22:49:40 +0000 (07:49 +0900)]
resolve: drop never matched condition

As dns_scope_good_domain() does not return negative errno.

(cherry picked from commit 830f50ab1e03fa7ee262876ed42023d10e89688d)

3 years agoresolve: synthesize null address, IPv4 broadcast address, or invalid domain
Yu Watanabe [Sun, 23 Jan 2022 21:36:53 +0000 (06:36 +0900)]
resolve: synthesize null address, IPv4 broadcast address, or invalid domain

These are filtered in `dns_scope_good_domain()`, but not synthesized.

Fixes #22229.

(cherry picked from commit 46b53e8035fb60c9a7f26dd32d6689ab3b7da97c)

3 years agoresolve: synthesize empty name
Yu Watanabe [Sun, 23 Jan 2022 21:07:33 +0000 (06:07 +0900)]
resolve: synthesize empty name

Do not return any error for empty name. Just returns empty answer.

Before:
---
$ dig .

; <<>> DiG 9.16.24-RH <<>> .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 13617
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;. IN A

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Mon Jan 24 05:49:30 JST 2022
;; MSG SIZE  rcvd: 28
---

After:
---
$ dig .

; <<>> DiG 9.16.24-RH <<>> .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7957
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;. IN A

;; Query time: 1 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Mon Jan 24 06:05:02 JST 2022
;; MSG SIZE  rcvd: 28
---

Replaces #22197.

Fixes RHBZ#2039854 (https://bugzilla.redhat.com/show_bug.cgi?id=2039854).

(cherry picked from commit 3b2ac14ac45bef01cf489c3231b868936866444b)

3 years agodns-domain: re-introduce dns_name_is_empty()
Yu Watanabe [Sun, 23 Jan 2022 21:06:55 +0000 (06:06 +0900)]
dns-domain: re-introduce dns_name_is_empty()

(cherry picked from commit 7bdf41983044268b4bc2f9d34462db7f89ba284a)

3 years agopackit: drop unnumbered patches as well
Frantisek Sumsal [Thu, 17 Feb 2022 13:02:04 +0000 (14:02 +0100)]
packit: drop unnumbered patches as well

(cherry picked from commit 729c6b6af8e3cef259b80746f7f7f10cc63d309f)

3 years agosd-dhcp-server: do not offer server address
Yu Watanabe [Wed, 16 Feb 2022 15:49:21 +0000 (00:49 +0900)]
sd-dhcp-server: do not offer server address

The server address may be in the pool.

(cherry picked from commit 9e0cb8b61f46a2164290a2380db89e45876b370c)

3 years agosd-dhcp-server: do not assign address reserved for static leases to non-matching...
Yu Watanabe [Thu, 27 Jan 2022 17:25:37 +0000 (02:25 +0900)]
sd-dhcp-server: do not assign address reserved for static leases to non-matching clients

This fix the root cause of the issue #22253.

(cherry picked from commit bd1a3eb65b9e308028c18e1ed7ffde474a3b1244)

3 years agosd-dhcp-server: explicitly refuse when conflicting address is requested
Yu Watanabe [Thu, 27 Jan 2022 18:50:57 +0000 (03:50 +0900)]
sd-dhcp-server: explicitly refuse when conflicting address is requested

(cherry picked from commit 7e98fe05a0b9cdfdad326f34189cd37257d9d4e4)

3 years agosd-dhcp-server: do not assign an address from pool when a static lease for the client...
Yu Watanabe [Thu, 27 Jan 2022 18:50:16 +0000 (03:50 +0900)]
sd-dhcp-server: do not assign an address from pool when a static lease for the client ID exists

(cherry picked from commit e2ba408084935fffa0c73007528de7babf9309c8)

3 years agosd-dhcp-server: rename get_pool_offset() -> address_is_in_pool()
Yu Watanabe [Thu, 27 Jan 2022 17:10:23 +0000 (02:10 +0900)]
sd-dhcp-server: rename get_pool_offset() -> address_is_in_pool()

As, the value of pool_offset is not used.

(cherry picked from commit 5cc8be890db8611b9003304769ec82c3548be6e1)

3 years agosd-dhcp-server: rename server_send_nak() -> server_send_nak_or_ignore()
Yu Watanabe [Thu, 27 Jan 2022 17:14:47 +0000 (02:14 +0900)]
sd-dhcp-server: rename server_send_nak() -> server_send_nak_or_ignore()

And logs error in the function.

(cherry picked from commit eb5bff9c9de2bd218f5ac431e3aead4b5747ecd9)

3 years agosd-dhcp-server: set DHCPLease::server before hashmap_put()
Yu Watanabe [Wed, 26 Jan 2022 15:17:23 +0000 (00:17 +0900)]
sd-dhcp-server: set DHCPLease::server before hashmap_put()

Otherwise, if the second push is failed, then the first hashmap contains
dirty entry.

Also, this makes hashmap_remove_value() used when removing leases to
make not wrong lease is removed from the hashmap.

Note, this just hide the root cause of the issue #22253, which will be
fixed in later commit.

Fixes #22253.

(cherry picked from commit 8a7d048d1ddb8916482f1422405d3e0e4bccb279)

3 years agoci: fix clang-13 installation
Frantisek Sumsal [Tue, 22 Feb 2022 13:43:40 +0000 (14:43 +0100)]
ci: fix clang-13 installation

For some reason Ubuntu Focal repositories now have `llvm-13` virtual
package which can't be installed, but successfully fools our check,
resulting in no clang/llvm being installed...

```
$ apt show llvm-13
Package: llvm-13
State: not a real package (virtual)
N: Can't select candidate version from package llvm-13 as it has no candidate
N: Can't select versions from package 'llvm-13' as it is purely virtual
N: No packages found

$ apt install --dry-run llvm-13
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package llvm-13 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'llvm-13' has no installation candidate
```

(cherry picked from commit b491d74064f9d5e17a71b38b014434237169a077)

3 years agoci: replace apt-key with signed-by
Evgeny Vereshchagin [Sun, 26 Dec 2021 01:11:00 +0000 (01:11 +0000)]
ci: replace apt-key with signed-by

to limit the scope of the key to apt.llvm.org only.

This is mostly inspired by https://blog.cloudflare.com/dont-use-apt-key/

(cherry picked from commit bfa6bd1be098adc4710e1819b9cd34d65b3855da)

3 years agonetwork: dhcp-pd: fix prefix length of address assigned to upstream interface
Yu Watanabe [Sun, 20 Feb 2022 02:23:18 +0000 (11:23 +0900)]
network: dhcp-pd: fix prefix length of address assigned to upstream interface

This effectively revert ab0c82d9f749cc397a6b7e0327ddb2c08cd7d7e0.

I have no idea why I did that...

Fixes #22559.

(cherry picked from commit 38488babe791639860068905177a415822b6b98b)

3 years agoresolve: add reference of the original bus message to the aux queries
Yu Watanabe [Fri, 11 Feb 2022 00:43:16 +0000 (09:43 +0900)]
resolve: add reference of the original bus message to the aux queries

Otherwise, the error in aux queries cannot be replied.

Fixes #22477.

(cherry picked from commit 08275791d85a1852e79951212f6cbbc727db789a)

3 years agoresolve: refuse AF_UNSPEC when resolving address
Yu Watanabe [Fri, 11 Feb 2022 00:49:13 +0000 (09:49 +0900)]
resolve: refuse AF_UNSPEC when resolving address

Fixes #22480.

(cherry picked from commit 0234f0c0531682e7f28a4ef51852c102c6e97267)

3 years agoudev-util: add parentheses to make coverity silent
Yu Watanabe [Fri, 18 Feb 2022 05:06:31 +0000 (14:06 +0900)]
udev-util: add parentheses to make coverity silent

Fixes CID#1474365.

(cherry picked from commit 9fa31df62dd504e8f3e43710df504a467ed430fa)

3 years agonetwork: call ethtool after link is initialized by udevd
Yu Watanabe [Wed, 16 Feb 2022 20:24:26 +0000 (05:24 +0900)]
network: call ethtool after link is initialized by udevd

Fixes #22538.

(cherry picked from commit e1658632aefc963c4a651de433cceb3a9512afd6)

3 years agonetwork: use udev_available() where applicable
Yu Watanabe [Thu, 17 Feb 2022 09:55:24 +0000 (18:55 +0900)]
network: use udev_available() where applicable

(cherry picked from commit 82f52245baa2fe26f1de7b50a036d3746deb7df1)

3 years agoudev-util: introduce udev_available() helper function
Yu Watanabe [Thu, 17 Feb 2022 09:47:26 +0000 (18:47 +0900)]
udev-util: introduce udev_available() helper function

(cherry picked from commit f92c5bb18cee41d48b95d61a2a2dc613203844ca)

3 years agovirt: Fix Xen Dom0 detection logic to no longer report as VM
Richard Neill [Wed, 2 Feb 2022 18:18:46 +0000 (18:18 +0000)]
virt: Fix Xen Dom0 detection logic to no longer report as VM

Fixes regression introduced in 599be274c13c503806c85073d7beb1a155ac27bd

Moving the Xen check before the CPUID check, in order to handle the case where
a Xen domain is nested within a hypervisor which can be detected by via the
CPUID check, had an unintended consequence of causing Dom0 to report as a Xen
VM when it is not nested.

This patch stops further checks once it has been determined that Dom0 is not
nested within another hypervisor, meaning that the non-nested case matches its
previous logic (where it does not report as a VM).

Also, tidy the conditionals for the Xen and UML checks by removing handling of
a VIRTUALIZATION_VM_OTHER result, which has no code path.

Fixes #22511

(cherry picked from commit ea583ed5a366cf51b80bd363db95e828a25ec27e)

3 years agoPartially revert "sd-dhcp-server: refuse too large packet to send"
Luca Boccassi [Tue, 15 Feb 2022 10:21:49 +0000 (10:21 +0000)]
Partially revert "sd-dhcp-server: refuse too large packet to send"

This test fails on this branch:

 949/1228 fuzz-dhcp-server-relay-message_clusterfuzz-testcase-minimized-fuzz-dhcp-server-relay-message-4972399731277824_address,undefined FAIL           0.00s (exit status 127)12:43
--- command ---12:43
01:47:36 UBSAN_OPTIONS='print_stacktrace=1:print_summary=1:halt_on_error=1' /usr/bin/env /tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/build-deb/fuzz-dhcp-server-relay-message:address,undefined /tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/test/fuzz/fuzz-dhcp-server-relay-message/clusterfuzz-testcase-minimized-fuzz-dhcp-server-relay-message-497239973127782412:43
--- stderr ---12:43
/usr/bin/env: ‘/tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/build-deb/fuzz-dhcp-server-relay-message:address,undefined’: No such file or directory

This partially reverts commit 76bcd1d6d26ebe0424e2c5edc7f5a31a82ae3a7c.

3 years agoRevert "tests: add a file triggering a memory leak in dhcp_lease_parse_search_domains"
Luca Boccassi [Tue, 15 Feb 2022 10:20:34 +0000 (10:20 +0000)]
Revert "tests: add a file triggering a memory leak in dhcp_lease_parse_search_domains"

The test fails on this branch:

 948/1228 fuzz-dhcp-client_minimized-from-555a2b073b8d208655b68c294f8dfd592a11e50a_address,undefined                                      FAIL           0.00s (exit status 127)12:43
--- command ---12:43
01:47:36 UBSAN_OPTIONS='print_stacktrace=1:print_summary=1:halt_on_error=1' /usr/bin/env /tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/build-deb/fuzz-dhcp-client:address,undefined /tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/test/fuzz/fuzz-dhcp-client/minimized-from-555a2b073b8d208655b68c294f8dfd592a11e50a12:43
--- stderr ---12:43
/usr/bin/env: ‘/tmp/autopkgtest-lxc.cl7c6fs0/downtmp/build.X6Z/src/build-deb/fuzz-dhcp-client:address,undefined’: No such file or directory

This reverts commit 87728a590ad82391e76a275024c9039625ff2b67.

3 years agomeson: disable export-dbus-interfaces target when cross-compiling
Luca Boccassi [Tue, 8 Feb 2022 13:19:52 +0000 (13:19 +0000)]
meson: disable export-dbus-interfaces target when cross-compiling

ERROR:
Cannot use target systemd as a generator because it is built for the
host machine and no exe wrapper is defined or needs_exe_wrapper is
true. You might want to set `native: true` instead to build it for
the build machine.

(cherry picked from commit 0628d48ec2af1c25bede6d94ae49107b17651b68)

Conflicts:
meson.build

3 years agoboot: Correctly check the return value of CheckEvent
Jan Janssen [Fri, 11 Feb 2022 12:17:23 +0000 (13:17 +0100)]
boot: Correctly check the return value of CheckEvent

Fixes: #22428
(cherry picked from commit ac3979abd7a38725b66c1ce0607fa905b3a3d782)

3 years agotest-network: add missing tests for bridge properties
Yu Watanabe [Thu, 10 Feb 2022 09:04:34 +0000 (18:04 +0900)]
test-network: add missing tests for bridge properties

(cherry picked from commit b6d5dab7bbb8ecf4ce1229840085daa15ab4cf57)

3 years agonetwork: bridge: fix endian of vlan protocol
Yu Watanabe [Thu, 10 Feb 2022 08:47:14 +0000 (17:47 +0900)]
network: bridge: fix endian of vlan protocol

Fixes #22469.

(cherry picked from commit 6eb35be8e0fa5f1f00dddd558cf4dc3642d9e53e)

3 years agojournal: Improve handling of corruption during upwards entry iteration
Daan De Meyer [Mon, 7 Feb 2022 20:19:29 +0000 (20:19 +0000)]
journal: Improve handling of corruption during upwards entry iteration

If we're going upwards in the journal file during entry iteration and we
can't reach the current entry due to corruption, start iterating upwards
from the last reachable entry array. This is equivalent to skipping
all entries in the array that can't be reached anymore.

Fixes #22431

(cherry picked from commit 952d1e784a0ad47e0c2c832d28299987c3c25529)

3 years agojournal: Fix upwards iteration of entry items in case of corruption
Daan De Meyer [Mon, 7 Feb 2022 20:15:07 +0000 (20:15 +0000)]
journal: Fix upwards iteration of entry items in case of corruption

8d801e35cb155faa08235a5af8b4d6ad60715837 didn't take into account
upwards iteration of entry items when we're working on a corrupted
journal file. Instead of moving to the previous entry array, we'd
always move to the next array, regardless of the iteration direction.

To fix this, we introduce bump_entry_array() that moves to the next
or previous entry array depending on the given direction. Since the
entry array chains are singly linked lists, we have to start iterating
from the front to find the previous array. We only reach this logic
if we're working on a corrupted journal file so being slow here shouldn't
matter too much.

(cherry picked from commit aa00163d79309f9873512a4cc14a48c05fee7c65)

3 years agoresolve: reuse timer event source for DnsQuery
Yu Watanabe [Sat, 5 Feb 2022 13:31:06 +0000 (22:31 +0900)]
resolve: reuse timer event source for DnsQuery

If the query get CNAME or DNAME, then the query will be restarted.
Even in that case, previously, the event source was freed and allocated
again. Let's slightly optimize it.

(cherry picked from commit ecdfb9a1ae0a09d22a976e2ca0dc99aacc6b9d1f)

3 years agoresolve: use _cleanup_ attribute for freeing DnsQuery
Yu Watanabe [Sat, 5 Feb 2022 13:04:42 +0000 (22:04 +0900)]
resolve: use _cleanup_ attribute for freeing DnsQuery

(cherry picked from commit c704288c473fa08820566fdb16c38726d24db026)

3 years agoresolve: fix possible memleak
Yu Watanabe [Sat, 5 Feb 2022 13:03:19 +0000 (22:03 +0900)]
resolve: fix possible memleak

Fortunately, unlike the issue fixed in the previous commit, the memleak
should be superficial and not become apparent, as the queries handled
here are managed by the stub stream, and will be freed when the stream
is closed.

Just for safety, and slightly reducing the runtime memory usage by the
stub stream.

(cherry picked from commit fe8c5ce615ee2123f17b1f0b3728c439e19e4b5b)

3 years agoresolve: fix potential memleak and use-after-free
Yu Watanabe [Sat, 5 Feb 2022 12:37:01 +0000 (21:37 +0900)]
resolve: fix potential memleak and use-after-free

When stub stream is closed early, then queries associated to the stream
are freed. Previously, the timer event source for queries may not be
disabled, hence may be triggered with already freed query.
See also dns_stub_stream_complete().

Note that we usually not set NULL or zero when freeing simple objects.
But, here DnsQuery is large and complicated object, and the element may
be referenced in subsequent freeing process in the future. Hence, for
safety, let's set NULL to the pointer.

(cherry picked from commit 73bfd7be042cc63e7649242b377ad494bf74ea4b)

3 years agoutil: another set of CVE-2021-4034 assert()s
Lennart Poettering [Tue, 1 Feb 2022 11:06:21 +0000 (12:06 +0100)]
util: another set of CVE-2021-4034 assert()s

It's a good idea that we validate argc/argv when we are supposed to
store them away.

(cherry picked from commit 007e03b284e8ffc0b92edb2122cd9d2d16f049ef)

3 years agocore: do not attempt to add 'private' symlinks when RootImage/RootDirectory are used
Luca Boccassi [Thu, 27 Jan 2022 14:10:34 +0000 (14:10 +0000)]
core: do not attempt to add 'private' symlinks when RootImage/RootDirectory are used

A bind mount is added directly from private on the host to the actual
destination directory, no need for the symlinks (which cannot be created
as the bind mount happens first and creates the target as an actual directory)

Fixes https://github.com/systemd/systemd/issues/22264

(cherry picked from commit 3fa80e5e75a98ef6f9a84b01770b71a1774478dc)

Conflicts:
test/units/testsuite-50.sh

3 years agocore: add clearer debug log when setting up ExecDirectories symlinks fails
Luca Boccassi [Thu, 27 Jan 2022 14:08:44 +0000 (14:08 +0000)]
core: add clearer debug log when setting up ExecDirectories symlinks fails

(cherry picked from commit 6d7c999ab5958d6f1f192e7d0a63b8c330a077cb)

3 years agotest: use mksquashfs -noappend
Luca Boccassi [Thu, 27 Jan 2022 14:08:05 +0000 (14:08 +0000)]
test: use mksquashfs -noappend

Makes the setup idempotent, as mksquashfs by default attempts to
append to an existing image

(cherry picked from commit 392d46d7a8f78169ff6b0d2740f82924e6fdc878)

3 years agotest: rename service used in TEST-29-PORTABLE to avoid conflict
Luca Boccassi [Thu, 27 Jan 2022 14:07:20 +0000 (14:07 +0000)]
test: rename service used in TEST-29-PORTABLE to avoid conflict

There's an app0.service in the extension app0.raw, so don't use the same
name for a unit in minimal.raw

(cherry picked from commit d76f0de746f4ee7c9014f42b531ba0449b834214)

3 years agosd-dhcp6-client: fix sending prefix delegation request during rebind
Thomas Haller [Thu, 3 Feb 2022 17:55:18 +0000 (18:55 +0100)]
sd-dhcp6-client: fix sending prefix delegation request during rebind

Fixes an assertion failure "pd->type == SD_DHCP6_OPTION_IA_PD" in dhcp6_option_append_pd().

Something similar was done in commit 26a63b81322a ('sd-dhcp6-client: Fix
sending prefix delegation request (#17136)'). The justification is
probably the same.

(cherry picked from commit 58da18251f468de9de4cc7b36804c924e2fd4421)

3 years agotest: add a test for mkdir_p()
Yu Watanabe [Wed, 2 Feb 2022 06:08:18 +0000 (15:08 +0900)]
test: add a test for mkdir_p()

(cherry picked from commit 6f6b017b9bc69df3f3e308c36c95597002ce6e29)

Conflicts:
src/test/meson.build

3 years agomkdir: allow to create directory whose path contains symlink
Yu Watanabe [Wed, 2 Feb 2022 05:20:48 +0000 (14:20 +0900)]
mkdir: allow to create directory whose path contains symlink

Fixes a regression caused by 3008a6f21c1c42efe852d69798a2fdd63fe657ec.

Before the commit, when `mkdir_parents_internal()` is called from `mkdir_p()`,
it uses `_mkdir()` as `flag` is zero. But after the commit, `mkdir_safe_internal()`
is always used. Hence, if the path contains a symlink, it fails with -ENOTDIR.

To fix the issue, this makes `mkdir_p()` calls `mkdir_parents_internal()` with
MKDIR_FOLLOW_SYMLINK flag.

Fixes #22334.

(cherry picked from commit 5117059ee9f84ed2fd37801ec0b90473db475422)

3 years agomkdir: CHASE_NONEXISTENT cannot used in chase_symlinks_and_stat()
Yu Watanabe [Wed, 2 Feb 2022 06:06:27 +0000 (15:06 +0900)]
mkdir: CHASE_NONEXISTENT cannot used in chase_symlinks_and_stat()

(cherry picked from commit e22916e61d1fdb7b46918b605ebf783d9017f9d8)

3 years agocore/mount: fail early if directory cannot be created
Yu Watanabe [Wed, 2 Feb 2022 05:05:45 +0000 (14:05 +0900)]
core/mount: fail early if directory cannot be created

Prompted by #22334.

(cherry picked from commit e4de58c8231e47509ffeb3aa47620ca42f22d7f6)

3 years agounits: we need systemd-journald.service from systemd-journal-flush.service
Lennart Poettering [Tue, 1 Feb 2022 17:11:04 +0000 (18:11 +0100)]
units: we need systemd-journald.service from systemd-journal-flush.service

This is a follow-up for d5ee050ffc9d413253932d9340ade8c8fb111092, and
reintroduces a requirement dep from systemd-journal-flush.service onto
systemd-journald.service, but a weaker one than originally: a Wants= one
instead of a Requires= one.

Why? Simply because the service issues an IPC call to the journald,
hence it should pull it in. (Note that socket activation doesn't happen
for the Varlink socket it uses, hence we should pull in the service
itself.)

(cherry picked from commit 23b1e8d087c9e8c5a2cdcc6a91510a4e7ca8f72f)

3 years agosd-dhcp-lease: fix memleak
Yu Watanabe [Sun, 30 Jan 2022 20:19:09 +0000 (05:19 +0900)]
sd-dhcp-lease: fix memleak

Fixes https://github.com/systemd/systemd/pull/22294#issuecomment-1024840811.

(cherry picked from commit 06cf04dff4dd6c69e527913ad137616c23861270)

3 years agosd-dhcp-lease: fix reading unaligned memory
Yu Watanabe [Sun, 30 Jan 2022 20:04:52 +0000 (05:04 +0900)]
sd-dhcp-lease: fix reading unaligned memory

The destination address was read twice, one is for prefixlen, and
other is for destination address itself. And for prefixlen, the address
might be read from unaligned buffer.

This also modernizes the code.

(cherry picked from commit 7b868543072bb9073174a4ae46032fdb6eb24c92)

3 years agotest-network: set xfrm interface ID
Yu Watanabe [Tue, 1 Feb 2022 04:26:40 +0000 (13:26 +0900)]
test-network: set xfrm interface ID

This also unifies two tests for xfrm, and checks the output of
'ip link' command.

Fixes #22329.

(cherry picked from commit 020483b248b45b15eb93d2ae322d7f211c61e44d)

3 years agonetwork: xfrm: refuse zero interface ID
Yu Watanabe [Tue, 1 Feb 2022 04:00:51 +0000 (13:00 +0900)]
network: xfrm: refuse zero interface ID

Since kernel 5.17-rc1, 5.16.3, and 5.15.17 (more specifically,
https://github.com/torvalds/linux/commit/8dce43919566f06e865f7e8949f5c10d8c2493f5)
the kernel refuses to create an xfrm interface with zero ID.

(cherry picked from commit fd11005951920a0cee96f0c56f36d9ff8bc66a41)

3 years agoexecute: document that the 'env' param is input *and* output
Lennart Poettering [Tue, 1 Feb 2022 12:50:28 +0000 (13:50 +0100)]
execute: document that the 'env' param is input *and* output

(cherry picked from commit 421bb42d1b366c00392ef5bbab6a67412295b6dc)

3 years agoexecute: line break comments a bit less aggressively
Lennart Poettering [Tue, 1 Feb 2022 12:50:13 +0000 (13:50 +0100)]
execute: line break comments a bit less aggressively

(cherry picked from commit cafc5ca147cb05b90bd731661d8594c299601f79)

3 years agoexecute: use _cleanup_ logic where appropriate
Lennart Poettering [Tue, 1 Feb 2022 12:49:56 +0000 (13:49 +0100)]
execute: use _cleanup_ logic where appropriate

(cherry picked from commit 46e5bbab5895b7137b03453dee08bd1c89c710e9)

3 years agopid1: pass PAM_DATA_SILENT to pam_end() in child
Lennart Poettering [Tue, 1 Feb 2022 11:37:51 +0000 (12:37 +0100)]
pid1: pass PAM_DATA_SILENT to pam_end() in child

Fixes: #22318
(cherry picked from commit 7feb2b5737ad110eb3985e8e9d8189f18d1c5147)

3 years agologin: use bus_error_message() at one more place
Yu Watanabe [Sat, 29 Jan 2022 20:38:35 +0000 (05:38 +0900)]
login: use bus_error_message() at one more place

(cherry picked from commit 80c8c786a314bceba180fac5506e72aa48c0764a)

3 years agocore/unit: use bus_error_message() at one more place
Yu Watanabe [Sat, 29 Jan 2022 20:38:01 +0000 (05:38 +0900)]
core/unit: use bus_error_message() at one more place

(cherry picked from commit 33322185554799b08e94aca036dd109aaee52408)

3 years agobus-util: retrieve bus error from message
Yu Watanabe [Sat, 29 Jan 2022 20:36:56 +0000 (05:36 +0900)]
bus-util: retrieve bus error from message

The error in argument is not input, but used for output.

(cherry picked from commit 853b94863cf26d084454edd63ce987cc7ab0505a)

3 years agoboot: Don't require a machine ID to be available
Daan De Meyer [Fri, 28 Jan 2022 15:40:09 +0000 (15:40 +0000)]
boot: Don't require a machine ID to be available

Regression introduced in https://github.com/systemd/systemd/pull/21807.

Fixes #22224

(cherry picked from commit 17e2e8073f3d387035595fcf6c3aa27acb24e2dc)

3 years agocore: don't fail on EEXIST when creating mount point
Luca Boccassi [Fri, 28 Jan 2022 22:56:10 +0000 (22:56 +0000)]
core: don't fail on EEXIST when creating mount point

systemd[1016]: Failed to mount /tmp/app1 (type n/a) on /run/systemd/unit-extensions/1 (MS_BIND ): No such file or directory
systemd[1016]: Failed to create destination mount point node '/run/systemd/unit-extensions/1': File exists

(cherry picked from commit 9d6d4c305ab8d65aab7f546450d7331f760b7259)

3 years agobasic: update CIFS magic
Frantisek Sumsal [Sun, 30 Jan 2022 22:40:05 +0000 (23:40 +0100)]
basic: update CIFS magic

Kernel commit dea2903719283c156b53741126228c4a1b40440f exposed (and
renamed) CIFS_MAGIC_NUMBER as CIFS_SUPER_MAGIC along with
SMB2_SUPER_MAGIC.

This fixes the following build fail on current Fedora Rawhide:
```
../src/basic/meson.build:389:8: ERROR: Problem encountered: found unknown filesystem(s) defined in kernel headers:

Filesystem found in kernel header but not in filesystems-gperf.gperf: CIFS_SUPER_MAGIC
Filesystem found in kernel header but not in filesystems-gperf.gperf: SMB2_SUPER_MAGIC
```

(cherry picked from commit bbe53713455be38c0a587626439fd171f28c77fc)

3 years agosd-dhcp-lease: fix a memory leak in dhcp_lease_parse_search_domains
Evgeny Vereshchagin [Sat, 29 Jan 2022 03:16:40 +0000 (03:16 +0000)]
sd-dhcp-lease: fix a memory leak in dhcp_lease_parse_search_domains

=================================================================
==81071==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x51245c in __interceptor_reallocarray (/home/vagrant/systemd/build/fuzz-dhcp-client+0x51245c)
    #1 0x7f01440c67e6 in strv_push /home/vagrant/systemd/build/../src/basic/strv.c:435:13
    #2 0x7f01440ca9e1 in strv_consume /home/vagrant/systemd/build/../src/basic/strv.c:506:13
    #3 0x7f01440ca9e1 in strv_extend /home/vagrant/systemd/build/../src/basic/strv.c:558:16
    #4 0x5806e3 in dhcp_lease_parse_search_domains /home/vagrant/systemd/build/../src/libsystemd-network/sd-dhcp-lease.c:900:21
    #5 0x57c1be in dhcp_lease_parse_options /home/vagrant/systemd/build/../src/libsystemd-network/sd-dhcp-lease.c:727:21
    #6 0x572450 in parse_options /home/vagrant/systemd/build/../src/libsystemd-network/dhcp-option.c:348:33
    #7 0x571c6a in dhcp_option_parse /home/vagrant/systemd/build/../src/libsystemd-network/dhcp-option.c:376:13
    #8 0x559a01 in client_handle_offer /home/vagrant/systemd/build/../src/libsystemd-network/sd-dhcp-client.c:1543:13
    #9 0x5592bd in LLVMFuzzerTestOneInput /home/vagrant/systemd/build/../src/libsystemd-network/fuzz-dhcp-client.c:74:16
    #10 0x44a379 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/vagrant/systemd/build/fuzz-dhcp-client+0x44a379)
    #11 0x42ae1f in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/home/vagrant/systemd/build/fuzz-dhcp-client+0x42ae1f)
    #12 0x432ade in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/vagrant/systemd/build/fuzz-dhcp-client+0x432ade)
    #13 0x421f86 in main (/home/vagrant/systemd/build/fuzz-dhcp-client+0x421f86)
    #14 0x7f0142fff55f in __libc_start_call_main (/lib64/libc.so.6+0x2d55f)

(cherry picked from commit 9591c0a8b3496d0e5cbbfe7c75161ba80089c143)

3 years agotests: add a file triggering a memory leak in dhcp_lease_parse_search_domains
Evgeny Vereshchagin [Sat, 29 Jan 2022 03:18:31 +0000 (03:18 +0000)]
tests: add a file triggering a memory leak in dhcp_lease_parse_search_domains

(cherry picked from commit 998ec39b1d20a40453a3b47f7eb68feacefd65d9)

3 years agosd-dhcp-lease: fix an infinite loop found by the fuzzer
Evgeny Vereshchagin [Sat, 29 Jan 2022 02:08:39 +0000 (02:08 +0000)]
sd-dhcp-lease: fix an infinite loop found by the fuzzer

(cherry picked from commit 86b06c666be8b7afb45541d35aa4d0ecb38056d1)

3 years agobasic: mac_[selinux,smack]_apply_fd does not work when applying labels
Donald Chan [Fri, 28 Jan 2022 22:53:46 +0000 (22:53 +0000)]
basic: mac_[selinux,smack]_apply_fd does not work when applying labels

Commit a7fdc6c introduced a regression where file descriptors are opened
using O_PATH option. mac_smack_apply_fd() calls fsetxattr() and would fail
with a -EBADF (Bad file descriptor) error.

Use FORMAT_PROC_FD_PATH(fd) to convert the fd back into a full path and
call setxattr() or setfilecon() instead.

Signed-off-by: Donald Chan <hoiho@amazon.com>
(cherry picked from commit a718364e9d9242cc2111c9860f2ab5bb9bb26db9)

3 years agosd-dhcp-server: refuse too large packet to send
Yu Watanabe [Fri, 28 Jan 2022 02:53:49 +0000 (11:53 +0900)]
sd-dhcp-server: refuse too large packet to send

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44134.

(cherry picked from commit 71df50a9734f7006bc1ac8be59ca81c797b39c35)

3 years agologind.conf: Fix name of option: RuntimeDirectoryInodes -> RuntimeDirectoryInodesMax
Arfrever Frehtes Taifersar Arahesis [Thu, 27 Jan 2022 00:00:00 +0000 (00:00 +0000)]
logind.conf: Fix name of option: RuntimeDirectoryInodes -> RuntimeDirectoryInodesMax

(cherry picked from commit a42a93830fcc18da073a5ac06f93c386efc9109d)

3 years agocore/namespace: s/normalize_mounts()/drop_unused_mounts()
Christian Brauner [Mon, 24 Jan 2022 09:12:57 +0000 (10:12 +0100)]
core/namespace: s/normalize_mounts()/drop_unused_mounts()

Rename the normalize_mounts() helper to drop_unused_mounts. All the
helpers called in there get rid of mounts that are unused for a variety
of reasons. And whereas the helpers are aptly prefixed with "drop" the
overall helper isn't and instead uses "normalize".

Make it more obvious what the helper actually does by renaming it from
normalize_mounts() to drop_unused_mounts(). Readers of code calling this
helper will immediately see that it will get rid of unused mounts.

Link: https://github.com/systemd/systemd/issues/22206
(cherry picked from commit fbf90c0d5cadc5d1e95485f770f45a7d4cd39daa)

3 years agocore/namespace: allow using ProtectSubset=pid and ProtectHostname=true together
Christian Brauner [Fri, 21 Jan 2022 12:08:19 +0000 (13:08 +0100)]
core/namespace: allow using ProtectSubset=pid and ProtectHostname=true together

If a service requests both ProtectSubset=pid and ProtectHostname=true
then it will currently fail to start. The ProcSubset=pid option
instructs systemd to mount procfs for the service with subset=pid which
hides all entries other than /proc/<pid>. Consequently trying to
interact with the two files /proc/sys/kernel/{hostname,domainname}
covered by ProtectHostname=true will fail.

Fix this by only performing this check when ProtectSubset=pid is not
requested. Essentially ProtectSubset=pid implies/provides
ProtectHostname=true.

(cherry picked from commit 1361f015773e3b4d74e382edf1565f3315a3396b)

3 years agosd-event: workaround maybe-uninitalized warning in sd_event_add_inotify()
Thomas Haller [Sat, 22 Jan 2022 14:02:04 +0000 (15:02 +0100)]
sd-event: workaround maybe-uninitalized warning in sd_event_add_inotify()

With LTO, the compiler might think that the variable is uninitialized
(from NetworkManager's fork, with gcc-11.2.1-1.fc35):

    src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c: In function 'sd_event_add_inotify':
    src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c:2120: error: 's' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2120 |                 *ret = s;
          |
    src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c:2102: note: 's' was declared here
     2102 |         sd_event_source *s;
          |
    lto1: all warnings being treated as errors

In particular, that would happen for codepaths where event_add_inotify_fd_internal()
returns `-errno`, and the compiler cannot be sure that the returned value will
be negative. Technically, the compiler is right, but we rely on libc functions
to set errno correctly, so this only happens in code paths, where something
bad already happend.

While LTO is prone to such false warnings, we are largely able to build systemd
without warnings. So it is feasible and we should make the effort of working
around warnings as they appear.

(cherry picked from commit 2091c779314133d8a4b68283b255d7388a5ec5ff)

3 years agoFix journald audit logging with fields > N_IOVEC_AUDIT_FIELDS.
YmrDtnJu [Fri, 21 Jan 2022 17:21:27 +0000 (18:21 +0100)]
Fix journald audit logging with fields > N_IOVEC_AUDIT_FIELDS.

ELEMENTSOF(iovec) is not the correct value for the newly introduced parameter m
to function map_all_fields because it is the maximum number of elements in the
iovec array, including those reserved for N_IOVEC_META_FIELDS. The correct
value is the current number of already used elements in the array plus the
maximum number to use for fields decoded from the kernel audit message.

(cherry picked from commit df4ec48f45f518b6926e02ef4d77c8ed1a8b4e2c)

3 years agoudevadm: cleanup-db: don't delete information for kept db entries
Martin Wilck [Thu, 20 Jan 2022 13:31:45 +0000 (14:31 +0100)]
udevadm: cleanup-db: don't delete information for kept db entries

devices with the db_persist property won't be deleted during database
cleanup. This applies to dm and md devices in particular.
For such devices, we should also keep the files under /run/udev/links,
/run/udev/tags, and /run/udev/watch, to make sure that after restart,
udevd has the same information about the devices as it did before
the cleanup.

If we don't do this, a lower-priority device that is discovered in
the coldplug phase may take over symlinks from a device that persisted.
Not removing the watches also enables udevd to resume watching a device
after restart.

Signed-off-by: Martin Wilck <mwilck@suse.com>
(cherry picked from commit 7ec624147a41d80f8e492c9fe19a24e2cda58c25)

3 years agoudevadm: cleanup_dir: use dot_or_dot_dot()
Martin Wilck [Fri, 21 Jan 2022 09:44:26 +0000 (10:44 +0100)]
udevadm: cleanup_dir: use dot_or_dot_dot()

which is safer than just checking dent[0].
Also, fix two style issues.

(cherry picked from commit 28d6e8545151d413f8614db9fa790f9f9edbb045)

3 years agooomd: handle situations when no cgroups are killed
Anita Zhang [Wed, 19 Jan 2022 21:26:01 +0000 (13:26 -0800)]
oomd: handle situations when no cgroups are killed

Currently if systemd-oomd doesn't kill anything in a selected cgroup, it
selects a new candidate immediately. But if a selected cgroup wasn't killed,
it is likely due to it disappearing or getting cleaned up between the time
it was selected as a candidate and getting sent SIGKILL(s). We should handle
it as though systemd-oomd did perform a kill so that it will check
swap/pressure again before it tries to select a new candidate.

(cherry picked from commit 914d4e99f43761f1ce77b520850cf096aa5196cd)

3 years agooomd: fix race with path unavailability when killing cgroups
Anita Zhang [Wed, 19 Jan 2022 18:40:46 +0000 (10:40 -0800)]
oomd: fix race with path unavailability when killing cgroups

There can be a situation where systemd-oomd would kill all of the processes
in a cgroup, pid1 would clean up that cgroup, and systemd-oomd would get
ENODEV trying to iterate the cgroup a final time to ensure it was empty.
systemd-oomd sees this as an error and immediately picks a new candidate even
though pressure may have recovered. To counter this, check and handle
path unavailability errnos specially.

Fixes: #22030
(cherry picked from commit 2ee209466bb51f39ae9df7fec4d5594ce8cfa3f0)