systemd/.git
4 years agosd-bus: fix memstream buffer extraction
Zbigniew Jędrzejewski-Szmek [Thu, 4 Mar 2021 20:19:02 +0000 (21:19 +0100)]
sd-bus: fix memstream buffer extraction

I'm getting the following error under valgrind:

==305970== Invalid free() / delete / delete[] / realloc()
==305970==    at 0x483E9F1: free (vg_replace_malloc.c:538)
==305970==    by 0x4012CD: mfree (alloc-util.h:48)
==305970==    by 0x4012EF: freep (alloc-util.h:83)
==305970==    by 0x4017F4: LLVMFuzzerTestOneInput (fuzz-bus-match.c:58)
==305970==    by 0x401A58: main (fuzz-main.c:39)
==305970==  Address 0x59972f0 is 0 bytes inside a block of size 8,192 free'd
==305970==    at 0x483FCE4: realloc (vg_replace_malloc.c:834)
==305970==    by 0x4C986F7: _IO_mem_finish (in /usr/lib64/libc-2.33.so)
==305970==    by 0x4C8F5E0: fclose@@GLIBC_2.2.5 (in /usr/lib64/libc-2.33.so)
==305970==    by 0x49D2CDB: fclose_nointr (fd-util.c:108)
==305970==    by 0x49D2D3D: safe_fclose (fd-util.c:124)
==305970==    by 0x4A4BCCC: fclosep (fd-util.h:41)
==305970==    by 0x4A4E00F: bus_match_to_string (bus-match.c:859)
==305970==    by 0x4016C2: LLVMFuzzerTestOneInput (fuzz-bus-match.c:58)
==305970==    by 0x401A58: main (fuzz-main.c:39)
==305970==  Block was alloc'd at
==305970==    at 0x483FAE5: calloc (vg_replace_malloc.c:760)
==305970==    by 0x4C98787: open_memstream (in /usr/lib64/libc-2.33.so)
==305970==    by 0x49D56D6: open_memstream_unlocked (fileio.c:97)
==305970==    by 0x4A4DEC5: bus_match_to_string (bus-match.c:859)
==305970==    by 0x4016C2: LLVMFuzzerTestOneInput (fuzz-bus-match.c:58)
==305970==    by 0x401A58: main (fuzz-main.c:39)
==305970==

So the fclose() which is called from _cleanup_fclose_ clearly reallocates the
buffer (maybe to save memory?). open_memstream(3) says:

  The locations referred to by these pointers are updated each time the
  stream is flushed (fflush(3)) and  when the stream is closed (fclose(3)).

This seems to mean that we should close the stream first before grabbing the
buffer pointer.

(cherry picked from commit 5963e6f43c4f33d5255ef0fb887cdf382bd51c9e)

4 years agorun: tweak algorithm for generating unit name from dbus unique name
Lennart Poettering [Thu, 4 Mar 2021 15:23:46 +0000 (16:23 +0100)]
run: tweak algorithm for generating unit name from dbus unique name

This reverts behaviour of systemd-run's unit name generation to the
status quo ante of #18871: we chop off the ":1." prefix if we can.
However, to address the issue that the unique name can overrun we then
do what #18871 did as fallback: only chop off the ":" prefix.

This way we should have pretty names that look like they always looked
in the common case, but in the case of a unique name overrun we still
will have names that work.

Follow-up for #18871

(cherry picked from commit e6283cbf48a3821d03ec73252620fc1b04bd4588)

4 years agotrans_time sec is int32,it will overflow if local system time is later than 2038.
caoxia [Thu, 28 Jan 2021 12:50:08 +0000 (20:50 +0800)]
trans_time sec is int32,it will overflow if local system time is later than 2038.

(cherry picked from commit 370d3c31b4637d1b2faeec555da3283e49a6744f)

4 years agorun: update dbus unique names check
Anita Zhang [Thu, 4 Mar 2021 01:25:40 +0000 (17:25 -0800)]
run: update dbus unique names check

Some code in systemd-run checks that a bus's unique name must start with
`:1.`. However the dbus specification on unique connection names only specifies
that it must begin with a colon. And the freedesktop/dbus implementation allows
allows unique names to go up to `:INT_MAX.INT_MAX`. So update the
current check to only look for a colon at the beginning.

(cherry picked from commit 01584bf9e43db1dfb7ea4ba628f533b3066e81cc)

4 years agocore: fix mtime calculation of dropin files
Zbigniew Jędrzejewski-Szmek [Wed, 3 Mar 2021 23:36:24 +0000 (00:36 +0100)]
core: fix mtime calculation of dropin files

Nominally, the bug was in unit_load_dropin(), which just took the last mtime
instead of calculating the maximum. But instead of adding code to wrap the
loop, this patch goes in the other direction.

All (correct) callers of config_parse() followed a very similar pattern to
calculate the maximum mtime. So let's simplify things by making config_parse()
assume that mtime is initialized and update it to the maximum. This makes all
the callers that care about mtime simpler and also fixes the issue in
unit_load_dropin().

config_parse_many_nulstr() and config_parse_many() are different, because it
makes sense to call them just once, and current ret_mtime behaviour make sense.

Fixes #17730, https://bugzilla.redhat.com/show_bug.cgi?id=1933137.

(cherry picked from commit da46a1bc3cd28ac36114002c216196dae004b05c)

