systemd/.git
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)

3 years agoresolve: fix assertion triggered when r == 0
Yu Watanabe [Wed, 19 Jan 2022 20:24:31 +0000 (05:24 +0900)]
resolve: fix assertion triggered when r == 0

Fixes #22178.

(cherry picked from commit 98b1eb711cfc70776fefd3d4ec437a6a4f9aeff2)

3 years agocore: refuse to mount ExtensionImages if the base layer doesn't at least have ID...
Luca Boccassi [Wed, 19 Jan 2022 00:08:57 +0000 (00:08 +0000)]
core: refuse to mount ExtensionImages if the base layer doesn't at least have ID in os-release

We can't match an extension if we don't at least have an ID,
so refuse to continue

(cherry picked from commit 78ab2b5064a0f87579ce5430f9cb83bba0db069a)

3 years agodissect-image: validate extension-release even if the host has only ID in os-release
Luca Boccassi [Wed, 19 Jan 2022 00:01:48 +0000 (00:01 +0000)]
dissect-image: validate extension-release even if the host has only ID in os-release

A rolling distro won't set VERSION_ID or SYSEXT_LEVEL in os-release,
which means we skip validation of ExtensionImages.
Validate even with just an ID, the lower level helper already
recognizes and accepts this use case.

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

(cherry picked from commit 37361f46d571ad0b71ef99dec6a9b76edbab38bb)

3 years agosysext: use LO_FLAGS_PARTSCAN when opening image
Luca Boccassi [Wed, 19 Jan 2022 00:27:45 +0000 (00:27 +0000)]
sysext: use LO_FLAGS_PARTSCAN when opening image

Jan 17 12:34:59 myguest1 (sd-sysext)[486]: Device '/var/lib/extensions/myext.raw' is loopback block device with partition scanning turned off, please turn it on.

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

(cherry picked from commit 70a5c6dce0872b3bb0a39be250adde86a0c8f35c)

3 years agonetwork: dhcp6: do not request address if UseAddress=no
Yu Watanabe [Tue, 11 Jan 2022 11:56:40 +0000 (20:56 +0900)]
network: dhcp6: do not request address if UseAddress=no

Fixes #22068.

(cherry picked from commit d5f8fd5b00e938710b5e80396f8b3fab59dd6d00)

3 years agoboot: Only build with debug symbols in developer mode
Jan Janssen [Fri, 21 Jan 2022 17:34:04 +0000 (18:34 +0100)]
boot: Only build with debug symbols in developer mode

The debug symbols are of very limited use in proper deployments
unlike with regular userspace. Unless someone goes through the pain
of setting up an EFI debugger (assuming their firmware even supports
this in the first place) any provided debug symbols will just be
useless.
Debugging under QEMU is possible, but even then it is non-trivial
to set up, so anyone willing to go that far can just build in
developer mode.

Meanwhile, at least x86 firmware tends to refuse binaries that contain
debug symbols. We do strip the files when converted to PE anyway, but
the elf file needs to stay around on other arches as objcopy does not
support PE as input there.

Also, the generated debug symbols seem to be not reproducible when
building with LTO. Whether this is an issue in tooling or our side
is unclear. This works around this issue.

Fixes: #22157
(cherry picked from commit 76fb85316e9c629b79762457d9515cb632112a6a)

3 years agoboot: Use -ffile-prefix-map when present
Jan Janssen [Wed, 19 Jan 2022 15:37:25 +0000 (16:37 +0100)]
boot: Use -ffile-prefix-map when present

This should make sure the stub elf binary is reproducible.

Fixes: #22157
(cherry picked from commit 1bc8417cfeeebb48b16039f26e0c75937784e75e)

3 years agomeson: Use files() for source lists for boot and fundamental
Jan Janssen [Fri, 7 Jan 2022 20:55:50 +0000 (21:55 +0100)]
meson: Use files() for source lists for boot and fundamental

This fixes build reproducibility as otherwise the full path
of the source files ends up in the output binary.

(cherry picked from commit b3c5a7074cd434bc02c4b560afe933d3df24759e)

