systemd/.git
5 years agonspawn: move payload to sub-cgroup first, then sync cgroup trees
Lennart Poettering [Tue, 5 Mar 2019 17:57:53 +0000 (18:57 +0100)]
nspawn: move payload to sub-cgroup first, then sync cgroup trees

if we sync the legacy and unified trees before moving to the right
subcgroup then ultimately the cgroup paths in the hierarchies will be
out-of-sync... Hence, let's move the payload first, and sync then.

Addresses: https://github.com/systemd/systemd/pull/9762#issuecomment-441187979
(cherry picked from commit 27da7ef0d09e00eae821f3ef26e1a666fe7aa087)
(cherry picked from commit 8ee1465520ad49892a0a378626ef93abc03f4d4e)

Resolves: #1837423

5 years agoudev-rules: make tape-changers also apprear in /dev/tape/by-path/
Joerg Steffens [Tue, 21 Nov 2017 11:21:49 +0000 (12:21 +0100)]
udev-rules: make tape-changers also apprear in /dev/tape/by-path/

It is important to be able to access tape changer ("Medium Changers") by
persistant name.
While tape devices can be accessed via /dev/tape/by-id/ and
/dev/tape/by-path/, tape-changers could only be accessed by
/dev/tape/by-id/.
However, in some cases, especially when accessing Amazon Webservice
Storage Gateway VTLs (or accessing iSCSI VTLs in general?) this does not
work, as all tape devices and the tape changer have the same ENV{ID_SERIAL}.
The results is, that only the last device is available in
/dev/tape/by-id/, as the former devices have been overwritten.

As this behavior is hard to change without breaking consistentcy,
this additional device in /dev/tape/by-path/ can be used to access the medium changes.
The tape devices can also be accessed by this path.

The content of the directory will now look like:

  # SCSI tape device, rewind (unchanged)
  /dev/tape/by-path/$env{ID_PATH} -> ../../st*

  # SCSI tape device, no-rewind (unchanged)
  /dev/tape/by-path/$env{ID_PATH}-nst -> ../../nst*

  # SCSI tape changer device (newly added)
  /dev/tape/by-path/$env{ID_PATH}-changer -> ../../sg*

Tape devices and tape changer have different ID_PATHs.
SCSI tape changer get the suffix "-changer"
to make them better distinguishable from tape devices.

(cherry picked from commit 7f8ddf96a25162f06bd94a684cf700c128d18142)
(cherry picked from commit f60e89ea4c38c11a9d0c1e642c0a78faa32aca56)
Resolves: #1836981

5 years agotest: store coredumps in journal
Frantisek Sumsal [Mon, 12 Aug 2019 22:14:54 +0000 (00:14 +0200)]
test: store coredumps in journal

To make debugging much easier, especially for crashes in tests under
QEMU, let's store the entire coredump bundle in the systemd journal,
which is usually kept around by various CIs. Right now, we usually end
up with a journal, but without the coredump itself, which is pretty
useless.

(cherry picked from commit 215bffe1b8d7cb72fe9f72ed53682d52d5c2a9c5)
(cherry picked from commit cac1e15554b8e3f102e00ac802cff7100b1def22)

Resolves: #1836979

5 years agotest: try to determine QEMU_SMP dynamically
Frantisek Sumsal [Tue, 5 Mar 2019 15:08:00 +0000 (16:08 +0100)]
test: try to determine QEMU_SMP dynamically

If the QEMU_SMP value has not been explicitly set, try to determine it
from the number of online CPUs using the nproc utility. If this approach
fails, fall back to the default value QEMU_SMP=1.

This change should significantly help when running integration tests
under QEMU on multicore systems.

(cherry picked from commit 5bfb2a93a4a36bba0d24199553dcda6e560cbb75)
(cherry picked from commit dd166ab28360ceeb821d7b6d04e3c360b9023896)

Resolves: #1836979

5 years agotest: parallelize tasks in TEST-24-UNIT-TESTS
Frantisek Sumsal [Tue, 5 Mar 2019 12:50:28 +0000 (13:50 +0100)]
test: parallelize tasks in TEST-24-UNIT-TESTS

(cherry picked from commit 2f2a0454efd07644a4e0ccb3f00f1db2d7043391)
(cherry picked from commit c06e3ad98d2d6bc03d3ed2cdeb1e73283702ef3a)

Resolves: #1836979

5 years agotest: make test-catalog relocatable
Yu Watanabe [Tue, 11 Sep 2018 00:18:33 +0000 (09:18 +0900)]
test: make test-catalog relocatable

Fixes #10045.

(cherry picked from commit d9b6baa69968132d33e4ad8627c7fe0bd527c859)
(cherry picked from commit 444ad721dc163d4952bb35a0b061e57c91bfc9ff)

Resolves: #1836979

5 years agotest: introduce test_is_running_from_builddir()
Yu Watanabe [Tue, 11 Sep 2018 00:17:22 +0000 (09:17 +0900)]
test: introduce test_is_running_from_builddir()

(cherry picked from commit 8cb10a4f4dabc508a04f76ea55f23ef517881b61)
(cherry picked from commit 4fa54d7a72600788349fc363b7814bb52849b5e6)

Resolves: #1836979

5 years agotest-execute: skip several tests when running in container
Yu Watanabe [Fri, 14 Sep 2018 06:47:42 +0000 (15:47 +0900)]
test-execute: skip several tests when running in container

(cherry picked from commit 642d1a6d6e98204ade25816bcc429cb67df92a29)
(cherry picked from commit 3a8ebd888d97c9f83df724264b47475e315d1a20)

Resolves: #1836979

5 years agotest-execute: also check python3 is installed or not
Yu Watanabe [Wed, 12 Sep 2018 09:18:33 +0000 (18:18 +0900)]
test-execute: also check python3 is installed or not

(cherry picked from commit 738c74d7b163ea18e3c68115c3ed8ceed166cbf7)
(cherry picked from commit 6750925014bcd2d2289af08cdc5d81b673c36779)

Resolves: #1836979

5 years agotest-process-util: skip several verifications when running in unprivileged container
Yu Watanabe [Thu, 20 Sep 2018 07:08:38 +0000 (16:08 +0900)]
test-process-util: skip several verifications when running in unprivileged container

(cherry picked from commit 767eab47501b06327a0e6030e5c54860a3fc427f)
(cherry picked from commit 2bc26a0ac181124ba06022bcf4744ae7d5bdcc9d)

Resolves: #1836979

5 years agotest-fs-util: skip some tests when running in unprivileged container
Yu Watanabe [Fri, 14 Sep 2018 06:51:04 +0000 (15:51 +0900)]
test-fs-util: skip some tests when running in unprivileged container

(cherry picked from commit 9590065f37be040996f1c2b9a246b9952fdc0c0b)
(cherry picked from commit bf2234c276fd14ac78e2c559c762751ea6145441)

Resolves: #1836979

5 years agotest: make install_keymaps() optionally install more keymaps
Yu Watanabe [Wed, 19 Sep 2018 01:54:28 +0000 (10:54 +0900)]
test: make install_keymaps() optionally install more keymaps

