Commit graph

32860 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 7435315812 basic/calendarspec: set a limit on length of calendarspec component chains
We probably should allow very deep calls of our recursive functions. Let's add
a limit to avoid resource exhaustion. 240 is 10 per hour (if somebody is using
this for time based triggers...), so it should be more than enough for most use
cases, and is conveniently below the 250 stack limit in msan.

oss-fuzz #6917.
2018-03-17 08:59:25 +01:00
Filipe Brandenburger 9b796f3523 test-execute: Introduce tests for environment values containing newlines
Also fix one case where the presence of a newline was used to generate
an invalid environment assignment.

Tested: with mkosi, which builds the local tree and run ninja tests.
2018-03-16 16:31:17 -07:00
Zbigniew Jędrzejewski-Szmek ba0c7754d8 core/manager: move some comments to a better place 2018-03-16 23:15:54 +01:00
Zbigniew Jędrzejewski-Szmek e63ebf71ed core: when reloading, delay any actions on journal and dbus connections
manager_recheck_journal() and manager_recheck_dbus() would be called to early
while we were deserialiazing units, before the systemd-journald.service and
dbus.service have been deserialized. In effect we'd disable logging to the
journald and close the bus connection. The first is not very noticable, it
mostly means that logs emitted during deserialization are lost. The second is
more noticeable, because manager_recheck_dbus() would call bus_done_api() and
bus_done_system() and close dbus connections. Logging and bus connection would
then be restored later after the respective units have been deserialized.

This is easily reproduced by calling:
  $ sudo gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method "org.freedesktop.systemd1.Manager.Reload"
which works fine before 8559b3b75c, and then starts failing with:
  Error: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Remote peer disconnected