3 years agoboot: Build BCD parser only on arches supported by Windows
Jan Janssen [Tue, 28 Dec 2021 12:10:39 +0000 (13:10 +0100)]
boot: Build BCD parser only on arches supported by Windows

(cherry picked from commit 77fcf28cb88b302453b4c991a6571cb37f10634d)

3 years agomeson: move efi file lists closer to where they are used
Zbigniew Jędrzejewski-Szmek [Thu, 23 Dec 2021 11:55:40 +0000 (12:55 +0100)]
meson: move efi file lists closer to where they are used

The goal is to have the detection of features and paths done first, and
then the build target constructions second.

(cherry picked from commit 65dcf9f9a0d877de0dc53558547462a7f1750c78)

3 years agopid1,cgroup-show: ignore -EOPNOTSUPP in cg_read_pid() v250.3
Yu Watanabe [Wed, 12 Jan 2022 15:09:38 +0000 (00:09 +0900)]
pid1,cgroup-show: ignore -EOPNOTSUPP in cg_read_pid()

The function is called in recursion, and cgroup.procs in some subcgroups
may not be read.

Fixes #22089.

(cherry picked from commit 1fb50408ce23e67e0be94ead69c891d26b4823e2)

3 years agostdio-bridge: make the error more straightforward
Zbigniew Jędrzejewski-Szmek [Mon, 17 Jan 2022 10:44:44 +0000 (11:44 +0100)]
stdio-bridge: make the error more straightforward

(cherry picked from commit a80f17844ef1d7c622d17cb4b41eb337d438fffb)

3 years agokernel-install: also remove modules.builtin.alias.bin
Yu Watanabe [Fri, 14 Jan 2022 18:37:40 +0000 (03:37 +0900)]
kernel-install: also remove modules.builtin.alias.bin

Fixes RHBZ#2016630.

(cherry picked from commit 06006691b5c56b6123044179d934b3ed81c237ca)

3 years agoman: enhance the description of systemd-stdio-bridge
Zbigniew Jędrzejewski-Szmek [Mon, 17 Jan 2022 10:43:48 +0000 (11:43 +0100)]
man: enhance the description of systemd-stdio-bridge

I hope that this fixes the comment
https://github.com/systemd/systemd/pull/22141#issuecomment-1013960371
> As someone who doesn't know what this prog does

The listing in the man page is sorted according to logical
use: all the options setting the address are now together.

(cherry picked from commit b7bb58ef70b0c876941a1c31ed4e2f5f1dc5ed0e)

3 years agosystemd-stdio-bridge: add manpage
Luca Boccassi [Sun, 16 Jan 2022 18:41:10 +0000 (18:41 +0000)]
systemd-stdio-bridge: add manpage

(cherry picked from commit cf18de1b265d06b8f72646a11a469e1191826030)

3 years agoman: change 'allow[s] to' -> 'allow[s] one to'
Luca Boccassi [Sun, 16 Jan 2022 12:44:52 +0000 (12:44 +0000)]
man: change 'allow[s] to' -> 'allow[s] one to'

Lintian is opinionated about this and we get nagged

(cherry picked from commit 6eed65d455e9e76b020acbd858c20eafa43cebf8)

3 years agocore: add missing dependency DBus properties
Yu Watanabe [Sun, 16 Jan 2022 06:32:27 +0000 (15:32 +0900)]
core: add missing dependency DBus properties

Follow-up for 0bc488c99ab2ed3464237607e381f4d72cd321d5.

Also sort dependency properties to make them match the definition of
`enum UnitDependency` in basic/unit-def.h.

Fixes #22133.

(cherry picked from commit adc1b76c30940da2f3fb11275f5b0e54ebbcd7f1)

3 years agocore: update log message
Yu Watanabe [Sun, 16 Jan 2022 11:19:19 +0000 (20:19 +0900)]
core: update log message

Fixes CID#1469009.

(cherry picked from commit cc8943b84ad5ffb6d327404ff577d9d185a5c316)