(cherry picked from commit ad931fee506e1313e8a520ae0ecc1c8e275d9941)
(cherry picked from commit bc06966ff3d335102287a4d0ec525e527bc6a139)

Resolves: #1836979

5 years agotest: add paths of keymaps in install_keymaps()
Yu Watanabe [Wed, 19 Sep 2018 01:54:16 +0000 (10:54 +0900)]
test: add paths of keymaps in install_keymaps()

It seems that the paths of directories storing keymaps are changed.

(cherry picked from commit 83a7051ee1edbfe8cd2278477d23083beb385409)
(cherry picked from commit 808bf3d4c789019fd7cc1a0568f3836e200d9550)

Resolves: #1836979

5 years agotest: replace duplicated Makefile by symbolic link
Yu Watanabe [Wed, 12 Sep 2018 18:01:42 +0000 (03:01 +0900)]
test: replace duplicated Makefile by symbolic link

(cherry picked from commit dd75c133d81f07c56c82ee4e7a80f391ffebd9ce)
(cherry picked from commit e02d918ddcc77b9ad87a328482b7a2c6f95d31ce)

Resolves: #1836979

5 years agotest: introduce install_zoneinfo()
Yu Watanabe [Wed, 12 Sep 2018 09:20:31 +0000 (18:20 +0900)]
test: introduce install_zoneinfo()

But it is not called by default.

(cherry picked from commit 7d10ec1cda8fed20c36b16d2387f529583645cda)
(cherry picked from commit a66d62e7c8c28d9e5382362a279d1dfa06089996)

Resolves: #1836979

5 years agotest: install libraries required by tests
Yu Watanabe [Wed, 12 Sep 2018 09:19:45 +0000 (18:19 +0900)]
test: install libraries required by tests

(cherry picked from commit e3d3dada248c5f30e2978840ca1f0a03a4675b53)
(cherry picked from commit 813d60bd9d668eb1e5c897edbea966bfae25647c)

Resolves: #1836979

5 years agotest: do not use global variable to pass error
Yu Watanabe [Fri, 14 Sep 2018 04:25:02 +0000 (13:25 +0900)]
test: do not use global variable to pass error

(cherry picked from commit 0013fac248a15be3acce84c17a65e3ae0377294b)
(cherry picked from commit a521c49bd30f6b985bb43284d7162b7b68ec7d1c)

Resolves: #1836979

5 years agosd-journal: remove the dead code and actually fix #14695 v239-31.1
Michal Sekletár [Fri, 27 Mar 2020 16:01:59 +0000 (17:01 +0100)]
sd-journal: remove the dead code and actually fix #14695

journal_file_fstat() returns an error if we call it on already unlinked
journal file and hence we never reach remove_file_real() which is the
entire point.

I must have made some mistake while testing the fix that got me thinking
the issue is gone while opposite was true.

Fixes #14695

(cherry picked from commit 8581b9f9732d4c158bb5f773230a65ce77f2c292)

Resolves: #1826217

5 years agosd-journal: close journal files that were deleted by journald before we've setup...
Michal Sekletár [Tue, 4 Feb 2020 13:23:14 +0000 (14:23 +0100)]
sd-journal: close journal files that were deleted by journald before we've setup inotify watch

Fixes #14695

(cherry picked from commit 28ca867abdb20d0e4ac1901e2ed669cdb41ea3f6)

Related: #1826217

5 years agopid1: add new kernel cmdline arg systemd.cpu_affinity= v239-31
Lennart Poettering [Tue, 26 Nov 2019 08:46:00 +0000 (09:46 +0100)]
pid1: add new kernel cmdline arg systemd.cpu_affinity=

Let's allow configuration of the CPU affinity via the kernel cmdline,
overriding CPUAffinity= in /etc/systemd/system.conf

Prompted by:

https://lists.freedesktop.org/archives/systemd-devel/2019-November/043754.html

(cherry picked from commit 68d58f38693e586b5ce5785274f8e42a79625196)

Resolves: #1827621

5 years agoswap: finish the secondary swap units' jobs if deactivation of the primary swap unit...
HATAYAMA Daisuke [Thu, 25 Jul 2019 03:54:48 +0000 (23:54 -0400)]
swap: finish the secondary swap units' jobs if deactivation of the primary swap unit fails

Currently, if deactivation of the primary swap unit fails:

    # LANG=C systemctl --no-pager stop dev-mapper-fedora\\x2dswap.swap
    Job for dev-mapper-fedora\x2dswap.swap failed.
    See "systemctl status "dev-mapper-fedora\\x2dswap.swap"" and "journalctl -xe" for details.

then there are still the running stop jobs for all the secondary swap units
that follow the primary one:

    # systemctl list-jobs
     JOB UNIT                                                                                                         TYPE STATE
     3233 dev-disk-by\x2duuid-2dc8b9b1\x2da0a5\x2d44d8\x2d89c4\x2d6cdd26cd5ce0.swap                                    stop running
     3232 dev-dm\x2d1.swap                                                                                             stop running
     3231 dev-disk-by\x2did-dm\x2duuid\x2dLVM\x2dyuXWpCCIurGzz2nkGCVnUFSi7GH6E3ZcQjkKLnF0Fil0RJmhoLN8fcOnDybWCMTj.swap stop running
     3230 dev-disk-by\x2did-dm\x2dname\x2dfedora\x2dswap.swap                                                          stop running
     3234 dev-fedora-swap.swap                                                                                         stop running

    5 jobs listed.

This remains endlessly because their JobTimeoutUSec is infinity:

    # LANG=C systemctl show -p JobTimeoutUSec dev-fedora-swap.swap
    JobTimeoutUSec=infinity

If this issue happens during system shutdown, the system shutdown appears to
get hang and the system will be forcibly shutdown or rebooted 30 minutes later
by the following configuration:

    # grep -E "^JobTimeout" /usr/lib/systemd/system/reboot.target
    JobTimeoutSec=30min
    JobTimeoutAction=reboot-force

The scenario in the real world seems that there is some service unit with
KillMode=none, processes whose memory is being swapped out are not killed
during stop operation in the service unit and then swapoff command fails.

On the other hand, it works well in successful case of swapoff command because
the secondary jobs monitor /proc/swaps file and can detect deletion of the
corresponding swap file.

This commit fixes the issue by finishing the secondary swap units' jobs if
deactivation of the primary swap unit fails.

Fixes: #11577
(cherry picked from commit 9c1f969d40f84d5cc98d810bab8b24148b2d8928)
(cherry picked from commit b89a1a9d19aa806feb984c8dba25116b5b5a52bc)

Resolves: #1821372

5 years agobasic: use comma as separator in cpuset cgroup cpu ranges v239-30
Michal Sekletár [Tue, 14 Apr 2020 14:16:45 +0000 (16:16 +0200)]
basic: use comma as separator in cpuset cgroup cpu ranges

This is a workaround for
https://bugzilla.redhat.com/show_bug.cgi?id=1819152 and should be
reverted in RHEL-8.3.

RHEL-only

Related: #1824129

