Commit graph

20653 commits

Author SHA1 Message Date
Lennart Poettering 4e2c0a227e namespace: extend list of masked files by ProtectKernelTunables=
This adds a number of entries nspawn already applies to regular service
namespacing too. Most importantly let's mask /proc/kcore and
/proc/kallsyms too.
2018-05-03 17:46:31 +02:00
Lennart Poettering 720f0a2f3c nspawn: move nspawn cgroup hierarchy one level down unconditionally
We need to do this in all cases, including on cgroupsv1 in order to
ensure the host systemd and any systemd in the payload won't fight for
the cgroup attributes of the top-level cgroup of the payload.

This is because systemd for Delegate=yes units will only delegate the
right to create children as well as their attributes. However, nspawn
expects that the cgroup delegated covers both the right to create
children and the attributes of the cgroup itself. Hence, to clear this
up, let's unconditionally insert a intermediary cgroup, on cgroupsv1 as
well as cgroupsv2, unconditionally.

This is also nice as it reduces the differences in the various setups
and exposes very close behaviour everywhere.
2018-05-03 17:45:42 +02:00
Lennart Poettering 910384c821 nspawn: let's make use of SPECIAL_MACHINE_SLICE macro, after all we already set it 2018-05-03 17:45:42 +02:00
Lennart Poettering 9ec5a93c98 nspawn: don't make /proc/kmsg node too special
Similar to the previous commit, let's just use our regular calls for
managing temporary nodes take care of this.
2018-05-03 17:45:42 +02:00
Lennart Poettering cdde6ba6b6 nspawn: mount boot ID from temporary file in /tmp
Let's not make /run too special and let's make sure the source file is
not guessable: let's use our regular temporary file helper calls to
create the source node.
2018-05-03 17:45:42 +02:00
Lennart Poettering d4b653c589 nspawn: lock down a few things in /proc by default
This tightens security on /proc: a couple of files exposed there are now
made inaccessible. These files might potentially leak kernel internals
or expose non-virtualized concepts, hence lock them down by default.
Moreover, a couple of dirs in /proc that expose stuff also exposed in
/sys are now marked read-only, similar to how we handle /sys.