3 years agonetwork: wireguard: also accept negative boolean values to disable adding routes
Yu Watanabe [Sun, 16 Jan 2022 06:59:45 +0000 (15:59 +0900)]
network: wireguard: also accept negative boolean values to disable adding routes

RouteTable=off was introduced to provide consistency with wg-quick
command. This makes the RouteTable= settings accepts other negative
boolean values.

(cherry picked from commit e135559d805e749a0a1f8d1396cf71f6edd94831)

3 years agonetwork: wireguard: do not add routes to AllowedIPs= by default
Yu Watanabe [Sun, 16 Jan 2022 06:53:13 +0000 (15:53 +0900)]
network: wireguard: do not add routes to AllowedIPs= by default

As setting such routes may break existing setups.

Closes #21964.

(cherry picked from commit cfe1237f3859c0cb19b98a47870f49942d5537d9)

3 years agosd-device: silence gcc warning with newest gcc
Zbigniew Jędrzejewski-Szmek [Sat, 15 Jan 2022 12:38:30 +0000 (13:38 +0100)]
sd-device: silence gcc warning with newest gcc

(cherry picked from commit 376ee2c312b87951028a0adff96b1052f32475fa)

3 years agojournal: Fix entry array iteration corruption checks
Daan De Meyer [Wed, 12 Jan 2022 18:10:54 +0000 (18:10 +0000)]
journal: Fix entry array iteration corruption checks

Previously, we'd try to handle corruption by bumping the index even
if it was an entry array object that was corrupted (which we can't
deal with).

Now, we only try to deal with corrupted entry objects by moving the
corruption handling into generic_array_get().

On top, we also add an additional check for -EADDRNOTAVAIL which can
also be caused by corrupted journal data.

(cherry picked from commit 8d801e35cb155faa08235a5af8b4d6ad60715837)

3 years agojournal: Remove unused arguments from journal_file_next_entry_for_data()
Daan De Meyer [Wed, 12 Jan 2022 17:31:57 +0000 (17:31 +0000)]
journal: Remove unused arguments from journal_file_next_entry_for_data()

(cherry picked from commit f2eceb5268f0d26d53db5f9dad318dd45fd900bd)

3 years agoman: Add more details about desktop file processing
Benjamin Berg [Thu, 13 Jan 2022 17:47:08 +0000 (18:47 +0100)]
man: Add more details about desktop file processing

In particular, mention the contract the generator has with external
ExecCondition= binaries that may be provided by desktop environments.

But, also mention all the other relevant keys. In particular
X-systemd-skip= is important to be documented.

(cherry picked from commit 048d46999995847095e3b7a513ba0627e0179dec)

3 years agoboot: Don't try to free loaded_image
Jan Janssen [Thu, 13 Jan 2022 13:29:46 +0000 (14:29 +0100)]
boot: Don't try to free loaded_image

EFI_LOADED_IMAGE is a protocol pointer and thus, we shouldn't try
to free it.

(cherry picked from commit acd28f39126289dd0cb76efc79def673c27c4d04)

3 years agoboot: Fix invalid free
Jan Janssen [Thu, 13 Jan 2022 11:32:07 +0000 (12:32 +0100)]
boot: Fix invalid free

LocateDevicePath() advances the device path pointer, making it invalid
when freed.

(cherry picked from commit 41b74a18b2879e37b1e084f7ab6bd276ce30c6c9)

3 years agotest: add testcase for broken NTP server option
Yu Watanabe [Thu, 13 Jan 2022 11:19:46 +0000 (20:19 +0900)]
test: add testcase for broken NTP server option

For issue #22099.

(cherry picked from commit 95c514e9a50925e3c85f3c3e510fd31caffd5c57)

3 years agotest: voidify test functions
Yu Watanabe [Thu, 13 Jan 2022 09:55:51 +0000 (18:55 +0900)]
test: voidify test functions

This also drops unnecessary arguments, and unbreak several lines.

(cherry picked from commit 37408dd2644e5c337774ccb02f2fc9c31aabeefe)