5 years agocore: fix re-realization of cgroup siblings
Lennart Poettering [Thu, 9 Jan 2020 16:30:31 +0000 (17:30 +0100)]
core: fix re-realization of cgroup siblings

This is a fix-up for eef85c4a3f8054d29383a176f6cebd1ef3a15b9a which
broke this.

Tracked down by @w-simon

Fixes: #14453
(cherry picked from commit 65f6b6bdcb500c576674b5838e4cc4c35e18bfde)

Related: #1824129

5 years agopid1: fix the names of AllowedCPUs= and AllowedMemoryNodes=
Zbigniew Jędrzejewski-Szmek [Sun, 24 Nov 2019 13:14:43 +0000 (14:14 +0100)]
pid1: fix the names of AllowedCPUs= and AllowedMemoryNodes=

The original PR was submitted with CPUSetCpus and CPUSetMems, which was later
changed to AllowedCPUs and AllowedMemmoryNodes everywhere (including the parser
used by systemd-run), but not in the parser for unit files.

Since we already released -rc1, let's keep support for the old names. I think
we can remove it in a release or two if anyone remembers to do that.

Fixes #14126. Follow-up for 047f5d63d7a1ab75073f8485e2f9b550d25b0772.

(cherry picked from commit 0b8d3075872a05e0449906d24421ce192f50c29f)

Related: #1824129

5 years agocryptsetup: Treat key file errors as a failed password attempt v239-29
Ryan Gonzalez [Sat, 23 Feb 2019 05:45:03 +0000 (23:45 -0600)]
cryptsetup: Treat key file errors as a failed password attempt

6f177c7dc092eb68762b4533d41b14244adb2a73 caused key file errors to immediately fail, which would make it hard to correct an issue due to e.g. a crypttab typo or a damaged key file.

Closes #11723.

(cherry picked from commit c20db3887569e0c0d9c0e2845c5286e7edf0133a)

Related: #1763155

5 years agotest: replace cursor file with a plain cursor v239-28
Frantisek Sumsal [Tue, 3 Mar 2020 14:54:29 +0000 (15:54 +0100)]
test: replace cursor file with a plain cursor

systemd in RHEL 8 doesn't support the --cursor-file option, so let's
fall back to a plain cursor string

Related: #1808940
rhel-only

5 years agotest: drop the missed || exit 1 expression
Frantisek Sumsal [Sat, 10 Aug 2019 14:05:07 +0000 (16:05 +0200)]
test: drop the missed || exit 1 expression

...as we've already done in the rest of the testsuite, see
cc469c3dfc398210f38f819d367e68646c71d8da

(cherry picked from commit 67c434b03f8a24f5350f017dfb4b2464406046db)

Related: #1808940

5 years agotest: add a simple sanity check for systems without NUMA support
Frantisek Sumsal [Mon, 5 Aug 2019 12:38:45 +0000 (14:38 +0200)]
test: add a simple sanity check for systems without NUMA support

(cherry picked from commit 92f8e978923f962a57d744c5f358520ac06f7892)

Related: #1808940

5 years agotest: give strace some time to initialize
Frantisek Sumsal [Mon, 22 Jul 2019 22:56:04 +0000 (00:56 +0200)]
test: give strace some time to initialize

The `coproc` implementation seems to be a little bit different in older
bash versions, so the `strace` is sometimes started AFTER `systemctl
daemon-reload`, which causes unexpected fails. Let's help it a little by
sleeping for a bit.

(cherry picked from commit c7367d7cfdfdcec98f8659f0ed3f1d7b77123903)

Related: #1808940

5 years agotest: skip the test on systems without NUMA support
Frantisek Sumsal [Tue, 2 Jul 2019 07:52:45 +0000 (09:52 +0200)]
test: skip the test on systems without NUMA support

(cherry picked from commit b030847163e9bd63d3dd6eec6ac7f336411faba6)

Related: #1808940

5 years agotest: make sure the strace process is indeed dead
Frantisek Sumsal [Mon, 1 Jul 2019 17:53:45 +0000 (19:53 +0200)]
test: make sure the strace process is indeed dead

It may take a few moments for the strace process to properly terminate
and write all logs to the backing storage

(cherry picked from commit 56425e54a2140f47b4560b51c5db08aa2de199a6)

Related: #1808940

5 years agotest: support MPOL_LOCAL matching in unpatched strace versions
Frantisek Sumsal [Mon, 1 Jul 2019 11:08:26 +0000 (13:08 +0200)]
test: support MPOL_LOCAL matching in unpatched strace versions

The MPOL_LOCAL constant is not recognized in current strace versions.
Let's match at least the numerical value of this constant until the
strace patch is approved & merged.

(cherry picked from commit ac14396d027023e1be910327989cb422cb2f6724)

Related: #1808940

5 years agotest: replace `tail -f` with journal cursor which should be...
Frantisek Sumsal [Mon, 1 Jul 2019 07:27:59 +0000 (09:27 +0200)]
test: replace `tail -f` with journal cursor which should be...

more reliable

(cherry picked from commit d0b2178f3e79f302702bd7140766eee03643f734)

Related: #1808940

5 years agotest: introduce TEST-36-NUMAPOLICY
Frantisek Sumsal [Tue, 25 Jun 2019 21:01:40 +0000 (23:01 +0200)]
test: introduce TEST-36-NUMAPOLICY

(cherry picked from commit 8f65e26508969610ac934d1aadbade8223bfcaac)

Related: #1808940

5 years agocgroup: make sure that cpuset is supported on cgroup v2 and disabled with v1
Michal Sekletár [Tue, 3 Mar 2020 10:45:00 +0000 (11:45 +0100)]
cgroup: make sure that cpuset is supported on cgroup v2 and disabled with v1

Resolves: #1808940

(rhel-only)

5 years agopid1: fix DefaultTasksMax initialization
Franck Bui [Wed, 2 Oct 2019 09:58:16 +0000 (11:58 +0200)]
pid1: fix DefaultTasksMax initialization

Otherwise DefaultTasksMax is always set to "inifinity".

This was broken by fb39af4ce42.

(cherry picked from commit c0000de87d2c7934cb1f4ba66a533a85277600ff)

Resolves: #1809037

5 years agocgroup: introduce support for cgroup v2 CPUSET controller v239-27
Pavel Hrdina [Mon, 29 Jul 2019 15:50:05 +0000 (17:50 +0200)]
cgroup: introduce support for cgroup v2 CPUSET controller

Introduce support for configuring cpus and mems for processes using
cgroup v2 CPUSET controller.  This allows users to limit which cpus
and memory NUMA nodes can be used by processes to better utilize
system resources.

The cgroup v2 interfaces to control it are cpuset.cpus and cpuset.mems
where the requested configuration is written.  However, it doesn't mean
that the requested configuration will be actually used as parent cgroup
may limit the cpus or mems as well.  In order to reflect the real
configuration cgroup v2 provides read-only files cpuset.cpus.effective
and cpuset.mems.effective which are exported to users as well.

(cherry picked from commit 047f5d63d7a1ab75073f8485e2f9b550d25b0772)

Related: #1724617

