Commit Graph

511 Commits

Author SHA1 Message Date
Yu Watanabe 0c09cb0e78
Merge pull request #9977 from sourcejedi/no-remount-superblock3
Namespace fixes
2018-09-01 23:18:01 +09:00
Alan Jenkins ad8e66dcc4 namespace: fix mode for TemporaryFileSystem=
... when no mount options are passed.

Change the code, to avoid the following failure in the newly added tests:

exec-temporaryfilesystem-rw.service: Executing: /usr/bin/sh -x -c
'[ "$(stat -c %a /var)" == 755 ]'
++ stat -c %a /var
+ '[' 1777 == 755 ']'
Received SIGCHLD from PID 30364 (sh).
Child 30364 (sh) died (code=exited, status=1/FAILURE)

(And I spotted an opportunity to use TAKE_PTR() at the end).
2018-09-01 17:22:14 +09:00
Alan Jenkins 69338c3dfb namespace: don't try to remount superblocks
We can't remount the underlying superblocks, if we are inside a user
namespace and running Linux <= 4.17.  We can only change the per-mount
flags (MS_REMOUNT | MS_BIND).

This type of mount() call can only change the per-mount flags, so we
don't have to worry about passing the right string options now.

Fixes #9914 ("Since 1beab8b was merged, systemd has been failing to start
systemd-resolved inside unprivileged containers" ... "Failed to re-mount
'/run/systemd/unit-root/dev' read-only: Operation not permitted").

> It's basically my fault :-). I pointed out we could remount read-only
> without MS_BIND when reviewing the PR that added TemporaryFilesystem=,
> and poettering suggested to change PrivateDevices= at the same time.
> I think it's safe to change back, and I don't expect anyone will notice
> a difference in behaviour.
>
> It just surprised me to realize that
> `TemporaryFilesystem=/tmp:size=10M,ro,nosuid` would not apply `ro` to the
> superblock (underlying filesystem), like mount -osize=10M,ro,nosuid does.
> Maybe a comment could note the kernel version (v4.18), that lets you
> remount without MS_BIND inside a user namespace.