3 years agosd-dhcp6-client: expose client_parse_message()
Yu Watanabe [Thu, 13 Jan 2022 11:19:01 +0000 (20:19 +0900)]
sd-dhcp6-client: expose client_parse_message()

To introduce tests for the function in later commits.

(cherry picked from commit 16de849fd866c9b75b269ed902c7d591df983174)

3 years agosd-dhcp6-client: ignore broken non-critical options
Yu Watanabe [Thu, 13 Jan 2022 11:13:03 +0000 (20:13 +0900)]
sd-dhcp6-client: ignore broken non-critical options

The commit b89a3758e92894162e3c2dcb594a55acff3274d5 made the validity
check of the received message stricter. E.g. if the client received a
message with broken NTP server option, then the entire message is
dropped.

This relaxes the check. If some non-critical options are broken, then
ignore the options, but the message itself is still accepted.

Fixes #22099.

(cherry picked from commit 0ac9daa4a169f627f5b3f85a4cdcdbd2c2b2e2ca)

3 years agojournal: Don't discard -b arg when followed by -e
Daan De Meyer [Thu, 13 Jan 2022 13:26:25 +0000 (13:26 +0000)]
journal: Don't discard -b arg when followed by -e

Allowing -e to be used to view the last logs of a previous boot seems
like a useful feature so let's not discard -b options anymore when
followed by -e.

Fixes #22107

(cherry picked from commit 4d6455c0754e31ddc9590c7b9c9a373d82ec0ed4)

3 years agojournal: Skip data objects with invalid offsets
Daan De Meyer [Wed, 12 Jan 2022 14:44:50 +0000 (14:44 +0000)]
journal: Skip data objects with invalid offsets

We already skip invalid objects, but don't yet skip invalid offsets.
Let's skip these as well to improve robustness when we're dealing with
corrupted journals.

Before:

```
➜  systemd git:(main) build/journalctl -r -n 5 --file ~/Downloads/system@0005d2b275abaaf8-f243a2818cb39b98.journal_
Failed to get journal fields: Cannot assign requested address
-- No entries --
```

After:

```
➜  systemd git:(main) ✗ build/journalctl -r -n 5 --file ~/Downloads/system@0005d2b275abaaf8-f243a2818cb39b98.journal_
Dec 09 08:32:38 snowball3 NetworkManager[911]: <info>  [1639038758.1464] device (wlp1s0): supplicant interface state: scanning -> authenticating
Dec 09 08:32:38 snowball3 kernel: wlp1s0: send auth to ec:a9:40:79:fb:ad (try 1/3)
Dec 09 08:32:38 snowball3 kernel: wlp1s0: authenticate with ec:a9:40:79:fb:ad
Dec 09 08:32:38 snowball3 wpa_supplicant[1003]: wlp1s0: SME: Trying to authenticate with ec:a9:40:79:fb:ad (SSID='UPC949397B' freq=5500 MHz)
```

(cherry picked from commit df207ccb7be02b1ca6bdd0a2066a898e5b24ee86)

3 years agoxdg-autostart-service: Ignore missing desktop-sepcific condition binary
Benjamin Berg [Mon, 10 Jan 2022 11:35:46 +0000 (12:35 +0100)]
xdg-autostart-service: Ignore missing desktop-sepcific condition binary

If a desktop specific ExecCondition= binary does not exist, this just
means that the desktop environment is not available. As such, it is not
an error condition that should prevent the service from being installed
in the .wants target.

Fix this by simply returning zero.

(cherry picked from commit 6d0aef1dd15088e7379681b3bd93c3cb450f3c55)

3 years agoman+docs: adjust links to the new page
Zbigniew Jędrzejewski-Szmek [Wed, 12 Jan 2022 10:32:53 +0000 (11:32 +0100)]
man+docs: adjust links to the new page

(cherry picked from commit 717e92ceb96471251f8242ad4f4c45cc2c68ecc9)

3 years agopolicy files: adjust landing page link
Zbigniew Jędrzejewski-Szmek [Wed, 12 Jan 2022 09:42:22 +0000 (10:42 +0100)]
policy files: adjust landing page link