5 years agocore: imply NNP and SUID/SGID restriction for DynamicUser=yes service v239-26
Lennart Poettering [Wed, 20 Mar 2019 19:19:38 +0000 (20:19 +0100)]
core: imply NNP and SUID/SGID restriction for DynamicUser=yes service

Let's be safe, rather than sorry. This way DynamicUser=yes services can
neither take benefit of, nor create SUID/SGID binaries.

Given that DynamicUser= is a recent addition only we should be able to
get away with turning this on, even though this is strictly speaking a
binary compatibility breakage.

(cherry picked from commit bf65b7e0c9fc215897b676ab9a7c9d1c688143ba)
Resolves: #1687512

5 years agounits: turn on RestrictSUIDSGID= in most of our long-running daemons
Lennart Poettering [Wed, 20 Mar 2019 18:52:20 +0000 (19:52 +0100)]
units: turn on RestrictSUIDSGID= in most of our long-running daemons

(cherry picked from commit 62aa29247c3d74bcec0607c347f2be23cd90675d)
Related: #1687512

5 years agoman: document the new RestrictSUIDSGID= setting
Lennart Poettering [Wed, 20 Mar 2019 18:45:32 +0000 (19:45 +0100)]
man: document the new RestrictSUIDSGID= setting

(cherry picked from commit 7445db6eb70e8d5989f481d0c5a08ace7047ae5b)
Related: #1687512

5 years agoanalyze: check for RestrictSUIDSGID= in "systemd-analyze security"
Lennart Poettering [Wed, 20 Mar 2019 18:20:35 +0000 (19:20 +0100)]
analyze: check for RestrictSUIDSGID= in "systemd-analyze security"

And let's give it a heigh weight, since it pretty much can be used for
bad things only.

(cherry picked from commit 9d880b70ba5c6ca83c82952f4c90e86e56c7b70c)
Related: #1687512

5 years agocore: expose SUID/SGID restriction as new unit setting RestrictSUIDSGID=
Lennart Poettering [Wed, 20 Mar 2019 18:09:09 +0000 (19:09 +0100)]
core: expose SUID/SGID restriction as new unit setting RestrictSUIDSGID=

(cherry picked from commit f69567cbe26d09eac9d387c0be0fc32c65a83ada)
Related: #1687512

5 years agotest: add test case for restrict_suid_sgid()
Jan Synacek [Tue, 12 Nov 2019 12:27:49 +0000 (13:27 +0100)]
test: add test case for restrict_suid_sgid()

(cherry picked from commit 167fc10cb352b04d442c9010dab4f8dc24219749)
Related: #1687512

5 years agoseccomp: introduce seccomp_restrict_suid_sgid() for blocking chmod() for suid/sgid...
Lennart Poettering [Wed, 20 Mar 2019 18:00:28 +0000 (19:00 +0100)]
seccomp: introduce seccomp_restrict_suid_sgid() for blocking chmod() for suid/sgid files

(cherry picked from commit 3c27973b13724ede05a06a5d346a569794cda433)
Related: #1687512

5 years agomain: introduce a define HIGH_RLIMIT_MEMLOCK similar to HIGH_RLIMIT_NOFILE v239-25
Lennart Poettering [Thu, 11 Oct 2018 16:31:11 +0000 (18:31 +0200)]
main: introduce a define HIGH_RLIMIT_MEMLOCK similar to HIGH_RLIMIT_NOFILE

(cherry picked from commit c8884aceefc85245b9bdfb626e2daf27521259bd)
Related: #1789930

5 years agopid1: make sure to restore correct default values for some rlimits
Jan Synacek [Wed, 12 Feb 2020 11:58:54 +0000 (12:58 +0100)]
pid1: make sure to restore correct default values for some rlimits

Commit fb39af4ce42d7ef9af63009f271f404038703704 forgot to restore the default
rlimit values (RLIMIT_NOFILE and RLIMIT_MEMLOCK) while PID1 is reloading.

This patch extracts the code in charge of initializing the default values for
those rlimits in order to create dedicated functions, which take care of their
initialization.

These functions are then called in parse_configuration() so we make sure that
the default values for these rlimits get restored every time PID1 is reloading
its configuration.

(cherry picked from commit a9fd4cd1206832a61aaf61fff583bb133e6cb965)
Resolves: #1789930

5 years agosd-bus: use "queue" message references for managing r/w message queues in connection...
Lennart Poettering [Thu, 17 Jan 2019 17:31:59 +0000 (18:31 +0100)]
sd-bus: use "queue" message references for managing r/w message queues in connection objects

Let's make use of the new concept the previous commit added.

See: #4846
(cherry picked from commit c1757a70eac0382c4837a3833d683919f6a48ed7)
Related: CVE-2020-1712

5 years agojournal: use cleanup attribute at one more place v239-24
Yu Watanabe [Tue, 28 May 2019 09:07:01 +0000 (18:07 +0900)]
journal: use cleanup attribute at one more place

(cherry picked from commit 627df1dc42b68a74b0882b06366d1185b1a34332)

Conflicts:
src/journal/journald-server.c

Related: #1788085

5 years agojournal: do not trigger assertion when journal_file_close() get NULL
Yu Watanabe [Tue, 28 May 2019 03:40:17 +0000 (12:40 +0900)]
journal: do not trigger assertion when journal_file_close() get NULL

We generally expect destructors to not complain if a NULL argument is passed.

Closes #12400.

(cherry picked from commit c377a6f3ad3d9bed4ce7e873e8e9ec6b1650c57d)
Resolves: #1788085

5 years agosysctl: let's by default increase the numeric PID range from 2^16 to 2^22
Michal Sekletár [Mon, 6 Jan 2020 11:30:58 +0000 (12:30 +0100)]
sysctl: let's by default increase the numeric PID range from 2^16 to 2^22

This should PID collisions a tiny bit less likely, and thus improve
security and robustness.

2^22 isn't particularly a lot either, but it's the current kernel
limitation.

Bumping this limit was suggested by Linus himself:

https://lwn.net/ml/linux-kernel/CAHk-=wiZ40LVjnXSi9iHLE_-ZBsWFGCgdmNiYZUXn1-V5YBg2g@mail.gmail.com/

Let's experiment with this in systemd upstream first. Downstreams and
users can after all still comment this easily.

Besides compat concern the most often heard issue with such high PIDs is
usability, since they are potentially hard to type. I am not entirely sure though
whether 4194304 (as largest new PID) is that much worse to type or to
copy than 65563.

This should also simplify management of per system tasks limits as by
this move the sysctl /proc/sys/kernel/threads-max becomes the primary
knob to control how many processes to have in parallel.

Resolves: #1744214

5 years agopolkit: when authorizing via PK let's re-resolve callback/userdata instead of caching it
Jan Synacek [Fri, 31 Jan 2020 14:17:25 +0000 (15:17 +0100)]
polkit: when authorizing via PK let's re-resolve callback/userdata instead of caching it

Previously, when doing an async PK query we'd store the original
callback/userdata pair and call it again after the PK request is
complete. This is problematic, since PK queries might be slow and in the
meantime the userdata might be released and re-acquired. Let's avoid
this by always traversing through the message handlers so that we always
re-resolve the callback and userdata pair and thus can be sure it's
up-to-date and properly valid.