The list is taken from what docker/runc based container managers
generally apply, but slightly extended.
2018-05-03 17:45:42 +02:00
Lennart Poettering 10af01a5ff nspawn: use free_and_replace() at more places 2018-05-03 17:19:46 +02:00
Lennart Poettering 88614c8a28 nspawn: size_t more stuff
A follow-up for #8840
2018-05-03 17:19:46 +02:00
Yu Watanabe 3776f9cf00
Merge pull request #8859 from poettering/virt-xen-lying
Prefer DMI over CPUID when detecting Xen
2018-05-03 23:23:32 +09:00
Lennart Poettering 5d01f5dce4 locale-util: add comment with link to unicode chars supported by eurlatgr (#8894)
See: #6443
2018-05-03 23:15:04 +09:00
Lennart Poettering fe80fcc7e8 mount-setup: add a comment that the character/block device nodes are "optional" (#8893)
if we lack privs to create device nodes that's fine, and creating
/run/systemd/inaccessible/chr or /run/systemd/inaccessible/blk won't
work then. Document this in longer comments.

Fixes: #4484
2018-05-03 23:10:35 +09:00
Evgeny Vereshchagin 1ab0a250c2
Merge pull request #8865 from yuwata/fix-signal
util: fix integer overflow
2018-05-03 16:35:38 +03:00
Lennart Poettering ec2b24f079 test: list more up-to-date urls in test-web-util
This is based on @jsynacek's patch from #8837, but adds the new URL in
two flavours instead of replacing the old, also making @keszybz happy.

Replaces: #8837
2018-05-03 10:55:16 +02:00
Yu Watanabe 50fb3437cd test: add tests for signal_from_string() 2018-05-03 16:52:55 +09:00
Yu Watanabe 29a3db75fd util: rename signal_from_string_try_harder() to signal_from_string()
Also this makes the new `signal_from_string()` function reject
e.g, `SIG3` or `SIG+5`.
2018-05-03 16:52:49 +09:00
Yu Watanabe 08d3fdc37e util: make signal_from_string() accept RTMIN, RTMAX, and RTMAX-n
Before this, `signal_from_string()` accepts simple signal name
or RTMIN+n. This makes the function also accept RTMIN, RTMAX,
and RTMAX-n.
Note that RTMIN+0 is equivalent to RTMIN, and RTMAX-0 is to RTMAX.

This also fixes the integer overflow reported by oss-fuzz #8064.
https://oss-fuzz.com/v2/testcase-detail/5648573352902656
2018-05-03 16:51:41 +09:00
Susant Sahani b296797f1c networkd: use ipv6_accept_ra_use_dns rather than dhcp_use_dns (#8836)
While Saving the DNS server use [IPv6AcceptRA] UseDNS= that is
ipv6_accept_ra_use_dns.

Closes #8420
2018-05-02 20:16:10 +02:00
Yu Watanabe fb702dd7dd udev: do not mark ari_enabled true when its sysattr value is 0 (#8870)
Fixes #8869.
2018-05-02 16:21:30 +02:00
Lennart Poettering c1c80f6c37
Merge pull request #8866 from yuwata/fix-8842
core: disable namespace sandboxing for '+' prefixed lines
2018-05-02 16:15:26 +02:00
Yu Watanabe 76283e5fd4 set: drop unused set_make() function (#8879)
The function causes compiler error when built with '-Ddebug=hashmap',
and is not used anymore. Let's drop it.
2018-05-02 10:54:52 +02:00
Lennart Poettering 9fc0345551
Merge pull request #8815 from poettering/get-unit-by-cgroup
add new GetUnitByControlGroup API
2018-05-02 10:51:48 +02:00
Adam Duskett 773c84349d add __nr_statx defines for extra architectures (#8872)
This includes:
 - arm
 - arm64
 - alpha
 - powerpc64
 - sparc

Taken from kernel 4.16.6
2018-05-02 10:04:50 +02:00
Yu Watanabe 1e4f1671c2 nspawn: fix warning by -Wnonnull (#8877) 2018-05-02 10:03:31 +02:00
Filipe Brandenburger a605e46f29 systemd-path: fix memory leak reported by ASAN (#8874)
The leak can be reproduced by running systemd-path --suffix .tmp under valgrind or asan:

    $ ./build/systemd-path --suffix .tmp search-binaries
    /usr/local/bin/.tmp:/usr/bin/.tmp:/usr/local/sbin/.tmp:/usr/sbin/.tmp:/home/vagrant/.local/bin/.tmp:/home/vagrant/bin/.tmp

    =================================================================
    ==19177==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 56 byte(s) in 1 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6ad2b93d2 in malloc_multiply ../src/basic/alloc-util.h:69
        *2 0x7fd6ad2bafd2 in strv_split ../src/basic/strv.c:269
        *3 0x7fd6ad42ba67 in search_from_environment ../src/libsystemd/sd-path/sd-path.c:409
        *4 0x7fd6ad42bffe in get_search ../src/libsystemd/sd-path/sd-path.c:482
        *5 0x7fd6ad42c55b in sd_path_search ../src/libsystemd/sd-path/sd-path.c:607
        *6 0x7fd6ad42b3a2 in sd_path_home ../src/libsystemd/sd-path/sd-path.c:348
        *7 0x55f59c65ebea in print_home ../src/path/path.c:97
        *8 0x55f59c65f157 in main ../src/path/path.c:177
        *9 0x7fd6abaea009 in __libc_start_main (/lib64/libc.so.6+0x21009)

    Indirect leak of 68 byte(s) in 5 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6abb5f689 in strndup (/lib64/libc.so.6+0x96689)

    Indirect leak of 25 byte(s) in 1 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6abb5f689 in strndup (/lib64/libc.so.6+0x96689)
        *2 0x6c2e2f746e617266  (<unknown module>)

    SUMMARY: AddressSanitizer: 149 byte(s) leaked in 7 allocation(s).
2018-05-02 09:47:04 +03:00
Yu Watanabe cfa24ca0e6 test: add tests for PrivateDevices= with '+' prefix 2018-05-01 13:44:24 +09:00
Yu Watanabe b5a33299b0 core: disable namespace sandboxing for '+' prefixed lines
Fixes #8842.
2018-05-01 13:44:06 +09:00
Guillem Jover 2955e0d4dc systemctl: make sure legacy "reboot", "suspend" and friends are always asynchronous (#8848)
Currently, "reboot" behaves differently in setups with and without logind.
If logind is used (which is probably the more common case) the operation
is asynchronous, we should behave in the same way as "systemctl <verb>".
Let's clean this up, and always expose the same behaviour, regardless if
logind is used or not: let's always make it asynchronous.

See: #6479
Fixes: commit 130246d2e8
2018-04-30 18:21:27 +02:00
Lennart Poettering c2b19b3cba virt: simplifications
Let's simplify the code a bit. Let's reduce the number of redundant if
checks a bit, (i.e. if we want to check for equality with
VIRTUALIZATION_VM_OTHER there's no need to check for non-equality with
VIRTUALIZATION_NONE first). As a very welcome side-effect this means we
lose some lines of code and our level of indentation is reduced.

No changes in behaviour.
2018-04-30 12:32:25 +02:00
Lennart Poettering f2fe2865cd virt: if we detect Xen by DMI, trust that over CPUID
Apparently Xen sometimes lies about its identity when queried via CPUID.
Let's hence prefer DMI tests for CPUID

Fixes: #8844
2018-04-30 12:32:25 +02:00
Zbigniew Jędrzejewski-Szmek 2ff04e5b7f
Merge pull request #8847 from poettering/transient-once
enforce that scope units are started at most once
2018-04-30 09:50:03 +02:00
Lennart Poettering d4fd1cf208 core: enforce that scope units can be started only once
Scope units are populated from PIDs specified by the bus client. We do
that when a scope is started. We really shouldn't allow scopes to be
started multiple times, as the PIDs then might be heavily out of date.
Moreover, clients should have the guarantee that any scope they allocate
has a clear runtime cycle which is not repetitive.
2018-04-27 21:52:45 +02:00
Lennart Poettering c81ebd35f2
Merge pull request #8808 from poettering/logind-signal
logind: process SIGTERM + SIGINT properly
2018-04-27 20:22:35 +02:00
Zbigniew Jędrzejewski-Szmek 8455706729
Merge pull request #8799 from poettering/exit-status-string
add friendly string support for BSD EX_ exit statusses
2018-04-27 18:26:19 +02:00
Lennart Poettering c8f054361b machined: minor code cleanups, such as voidifying calls 2018-04-27 18:13:51 +02:00
Lennart Poettering 90b8a009a7 logind: (void)ify all things we knowingly ignore 2018-04-27 18:13:51 +02:00
Lennart Poettering fcfa765d18 logind: terminate cleanly on SIGTERM/SIGINT
Let's properly terminate on SIGTERM or SIGINT. Previously we'd just rely
on the implicit process clean-up logic on UNIX. By shutting down
properly on SIGTERM/SIGINT we make it easier to track down memory leaks
by employing valgrind.
2018-04-27 18:11:13 +02:00
Lennart Poettering 2346216853 logind: modernize Manager object allocation and freeing
Let's propagate errors correctly, and stick to the usual naming and
behaviour of these functions. Or in other words, make this closer to the
matching code in machined.
2018-04-27 18:11:13 +02:00
Zbigniew Jędrzejewski-Szmek d1a1f0aaf0 basic/log: always ignore errno from the enviornment (#8841)
This extends the change done in b29f6480ec to other logging functions.

This actually fixes some bugs in callers of log_struct(), for example
config_parse_alias() called 'return log_syntax(..., 0, ...)' which could result
in a bogus non-zero return value.

Calls to log_object() and log_format_iovec() — which is only used by
server_driver_message() — appear correct.
2018-04-27 18:00:58 +02:00
Lennart Poettering 702bd55cfb journal-send: drop redundant parenthesis
As suggested in @keszybz' comments on #8840
2018-04-27 17:32:01 +02:00
Lennart Poettering 0a233ba179 exit-status: list BSD exit codes too
Let's optionally translate BSD exit codes to error strings too.

My first approach on adding this was to turn ExitStatusLevel into a
bitmask rather than a linear level, with one bit for the various feature
bits. However, the exit code ranges are generally not defined
independently from each other, i.e. our own ones are defined with the
LSB ones in mind, and most sets are defined with the ISO C ones.

Hence, instead I changed the existing hierarchy of MINIMAL, SYSTEMD, LSB
with an alias of FULL == LSB, only slightly by seperating FULL and LSB
into two separate levels, so that there's now:

1. MINIMAL (only EXIT_SUCCESS/EXIT_FAILURE)
2. SYSTEMD (incorporating our own exit codes)
3. LSB (like SYSTEMD but adding in LSB service exit codes)
4. FULL (like FULL but adding BSD exit codes)

Note that across the codebase only FULL, SYSTEMD, and MINIMAL are used,
depending on context, how much we know about the process and whether we
are logging for debugging purposes or not. This means the LSB level
wouldn't really have to be separate, but it appeared careless to me to
fold it into FULL along with the BSD exit codes.

Note that this commit doesn't change much for regular codepaths: the
FULL exit status level is only used during debug logging, as a helper to
the user reading the debug logs.
2018-04-27 17:32:01 +02:00
Lennart Poettering cf409d15fa tree-wide: use newa() rather than alloca() where we can 2018-04-27 14:29:06 +02:00
Lennart Poettering 1232c44718 alloca: add an overflow check too
Of course, alloca() shouldn't be used with anything that can grow
without bounds anyway, but let's better safe than sorry, and catch this
early.

Since alloca() is not supposed to return an error we trigger an
assert() instead, which is still better than heap trickery.
2018-04-27 14:29:06 +02:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Yu Watanabe 2c19af832c login: drop unnecessary headers 2018-04-27 17:50:26 +09:00
Susant Sahani 7f9915f0de networkd: Bridge Property Use kernel defaults. (#8825)
Rather than choosing to set or unset any of these flag
use kernel defaults. This patch makes following properties to unset.

UseBPDU = unset
HairPin = unset
FastLeave = unset
AllowPortToBeRoot = unset
UnicastFlood = unset
2018-04-27 10:32:28 +02:00
Lennart Poettering 385f3a0d8d
Merge pull request #7599 from keszybz/slice-templates
Make user@.service independent of logind
2018-04-26 21:39:05 +02:00
Lennart Poettering be737420b7
Merge pull request #8798 from yuwata/follow-up-8675
device: fix serialization and deserialization of DeviceFound
2018-04-26 21:19:16 +02:00
Yu Watanabe 587c458665 network: recreate link if its interface name is changed (#8795)
If an interface name is changed, then the link state, especially
managed or not, may need to be updated, as its corresponding
.link or .network files may be different. So, let's once drop
the link and recreate a new link object.

Fixes #8794.
2018-04-26 21:05:32 +02:00
Lennart Poettering cd81a8fc82
Merge pull request #8776 from poettering/mtu-cleanup
networkd/udev: clean up parsing and handling of MTU values
2018-04-26 21:02:55 +02:00
Yu Watanabe d48013f8a1 core: an empty string resets delegate controllers but enables Delegate= (#8826)
This partially reverts ff1b8455c2.
2018-04-26 15:40:45 +02:00