(cherry picked from commit d6e2c1ab7158d52425d3cb72459c5624db12368c)

3 years agodocs: use https:// for fd.o links
Zbigniew Jędrzejewski-Szmek [Wed, 12 Jan 2022 09:39:00 +0000 (10:39 +0100)]
docs: use https:// for fd.o links

(cherry picked from commit 931bc1957b13817fcb0ffe69958dd562202c8e4c)

3 years agoREADME: link to the new page
Zbigniew Jędrzejewski-Szmek [Wed, 12 Jan 2022 09:33:57 +0000 (10:33 +0100)]
README: link to the new page

Lennart's blog is now mostly of historical interest, and the wiki
landing page has been replaced by systemd.io.

(cherry picked from commit 2777a4a3bfe153cb675d3d66b383a26043c187b8)

3 years agoNEWS: adjust links to moved pages
Zbigniew Jędrzejewski-Szmek [Wed, 12 Jan 2022 09:33:10 +0000 (10:33 +0100)]
NEWS: adjust links to moved pages

All those pages contain a redirect at the top of the page, so it doesn't
make much sense to tell people to take the detour. Linking directly will
also increase the search rankings of the new pages.

(cherry picked from commit a794a4d87219367e8b24469fcafce83a9f224080)

3 years agofix test-string-util failed when locale is not utf8
yangmingtai [Tue, 11 Jan 2022 12:22:11 +0000 (20:22 +0800)]
fix test-string-util failed when locale is not utf8

(cherry picked from commit 647082cf7f07a87c65601626e86c3ed9f78fb387)

3 years agonss: only read logging config from environment variables
Zbigniew Jędrzejewski-Szmek [Tue, 11 Jan 2022 12:36:39 +0000 (13:36 +0100)]
nss: only read logging config from environment variables

log_parse_environment() uses should_parse_proc_cmdline() to determine whether
it should parse settings from the kernel command line. But the checks that
should_parse_proc_cmdline() apply to the whole process, and we could get a positive
answer also when log_parse_environment() was called from one of the nss modules.
In case of nss-modules, we don't want to look at the kernel command line.

log_parse_environment_variables() that only looks at the environment variables
is split out and used in the nss modules.

Fixes #22020.

(cherry picked from commit a7d15a24659770b0fa9f4cd26fc7bbb17765cbb7)

3 years agonss: drop dummy setup_logging() helpers
Zbigniew Jędrzejewski-Szmek [Tue, 11 Jan 2022 12:23:27 +0000 (13:23 +0100)]
nss: drop dummy setup_logging() helpers

log_parse_environment() stopped being a macro in 9fdee66f2d9.
As reported by @bauen1 in https://github.com/systemd/systemd/issues/22020,
the comment was out of date.

(cherry picked from commit 56a5f4969b96529c82ec8cc08db4fa8e9c61e7b9)

3 years agobootctl: do not update sd-boot if it wasn't installed in the first place
Zbigniew Jędrzejewski-Szmek [Tue, 11 Jan 2022 09:56:50 +0000 (10:56 +0100)]
bootctl: do not update sd-boot if it wasn't installed in the first place

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2038289.

(cherry picked from commit 49927ad81313b77eab09749520d20a8f4ba7cc96)

3 years agobootctl: split out the check whether sd-boot is installed
Zbigniew Jędrzejewski-Szmek [Tue, 11 Jan 2022 09:49:37 +0000 (10:49 +0100)]
bootctl: split out the check whether sd-boot is installed

(cherry picked from commit d9f048b5d113b85b65093f582a8153f79110c49e)