Resolves: CVE-2020-1712

5 years agosd-event: add sd_event_source_disable_unref() helper
Zbigniew Jędrzejewski-Szmek [Wed, 8 May 2019 12:39:57 +0000 (14:39 +0200)]
sd-event: add sd_event_source_disable_unref() helper

(cherry picked from commit afd15bbb4b6414b9356799c63029e36642dae8e4)
Related: CVE-2020-1712

5 years agosd-bus: introduce API for re-enqueuing incoming messages
Jan Synacek [Fri, 31 Jan 2020 10:34:45 +0000 (11:34 +0100)]
sd-bus: introduce API for re-enqueuing incoming messages

When authorizing via PolicyKit we want to process incoming method calls
twice: once to process and figure out that we need PK authentication,
and a second time after we aquired PK authentication to actually execute
the operation. With this new call sd_bus_enqueue_for_read() we have a
way to put an incoming message back into the read queue for this
purpose.

This might have other uses too, for example debugging.
Related: CVE-2020-1712

5 years agobus-message: introduce two kinds of references to bus messages
Lennart Poettering [Thu, 17 Jan 2019 17:18:54 +0000 (18:18 +0100)]
bus-message: introduce two kinds of references to bus messages

Before this commit bus messages had a single reference count: when it
reached zero the message would be freed. This simple approach meant a
cyclic dependency was typically seen: a message that was enqueued in a
bus connection object would reference the bus connection object but also
itself be referenced by the bus connection object. So far out strategy
to avoid cases like this was: make sure to process the bus connection
regularly so that messages don#t stay queued, and at exit flush/close
the connection so that the message queued would be emptied, and thus the
cyclic dependencies resolved. Im many cases this isn't done properly
however.

With this change, let's address the issue more systematically: let's
break the reference cycle. Specifically, there are now two types of
references to a bus message:

1. A regular one, which keeps both the message and the bus object it is
   associated with pinned.

2. A "queue" reference, which is weaker: it pins the message, but not
   the bus object it is associated with.

The idea is then that regular user handling uses regular references, but
when a message is enqueued on its connection, then this takes a "queue"
reference instead. This then means that a queued message doesn't imply
the connection itself remains pinned, only regular references to the
connection or a message associated with it do. Thus, if we end up in the
situation where a user allocates a bus and a message and enqueues the
latter in the former and drops all refs to both, then this will detect
this case and free both.

Note that this scheme isn't perfect, it only covers references between
messages and the busses they are associated with. If OTOH a bus message
is enqueued on a different bus than it is associated with cyclic deps
cannot be recognized with this simple algorithm, and thus if you enqueue
a message associated with a bus A on a bus B, and another message
associated with bus B on a bus A, a cyclic ref will be in effect and not
be discovered. However, given that this is an exotic case (though one
that happens, consider systemd-bus-stdio-bridge), it should be OK not to
cover with this, and people have to explicit flush all queues on exit in
that case.

Note that this commit only establishes the separate reference counters
per message. A follow-up commit will start making use of this from the
bus connection object.

(cherry picked from commit 1b3f9dd759ca0ea215e7b89f8ce66d1b724497b9)
Related: CVE-2020-1712

5 years agosd-bus: always go through sd_bus_unref() to free messages
Lennart Poettering [Thu, 17 Jan 2019 20:07:42 +0000 (21:07 +0100)]
sd-bus: always go through sd_bus_unref() to free messages

Don't try to be smart, don't bypass the ref counting logic if there's no
real reason to.

This matters if we want to tweak the ref counting logic later.

(cherry picked from commit b41812d1e308de03c879cfca490105216d528c4b)
Related: CVE-2020-1712

5 years agosd-bus: initialize mutex after we allocated the wqueue
Lennart Poettering [Thu, 17 Jan 2019 20:06:30 +0000 (21:06 +0100)]
sd-bus: initialize mutex after we allocated the wqueue

That way the mutex doesn't have to be destroyed when we exit early due
to OOM.

(cherry picked from commit 2fe9a10d7695c4c3a748969a0d1662c624e50e5e)
Related: CVE-2020-1712

5 years agosd-bus: drop two inappropriate empty lines
Lennart Poettering [Thu, 17 Jan 2019 17:18:18 +0000 (18:18 +0100)]
sd-bus: drop two inappropriate empty lines

(cherry picked from commit 39feb2ce417e54cf9746e64b5dfd610cef6ac440)
Related: CVE-2020-1712

5 years agosd-bus: make sure dispatch_rqueue() initializes return parameter on all types of...
Lennart Poettering [Thu, 17 Jan 2019 17:15:37 +0000 (18:15 +0100)]
sd-bus: make sure dispatch_rqueue() initializes return parameter on all types of success

Let's make sure our own code follows coding style and initializes all
return values on all types of success (and leaves it uninitialized in
all types of failure).

(cherry picked from commit c0bc4ec5cc17ac61773d1e9362b0ffa8382c1ff1)
Related: CVE-2020-1712

5 years agosd-bus: reorder bus ref and bus message ref handling
Lennart Poettering [Thu, 17 Jan 2019 17:14:17 +0000 (18:14 +0100)]
sd-bus: reorder bus ref and bus message ref handling

Let's always place handling of these references together, so that all
reference counting during allocation is at a single place.

(cherry picked from commit e593b6a87a335267e5f7238b14683b7f840a01a3)
Related: CVE-2020-1712

5 years agosd-bus: make rqueue/wqueue sizes of type size_t
Lennart Poettering [Thu, 17 Jan 2019 17:13:03 +0000 (18:13 +0100)]
sd-bus: make rqueue/wqueue sizes of type size_t

Let's do this like we usually do and size arrays with size_t.

We already do this for the "allocated" counter correctly, and externally
we expose the queue sizes as uint64_t anyway, hence there's really no
point in usigned "unsigned" internally.

(cherry picked from commit 143d4e045a798ccc87889b2a8a60d7fbe44be441)
Related: CVE-2020-1712

5 years agorules: reintroduce 60-alias-kmsg.rules
Jan Synacek [Wed, 18 Dec 2019 08:41:29 +0000 (09:41 +0100)]
rules: reintroduce 60-alias-kmsg.rules

Resolves:#1739353
rhel-only

5 years agocryptsetup: rework how we log about activation failures v239-23
Lennart Poettering [Mon, 21 Jan 2019 19:20:35 +0000 (20:20 +0100)]
cryptsetup: rework how we log about activation failures

First of all let's always log where the errors happen, and not in an
upper stackframe, in all cases. Previously we'd do this somethis one way
and sometimes another, which resulted in sometimes duplicate logging and
sometimes none.

When we cannot activate something due to bad password the kernel gives
us EPERM. Let's uniformly return this EAGAIN, so tha the next password
is tried. (previously this was done in most cases but not in all)

When we get EPERM let's also explicitly indicate that this probably
means the password is simply wrong.

Fixes: #11498
(cherry picked from commit 6f177c7dc092eb68762b4533d41b14244adb2a73)

Related: #1776408