This makes the code longer and I guess this function is still ugly, sorry.
One obstacle to cleaning it up is the interaction between
`PrivateDevices=yes` and `ReadOnlyPaths=/dev`.  I've added a test for the
existing behaviour, which I think is now the correct behaviour.
2018-08-30 11:17:16 +01:00
Evgeny Vereshchagin 746fbd9c34 tests: also run TEST-01-BASIC in an unprivileged container (#9957)
This should make it much easier to catch regressions like
https://github.com/systemd/systemd/issues/9914 and
https://github.com/systemd/systemd/issues/8535.
2018-08-30 13:01:18 +09:00
Yu Watanabe a1a605f144 test: add testcase for issue 10007 by oss-fuzz 2018-08-22 15:46:47 +09:00
Franck Bui 4dc7bfdf4f tmpfiles: use fd_get_path() even less excessively
A follow-up for commit 9d874aec45.

This patch makes "path" parameter mandatory in fd_set_*() helpers removing the
need to use fd_get_path() when NULL was passed. The caller is supposed to pass
the fd anyway so assuming that it also knows the path should be safe.

Actually, the only case where this was useful (or used) was when we were
walking through directory trees (in item_do()). But even in those cases the
paths could be constructed trivially, which is still better than relying on
fd_get_path() (which is an ugly API).

A very succinct test case is also added for 'z/Z' operators so the code dealing
with recursive operators is tested minimally.
2018-08-21 19:48:08 +02:00
Lennart Poettering cacf99152e test: make TEST-22 easier to debug, by outputting to /dev/console 2018-08-08 11:59:39 +02:00
Lennart Poettering 721474fe79 test: don't use "nobody:nogroup" for tests
This user/group doesn't apply to Fedora.

Let's use daemon:daemon instead like the other tests, as it actually
tends to exist everywhere.
2018-08-08 11:59:39 +02:00
Franck Bui 9f36a8fb38 tmpfiles: add more tests 2018-07-30 16:04:23 +02:00
Michael Biebl 48c20af38e test: Increase qemu timeout from 90s to 180s
The usage of an initrd made TEST-09-ISSUE-2691 more likely to fail with
a timeout, so increase the timeout by 90s and adjust TimeoutStopSec=
accordingly.
2018-07-27 14:35:26 +03:00
Zbigniew Jędrzejewski-Szmek 7426028b7a
Merge pull request #9720 from yuwata/fix-9702
Fix DynamicUser=yes with static User= whose UID and GID are different
2018-07-26 11:42:00 +02:00
Yu Watanabe 9f82d685f3 test: add tests for DynamicUser= with static User= whose UID and GID are different 2018-07-26 16:32:10 +09:00
Lennart Poettering 0e1f17561f test: add test for Type=exec 2018-07-25 22:48:11 +02:00
Zsolt Dollenstein 566b7d23eb Add support for opening files for appending
Addresses part of #8983
2018-07-20 03:54:22 -07:00
Evgeny Vereshchagin 57916ea352 tests: allow passing additional arguments to nspawn via NSPAWN_ARGUMENTS 2018-07-18 09:56:23 +09:00
Evgeny Vereshchagin 016fa3b9e8 tests: use the asan wrapper to boot a VM/container if systemd is built with ASAN 2018-07-18 09:56:23 +09:00
Evgeny Vereshchagin ec9181d2ce tests: create the asan wrapper automatically if systemd has been built with ASAN 2018-07-18 09:56:23 +09:00
Michael Biebl c2d4da0020 test: Drop SKIP_INITRD for QEMU-based tests
Not all distros support booting without an initrd. E.g. the Debian
kernel builds ext4 as a module and so relies on an initrd to
successfully start the QEMU-based images.
2018-07-16 11:31:24 +02:00
Michael Biebl 025fda6a15 test: Fix typo in TEST-19-DELEGATE 2018-07-15 21:13:56 +02:00
Martin Pitt c4a0a2d5f8 test: Fix networkd test for an already running service
Mount tmpfses over the networkd and resolved config and state
directories, and stop the services beforehand. This ensures that the
test does not mess with an existing networkd/resolved setup. At least
for ethernet setups, this does not sever existing links, so is good
enough for the CI cases we are interested in (QEMU and LXC).

Relax the skip check to only skip the test when trying to run this on
real iron, but start running it in virtual machines now.

This allows us to run the test on Ubuntu 18.04 LTS in CI, which uses
both services by default.
2018-07-09 16:44:03 +02:00
Martin Pitt 207f5f4d93 test: Reset systemd-resolved.service in networkd test
Like s-networkd.service itself, it can happen that s-resolved.service
runs into restart limits. Don't enforce a successful call, as on
machines without resolved the unit might not be loaded.
2018-07-09 16:42:32 +02:00
Evgeny Vereshchagin 88ed0f261b tests: redirect ASAN reports on journald to a file
Otherwise, they will end up in /dev/null.
2018-07-03 19:50:49 +00:00
Evgeny Vereshchagin 1786fae366 tests: add a wrapper for when systemd is built with ASAN 2018-07-03 15:55:19 +00:00
Martin Pitt c44c1b8ab5 test: fix networkd-test.py rate limiting and dynamic user
- Reset systemd-networkd.service before each test run, to avoid running
   into restart limits.
 - Our networkd-test-router.service unit needs to run as root and thus
   can't use `User=`; but networkd still insists on the
   `systemd-network` system user to exist, so create it.
2018-07-03 14:49:50 +02:00
Evgeny Vereshchagin 28c7474e60 tests: up the image size a little, use twice that size with STRIP_BINARIES=no
to make sure that there's enough room for unstripped binaries.
2018-07-02 13:54:26 +02:00
Yu Watanabe d45e481ed2 test: add test for specifier of configuration directory root 2018-06-21 03:24:09 +09:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering c602fd0f19
Merge pull request #9246 from keszybz/ellipsize-invalid-mem-ref
Fix invalid memory reference in ellipsize_mem()
2018-06-11 12:52:38 +02:00
Zbigniew Jędrzejewski-Szmek 21e4e3e06f basic/ellipsize: do not assume the string is NUL-terminated when length is given
oss-fuzz flags this as:

==1==WARNING: MemorySanitizer: use-of-uninitialized-value

0. 0x7fce77519ca5 in ascii_is_valid systemd/src/basic/utf8.c:252:9
1. 0x7fce774d203c in ellipsize_mem systemd/src/basic/string-util.c:544:13
2. 0x7fce7730a299 in print_multiline systemd/src/shared/logs-show.c:244:37
3. 0x7fce772ffdf3 in output_short systemd/src/shared/logs-show.c:495:25
4. 0x7fce772f5a27 in show_journal_entry systemd/src/shared/logs-show.c:1077:15
5. 0x7fce772f66ad in show_journal systemd/src/shared/logs-show.c:1164:29
6. 0x4a2fa0 in LLVMFuzzerTestOneInput systemd/src/fuzz/fuzz-journal-remote.c:64:21
...

I didn't reproduce the issue, but this looks like an obvious error: the length
is specified, so we shouldn't use the string with any functions for normal
C-strings.
2018-06-11 10:04:10 +02:00
Zbigniew Jędrzejewski-Szmek 4215ed6dbd meson: add fuzz regressions to list
Apparently I haven't been very good at remembering to do this.
2018-06-11 10:03:30 +02:00
Yu Watanabe b474ff59e6 fuzz: add testcase for issue 8827 2018-06-11 12:39:59 +09:00
Lennart Poettering b2ad25d388 test: turn off the kernel's passive agressive /dev/kmsg ratelimit for our tests 2018-06-06 11:24:34 +02:00
Lennart Poettering efd0b6ccca test: make sure output of test TEST-03 test service ends up on console 2018-06-06 11:24:34 +02:00
Lennart Poettering 3edc0c590d test: disable QEMU based testing for TEST-16-EXTEND-TIMEOUT
The test is heavily dependent on timeouts, and if we are run in
potentially very slow QEMU instances there's a good chance we'll miss
some which we normally wouldn't miss. Hence, let's test this one in
nspawn only. Given that the test is purely in service management it
shouldn't matter whether it runs in nspawn or qemu, hence keep running
it in nspawn, but don't bother with qemu.

Similar, do this for TEST-03-JOBS, too, which operates with relatively
short sleep times internally.

Fixes: #9123
2018-06-06 11:24:09 +02:00
Lennart Poettering cc4338e435 tests: tighten check for TEST-06-SELINUX dependencies a bit
As it turns out /usr/share/selinux/devel/ is now included in more RPMs
than just selinux-policy-devel (specifically container-selinux, which is
pulled in by various container related RPMs). Let's hence tighten the
dependency check a bit and look for systemd's .if file, which is what we
actually care about.
2018-06-06 10:17:38 +02:00
Lennart Poettering b5b74e4b12
Merge pull request #9167 from keszybz/ellipsization
Ellipsization fixes based on unit-testing and fuzzing
2018-06-04 13:45:03 +02:00
Yu Watanabe 2b633119a0 test: add test for trailing dot in WorkingDirectory= and RuntimeDirectory= 2018-06-03 23:59:51 +09:00
Zbigniew Jędrzejewski-Szmek 9924aef690 test-ellipsize: add tests for ellipsize_mem, fix bugs
First, ellipsize() and ellipsize_mem() should not read past the input
buffer. Those functions take an explicit length for the input data, so they
should not assume that the buffer is terminated by a nul.

Second, ellipsization was off in various cases where wide on multi-byte
characters were used.

We had some basic test for ellipsize(), but apparently it wasn't enough to
catch more serious cases.

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8686.
2018-06-02 21:53:25 +02:00
Zbigniew Jędrzejewski-Szmek 03d1319b12 shared/logs-show: be more careful before using a _SOURCE_REALTIME_TIMESTAMP entry
journalctl -o short would display those entries, but journalctl -o short-full
would refuse. If the entry is bad, just fall back to the receive-side realtime
timestamp like we would if it was completely missing.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek 324d6aa926 shared/logs-show: fix mixup between length-based memory duplication and string operations
We'd look for a '=' separator using memchr, i.e. ignoring any nul bytes in the
string, but then do a strndup, which would terminate on any nul byte, and then
again do a memcmp, which would access memory past the chunk allocated by strndup.

Of course, we probably shouldn't allow keys with nul bytes in them. But we
currently do, so there might be journal files like that out there. So let's fix
the journal-reading code first.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek e743ce7053 journal-remote: when an entry is rejected with -EBADMSG, do not rotate the journal file
Something is wrong with the entry (probably a missing timestamp), so no point
in rotating. But suppress the error in process_source(), so that the processing
of the data stream continues.

Also, just return 0 from writer_write() on success, the only caller doesn't
care.
2018-05-31 13:04:18 +02:00
Zbigniew Jędrzejewski-Szmek a38f7fec44 fuzz-journal-remote: a fuzzer for journal-remote over-the-wire input 2018-05-31 13:04:18 +02:00
Sergio Lindo Mansilla c2f32f616b Fix pattern to detect distribution
With operator '=', when in /etc/os-release:
ID_LIKE="opensuse suse" # Tumbleweed since at least 2018-04-24
or
ID_LIKE="suse opensuse" # Leap 15
2018-05-30 18:13:14 +02:00
Lennart Poettering b294e5943f core: introduce specifiers for /tmp and /var/tmp
This corresponds nicely with the specifiers we already pass for
/var/lib, /var/cache, /run and so on.

This is particular useful to update the test-path service files to
operate without guessable files, thus allowing multiple parallel
test-path invocations to pass without issues (the idea is to set $TMPDIR
early on in the test to some private directory, and then only use the
new %T or %V specifier to refer to it).
2018-05-29 11:39:15 +02:00
Lennart Poettering cdc0f9be92
Merge pull request #8817 from yuwata/cleanup-nsflags
core: allow to specify RestrictNamespaces= multiple times
2018-05-24 16:49:13 +02:00
Yu Watanabe 1c5873096e test-execute: remove state directories before running tests
Fixes #8679.
2018-05-10 22:50:51 -07:00
Joost Heitbrink b6887d7ae4 test: add testcase for environment file variables with backslashes
systemd silently strips out backslashes in variables from environment
files. Add a testcase that explicitly tests for this behaviour.
2018-05-11 13:15:16 +09:00