3 years agosd-bus/man: document EBUSY error in bus_message_read (#21954)
lincoln auster [Tue, 11 Jan 2022 10:47:31 +0000 (03:47 -0700)]
sd-bus/man: document EBUSY error in bus_message_read (#21954)

* sd-bus/man: document EBUSY error in bus_message_read

The EBUSY error can be returned from sd_bus_exit_container(), and, if
that happens, it will be propogated upwards towards bus_message_read. In
terms of documentation, this means that bus_message_read's man page
can't just include the error text for sd_bus_message_read_basic, as
reading basic types exclusively doesn't have the potential for this
error.

sd_bus_message_read_basic's error documentation isn't incorrect when
applied to sd_bus_message_read, it's just incomplete.  While EBUSY is
documented in sd_bus_message_open_container.xml,
it's explanation is unique to the sd_bus_message_exit_container function
and makes for poor documentation of the general read API.

(cherry picked from commit a1a03fa54bfb45315eefaa49ceb38a21aceafde8)

3 years agoboot: Fix readdir_harder() on VirtualBox
Jan Janssen [Mon, 10 Jan 2022 10:16:26 +0000 (11:16 +0100)]
boot: Fix readdir_harder() on VirtualBox

Fixes: #22073
(cherry picked from commit ed3abbfbde674bd163cb1c64d9e31dd24e352f85)

3 years agobpf: fix bpf_can_link_lsm_program condition v250.2
Julia Kartseva [Mon, 10 Jan 2022 05:35:35 +0000 (21:35 -0800)]
bpf: fix bpf_can_link_lsm_program condition

Since bpf_can_link_lsm_program return value is boolean, the expression
`r < 0` is always false.

(cherry picked from commit ccfc534deed2f3873c967851497af10d8a1ee01c)

3 years agobpf: check if lsm link ptr is libbpf error
Julia Kartseva [Fri, 7 Jan 2022 23:02:57 +0000 (15:02 -0800)]
bpf: check if lsm link ptr is libbpf error

BPF_RAW_TRACEPOINT_OPEN is expected to work only on x86 and x86_64,
since BPF trampoline is implemented only on these architectures.

Attach probing by bpf_program__attach_lsm already happens in
`bpf_lsm_supported`. The resulting pointer can store libbpf error and
that is the case for unsupported architectures.
Add libbpf error check to `bpf_lsm_supported` so execution does not
reach the point where unit startup fails.

(cherry picked from commit f409aa5c6363144c9711226319614f3b248d9828)

3 years agoshared/rm-rf: loop over nested directories instead of instead of recursing
Zbigniew Jędrzejewski-Szmek [Tue, 30 Nov 2021 21:29:05 +0000 (22:29 +0100)]
shared/rm-rf: loop over nested directories instead of instead of recursing

To remove directory structures, we need to remove the innermost items first,
and then recursively remove higher-level directories. We would recursively
descend into directories and invoke rm_rf_children and rm_rm_children_inner.
This is problematic when too many directories are nested.

Instead, let's create a "TODO" queue. In the the queue, for each level we
hold the DIR* object we were working on, and the name of the directory. This
allows us to leave a partially-processed directory, and restart the removal
loop one level down. When done with the inner directory, we use the name to
unlinkat() it from the parent, and proceed with the removal of other items.

Because the nesting is increased by one level, it is best to view this patch
with -b/--ignore-space-change.

This fixes CVE-2021-3997, https://bugzilla.redhat.com/show_bug.cgi?id=2024639.
The issue was reported and patches reviewed by Qualys Team.
Mauro Matteo Cascella and Riccardo Schirone from Red Hat handled the disclosure.

(cherry picked from commit 5b1cf7a9be37e20133c0208005274ce4a5b5c6a1)

3 years agoshared/rm_rf: refactor rm_rf() to shorten code a bit
Zbigniew Jędrzejewski-Szmek [Tue, 23 Nov 2021 15:56:42 +0000 (16:56 +0100)]
shared/rm_rf: refactor rm_rf() to shorten code a bit

(cherry picked from commit 84ced330020c0bae57bd4628f1f44eec91304e69)

3 years agoshared/rm_rf: refactor rm_rf_children_inner() to shorten code a bit
Zbigniew Jędrzejewski-Szmek [Tue, 23 Nov 2021 14:55:45 +0000 (15:55 +0100)]
shared/rm_rf: refactor rm_rf_children_inner() to shorten code a bit

(cherry picked from commit 3bac86abfa1b1720180840ffb9d06b3d54841c11)