None of this should happen, and we should delay changing state until after
deserialization is complete when reloading. manager_reload() already included
the calls to manager_recheck_journal() and manager_recheck_dbus(), so the
connection state will be updated after deserialization during reloading is done.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1554578.
2018-03-16 23:14:04 +01:00
Filipe Brandenburger b4346b9a77 basic/env-util: Allow newlines in values of environment variables
They are allowed by the shell and the EnvironmentFile parsing passes
them through, so we should just accept them, same as we accept tabs.
2018-03-16 13:45:03 -07:00
futpib d24e70fe8b hwdb: fix comment suggested udevadm trigger command (#8465) 2018-03-16 23:25:14 +09:00
Yu Watanabe 0caa99466d udev: use startswith() instead of the combination of strneq() and strlen() (#8459) 2018-03-16 10:29:57 +01:00
Zbigniew Jędrzejewski-Szmek 71ae04c400 core/umount: use libmount to enumerate /proc/swaps
example.swaps with "(deleted)" does not cause bogus entries in the list now,
but a memleak in libmount instead. The memleaks is not very important since
this code is run just once.
Reported as https://github.com/karelzak/util-linux/issues/596.

$ build/test-umount
...
/* test_swap_list("/proc/swaps") */
path=/var/tmp/swap o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
/* test_swap_list("/home/zbyszek/src/systemd/test/test-umount/example.swaps") */
path=/some/swapfile o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
==26912==
==26912== HEAP SUMMARY:
==26912==     in use at exit: 16 bytes in 1 blocks
==26912==   total heap usage: 1,546 allocs, 1,545 frees, 149,008 bytes allocated
==26912==
==26912== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1
==26912==    at 0x4C31C15: realloc (vg_replace_malloc.c:785)
==26912==    by 0x55C5D8C: _IO_vfscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x55D8AEC: vsscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x55D25C3: sscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x53236D0: mnt_table_parse_stream (in /usr/lib64/libmount.so.1.1.0)
==26912==    by 0x53249B6: mnt_table_parse_file (in /usr/lib64/libmount.so.1.1.0)
==26912==    by 0x10D157: swap_list_get (umount.c:194)
==26912==    by 0x10B06E: test_swap_list (test-umount.c:34)
==26912==    by 0x10B24B: main (test-umount.c:56)
==26912==
==26912== LEAK SUMMARY:
==26912==    definitely lost: 16 bytes in 1 blocks
==26912==    indirectly lost: 0 bytes in 0 blocks
==26912==      possibly lost: 0 bytes in 0 blocks
==26912==    still reachable: 0 bytes in 0 blocks
==26912==         suppressed: 0 bytes in 0 blocks
2018-03-16 10:12:50 +01:00
Zbigniew Jędrzejewski-Szmek 1fd8edb53a test-umount: add a simple test for swap_list_get()
The implementation seems buggy:
/* test_swap_list("/home/zbyszek/src/systemd/test/test-umount/example.swaps") */
path=0 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile2 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
2018-03-16 10:12:50 +01:00
Zbigniew Jędrzejewski-Szmek a6dcd22976 core/umount: use _cleanup_ 2018-03-16 10:12:50 +01:00
Zbigniew Jędrzejewski-Szmek 6fa392bf91 tests: add a simple test for the mountinfo parsing logic 2018-03-16 10:12:50 +01:00
Zbigniew Jędrzejewski-Szmek 95b862b054 shutdown: use libmount to enumerate /proc/self/mountinfo
This is analogous to 8d3ae2bd4c, except that now
src/core/umount.c not src/core/mount.c is converted.

Might help with https://bugzilla.redhat.com/show_bug.cgi?id=1554943, or not.

In the patch, mnt_free_tablep and mnt_free_iterp are declared twice. It'd
be nicer to define them just once in mount-setup.h, but then libmount.h would
have to be included there. libmount.h seems to be buggy, and declares some
defines which break other headers, and working around this is more pain than
the two duplicate lines. So let's live with the duplication for now.

This fixes memleak of MountPoint in mount_points_list_get() on error, not that
it matters any.
2018-03-16 10:09:46 +01:00
Franck Bui 563dc6f8e2 sysusers: do not append entries after the NIS ones
The NIS-catchall entry switches from files to NIS lookup and never goes back,
so it must be the last entry in /etc/passwd (the other +/-{user,@netgroup}
entries don't have to be).

That's how the nss_compat mode for /etc/passwd (and /etc/group) traditionally
works.

It's age-old historic behaviour that the NIS entry must be the last one.  It
doesn't seem to be specified somewhere, but it worked like this since very
early SunOS when NIS was first included.

Fixes: #8467
2018-03-16 10:01:33 +01:00
Filipe Brandenburger 8eebb6a9e5 udev/net-id: Fix check for address to keep interface names stable (#8458)
This was a bug inadvertently added by commit 73fc96c8ac.

The intent of the check is to "match slot address with device by
stripping the function" (as the comment above states it), for example
match network device PCI address 0000:05:00.0 (including a .0 for
function) to PCI slot address 0000:05:00, but changing that to a streq()
call prevented the match.

Change that to startswith(), which should both fix the bug and make the
intent of the check more clear and prevent unintentional bugs from being
introduced by future refactorings.
2018-03-16 02:42:38 +09:00
Franck Bui 848e863acc basic/macros: rename noreturn into _noreturn_ (#8456)
"noreturn" is reserved and can be used in other header files we include:

  [   16s] In file included from /usr/include/gcrypt.h:30:0,
  [   16s]                  from ../src/journal/journal-file.h:26,
  [   16s]                  from ../src/journal/journal-vacuum.c:31:
  [   16s] /usr/include/gpg-error.h:1544:46: error: expected ‘,’ or ‘;’ before ‘)’ token
  [   16s]  void gpgrt_log_bug (const char *fmt, ...)    GPGRT_ATTR_NR_PRINTF(1,2);

Here we include grcrypt.h (which in turns include gpg-error.h) *after* we
"noreturn" was defined in macro.h.
2018-03-15 14:23:46 +09:00
Zbigniew Jędrzejewski-Szmek 5ee45c6d63 test-calendarspec: add the test case from oss-fuzz 6886
Before the fix 55a30fd4e8 in this would crash in calendarspec_from_time_t().
2018-03-15 00:15:15 +01:00
Evgeny Vereshchagin 3b71cf46be
Merge pull request #8441 from keszybz/oss-fuzz-fixes
Fixes for bugs found by oss-fuzz
2018-03-14 21:25:56 +03:00
Zbigniew Jędrzejewski-Szmek 55a30fd4e8 basic/calendarspec: fix assert crash when year is too large in calendarspec_from_time_t()
gmtime_r() will return NULL in that case, and we would crash.

I committed the reproducer case in fuzz-regressions/, even though we don't have
ubsan hooked up yet. Let's add it anyway in case it is useful in the future. We
actually crash anyway when compiled with asserts, so this can be easily
reproduced without ubsan.

oss-fuzz #6886.
2018-03-14 16:50:09 +01:00
Zbigniew Jędrzejewski-Szmek 20d52ab60e shared/conf-parser: fix crash when specifiers cannot be resolved in config_parse_device_allow()
oss-fuzz #6885.
2018-03-14 16:50:08 +01:00
Zbigniew Jędrzejewski-Szmek 0d032da993 TODO: trim obsolete entries
set -e is now used in test/TEST-*/test.sh, BUILD_DIR may be specified,
and symlinks are created as of ba7f4ae617.
2018-03-14 16:37:09 +01:00
Zbigniew Jędrzejewski-Szmek 8d89e51f3c fuzz: commit test case for oss-fuzz issue 6884
This seems to be a false positive in msan:
https://github.com/google/sanitizers/issues/767.

I don't see anything wrong with the code either, and valgrind does not see the
issue. Anyway, let's add the test case.

We don't have msan hooked up yet, but hopefully we'll in the future.

oss-fuzz #6884.
2018-03-14 15:20:02 +01:00
Zbigniew Jędrzejewski-Szmek 52d4d1d339 test: run all fuzz regression tests with all sanitizers
We currently have just one sanitizer for tests, asan, but we may add more in
the future. So let's keep the loop over the sanitizers in meson.build, but
just enable all regression cases under all sanitizers. If it fails under one
of them, it might fail under a different one.

In subsequent commits I'll add test cases which might not fail under asan,
but it's good to commit them for future use.

The test names are made more verbose:
256/257 fuzz-dns-packet:oss-fuzz-5465:address   OK       0.04 s
257/257 fuzz-dns-packet:issue-7888:address      OK       0.03 s
2018-03-14 14:27:04 +01:00
Zbigniew Jędrzejewski-Szmek b93618644b core/umount: fix unitialized fields in MountPoint in dm_list_get()
This one might actually might cause a crash.
2018-03-14 12:38:43 +01:00
Peter Hutterer 539ad37f18 hwdb: add axis override for the Razer Blade Stealth (#8436)
This touchpad has heavy jitter, set a fuzz of 8 to work around this.

From https://bugs.freedesktop.org/show_bug.cgi?id=105409
2018-03-14 05:36:29 +09:00
Zbigniew Jędrzejewski-Szmek 46af0be929 boot: also use _cleanup_freepool_ in util.c
efivar_get() was leaking memory on success, afaict.
2018-03-13 11:42:02 +01:00
Zbigniew Jędrzejewski-Szmek a42d7cf165 sd-boot: introduce _cleanup_freepool_ 2018-03-13 11:41:32 +01:00
Zbigniew Jędrzejewski-Szmek d4f5c00153
Merge pull request #8429 from medhefgo/sd-shutdown
sd-shutdown improvements
2018-03-13 09:47:09 +01:00
Doug Christman ce21568dc3 zsh-completion: add calendar to systemd-analyze (#8438) 2018-03-13 09:41:07 +01:00
Zbigniew Jędrzejewski-Szmek 6a2b82a713 basic: trivial indentation fix 2018-03-13 08:33:14 +01:00
Evgeny Vereshchagin 7a30dfeb18
Merge pull request #8423 from keszybz/unit-file-fuzzer
Unit file fuzzer
2018-03-12 23:08:32 +03:00
Jan Janssen 456b2199f6 shutdown: Reduce log level of unmounts
There is little point in logging about unmounting errors if the
exact mountpoint will be successfully unmounted in a later retry
due unmounts below it having been removed.

Additionally, don't log those errors if we are going to switch back
to a initrd, because that one is also likely to finalize the remaining
mountpoints. If not, it will log errors then.
2018-03-12 18:32:26 +01:00
Jan Janssen e783b4902f umount: Don't bother remounting api and ro filesystems read-only 2018-03-12 18:32:26 +01:00
Jan Janssen 8645ffd12b umount: Try unmounting even if remounting read-only failed
In the case of some api filesystems remounting read-only fails
while unmounting succeeds.
2018-03-12 18:32:26 +01:00
Jan Janssen 3bc341bee9 umount: Provide the same mount flags too when remounting read-only
This most likely amounts to no real benefits and is just here for
completeness sake.
2018-03-12 18:32:26 +01:00
Jan Janssen 1d62d22d94 umount: Decide whether to remount read-only earlier 2018-03-12 18:32:26 +01:00
Jan Janssen 0494cae03d umount: Add more asserts and remove some unused arguments 2018-03-12 18:32:10 +01:00
Zbigniew Jędrzejewski-Szmek 99eae076eb
Merge pull request #8296 from poettering/resolvconf
resolvconf(8) compat interface
2018-03-12 17:27:39 +01:00
Yu Watanabe dace710c4a dhcp4: introduce new option 'duid-only' for ClientIdentifier= (#8350)
This makes users can configure DHCPv4 client with ClientIdentifier=duid-only.
If set so, then DHCP client sends only DUID as the client identifier.
This may not be RFC compliant, but some setups require this.

Closes #7828.
2018-03-12 17:18:07 +01:00
Zbigniew Jędrzejewski-Szmek 36cd9913ce tools/oss-fuzz: add clang library dir using -L
I have no idea why clang doesn't do this on its own, and why clang
makes it so hard to query this path (-dumpversion returns something
unrelated...).

I know this is an ugly hack, but this is a very specialized script,
so it should be OK to make it a bit hacky.

Tested to work on Fedora (27) and Debian (unstable).

Fixes #8428.
2018-03-12 15:59:25 +01:00
Zbigniew Jędrzejewski-Szmek 9037a0e022 Rename scripts/oss-fuzz.sh to tools/oss-fuzz.sh 2018-03-12 15:40:37 +01:00
Zbigniew Jędrzejewski-Szmek 748c59b110 Rename scripts/coverity.sh to tools/coverity.sh
There are only two files in tools/, I don't think we need a separate
directory for them.
2018-03-12 15:39:21 +01:00
Jan Janssen 659b15313b umount: Fix memory leak 2018-03-12 13:40:14 +01:00
Daniel Dao f02ba16389 setup route expiration in kernel if supported
kernel >= 4.5 (with commit 32bc201e19) supports
RTA_EXPIRES netlink attribute to set router lifetime. This simply detect
the kernel version (>=4.5) and set the lifetime properly, fallback to
expiring route in userspace for kernel that doesnt support it.

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
2018-03-12 11:36:25 +00:00
Zbigniew Jędrzejewski-Szmek 6910dceef2
Merge pull request #8377 from sourcejedi/logind_restart_is_sorely_lacking_in_testing3
login: don't remove all devices from PID1 when only one was removed
2018-03-11 16:40:41 +01:00
Zbigniew Jędrzejewski-Szmek d14829c8b7 fuzz-dhcp-server: fix name of options file 2018-03-11 16:33:59 +01:00
Zbigniew Jędrzejewski-Szmek 170dd5f916 fuzz-unit-file: add a dump of systemd.directives(7) as a corpus entry
$ ( echo service; man systemd.directives|grep =|grep -v -e --|sed 's/ //g'
  ) >> test/fuzz-corpus/unit-file/directives.service
2018-03-11 16:33:59 +01:00
Zbigniew Jędrzejewski-Szmek b872843c4d fuzz: allow logging to be configured, disable in fuzz-unit-file
fuzz-unit-file generated too much logs about invalid config lines. This just
slows things down and fills the logs. If necessary, it's better to rerun the
interesting cases with SYSTEMD_LOG_LEVEL=debug.
2018-03-11 16:33:59 +01:00
Zbigniew Jędrzejewski-Szmek af7bce4165 fuzz: skip bus error map in bus_error_name_to_errno()
Fuzzing with AddressSanitizer reports an error here:
==11==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fe53f5497d8 at pc 0x7fe53ef055c9 bp 0x7ffd344e9380 sp 0x7ffd344e9378
READ of size 4 at 0x7fe53f5497d8 thread T0
SCARINESS: 27 (4-byte-read-global-buffer-overflow-far-from-bounds)
    #0 0x7fe53ef055c8 in bus_error_name_to_errno /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:118:24
    #1 0x7fe53ef0577b in bus_error_setfv /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:274:17
    #2 0x7fe53ef0595a in sd_bus_error_setf /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:284:21
    #3 0x561059 in manager_load_unit_prepare /work/build/../../src/systemd/src/core/manager.c
    #4 0x560680 in manager_load_unit /work/build/../../src/systemd/src/core/manager.c:1773:13
    #5 0x5d49a6 in unit_add_dependency_by_name /work/build/../../src/systemd/src/core/unit.c:2882:13
    #6 0x538996 in config_parse_unit_deps /work/build/../../src/systemd/src/core/load-fragment.c:152:21
    #7 0x6db771 in next_assignment /work/build/../../src/systemd/src/shared/conf-parser.c:155:32
    #8 0x6d697e in parse_line /work/build/../../src/systemd/src/shared/conf-parser.c:273:16
    #9 0x6d5c48 in config_parse /work/build/../../src/systemd/src/shared/conf-parser.c:390:21
    #10 0x535678 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-unit-file.c:41:16
    #11 0x73bd60 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:517:13
    #12 0x73a39f in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:442:3
    #13 0x73d9bc in fuzzer::Fuzzer::MutateAndTestOne() /src/libfuzzer/FuzzerLoop.cpp:650:19
    #14 0x73fa05 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:773:5
    #15 0x71f75d in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:754:6
    #16 0x71285c in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #17 0x7fe53da0482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #18 0x430e68 in _start (/out/fuzz-unit-file+0x430e68)

0x7fe53f5497d8 is located 8 bytes to the right of global variable 'bus_common_errors' defined in '../../src/systemd/src/libsystemd/sd-bus/bus-common-errors.c:28:51' (0x7fe53f549300) of size 1232
SUMMARY: AddressSanitizer: global-buffer-overflow /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:118:24 in bus_error_name_to_errno
Shadow bytes around the buggy address:
  0x0ffd27ea12a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ffd27ea12f0: 00 00 00 00 00 00 00 00 00 00 f9[f9]f9 f9 f9 f9
  0x0ffd27ea1300: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ffd27ea1310: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ffd27ea1320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea1330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea1340: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==11==ABORTING

but I think it's a false positive because of our low-level magic in how this
area is constructed.
2018-03-11 16:33:59 +01:00
Zbigniew Jędrzejewski-Szmek ec7a02ea54 Add fuzzer for unit file parser 2018-03-11 16:33:59 +01:00
Zbigniew Jędrzejewski-Szmek e8112e67e4 Make MANAGER_TEST_RUN_MINIMAL just allocate data structures
When running tests like test-unit-name, there is not point in setting
up the cgroup and signals and interacting with the environment. Similarly
when running fuzz testing of the parser.

Add new MANAGER_TEST_RUN_BASIC which takes the role of MANAGER_TEST_RUN_MINIMAL,
and redefine MANAGER_TEST_RUN_MINIMAL to just create the basic data structures.
2018-03-11 16:33:59 +01:00