4 years agoudev: add i2c to 60-persistent-input.rules for by-path (#18808)
Tom Shield [Tue, 2 Mar 2021 09:56:06 +0000 (03:56 -0600)]
udev: add i2c to 60-persistent-input.rules for by-path (#18808)

Add the i2c subsystem to those that create by-path links.
i2c devices may not have IDs so we can't rely on the by-id links
but they (or some of them) should at least have a path that we can use.

(cherry picked from commit e595edf1a3d7318811325cf97663c4b5a3859c6e)

4 years agosd-device: don't use BPF filtering for kernel monitors
Martin Wilck [Thu, 25 Feb 2021 16:09:03 +0000 (17:09 +0100)]
sd-device: don't use BPF filtering for kernel monitors

BPF filtering accesses fields in the netlink header that are
only filled in by libudev, never by the kernel. Therefore adding
BPF filters for kernel monitors is pointless. Even false filtering
of kernel events might be possible; at least it's hard to prove that
it can't occur.

(cherry picked from commit d8ce385fe3e5be91b6f414415e10f8897e41d942)

4 years agoFix path typo in systemd.unit
Lajos Veres [Sun, 28 Feb 2021 22:48:08 +0000 (22:48 +0000)]
Fix path typo in systemd.unit

/etc/systemd/systemd/ => /etc/systemd/system/

(cherry picked from commit 57733518817c1217b9f442ca790ff3f50705b1c8)

4 years agoudev: when btrfs.ko is not available consider btrfs filesystems not ready
Lennart Poettering [Thu, 25 Feb 2021 14:04:25 +0000 (15:04 +0100)]
udev: when btrfs.ko is not available consider btrfs filesystems not ready

Let's add a special tweak to the btrfs builtin: if /dev/btrfs-control is
not there, let's consider all btrfs file systems as SYSTEMD_READY=0.
This is useful in initrds, where btrfs.ko might be missing. After the
initrd → host transition we can then retigger the device and undo the
SYSTEMD_READY=0 marking.

(cherry picked from commit 97e535c7248cc0457395e2d62b6e7d6c342a0bd2)

4 years agoman: fix indentation of example
Lennart Poettering [Thu, 25 Feb 2021 13:36:18 +0000 (14:36 +0100)]
man: fix indentation of example

The man page otherwise looks very weirdly aligned.

(cherry picked from commit 8b596d51a9b347f6fe5d130cbb0d26693149ce25)

4 years agoman: advertise shared drop-ins more
Zbigniew Jędrzejewski-Szmek [Thu, 25 Feb 2021 13:54:54 +0000 (14:54 +0100)]
man: advertise shared drop-ins more

systemd.unit(5) is a wall of text. And this particular feature can be very useful
in the context of resource control. Let's avertise this cool feature a bit more.

Fixes #17900.

(cherry picked from commit a8136f1bc03d1bdf93b9071b4f82123b81a05c8e)

4 years agoman: fix two issues in udev(7)
Zbigniew Jędrzejewski-Szmek [Thu, 25 Feb 2021 13:30:34 +0000 (14:30 +0100)]
man: fix two issues in udev(7)

Fixed #18050.

(cherry picked from commit 4fc8a70d9f062b7b51c6c808a24ca3fd22df668f)

4 years agocgroup: don't generate BPF firewall unsupported warning on wrong unit
Lennart Poettering [Wed, 24 Feb 2021 16:49:32 +0000 (17:49 +0100)]
cgroup: don't generate BPF firewall unsupported warning on wrong unit

Let's generate the warning on a unit that actually needs the BPF
firewall, and not confusingly already for a sibling of one.

(cherry picked from commit a437c5e4da666d16f15649461ce45e0e6d735148)

4 years agoresolved: don't discard mDNS queries with bad flags
Sergey Bugaev [Fri, 19 Feb 2021 12:29:02 +0000 (15:29 +0300)]
resolved: don't discard mDNS queries with bad flags

Even though RFC 6762 specifies these bits MUST be zero, it also says they MUST
be ignored on reception.

(cherry picked from commit 2aaf3765974c9f340c0c3d705e9f0609073cf83c)

4 years agoresolved: don't discard mDNS packets with ip6.arpa RRs
Sergey Bugaev [Mon, 15 Feb 2021 16:03:27 +0000 (19:03 +0300)]
resolved: don't discard mDNS packets with ip6.arpa RRs

ip6.arpa is also a valid domain name to put in mDNS packets.

(cherry picked from commit 7675501540980eff80c0e055c219e5e1efde6b62)

4 years agotimedate: do not ignore fix_system argument in SetLocalRTC method
Yu Watanabe [Wed, 24 Feb 2021 04:16:15 +0000 (13:16 +0900)]
timedate: do not ignore fix_system argument in SetLocalRTC method

Fixes #18391.

(cherry picked from commit 2be6c4758e3c27a3f502735881a355e5bfae97b0)

4 years agodhcp6: do not set T1 and T2 by dhcp6_option_append_pd() in client
Yu Watanabe [Mon, 22 Feb 2021 13:39:31 +0000 (22:39 +0900)]
dhcp6: do not set T1 and T2 by dhcp6_option_append_pd() in client

Fixes #18090.

(cherry picked from commit 73b49d433c2c8e6304c8b82538bd4231d070fce4)

4 years agodhcp6: do not set T1 and T2 by dhcp6_option_append_ia() in client
Yu Watanabe [Mon, 22 Feb 2021 12:54:32 +0000 (21:54 +0900)]
dhcp6: do not set T1 and T2 by dhcp6_option_append_ia() in client

(cherry picked from commit e7613578b4747488bef9b558dc35e41d7075f18a)

4 years agodhcp6: make dhcp6_option_parse_{address,pdprefix}() return -EINVAL when received...
Yu Watanabe [Tue, 23 Feb 2021 10:25:17 +0000 (19:25 +0900)]
dhcp6: make dhcp6_option_parse_{address,pdprefix}() return -EINVAL when received address or prefix is refused

And then the caller ignores the error.
Otherwise, `ret_liftime_valid` is not set even if they succeeds.

(cherry picked from commit 1e84213a433f8a80c94dea34514744cc4937efd0)

4 years agodhcp6: do not use input value before checking
Yu Watanabe [Mon, 22 Feb 2021 12:59:24 +0000 (21:59 +0900)]
dhcp6: do not use input value before checking

(cherry picked from commit cf6c33bd6b6ca606f0756312bd73ae066c6aa9a8)

4 years agobootspec: assume that the root dir is at the top of its file system
Lennart Poettering [Tue, 23 Feb 2021 14:02:33 +0000 (15:02 +0100)]
bootspec: assume that the root dir is at the top of its file system

Fixes: #17746
(cherry picked from commit eceb61112c8ece03adfb4fcbc83e357875ca0ceb)

4 years agoman: add a description of how manager env block is set
Zbigniew Jędrzejewski-Szmek [Tue, 23 Feb 2021 16:18:05 +0000 (17:18 +0100)]
man: add a description of how manager env block is set

(cherry picked from commit d51586434677423e97decd0f8c02db0a266dd4e7)

4 years agoefi stub: accept it if our loaded image has no FilePath field set
Lennart Poettering [Tue, 23 Feb 2021 13:16:08 +0000 (14:16 +0100)]
efi stub: accept it if our loaded image has no FilePath field set

The firmware spec doesn't really say whether FilePath of the LoadedImage
protocol may be NULL or not. So far we assumed it to be non-NULL, but
apparently the FreeBSD UEFI chainloader sets it to NULL. Handle this
gracefully.

(Noticed and tracked down by Alexander Schreiber)

Fixes: #18733
(cherry picked from commit 685097b9cadf92d21dfa857c3a7ddc1ba115088e)

4 years agoman: various improvements to systemd.generator(7)
Lennart Poettering [Tue, 23 Feb 2021 13:07:46 +0000 (14:07 +0100)]
man: various improvements to systemd.generator(7)

In particular, make clear the .d/*.conf unit file drop-ins are OK to
generate from generators.

Inspired by: https://lists.freedesktop.org/archives/systemd-devel/2021-February/046148.html

(cherry picked from commit 3acf00a5a4ff656e2799f7f3e2544891b09bbc35)

4 years agoresolved: add another explanatory message to stub resolv.conf files
Zbigniew Jędrzejewski-Szmek [Tue, 23 Feb 2021 00:31:15 +0000 (01:31 +0100)]
resolved: add another explanatory message to stub resolv.conf files

Apparently people do "cat /etc/resolv.conf" and not realize that they
are looking at a file in /run.

(cherry picked from commit 2b767e9222809103cb756e368f0d71e906623bca)

4 years agocryptsetup: unescape ID_PART_ENTRY_NAME udev property before using it
Lennart Poettering [Mon, 22 Feb 2021 16:38:02 +0000 (17:38 +0100)]
cryptsetup: unescape ID_PART_ENTRY_NAME udev property before using it

Fixes: #18729
(cherry picked from commit fadd34dd5af9a26edf2906b237ac212169d39f0c)

4 years agoman: try to improve documentation of conditions/asserts
Lennart Poettering [Mon, 22 Feb 2021 17:12:34 +0000 (18:12 +0100)]
man: try to improve documentation of conditions/asserts

Fixes: #18725
(cherry picked from commit 0a6aa7a238e1130ebe1b797a62da06645fb73ad4)

4 years agoman: correct documentaiton of StandardInput='s defaults in regards to "data"
Lennart Poettering [Mon, 22 Feb 2021 16:52:20 +0000 (17:52 +0100)]
man: correct documentaiton of StandardInput='s defaults in regards to "data"

Fixes: #18710
(cherry picked from commit c6e33c293ecb1cad5f975fe3cd12ec5aff3df221)

4 years agoman: correct the unit file directory for attached images
Tyler Hicks [Sun, 21 Feb 2021 18:53:22 +0000 (12:53 -0600)]
man: correct the unit file directory for attached images

Commit 83f72cd65fb8 ("man,docs: document the new unit file directory for
attached images") updated the docs and man page with the new unit file
directory for attached images but included a system.attached ->
systemd.attached typo in the man page portion of the change. Fix the
typo to document the correct path.

(cherry picked from commit e4d54220a1ffa6629c0aad717a8b7601c0319657)

4 years agosysctl.d: silence warning if net.core.default_qdisc cannot be set
Zbigniew Jędrzejewski-Szmek [Fri, 19 Feb 2021 18:02:38 +0000 (19:02 +0100)]
sysctl.d: silence warning if net.core.default_qdisc cannot be set

Kernels can be compiled without the attribute. It's fine if this is not
set, so silence the warning.

(cherry picked from commit fa98c99ea7f7c5bec3962fa52f4d3496a9777024)

4 years agoxdg-autostart-generator: ignore DBusActivatable=true
Zbigniew Jędrzejewski-Szmek [Fri, 19 Feb 2021 08:50:09 +0000 (09:50 +0100)]
xdg-autostart-generator: ignore DBusActivatable=true

See https://wiki.gnome.org/HowDoI/DBusApplicationLaunching and
https://wiki.gnome.org/Initiatives/GnomeGoals/DBusActivatable for a description
of this key:
> Instead of the typical UNIX-style fork()/exec() approach to process creation,
> launching an application is done by sending a D-Bus message to the well-known
> name of that application, causing a D-Bus activation.
>
> Starting processes with D-Bus activation ensures that each application gets
> started in its own pristine environment, as a direct descendent of the
> session -- not in the environment of whatever its parent happened to be. This
> is important for ensuring the app ends up in the correct cgroup, for example.

So this motivation is not important for us: we launch stuff ourselves better.

This fixes warnings during boot:
systemd-xdg-autostart-generator[2274]: /etc/xdg/autostart/org.freedesktop.problems.applet.desktop:92: Unknown key name 'DBusActivatable' in section 'Desktop Entry', ignoring.

(cherry picked from commit 36290e0b97ba032cbd71723f2255917924eadc05)

4 years agoxdg-autostart-generator: reindent
Zbigniew Jędrzejewski-Szmek [Fri, 19 Feb 2021 08:47:32 +0000 (09:47 +0100)]
xdg-autostart-generator: reindent

(cherry picked from commit 9f11f565556410f9484db9e4991f6c04eeafffc7)

4 years agoRecommend drop-ins over modifications to the main config file
Zbigniew Jędrzejewski-Szmek [Thu, 18 Feb 2021 19:57:06 +0000 (20:57 +0100)]
Recommend drop-ins over modifications to the main config file

As discussed in https://github.com/systemd/systemd/pull/18347.

(cherry picked from commit 09db71a4a3fb9cee19f89cb75ad453caa46209b8)

4 years agorfkill: use short writes and accept long reads
Zbigniew Jędrzejewski-Szmek [Thu, 18 Feb 2021 09:48:08 +0000 (10:48 +0100)]
rfkill: use short writes and accept long reads

I'm seeing the following with kernel-core-5.10.16-200.fc33.x86_64:

$ sudo SYSTEMD_LOG_LEVEL=debug build/systemd-rfkill
Reading struct rfkill_event: got 8 bytes.
A new rfkill device has been added with index 0 and type bluetooth.
Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
Found container virtualization none.
rfkill0: Operating on rfkill device 'tpacpi_bluetooth_sw'.
Writing struct rfkill_event successful (8 of 9 bytes).
Loaded state '0' from /var/lib/systemd/rfkill/platform-thinkpad_acpi:bluetooth.
Reading struct rfkill_event: got 8 bytes.
A new rfkill device has been added with index 1 and type wwan.
rfkill1: Operating on rfkill device 'tpacpi_wwan_sw'.
Writing struct rfkill_event successful (8 of 9 bytes).
Loaded state '0' from /var/lib/systemd/rfkill/platform-thinkpad_acpi:wwan.
Reading struct rfkill_event: got 8 bytes.
A new rfkill device has been added with index 2 and type bluetooth.
rfkill2: Operating on rfkill device 'hci0'.
Writing struct rfkill_event successful (8 of 9 bytes).
Loaded state '0' from /var/lib/systemd/rfkill/pci-0000:00:14.0-usb-0:7:1.0:bluetooth.
Reading struct rfkill_event: got 8 bytes.
A new rfkill device has been added with index 3 and type wlan.
rfkill3: Operating on rfkill device 'phy0'.
Writing struct rfkill_event successful (8 of 9 bytes).
Loaded state '0' from /var/lib/systemd/rfkill/pci-0000:04:00.0:wlan.
All events read and idle, exiting.

We were expecting a read of exactly RFKILL_EVENT_SIZE_V1==8 bytes. But the
structure has 9 after [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=14486c82612a177cb910980c70ba900827ca0894

For some reason the kernel does not accept the full structure size, but cuts
the write short after 8 bytes:

static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
size_t count, loff_t *pos)
{
struct rfkill_event ev;

/* we don't need the 'hard' variable but accept it */
if (count < RFKILL_EVENT_SIZE_V1 - 1)
return -EINVAL;

/*
 * Copy as much data as we can accept into our 'ev' buffer,
 * but tell userspace how much we've copied so it can determine
 * our API version even in a write() call, if it cares.
 */
count = min(count, sizeof(ev));
if (copy_from_user(&ev, buf, count))
return -EFAULT;

... so it should accept the full size. I'm not sure what is going on here.

But we don't care about the extra fields, so let's accept a write as long as
it's at least RFKILL_EVENT_SIZE_V1.

Fixes #18677.

(cherry picked from commit a71c09685021cbcecb7566a00342421f635cc002)

4 years agorfkill: improve error logging
Zbigniew Jędrzejewski-Szmek [Thu, 18 Feb 2021 09:40:16 +0000 (10:40 +0100)]
rfkill: improve error logging

If we get something of unexpected size, log the sizes. Also, don't log twice.

(cherry picked from commit 6c7afdeab010025c80508effd2b0039bc5181b82)

4 years agojournald: when we fail to add a new entry to a journal, return the seqno
Lennart Poettering [Wed, 17 Feb 2021 22:11:42 +0000 (23:11 +0100)]
journald: when we fail to add a new entry to a journal, return the seqno

Fixes: #18005
(cherry picked from commit 0eaee8281d4699903b8b2cce18c836d4a144aee3)

4 years agoRemove outdated disable_ipv6 docs
Richard Laager [Thu, 18 Feb 2021 07:11:53 +0000 (01:11 -0600)]
Remove outdated disable_ipv6 docs

This was changed in commit 482efedc081b0c4bf2e77a3dee6b979d9c9a5765,
which was released in v243, to only enable and never disable IPv6.

Signed-off-by: Richard Laager <rlaager@wiktel.com>
(cherry picked from commit f542f3b2ed3cf3e71692d1736f3fdd0ebdc226ef)

4 years agojournal-file: fix archiving offline journals
Vito Caputo [Sun, 29 Nov 2020 00:28:08 +0000 (16:28 -0800)]
journal-file: fix archiving offline journals

The existing set_offline() short-circuit erroneously included
when f->archive was true and header->state was STATE_OFFLINE.

This commit makes the short-circuit f->archive aware, so it will
only catch scenarios where there's not an offlining in progress
and the header state matches the target state of either archived
or offline.

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

(cherry picked from commit bb1296b55a222cbab24d533006e730529009258c)

4 years agostat-util: fix dir_is_empty_at without path
Luca Boccassi [Mon, 18 Jan 2021 20:15:03 +0000 (20:15 +0000)]
stat-util: fix dir_is_empty_at without path

Use the right FD, and do a fd_reopen instead of a dup, since the
latter will still share the internal pointer which then gets
moved by FOREACH_DIRENT, affecting the caller's FD.

(cherry picked from commit b8f762f2fe59c94323c95d2aadea68612dca2b04)

4 years agojournalctl: rotation is not a reason to warn, but certainly noteworthy
Lennart Poettering [Mon, 15 Feb 2021 22:31:54 +0000 (23:31 +0100)]
journalctl: rotation is not a reason to warn, but certainly noteworthy

Downgrade the phrasing, since it is a bit misleading.

Fixes: #18465
(cherry picked from commit 71311efe2377d7e37a6af76f110882eed2332f4e)

4 years agono blkid for mmcblk[0-9]boot[0-9]
Alan Perry [Sat, 13 Feb 2021 03:08:28 +0000 (19:08 -0800)]
no blkid for mmcblk[0-9]boot[0-9]

Don't run blkid on mmcblk[0-9]boot[0-9] devices because they contain
bootloaders or boot parameters, and not partitions or file systems.

(cherry picked from commit 8db704b28b4fd4d13e376cf3495005010443937e)

4 years agoudev: make net_setup_link builtin quiet when link vanishes while we operate on it
Lennart Poettering [Fri, 12 Feb 2021 20:16:27 +0000 (21:16 +0100)]
udev: make net_setup_link builtin quiet when link vanishes while we operate on it

Fixes: #16175
(cherry picked from commit 3ec2f7f2e3fc04699d8de27d3cc2e5eecf9a3698)

4 years agonetwork: dhcp6: fix condtion check
Yu Watanabe [Wed, 3 Feb 2021 15:52:28 +0000 (00:52 +0900)]
network: dhcp6: fix condtion check

(cherry picked from commit b54aed29c61b9b86dc9cfa214c946586ea1f4972)

4 years agohomework: fix unitialized variable
Zbigniew Jędrzejewski-Szmek [Thu, 11 Feb 2021 11:00:09 +0000 (12:00 +0100)]
homework: fix unitialized variable

Coverity CID#1444703.

(cherry picked from commit a4aa5742f75f0753c4dfa812059af608c9bab7b6)

4 years agofsck: make sure we don't read an unitialized variable
Zbigniew Jędrzejewski-Szmek [Thu, 11 Feb 2021 08:50:49 +0000 (09:50 +0100)]
fsck: make sure we don't read an unitialized variable

This use on %n was completely unnecessary: fprintf returns the number of
characters written. And the issue was that if fprintf failed for whatever
reason, it would not process the %n and m would be unitialized. Rework the
code a bit to simplify it.

Coverity CID#1444708.

(cherry picked from commit 333ab199a12c7b060d3a3f4d50a8f73ee4fd5ebd)

4 years agosd-journal: add forgotten unmap in error path
Zbigniew Jędrzejewski-Szmek [Thu, 11 Feb 2021 08:35:52 +0000 (09:35 +0100)]
sd-journal: add forgotten unmap in error path

Bug introduced in 4b5bc5396c090ee41c45cab9052372d296c4a2f4 :(

Coverity CID#1444709.

(cherry picked from commit 363729c4704b9838f351eaba3acb8b1ed16fae0e)

4 years agoanalyze: slightly reword PrivatTmp= message
Lennart Poettering [Wed, 10 Feb 2021 09:50:23 +0000 (10:50 +0100)]
analyze: slightly reword PrivatTmp= message

Apparently there way confusion about "does not apply". Let's say "is not
appropriate".

Fixes: #13095
(cherry picked from commit 77552b9520ba0d47cbf33cdbe1ddedb9ce9b5bf3)

4 years agoinhibit: cut off overly long "who" fields
Lennart Poettering [Tue, 9 Feb 2021 14:03:46 +0000 (15:03 +0100)]
inhibit: cut off overly long "who" fields

systemd-inhibit when invoked with a command line will put the whole
command line in the "who" field of the inhibitor lock. This can get
extremely long for shell expressions, making the table "systemd-inhibit
--list" shows ridiculously weirdly formatted. Let's put a limit on the
column width: half of the screen, not more.

(cherry picked from commit 619b0c077cbb12b85c9d752779095b99cfd2c66c)

4 years agoformat-table: don't hit assert if column got less width than it asked for
Lennart Poettering [Tue, 9 Feb 2021 14:02:21 +0000 (15:02 +0100)]
format-table: don't hit assert if column got less width than it asked for

If one field in a specific column has a maximum size limit, other fields
in the same column might affected by it and get less than they asked
for. Let's make sure we can handle this, and don't assert on this
because surprisingly we got less than what we asked for.

(cherry picked from commit 2cd9f773e29873df1b9f9b09c6c4f78853b16215)

4 years agoUse correct config parser for MountAPIVFS (#18501)
Antonius Frie [Mon, 8 Feb 2021 08:15:15 +0000 (09:15 +0100)]
Use correct config parser for MountAPIVFS (#18501)

As far as I can see, at some point the parser function for MountAPIVFS
was changed from the generic bool parser to a custom implementation, to
allow the context to keep track of whether MountAPIVFS had been set
explicitly. If not, exec_context_get_effective_mount_apivfs would fall
back to a default value. However, the corresponding entry in the big
parser table wasn't updated, meaning that the old bool parser was still
used, meaning that context->mount_apivfs_set remained at its default
value of false, meaning that the default value was always used and the
config option was effectively ignored.

Fix for 5e98086d1629f5c5b73645ba2568de4b09b7d958.

(cherry picked from commit 4d0052d52f1359a054e83037c733bb3330ba4124)

4 years agoman: fix misspellings of "NameSeviceSwitch"
Julia Cartwright [Fri, 5 Feb 2021 21:16:18 +0000 (15:16 -0600)]
man: fix misspellings of "NameSeviceSwitch"

Fixup NameSeviceSwitch -> NameServiceSwitch spelling error in
documentation.

Found through inspection of documentation.

(cherry picked from commit afe6a9c48e956c8ddfaa0f201cf371b01a22f970)

4 years agoresolved: suppress ifindex info in varlink JSON responses if zero
Lennart Poettering [Fri, 5 Feb 2021 17:43:55 +0000 (18:43 +0100)]
resolved: suppress ifindex info in varlink JSON responses if zero

If we don't have ifindex info, don't set the field for it.

We already do that for parsed IP address replies, let's do it for all
cases: it's a bit nicer to suppress the ifindex prop if it doesn't apply
than to pass it invalid.

This is the other side of #18482, i.e. fixes things so that the parser
doesn't get tripped up by this.

(This too makes a problem go away we should track down properly, i.e.
figure out how the ifindex got lost in
https://github.com/systemd/systemd/pull/17823#issuecomment-742439422 )

(cherry picked from commit f8f5b8d864d3d034dbbfb84fdad4f2cbeb7790f9)

4 years agonss-resolve: shortcut fixing of ifindex if it's zero anyway
Lennart Poettering [Fri, 5 Feb 2021 17:46:18 +0000 (18:46 +0100)]
nss-resolve: shortcut fixing of ifindex if it's zero anyway

(cherry picked from commit 425ed13991153bd274a86009459b00ec8a709f30)

4 years agonss-resolve: accept zero ifindex when parsing resolved reply
Lennart Poettering [Fri, 5 Feb 2021 17:44:22 +0000 (18:44 +0100)]
nss-resolve: accept zero ifindex when parsing resolved reply

Sometimes a reply isn't associated to any specific interface, it might
be a general truth (for example served from /etc/hosts or so). In this
case the server might pass ifindex == 0. Accept that.

https://github.com/systemd/systemd/pull/17823#issuecomment-742439422
(cherry picked from commit 6da52ca861a1cae3f453d50dbb6fac6666a73f4b)

4 years agoPATCH] Always free deserialized_subscribed on reload
Ali Abdallah [Thu, 21 Jan 2021 06:37:21 +0000 (07:37 +0100)]
PATCH] Always free deserialized_subscribed on reload

Otherwise, it will keep consuming memory on systemctl daemon-reload.

(cherry picked from commit 3deed59afdc2c18ecb76fe90b9bba0cd66045dfa)

4 years agocore: map io.bfq.weight to 1..1000
Zbigniew Jędrzejewski-Szmek [Thu, 4 Feb 2021 08:48:19 +0000 (09:48 +0100)]
core: map io.bfq.weight to 1..1000

Aaargh. See the comment in the code.

Apparently the range is like that:
$ sudo bash -c 'echo "default 1001" >/sys/fs/cgroup/user.slice/io.bfq.weight'
bash: line 0: echo: write error: Numerical result out of range

$ uname -r
5.11.0-0.rc4.129.fc34.x86_64

(cherry picked from commit 29eb0eefd14afc9a2424781a28b376db47c3c570)

4 years agoman: reword the description of "main conf file"
Zbigniew Jędrzejewski-Szmek [Thu, 4 Feb 2021 10:05:39 +0000 (11:05 +0100)]
man: reword the description of "main conf file"

While not really "wrong", the text we had could use a little editing.

Fixes #18458.

(cherry picked from commit a7a1887869695f16a1114c355c13d731ed7be109)

4 years agotest-network: add tests for fib rules with Family=both vs networkctl reload or reconf...
Yu Watanabe [Tue, 29 Dec 2020 18:32:07 +0000 (03:32 +0900)]
test-network: add tests for fib rules with Family=both vs networkctl reload or reconfigure

[#18109,7/7] cherry-picked from 49ff3f34d549ad214924548f46a71315b5cd23c6

4 years agonetwork: drop fib rules configured with Family=both
Yu Watanabe [Tue, 29 Dec 2020 18:15:44 +0000 (03:15 +0900)]
network: drop fib rules configured with Family=both

[#18109,6/7] cherry-picked from a75466ed198fad0f50054b4715cfc55c17ffba09

4 years agonetwork: set RoutingPolicyRule::family based on Family= setting
Yu Watanabe [Tue, 29 Dec 2020 18:07:33 +0000 (03:07 +0900)]
network: set RoutingPolicyRule::family based on Family= setting

[#18109,5/7] cherry-picked from 49de8d5cedc9f381a8b61cc9dcd40781cacf7e68

4 years agonetwork: always re-configure rules even if already exist
Yu Watanabe [Tue, 29 Dec 2020 17:45:25 +0000 (02:45 +0900)]
network: always re-configure rules even if already exist

routing_policy_rule_get() in link_set_routing_policy_rules() does not
work when [RoutingPolicyRule] section does not have From= or To=.

[#18109,4/7] cherry-picked from c1934a8f2f37b8e64d4b65f465d823c2a96abbc7

4 years agonetwork: drop unnecessary checks
Yu Watanabe [Tue, 29 Dec 2020 18:17:35 +0000 (03:17 +0900)]
network: drop unnecessary checks

By the previous commit, the checks are not necessary any more.

[#18109,3/7] cherry-picked from 57fe5a42f0975ca12ff856ca221c081a1ad3e87e

4 years agonetwork: constify several arguments
Yu Watanabe [Tue, 29 Dec 2020 17:03:48 +0000 (02:03 +0900)]
network: constify several arguments

[#18109,1/7] cherry-picked from 3141c8173632c100654144faa3d78b84bdffd72f

4 years agonetwork: do not serialize/deserialize routing policy rules
Yu Watanabe [Wed, 28 Oct 2020 08:02:41 +0000 (17:02 +0900)]
network: do not serialize/deserialize routing policy rules

We already handle foreign routing policy rules correctly by the previous
commit. So, the serialization/deserialization of rules are not necessary
anymore.

[#17477,5/5] cherry-picked from a9d240f4bfefcd85de22381f6250e1e1ab58ea55

4 years agonetwork: drop unnecessary routing policy rules
Yu Watanabe [Wed, 28 Oct 2020 11:27:23 +0000 (20:27 +0900)]
network: drop unnecessary routing policy rules

networkd already drop foreign address, routes, and nexthops on startup,
except those created by kernel. However, previously, routing policy
rules were not. The logic of serialization/deserialization of rules only
works for rules created by previous invocation of networkd, and does not
work for one created by other tools like `ip rule`.

This makes networkd drop foreign routing policy rules except created by
kernel on startup. Also, remove rules created by networkd when the
corresponding links are dropped or networkd is stopping.

[#17477,4/5] cherry-picked from 0b81225e5791f660506f7db0ab88078cf296b771

4 years agonetwork: treat rule which has l3mdev flag as created by kernel
Yu Watanabe [Thu, 29 Oct 2020 02:55:12 +0000 (11:55 +0900)]
network: treat rule which has l3mdev flag as created by kernel

[#17477,3/5] cherry-picked from e737dce5445ac2359f4f260aa462056b02d68d54

4 years agonetwork: adjust protocol of rules sent from kernel when kernel does not support FRA_P...
Yu Watanabe [Thu, 29 Oct 2020 02:34:36 +0000 (11:34 +0900)]
network: adjust protocol of rules sent from kernel when kernel does not support FRA_PROTOCOL

Otherwise, each configured rule is treated as foreign.

[#17477,2/5] cherry-picked from 569eeb0c059047601f16b9f6df2bbbc1582793a1

4 years agonetwork: set FRA_PROTOCOL to RTPROT_STATIC by default
Yu Watanabe [Wed, 28 Oct 2020 07:54:51 +0000 (16:54 +0900)]
network: set FRA_PROTOCOL to RTPROT_STATIC by default

[#17477,1/5] cherry-picked from 1e5fd3216a8c73b636ad61e6ebee0c161b6c2063

4 years agonetwork: use netlink_message_read_in_addr_union() where applicable
Yu Watanabe [Wed, 28 Oct 2020 08:28:36 +0000 (17:28 +0900)]
network: use netlink_message_read_in_addr_union() where applicable

[#17960,4/4] cherry-picked from c18c53c36e39f873a7a83e1c0fad1a12c3a650d3

4 years agonetwork: introduce log_routing_policy_rule_debug()
Yu Watanabe [Wed, 28 Oct 2020 08:22:58 +0000 (17:22 +0900)]
network: introduce log_routing_policy_rule_debug()

[#17960,3/4] cherry-picked from ea81208f03afdc03e7e6efd1b5d9515c1ebd4e72

4 years agonetwork: introduce routing_policy_rule_equal()
Yu Watanabe [Thu, 29 Oct 2020 02:41:01 +0000 (11:41 +0900)]
network: introduce routing_policy_rule_equal()

[#17960,2/4] cherry-picked from 40424f1ad97db59958e40a395986a5e248da6f05

4 years agonetwork: make routing_policy_rule_remove() take Manager instead of Link
Yu Watanabe [Wed, 28 Oct 2020 07:16:58 +0000 (16:16 +0900)]
network: make routing_policy_rule_remove() take Manager instead of Link

As routing policy rules are managed by Manager.

[#17960,1/4] cherry-picked from 18f2ee33102d1ff4f658829f971697895d813cfd

4 years agoMountImages: parse unit specifiers after permissive hyphen
Luca Boccassi [Mon, 22 Feb 2021 21:31:44 +0000 (21:31 +0000)]
MountImages: parse unit specifiers after permissive hyphen

The permissive bit it not something a specifier might synthetise

(cherry picked from commit 6c3f7ca036829825f344ffb364354faee5db174e)

4 years agoMountImages: fix exec_context_dump printf
Luca Boccassi [Mon, 22 Feb 2021 10:12:34 +0000 (10:12 +0000)]
MountImages: fix exec_context_dump printf

Use strempty as options might not be set, and add the separator
for each option tuple

(cherry picked from commit 79e20ceb59157662eb32fdf3a7eb1e4d9d8bf00b)

4 years agoMountImages: actually support optional paths
Luca Boccassi [Thu, 28 Jan 2021 13:25:41 +0000 (13:25 +0000)]
MountImages: actually support optional paths

ENOENT did not cause an image mount to be skipped, fix it

(cherry picked from commit b850a9b29f2bc14836415f0c85d42e7d4990285d)

Conflicts:
src/core/namespace.c

4 years agoportablectl: start/stop path/timer units too
Luca Boccassi [Fri, 5 Mar 2021 14:53:20 +0000 (14:53 +0000)]
portablectl: start/stop path/timer units too

Partial backport from:

https://github.com/systemd/systemd/commit/e26fe5f91158a0d9133e61347650dfb73aadd6bb

4 years agosd-netlink: spread out sequence numbers a bit
Lennart Poettering [Wed, 10 Feb 2021 22:05:51 +0000 (23:05 +0100)]
sd-netlink: spread out sequence numbers a bit

An (imperfect) fix for #14760.

This makes collisions unlikely, but still theoretically possible.

Fixes: #14760
(cherry picked from commit ac3bc1b819b66f925145629a5c2ccb0a098f0446)

4 years agosd-netlink: reduce indentation levels a bit
Lennart Poettering [Wed, 10 Feb 2021 17:12:58 +0000 (18:12 +0100)]
sd-netlink: reduce indentation levels a bit

(cherry picked from commit baf78f1a51793c3dbbeb2b420783573d627f85a8)

4 years agosd-netlink: use getsockopt_int() where appropriate
Lennart Poettering [Wed, 10 Feb 2021 17:11:20 +0000 (18:11 +0100)]
sd-netlink: use getsockopt_int() where appropriate

(cherry picked from commit 13ec9f103b53ecc555a16048c3901d3320b26ef3)

4 years agosd-netlink: revamp message serial handling
Lennart Poettering [Wed, 10 Feb 2021 16:59:46 +0000 (17:59 +0100)]
sd-netlink: revamp message serial handling

Let's use uint32_t everywhere to maintain the seqno, since that's what
the kernel does. Prviously in the reply_callback logic we used 64bit,
for no apparent reason.

Using 32bit also provides us with the benefit that we can avoid using
uint64_hash_ops, and can use trivial_hash_ops instead for the reply
hashmap, so that we can store the seqno in the key pointer directly.

While we are at it, let's make sure we never run into serial collisions
internally (32bit is a lot, but not that much), and let's put a limit on
outstanding serials, to catch programming errors.

(cherry picked from commit b522c4b92a1a8999e008002f0a30acbaf58b55e4)

4 years agosocket-util: add getsockopt_int() helper
Lennart Poettering [Mon, 16 Nov 2020 11:41:39 +0000 (12:41 +0100)]
socket-util: add getsockopt_int() helper

(cherry picked from commit 4e25d4cf0f78ef7c960f2b77c941e3d8751535df)

4 years agoresolved: gracefully handle with packets with too large RR count
Lennart Poettering [Tue, 10 Nov 2020 13:48:13 +0000 (14:48 +0100)]
resolved: gracefully handle with packets with too large RR count

Apparently, there are plenty routers in place that report an incorrect
RR count in the packets: they declare more RRs than are actually
included.

Let's accept these responses, but let's downgrade them to baseline, i.e.
let's suppress OPT in this case: if they don't even get the RR count
right, let's operate on the absolute baseline, and not bother with
anything fancier such as EDNS.

Prompted-by: https://github.com/systemd/systemd/issues/12841#issuecomment-724063973
Fixes: #3980
Most likely fixes: #12841

(cherry picked from commit 18674159ebbf622a9e6e5a45cc36b38f74dae315)

4 years agotest: fix fd_is_mount_point() check v247.3
Lennart Poettering [Thu, 17 Dec 2020 15:19:09 +0000 (16:19 +0100)]
test: fix fd_is_mount_point() check

So the currentl and only fd_is_mount_point() check is actually entirely
bogus: it passes "/" as filename argument, but that's not actually a
a valid filename, but an absolute path.

fd_is_mount_point() is written in a way tha the fd refers to a directory
and the specified path is a file directly below it that shall be
checked. The test call actually violated that rule, but still expected
success.

Let's fix this, and check for this explicitly, and refuse it.

Let's extend the test and move it to test-mountpoint-util.c where the
rest of the tests for related calls are placed.

Replaces: #18004
Fixes: #17950
(cherry picked from commit 95231c7215c3ff14c491eb1d2a93312a8fe0c4f6)

4 years agosd-device: make TAGS= property prefixed and suffixed with ":"
Yu Watanabe [Thu, 10 Dec 2020 23:34:13 +0000 (08:34 +0900)]
sd-device: make TAGS= property prefixed and suffixed with ":"

The commit 6f3ac0d51766b0b9101676cefe5c4ba81feba436 drops the prefix and
suffix in TAGS= property. But there exists several rules that have like
`TAGS=="*:tag:*"`. So, the property must be always prefixed and suffixed
with ":".

Fixes #17930.

(cherry picked from commit 8d80f275303385eb9e2452f97f9c11be5c196862)

4 years agosd-device: keep escaped strings in DEVLINK= property
Yu Watanabe [Sun, 6 Dec 2020 12:10:34 +0000 (21:10 +0900)]
sd-device: keep escaped strings in DEVLINK= property

This fixes a bug introduced by 87a4d416e5126b6fb2528ae192a6a6a8033539ce.

Fixes #17772.

(cherry picked from commit 31063db0b4842a452c6eadde5b969aaee2a0516a)

4 years agosd-device: use set_strjoin()
Yu Watanabe [Sun, 6 Dec 2020 11:11:37 +0000 (20:11 +0900)]
sd-device: use set_strjoin()

This slightly changes TAGS= and CURRENT_TAGS= properties:

Before
E: TAGS=:aaa:bbb:

After
E: TAGS=aaa:bbb

(cherry picked from commit 6f3ac0d51766b0b9101676cefe5c4ba81feba436)

4 years agoset: introduce set_strjoin()
Yu Watanabe [Sun, 6 Dec 2020 11:10:48 +0000 (20:10 +0900)]
set: introduce set_strjoin()

(cherry picked from commit 4dbce717873000cff7b56f89266d1d2fe53f9284)

4 years agotools: make update-dbus-docs compatible with Python 3.6
Anita Zhang [Mon, 1 Feb 2021 03:04:34 +0000 (19:04 -0800)]
tools: make update-dbus-docs compatible with Python 3.6

668b3a42fe9e250912bd3efa4460ed691452d9bf allowed update-dbus-docs.py to start
running on Cent OS 8 (instead of skipping). But subprocess.check_output()'s
text argument didn't exist until Python 3.7 and C8 is still running
Python 3.6. Use universal_newlines instead for backwards compatibility.

(cherry picked from commit 934d0d023e33aa38c56e1e12118be8ddbd839284)

4 years agoman: fix small issue in AllowedMemoryNodes description
Pavel Hrdina [Sat, 30 Jan 2021 17:03:40 +0000 (18:03 +0100)]
man: fix small issue in AllowedMemoryNodes description

It should not mention "CPU" but "NUMA nodes".

(cherry picked from commit 16455ee2b1853238cf0e936735ff92e690a20253)

4 years agoman: make it clear how systemd calculate the DefaultTasksMax.
Einsler Lee [Sat, 30 Jan 2021 03:14:35 +0000 (11:14 +0800)]
man: make it clear how systemd calculate the DefaultTasksMax.

Actually, systemd takes the minimum of
* a) the maximum tasks value the kernel allows on this architecture
* b) the cgroups pids_max attribute for the system
* c) the kernel's configured maximum PID value
to calculate the DefaultTasksMax. Here, kernel.thread-max should also be methioned.

(cherry picked from commit 9c587d66187976de49e2d2028cebe1aef5b77b9c)

4 years agoresolved: use reference counting for DnsQueryCandidate objects
Zbigniew Jędrzejewski-Szmek [Fri, 29 Jan 2021 15:21:08 +0000 (16:21 +0100)]
resolved: use reference counting for DnsQueryCandidate objects

Follow-up for 4ea8b443de. The logic that manages DnsQueryCandidate is rather
complicated: a calls to dns_query_complete() that wants to destroy a
DnsQueryCandidate can be nested inside a deep chain of calls. Using reference
counts seems like the simplest approach.

DnsSearchDomain already uses reference counting.

This patch effectively brings dns_query_candidate_go() to the state before
4ea8b443de, but wraps the iteration over DnsQueryCandidate.transactions in
dns_query_candidate_ref+dns_query_candidate_unref.

(cherry picked from commit 0e0fd08fc832b8f42e567d722d388eba086da5ff)

4 years agoresolved: minor cleanups
Zbigniew Jędrzejewski-Szmek [Fri, 29 Jan 2021 15:18:12 +0000 (16:18 +0100)]
resolved: minor cleanups

(cherry picked from commit c805014a350da7c32eb2bdb408a9fa643c191dee)

4 years agotools: make update-dbus-docs compatible with Python 3.7
Luca Boccassi [Tue, 19 Jan 2021 11:57:46 +0000 (11:57 +0000)]
tools: make update-dbus-docs compatible with Python 3.7

Debian Stable uses Python 3.7, but there are a couple of 3.8 features used
in the script. Add fallbacks.

(cherry picked from commit 668b3a42fe9e250912bd3efa4460ed691452d9bf)

4 years agonetwork: drop wrong flag for neighbor entry
Yu Watanabe [Tue, 26 Jan 2021 16:19:24 +0000 (01:19 +0900)]
network: drop wrong flag for neighbor entry

NLM_F_REQUEST is a nlmsg flag, not a neighbor flag.

(cherry picked from commit 4816e7bb75cc573d188f325f14eb59a90357eec2)

4 years agosysusers: flush nscd's caches whenever /etc/{passwd,group} are modified
Franck Bui [Mon, 25 Jan 2021 15:32:44 +0000 (16:32 +0100)]
sysusers: flush nscd's caches whenever /etc/{passwd,group} are modified

(cherry picked from commit d481b8305280cc7780fcd1ce2c391f12ff31786f)

4 years agotree-wide: ignore messages with too long control data
Lennart Poettering [Tue, 19 Jan 2021 20:34:20 +0000 (21:34 +0100)]
tree-wide: ignore messages with too long control data

Apparently SELinux inserts control data into AF_UNIX datagrams where we
don't expect it, thus miscalculating the control data. This looks like
something to fix in SELinux, but we still should handle this gracefully
and just drop the offending datagram and continue.

recvmsg_safe() actually already drops the datagram, it's just a matter
of actually ignoring EXFULL (which it generates if control data is too
large) in the right places.

This does this wherever an AF_UNIX/SOCK_DGRAM socket is used with
recvmsg_safe() that is not just internal communication.

Fixes: #17795
Follow-up for: 3691bcf3c5eebdcca5b4f1c51c745441c57a6cd1

(cherry picked from commit 741bfd7f4e60fdc07ecaadbd93f1196dbee657ca)

4 years agosystemctl: warn when importing environment variables with control characters
Zbigniew Jędrzejewski-Szmek [Tue, 19 Jan 2021 13:20:16 +0000 (14:20 +0100)]
systemctl: warn when importing environment variables with control characters

I don't think it is useful to warn about about environemnt variables where the user
explicitly configured some value. If they went through the effort of escaping the cc
to include it in the setting (e.g. Environment="VAR=\efoo"), and we pass this through,
there isn't anything to warn about. This also applies to 'systemctl set-environment',
where the variable name and value are passed as arguments.

The only case where the warning *might* be useful is where the user might be
surprised by the value. This occurs when importing variables from the inherited
environment, i.e. in 'systemctl import-environment'. In not convinced that this is
useful, since the user better control their shell environment anyway.

$ systemctl import-environment
Calling import-environment without a list of variable names is deprecated.
Environment variable $LESS_TERMCAP_mb contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_md contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_me contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_se contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_so contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_ue contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_us contains control characters, importing anyway.
Environment variable $ZZZ contains control characters, importing anyway.

(cherry picked from commit e9155cd0778499a7e20edd2af8429247bbb1daa9)

4 years agoAllow control characters in environment variable values
Zbigniew Jędrzejewski-Szmek [Sun, 3 Jan 2021 21:26:52 +0000 (22:26 +0100)]
Allow control characters in environment variable values

So far, we would allow certain control characters (NL since
b4346b9a77bc6129dd3e, TAB since 6294aa76d818e831de45), but not others. Having
other control characters in environment variable *value* is expected and widely
used, for various prompts like $LESS, $LESS_TERMCAP_*, and other similar
variables. The typical environment exported by bash already contains a dozen or
so such variables, so programs need to handle them.

We handle then correctly too, for example in 'systemctl show-environment',
since 804ee07c1370d49aa9a. But we would still disallow setting such variables
by the user, in unit file Environment= and in set-environment/import-environment
operations. This is unexpected and confusing and doesn't help with anything
because such variables are present in the environment through other means.

When printing such variables, 'show-environment' escapes all special
characters, so variables with control characters are plainly visible.
In other uses, e.g. 'cat -v' can be used in similar fashion. This would already
need to be done to suppress color codes starting with \[.

Note that we still forbid invalid utf-8 with this patch. (Control characters
are valid, since they are valid 7-bit ascii.) I'm not sure if we should do
that, but since people haven't been actually asking for invalid utf-8, and only
for control characters, and invalid utf-8 causes other issues, I think it's OK
to leave this unchanged.

Fixes #4446, https://gitlab.gnome.org/GNOME/gnome-session/-/issues/45.

(cherry picked from commit 30927a24848c4d727f7619cc74b878f098cdd724)

4 years agosystemctl: print a warning when trying to import a nonexistent variable
Zbigniew Jędrzejewski-Szmek [Sun, 3 Jan 2021 20:53:38 +0000 (21:53 +0100)]
systemctl: print a warning when trying to import a nonexistent variable

I was quite confused what is happening:
$ XXX=xxx
$ systemctl --user import-environment XXX
$ systemctl --user show-environment | grep XXX
(nothing)

Obviously, 'export XXX' was missing. Without any indication why the
export is not happening, this can be hard to figure out.

Another option would be to error out. But so far we didn't, and doing
that could break some script which optimistically tries to export some
variables, if present.

(cherry picked from commit c4899ea427fe93b5b2beac8ab10bfee7dfbf2021)

4 years agoresolved: fix use-after-free with queries hitting the cache
Zbigniew Jędrzejewski-Szmek [Sun, 17 Jan 2021 18:51:28 +0000 (19:51 +0100)]
resolved: fix use-after-free with queries hitting the cache

When dns_transaction_complete() manages to resolve a query, it invalidates the
query candidate object. It shall not be accessed afterwards.

We have the following chain of calls:
dns_query_candidate_go → dns_transaction_go → dns_transaction_prepare → dns_cache_lookup (success: 1)
                                                                      → dns_transaction_complete
After returning back to dns_query_candidate_go(), we'd attempt to continue
iteration over the list of transactions attached to the query candidate,
accessing already freed (and overwritten) memory:

(gdb) bt
0  0x00007f637297cf47 in hashmap_iterate_entry (i=0x7ffe7e15cc90, h=0x706f746b73656465) at ../src/basic/hashmap.c:703
1  _hashmap_iterate (h=0x706f746b73656465, i=i@entry=0x7ffe7e15cc90, value=value@entry=0x7ffe7e15cc88,
    key=key@entry=0x0) at ../src/basic/hashmap.c:712
2  0x00007f637297d01b in set_iterate (s=<optimized out>, i=i@entry=0x7ffe7e15cc90, value=value@entry=0x7ffe7e15cc88)
    at ../src/basic/hashmap.c:733
hence we crash

3  0x0000557bc99eb80f in dns_query_candidate_go (c=c@entry=0x557bcaf86890) at ../src/resolve/resolved-dns-query.c:139
...but c is not valid here in the second iteration of the loop

4  0x0000557bc99eb720 in dns_query_candidate_notify (c=0x557bcaf86890) at ../src/resolve/resolved-dns-query.c:271
c was valid here at entry...

5  0x0000557bc99efe28 in dns_transaction_complete (t=0x557bcac072f0, state=<optimized out>)
    at ../src/resolve/resolved-dns-transaction.c:350
t is a valid transaction (11481 in the backtrace below)

6  0x0000557bc99f1efb in dns_transaction_process_reply (t=0x557bcac072f0, p=<optimized out>)
    at ../src/resolve/resolved-dns-transaction.c:1171
7  0x0000557bc99f2d41 in on_dns_packet (s=<optimized out>, fd=<optimized out>, revents=<optimized out>,
    userdata=0x557bcac072f0) at ../src/resolve/resolved-dns-transaction.c:1223
8  0x00007f6372a25217 in source_dispatch (s=s@entry=0x557bcb162c50) at ../src/libsystemd/sd-event/sd-event.c:3181
9  0x00007f6372a254fd in sd_event_dispatch (e=0x557bcb15b050) at ../src/libsystemd/sd-event/sd-event.c:3620
10 0x00007f6372a267c8 in sd_event_run (e=e@entry=0x557bcb15b050, timeout=timeout@entry=18446744073709551615)
    at ../src/libsystemd/sd-event/sd-event.c:3678
11 0x00007f6372a269ef in sd_event_loop (e=0x557bcb15b050) at ../src/libsystemd/sd-event/sd-event.c:3700
12 0x0000557bc99ddc14 in run (argc=<optimized out>, argv=<optimized out>) at ../src/resolve/resolved.c:92
13 0x0000557bc99d260a in main (argc=<optimized out>, argv=<optimized out>) at ../src/resolve/resolved.c:99

xxx.name.net systemd-resolved[31705]: Got message type=method_call sender=:1.3644 destination=org.freedesktop.resolve1 path=/org/freedesktop/resolve1 interface=org.freedesktop.resolve1.Manager member=ResolveHostname cookie=2 reply_cookie=0 signature=isit error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: idn2_lookup_u8: xxx → xxx
xxx.name.net systemd-resolved[31705]: Looking up RR for xxx IN A.
xxx.name.net systemd-resolved[31705]: Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=AddMatch cookie=1102 reply_cookie=0 signature=s error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=GetNameOwner cookie=1103 reply_cookie=0 signature=s error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Got message type=method_return sender=org.freedesktop.DBus destination=:1.3324 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1103 signature=s error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Cache miss for xxx.name.net IN A
xxx.name.net systemd-resolved[31705]: Transaction 11481 for <xxx.name.net IN A> scope dns on enp42s0/*.
xxx.name.net systemd-resolved[31705]: Using feature level UDP for transaction 11481.
xxx.name.net systemd-resolved[31705]: Using DNS server 192.168.1.1 for transaction 11481.
xxx.name.net systemd-resolved[31705]: Sending query packet with id 11481 of size 35.
xxx.name.net systemd-resolved[31705]: Got message type=method_return sender=org.freedesktop.DBus destination=:1.3324 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1102 signature= error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Match type='signal',sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0=':1.3644' successfully installed.
xxx.name.net systemd-resolved[31705]: Processing incoming packet on transaction 11481 (rcode=NXDOMAIN).
xxx.name.net systemd-resolved[31705]: Not caching negative entry without a SOA record: xxx.name.net IN A
xxx.name.net systemd-resolved[31705]: Transaction 11481 for <xxx.name.net IN A> on scope dns on enp42s0/* now complete with <rcode-failure> from network (unsigned).
xxx.name.net systemd-resolved[31705]: Positive cache hit for xxx.lan IN A
xxx.name.net systemd-resolved[31705]: Transaction 64364 for <xxx.lan IN A> on scope dns on enp42s0/* now complete with <success> from cache (unsigned).
xxx.name.net systemd-resolved[31705]: Sent message type=method_return sender=n/a destination=:1.3644 path=n/a interface=n/a member=n/a cookie=1104 reply_cookie=2 signature=a(iiay)st error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RemoveMatch cookie=1105 reply_cookie=0 signature=s error-name=n/a error-message=n/a
xxx.name.net systemd-resolved[31705]: Freeing transaction 64364.
xxx.name.net systemd[1]: systemd-resolved.service: Main process exited, code=dumped, status=11/SEGV
xxx.name.net systemd[1]: systemd-resolved.service: Failed with result 'core-dump'.

Fixes #16168, https://bugzilla.redhat.com/show_bug.cgi?id=1895937.

(cherry picked from commit 4ea8b443de8be0f7a932f325dfafa1ee2a843795)