5 years agocryptsetup: downgrade a log message we ignore
Lennart Poettering [Mon, 21 Jan 2019 19:19:57 +0000 (20:19 +0100)]
cryptsetup: downgrade a log message we ignore

(cherry picked from commit 44ce4255147ab308c1f13580147c693204c322e8)

Related: #1776408

5 years agocryptsetup: add some commenting about EAGAIN generation
Lennart Poettering [Mon, 21 Jan 2019 19:13:11 +0000 (20:13 +0100)]
cryptsetup: add some commenting about EAGAIN generation

(cherry picked from commit b7a0fead10959b03a1fa642a5ae7aca3a6a3dee9)

Related: #1776408

5 years agocrypt-util: Translate libcryptsetup log level instead of using log_debug()
Jan Janssen [Mon, 25 Jun 2018 18:33:31 +0000 (20:33 +0200)]
crypt-util: Translate libcryptsetup log level instead of using log_debug()

This makes sure that errors reported by libcryptsetup are shown to the
user instead of getting swallowed up by log_debug().

(cherry picked from commit aa2cc005d77890b07e8c579f25e1333ff8ba8dac)

Resolves: #1776408

5 years agocryptsetup-generator: guess whether the keyfile argument is two items or one
Zbigniew Jędrzejewski-Szmek [Wed, 13 Nov 2019 09:32:30 +0000 (10:32 +0100)]
cryptsetup-generator: guess whether the keyfile argument is two items or one

Fixes #13615.

See the inline comment for documentation.

(cherry picked from commit 32c6237a7c2e697d2fc4f3403319db16858fb8e3)

Related: #1763155

5 years agocryptsetup: don't assert on variable which is optional
Zbigniew Jędrzejewski-Szmek [Thu, 1 Aug 2019 06:15:43 +0000 (08:15 +0200)]
cryptsetup: don't assert on variable which is optional

https://github.com/systemd/systemd/commit/50d2eba27b9bfc77ef6b40e5721713846815418b#commitcomment-34519739

In add_crypttab_devices() split_keyspec is called on the keyfile argument,
which may be NULL.

(cherry picked from commit fef716b28be6e866b8afe995805d5ebe2af6bbfa)

Related: #1763155

5 years agocryptsetup: use unabbrieviated variable names
Zbigniew Jędrzejewski-Szmek [Thu, 1 Aug 2019 06:13:13 +0000 (08:13 +0200)]
cryptsetup: use unabbrieviated variable names

Now that "ret_" has been added to the output variables, we can name
the internal variables without artificial abbrevs.

(cherry picked from commit 5d2100dc4c32abbce4109e75cbfbbef6e1b2b7b1)

Related: #1763155

5 years agocryptsetup: add documentation for keyfile-timeout
shinygold [Tue, 16 Jul 2019 11:05:34 +0000 (13:05 +0200)]
cryptsetup: add documentation for keyfile-timeout

(cherry picked from commit 4e1334512debb27f4a0c4a6da237a4b8d59fea08)

Related: #1763155

5 years agocryptsetup: add keyfile-timeout to allow a keydev timeout and allow to fallback to...
shinygold [Tue, 16 Jul 2019 11:06:16 +0000 (13:06 +0200)]
cryptsetup: add keyfile-timeout to allow a keydev timeout and allow to fallback to a password if it fails.

(cherry picked from commit 50d2eba27b9bfc77ef6b40e5721713846815418b)

Resolves: #1763155

5 years agocatalog: fix name of variable
Zbigniew Jędrzejewski-Szmek [Mon, 15 Oct 2018 20:41:49 +0000 (22:41 +0200)]
catalog: fix name of variable

All the messages would (literally) say "The start-up result is RESULT."
because @RESULT@ was not defined.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1639482
and the first part of #8005.

Fixup for 646cc98dc81c4d0edbc1b57e7bca0f474b47e270.

(cherry picked from commit 65d51875c2a7b27b61de090f1bd6311b0cef2016)

Resolves: #1677768

5 years agotest-cpu-set-util: fix allocation size check on i386 v239-21 v239-22
Zbigniew Jędrzejewski-Szmek [Tue, 4 Jun 2019 07:40:38 +0000 (09:40 +0200)]
test-cpu-set-util: fix allocation size check on i386

We get just 28 bytes not 32 as on 64-bit architectures (__cpu_set_t is 4 bytes,
we need at least 26, so 28 satisfies the constraints).

(cherry picked from commit 64412970ac0d4b6f5c4bbd8816edc9bff9eab2de)

Related: #1734787

5 years agotest-cpu-set-util: fix comparison for allocation size
Zbigniew Jędrzejewski-Szmek [Tue, 4 Jun 2019 07:19:04 +0000 (09:19 +0200)]
test-cpu-set-util: fix comparison for allocation size

On i386, __cpu_mask is 4 bytes, so we'd check if c.allocated >= 0, and
gcc would warn about a bogus comparison. Let's round up.

Fixes #12726.

(cherry picked from commit a299ce058b41b21c87f36e77e2c563b0ddd1be0d)

Related: #1734787

6 years agodebug-generator: enable custom systemd.debug_shell tty v239-20
Jan Synacek [Thu, 25 Apr 2019 10:19:16 +0000 (12:19 +0200)]
debug-generator: enable custom systemd.debug_shell tty

(cherry picked from commit 93912e872fb14e9c372e090409e429084a6450f5)

Resolves: #1723722

6 years agocore, job: fix breakage of ordering dependencies by systemctl reload command
HATAYAMA Daisuke [Mon, 28 Oct 2019 10:35:24 +0000 (19:35 +0900)]
core, job: fix breakage of ordering dependencies by systemctl reload command

Currently, systemctl reload command breaks ordering dependencies if it's
executed when its target service unit is in activating state.

For example, prepare A.service, B.service and C.target as follows:

    # systemctl cat A.service B.service C.target
    # /etc/systemd/system/A.service
    [Unit]
    Description=A

    [Service]
    Type=oneshot
    ExecStart=/usr/bin/echo A1
    ExecStart=/usr/bin/sleep 60
    ExecStart=/usr/bin/echo A2
    ExecReload=/usr/bin/echo A reloaded
    RemainAfterExit=yes

    # /etc/systemd/system/B.service
    [Unit]
    Description=B
    After=A.service

    [Service]
    Type=oneshot
    ExecStart=/usr/bin/echo B
    RemainAfterExit=yes

    # /etc/systemd/system/C.target
    [Unit]
    Description=C
    Wants=A.service B.service

Start them.

    # systemctl daemon-reload
    # systemctl start C.target

Then, we have:

    # LANG=C journalctl --no-pager -u A.service -u B.service -u C.target -b
    -- Logs begin at Mon 2019-09-09 00:25:06 EDT, end at Thu 2019-10-24 22:28:47 EDT. --
    Oct 24 22:27:47 localhost.localdomain systemd[1]: Starting A...
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Child 967 belongs to A.service.
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Running next main command for state start.
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Passing 0 fds to service
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: About to execute: /usr/bin/sleep 60
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Forked /usr/bin/sleep as 968
    Oct 24 22:27:47 localhost.localdomain systemd[968]: A.service: Executing: /usr/bin/sleep 60
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Trying to enqueue job A.service/reload/replace
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Merged into running job, re-running: A.service/reload as 1288
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Enqueued job A.service/reload as 1288
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Unit cannot be reloaded because it is inactive.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Job 1288 A.service/reload finished, result=invalid
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Passing 0 fds to service
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: About to execute: /usr/bin/echo B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Forked /usr/bin/echo as 970
    Oct 24 22:27:52 localhost.localdomain systemd[970]: B.service: Executing: /usr/bin/echo B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Failed to send unit change signal for B.service: Connection reset by peer
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Changed dead -> start
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Starting B...
    Oct 24 22:27:52 localhost.localdomain echo[970]: B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Child 970 belongs to B.service.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Changed start -> exited
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Job 1371 B.service/start finished, result=done
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Started B.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: C.target: Job 1287 C.target/start finished, result=done
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Reached target C.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: C.target: Failed to send unit change signal for C.target: Connection reset by peer
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Child 968 belongs to A.service.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Running next main command for state start.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Passing 0 fds to service
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: About to execute: /usr/bin/echo A2
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Forked /usr/bin/echo as 972
    Oct 24 22:28:47 localhost.localdomain systemd[972]: A.service: Executing: /usr/bin/echo A2
    Oct 24 22:28:47 localhost.localdomain echo[972]: A2
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Child 972 belongs to A.service.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Changed start -> exited

The issue occurs not only in reload command, i.e.:

  - reload
  - try-restart
  - reload-or-restart
  - reload-or-try-restart commands

The cause of this issue is that job_type_collapse() doesn't take care of the
activating state.

Fixes: #10464
(cherry picked from commit d1559793df555212271e490a4a72f55826caf5b4)

Resolves: #1766417

6 years agocryptsetup: reduce the chance that we will be OOM killed
Michal Sekletár [Wed, 27 Nov 2019 13:27:58 +0000 (14:27 +0100)]
cryptsetup: reduce the chance that we will be OOM killed

cryptsetup introduced optional locking scheme that should serialize
unlocking keyslots which use memory hard key derivation
function (argon2). Using the serialization should prevent OOM situation
in early boot while unlocking encrypted volumes.

(cherry picked from commit 408c81f62454684dfbff1c95ce3210d06f256e58)

Resolves: #1696602

6 years agoset kptr_restrict=1
David Tardon [Tue, 3 Dec 2019 13:04:00 +0000 (14:04 +0100)]
set kptr_restrict=1

Resolves: #1689346

6 years agocore: disable CPUAccounting by default
Michal Sekletár [Thu, 28 Nov 2019 14:47:43 +0000 (15:47 +0100)]
core: disable CPUAccounting by default

Related: #1734787

[RHEL-only]

6 years agocore: introduce NUMAPolicy and NUMAMask options
Michal Sekletár [Mon, 18 Nov 2019 11:50:11 +0000 (12:50 +0100)]
core: introduce NUMAPolicy and NUMAMask options

Make possible to set NUMA allocation policy for manager. Manager's
policy is by default inherited to all forked off processes. However, it
is possible to override the policy on per-service basis. Currently we
support, these policies: default, prefer, bind, interleave, local.
See man 2 set_mempolicy for details on each policy.

Overall NUMA policy actually consists of two parts. Policy itself and
bitmask representing NUMA nodes where is policy effective. Node mask can
be specified using related option, NUMAMask. Default mask can be
overwritten on per-service level.

(cherry-picked from commit fe9c54b2188e6cd23262a319f96b13215f2c5e9c)

Resolves: #1734787

6 years agocpu-set-util: use %d-%d format in cpu_set_to_range_string() only for actual ranges
Michal Sekletar [Mon, 3 Jun 2019 08:12:35 +0000 (10:12 +0200)]
cpu-set-util: use %d-%d format in  cpu_set_to_range_string() only for actual ranges

(cherry picked from commit 71923237b18df35401626993d8a285cd998be78d)

Related: #1734787

6 years agoexecute: dump CPUAffinity as a range string instead of a list of CPUs
Michal Sekletar [Fri, 31 May 2019 16:02:20 +0000 (18:02 +0200)]
execute: dump CPUAffinity as a range string instead of a list of CPUs

We do this already when printing the property in systemctl so be
consistent and do the same for systemd-analyze dump.

(cherry picked from commit e7fca352ba43988682a927de6b1f629b3f10a415)

Related: #1734787

6 years agoshared/cpu-set-util: only force range printing one time
Zbigniew Jędrzejewski-Szmek [Wed, 29 May 2019 08:17:43 +0000 (10:17 +0200)]
shared/cpu-set-util: only force range printing one time

The idea is to have at least one range to make the new format clearly
distinguishable from the old. But it is enough to just do it once.
In particular, in case the affinity would be specified like 0, 2, 4, 6…,
this gives much shorter output.

(cherry picked from commit 1f57a176af5152d05719bf43740e87a47e37af50)

Related: #1734787

6 years agosystemctl: present CPUAffinity mask as a list of CPU index ranges
Michal Sekletar [Wed, 22 May 2019 15:14:21 +0000 (17:14 +0200)]
systemctl: present CPUAffinity mask as a list of CPU index ranges

(cherry picked from commit a047f4f10ed2f922d6079c033d24a443b0e95f38)

Related: #1734787

6 years agoshared/cpu-set-util: introduce cpu_set_to_range()
Michal Sekletar [Thu, 23 May 2019 12:27:18 +0000 (14:27 +0200)]
shared/cpu-set-util: introduce cpu_set_to_range()

(cherry picked from commit 71b28519b55b496237146f9bcb5a627455f15f7e)

Related: #1734787

6 years agotest-cpu-set-util: add test for dbus conversions
Zbigniew Jędrzejewski-Szmek [Wed, 29 May 2019 07:44:16 +0000 (09:44 +0200)]
test-cpu-set-util: add test for dbus conversions

(cherry picked from commit 1bf0d6c28f8c884e187c7dacc1a969c0763ff4e3)

Related: #1734787

6 years agoshared/cpu-set-util: make transfer of cpu_set_t over bus endian safe
Michal Sekletar [Wed, 22 May 2019 11:55:49 +0000 (13:55 +0200)]
shared/cpu-set-util: make transfer of cpu_set_t over bus endian safe

(cherry picked from commit c367f996f5f091a63f812f0140b304c649be77fc)

Related: #1734787

6 years agoshared/cpu-set-util: drop now-unused cleanup function
Zbigniew Jędrzejewski-Szmek [Tue, 28 May 2019 19:40:10 +0000 (21:40 +0200)]
shared/cpu-set-util: drop now-unused cleanup function

(cherry picked from commit cb0d3acf55ef335001cac5dd9c335ec5e75e9b56)

Related: #1734787

6 years agotest-execute: use CPUSet too
Zbigniew Jędrzejewski-Szmek [Tue, 28 May 2019 19:38:41 +0000 (21:38 +0200)]
test-execute: use CPUSet too

cpu_set_malloc() was the last user. It doesn't seem useful to keep
it just to save the allocation of a few hundred bytes in a test, so
it is dropped and a fixed maximum is allocated (1024 bytes).

(cherry picked from commit 167a776dbe9d033523bd6881e5a695f2155dc321)

Related: #1734787

6 years agopid1: when reloading configuration, forget old settings
Zbigniew Jędrzejewski-Szmek [Fri, 24 May 2019 07:41:44 +0000 (09:41 +0200)]
pid1: when reloading configuration, forget old settings

If we had a configuration setting from a configuration file, and it was
removed, we'd still remember the old value, because there's was no mechanism to
"reset" everything, just to assign new values.

Note that the effect of this is limited. For settings that have an "ongoing" effect,
like systemd.confirm_spawn, the new value is simply used. But some settings can only
be set at start.

In particular, CPUAffinity= will be updated if set to a new value, but if
CPUAffinity= is fully removed, it will not be reset, simply because we don't
know what to reset it to. We might have inherited a setting, or we might have
set it ourselves. In principle we could remember the "original" value that was
set when we were executed, but propagate this over reloads and reexecs, but
that would be a lot of work for little gain. So this corner case of removal of
CPUAffinity= is not handled fully, and a reboot is needed to execute the
change. As a work-around, a full mask of CPUAffinity=0-8191 can be specified.

(cherry picked from commit fb39af4ce42d7ef9af63009f271f404038703704)

Related: #1734787

6 years agopid1: don't reset setting from /proc/cmdline upon restart
Zbigniew Jędrzejewski-Szmek [Fri, 24 May 2019 06:59:23 +0000 (08:59 +0200)]
pid1: don't reset setting from /proc/cmdline upon restart

We have settings which may be set on the kernel command line, and also
in /proc/cmdline (for pid1). The settings in /proc/cmdline have higher priority
of course. When a reload was done, we'd reload just the configuration file,
losing the overrides.

So read /proc/cmdline again during reload.

Also, when initially reading the configuration file when program starts,
don't treat any errors as fatal. The configuration done in there doesn't
seem important enough to refuse boot.

(cherry picked from commit 470a5e6dcec4637439ae953002127af214d396ac)

Related: #1734787

6 years agopid1: parse CPUAffinity= in incremental fashion
Zbigniew Jędrzejewski-Szmek [Fri, 24 May 2019 06:35:51 +0000 (08:35 +0200)]
pid1: parse CPUAffinity= in incremental fashion

This makes the handling of this option match what we do in unit files. I think
consistency is important here. (As it happens, it is the only option in
system.conf that is "non-atomic", i.e. where there's a list of things which can
be split over multiple assignments. All other options are single-valued, so
there's no issue of how to handle multiple assignments.)

(cherry picked from commit 61fbbac1d517a0b3498a689c736c6ca918497904)

Related: #1734787

6 years agotest-cpu-set-util: add a smoke test for test_parse_cpu_set_extend()
Zbigniew Jędrzejewski-Szmek [Fri, 24 May 2019 06:50:41 +0000 (08:50 +0200)]
test-cpu-set-util: add a smoke test for test_parse_cpu_set_extend()

(cherry picked from commit b54d7241f25b859c6c008e516c2131c39902e6e4)

Related: #1734787

6 years agotest-cpu-set-util: add simple test for cpus_in_affinity_mask()
Zbigniew Jędrzejewski-Szmek [Tue, 21 May 2019 07:01:34 +0000 (09:01 +0200)]
test-cpu-set-util: add simple test for cpus_in_affinity_mask()

(cherry picked from commit 9d1345f0657c707df89b41b2738776efb40aec8e)

Related: #1734787

6 years agoMove cpus_in_affinity_mask() to cpu-set-util.[ch]
Zbigniew Jędrzejewski-Szmek [Tue, 28 May 2019 19:28:31 +0000 (21:28 +0200)]
Move cpus_in_affinity_mask() to cpu-set-util.[ch]

It just seems to fit better there and it's always better to have things
in shared/ rather than basic/.

(cherry picked from commit f44b3035d4a698aa0ce08a552199b54d43de3d85)

Related: #1734787

6 years agoRework cpu affinity parsing
Zbigniew Jędrzejewski-Szmek [Tue, 21 May 2019 06:45:19 +0000 (08:45 +0200)]
Rework cpu affinity parsing

The CPU_SET_S api is pretty bad. In particular, it has a parameter for the size
of the array, but operations which take two (CPU_EQUAL_S) or even three arrays
(CPU_{AND,OR,XOR}_S) still take just one size. This means that all arrays must
be of the same size, or buffer overruns will occur. This is exactly what our
code would do, if it received an array of unexpected size over the network.
("Unexpected" here means anything different from what cpu_set_malloc() detects
as the "right" size.)

Let's rework this, and store the size in bytes of the allocated storage area.

The code will now parse any number up to 8191, independently of what the current
kernel supports. This matches the kernel maximum setting for any architecture,
to make things more portable.

Fixes #12605.

(cherry picked from commit 0985c7c4e22c8dbbea4398cf3453da45ebf63800)

Related: #1734787

6 years agoshared/cpu-set-util: remove now-unused CPU_SIZE_TO_NUM()
Zbigniew Jędrzejewski-Szmek [Sun, 19 May 2019 16:08:39 +0000 (18:08 +0200)]
shared/cpu-set-util: remove now-unused CPU_SIZE_TO_NUM()

(cherry picked from commit b12ef7141648be40fd8c4b0209a742f2151736d9)

Related: #1734787

6 years agoshared/cpu-set-util: move the part to print cpu-set into a separate function
Zbigniew Jędrzejewski-Szmek [Sun, 19 May 2019 16:02:38 +0000 (18:02 +0200)]
shared/cpu-set-util: move the part to print cpu-set into a separate function

Also avoid unnecessary asprintf() when we can write to the output area
directly.

(cherry picked from commit a832893f9c4f0a0329768e90f67e2fa24bb0008e)

Related: #1734787

6 years agocore/dbus-execute: remove unnecessary initialization
Zbigniew Jędrzejewski-Szmek [Sun, 19 May 2019 14:05:02 +0000 (16:05 +0200)]
core/dbus-execute: remove unnecessary initialization

(cherry picked from commit bd0abfaea1514bdd7cb60228d7a3f94c17ba916d)

Related: #1734787

6 years agocore: change ownership/mode of the execution directories also for static users
Lennart Poettering [Thu, 14 Mar 2019 16:19:30 +0000 (17:19 +0100)]
core: change ownership/mode of the execution directories also for static users

It's probably unexpected if we do a recursive chown() when dynamic users
are used but not on static users.

hence, let's tweak the logic slightly, and recursively chown in both
cases, except when operating on the configuration directory.

Fixes: #11842
(cherry picked from commit 206e9864de460dd79d9edd7bedb47dee168765e1)

Resolves: #1778384

6 years agoexecute: remove one redundant comparison check
Lennart Poettering [Thu, 14 Mar 2019 16:01:46 +0000 (17:01 +0100)]
execute: remove one redundant comparison check

(cherry picked from commit d484580ca6f0e79abe6f3f5c677323a22d9e22d7)

Related: #1778384