Commit Graph

22087 Commits

Author SHA1 Message Date
Lennart Poettering 8eb41f4c08 sd-radv: EAGAIN is not really unexpected, distinguishit from other errors when logging 2018-10-02 16:26:50 +02:00
Lennart Poettering 437524f178 sd-ndisc: generate debug log messages on unexpected errors
We really should make it possible to debug unexpected errors, hence log
something at LOG_DEBUG.
2018-10-02 16:25:54 +02:00
Lennart Poettering fdc2afc102 sd-radv: remove log_radv_warning_errno()
According to our CODING_STYLE our library code should generally not log
beyond LOG_DEBUG. Let's hence get rid of log_radv_warning_errno() and
just use log_radv_errno() instead.
2018-10-02 16:22:54 +02:00
Ronny Chevalier afc1feaeba bus-unit-util: fix parsing of IPAddress{Allow,Deny}
While the config parser correctly handles the case of multiple IPs,
bus_append_cgroup_property was only parsing one IP,
and it would fail with "Failed to parse IP address prefix" when given
a list of IPs.
2018-10-02 15:46:15 +02:00
Lennart Poettering c3281539da
Merge pull request #10246 from keszybz/fuzz-buss
Bus fuzzer
2018-10-02 15:45:21 +02:00
Evgeny Vereshchagin 14f37112c8 icmp6-util: stop ignoring EAGAIN and EINTR in icmp6_receive
The code handling the errors was originally part of ndisc_recv, which,
being an event handler, would be simply turned off if it returned a negative
error code. It's no longer necessary. Plus, it helps avoid passing
an uninitialized value to radv_send.

Closes https://github.com/systemd/systemd/issues/10223.
2018-10-02 12:58:07 +02:00
Zbigniew Jędrzejewski-Szmek 902000c198 bus-message: avoid wrap-around when using length read from message
We would read (-1), and then add 1 to it, call message_peek_body(..., 0, ...),
and when trying to make use of the data.

The fuzzer test case is just for one site, but they all look similar.

v2: fix two UINT8_MAX/UINT32_MAX mismatches founds by LGTM
2018-10-02 11:59:08 +02:00
Zbigniew Jędrzejewski-Szmek d831fb6f2b bus-message: return -EBADMSG not -EINVAL on invalid !gvariant messages 2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 3d338a302f bus-message: also properly copy struct signature when skipping
The change is similar to that in the previous commit, but I don't have
a reproducer / test case case for this one, so I'm keeping it seperate.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 73777ddba5 bus-message: fix skipping of array fields in !gvariant messages
We copied part of the string into a buffer that was off by two.
If the element signature had length one, we'd copy 0 bytes and crash when
looking at the "first" byte. Otherwise, we would crash because strncpy would
not terminate the string.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 0b4775b527 bus-message: output debug information about offset troubles 2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 10a7ec96d8 test-bus-gvariant: turn on debug output
I thought the test was wrong, but it turns out one of my patches was at
fault. But this helps to diagnose issues.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 8792bdf8a3 bus-message: drop asserts in functions which are wrappers for varargs version
The function does no processing on it's own, and just forwards arguments
to the other function. Let's just use the asserts there.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek f88214cf9d bus-message: fix calculation of offsets table for arrays
This is similar to the grandparent commit 'fix calculation of offsets table',
except that now the change is for array elements. Same story as before: we need
to make sure that the offsets increase enough taking alignment into account.

While at it, rename 'p' to 'previous' to match similar code in other places.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 4d82a8d505 bus-message: remove duplicate assignment 2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 12603b84d2 bus-message: fix calculation of offsets table
The offsets specify the ends of variable length data. We would trust the
incoming data, putting the offsets specified in our message
into the offsets tables after doing some superficial verification.
But when actually reading the data we apply alignment, so we would take
the previous offset, align it, making it bigger then current offset, and
then we'd try to read data of negative length.

In the attached example, the message specifies the following offsets:
[1, 4]
but the alignment of those items is
[1, 8]
so we'd calculate the second item as starting at 8 and ending at 4.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek e8fd7e4b5b bus: do not print (null) if the message has unknown type 2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek f22c308aff bus-message: use define 2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 9c65778d61 bus-message: rename function for clarity
There's already message_free_last_container(), so rename to match.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 81b6e63029 bus-message: do not crash on message with a string of zero length
We'd calculate the "real" length of the string as 'item_size - 1', which does
not work out well when item_size == 0.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 69bd42ca07 bus-message: let's always use -EBADMSG when the message is bad
-EINVAL means the arguments were somehow wrong, so translate the code we get
internally into -EBADMSG when returning.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek ec6bda56cb bus-message: avoid an infinite loop on empty structures
The alternative would be to treat gvariant and !gvariant messages differently.
But this is a problem because we check signatures is variuos places before we
have an actual message, for example in sd_bus_add_object_vtable(). It seems
better to treat things consistent (i.e. follow the lowest common denominator)
and disallow empty structures everywhere.
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek 6d1e0f4fcb sd-bus: unify three code-paths which free struct bus_container
We didn't free one of the fields in two of the places.

$ valgrind --show-leak-kinds=all --leak-check=full \
  build/fuzz-bus-message \
  test/fuzz/fuzz-bus-message/leak-c09c0e2256d43bc5e2d02748c8d8760e7bc25d20
...
==14457== HEAP SUMMARY:
==14457==     in use at exit: 3 bytes in 1 blocks
==14457==   total heap usage: 509 allocs, 508 frees, 51,016 bytes allocated
==14457==
==14457== 3 bytes in 1 blocks are definitely lost in loss record 1 of 1
==14457==    at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==14457==    by 0x53AFE79: strndup (in /usr/lib64/libc-2.27.so)
==14457==    by 0x4F52EB8: free_and_strndup (string-util.c:1039)
==14457==    by 0x4F8E1AB: sd_bus_message_peek_type (bus-message.c:4193)
==14457==    by 0x4F76CB5: bus_message_dump (bus-dump.c:144)
==14457==    by 0x108F12: LLVMFuzzerTestOneInput (fuzz-bus-message.c:24)
==14457==    by 0x1090F7: main (fuzz-main.c:34)
==14457==
==14457== LEAK SUMMARY:
==14457==    definitely lost: 3 bytes in 1 blocks
2018-10-02 11:53:20 +02:00
Zbigniew Jędrzejewski-Szmek cf81c68e96 bus-message: use structured initialization to avoid use of unitialized memory
As far as I can see, we would either reuse some values from a previously exited
container or just random bytes from the heap.

Should fix #10127.
2018-10-02 11:53:18 +02:00
Zbigniew Jędrzejewski-Szmek 7f546026ab Introduce free_and_strndup and use it in bus-message.c
v2: fix error in free_and_strndup()

When the orignal and copied message were the same, but shorter than specified
length l, memory read past the end of the buffer would be performed. A test
case is included: a string that had an embedded NUL ("q\0") is used to replace
"q".

v3: Fix one more bug in free_and_strndup and add tests.

v4: Some style fixed based on review, one more use of free_and_replace, and
make the tests more comprehensive.
2018-10-02 11:42:45 +02:00
Zbigniew Jędrzejewski-Szmek 56b560c263 fuzz-bus-message: add fuzzer for message parsing
As with other fuzzers, SYSTEMD_FUZZ_OUTPUT=1 and SYSTEMD_LOG_LEVEL=debug can be
used for debugging.
2018-10-02 11:09:05 +02:00
Zbigniew Jędrzejewski-Szmek 3ddf3d4394 test-bus-marshal: use cescaping instead of hexmem
It is easier to see the contents this way by eye.
2018-10-02 09:41:25 +02:00
Yu Watanabe 5c434af721
Merge pull request #10218 from keszybz/export-sd-device-hwdb
Export functions in sd-device and sd-hwdb
2018-10-01 19:45:55 +02:00
Zbigniew Jędrzejewski-Szmek 4dd73b883f test-sd-hwdb: skip tests if hwdb cannot be opened 2018-10-01 15:22:55 +02:00
Yu Watanabe f9c8c01fcc test: try system bus if user bus cannot be opened 2018-10-01 10:15:54 +02:00
Zbigniew Jędrzejewski-Szmek 3bdce0eac0
Merge pull request #10138 from yuwata/test-check-container
test: skip several tests when running in container
2018-10-01 10:09:54 +02:00
Zbigniew Jędrzejewski-Szmek 41ad5ea198
Merge pull request #10220 from floppym/efi-cc
meson: use an array option for efi-cc
2018-10-01 09:28:22 +02:00
Yu Watanabe e986910e87 import: sparse_write() returns negative errno 2018-10-01 08:29:16 +02:00
Mike Gilbert 5f723125ae meson: avoid calling the shell to resolve efi_libdir 2018-09-30 16:22:07 -04:00
Mike Gilbert 595343fb4c meson: use an array option for efi-cc
Fixes: https://github.com/systemd/systemd/issues/10211
2018-09-30 15:43:39 -04:00
Thomas Haller f21f31b24b trivial: fix spelling in code comments
Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
2018-09-30 21:32:33 +02:00
Zbigniew Jędrzejewski-Szmek 6083c4b763 libsystemd: export all functions in sd-hwdb.h
sd-hwdb.h is now also installed in /usr/include/systemd.
2018-09-30 20:39:02 +02:00
Zbigniew Jędrzejewski-Szmek ca7a9afc7e test-sd-hwdb: add a simple test for export sd-hwdb functions 2018-09-30 20:39:02 +02:00
Zbigniew Jędrzejewski-Szmek 3f608087bd libsystemd: export all functions in sd-device.h
sd-device.h is now also installed in /usr/include/systemd.
2018-09-30 20:39:02 +02:00
Yu Watanabe 213e759ad5 dhcp6: fix memleak about sd_event 2018-09-30 14:17:33 +02:00
Evgeny Vereshchagin b387d3c132 dhcp6: fix an off-by-one error in dhcp6_option_parse_domainname
==14==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200055fa9c at pc 0x0000005458f1 bp 0x7ffc78940d90 sp 0x7ffc78940d88
READ of size 1 at 0x60200055fa9c thread T0
    #0 0x5458f0 in dhcp6_option_parse_domainname /work/build/../../src/systemd/src/libsystemd-network/dhcp6-option.c:555:29
    #1 0x54706e in dhcp6_lease_set_domains /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-lease.c:242:13
    #2 0x53fce0 in client_parse_message /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:984:29
    #3 0x53f3bc in client_receive_advertise /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:1083:13
    #4 0x53d57f in client_receive_message /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:1182:21
    #5 0x7f0f7159deee in source_dispatch /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3042:21
    #6 0x7f0f7159d431 in sd_event_dispatch /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3455:21
    #7 0x7f0f7159ea8d in sd_event_run /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3512:21
    #8 0x531f2b in fuzz_client /work/build/../../src/systemd/src/fuzz/fuzz-dhcp6-client.c:44:9
    #9 0x531bc1 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-dhcp6-client.c:53:9
    #10 0x57bec8 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:570:15
    #11 0x579d67 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:479:3
    #12 0x57dc92 in fuzzer::Fuzzer::MutateAndTestOne() /src/libfuzzer/FuzzerLoop.cpp:707:19
    #13 0x580ca6 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:838:5
    #14 0x55e968 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:764:6
    #15 0x551a1c in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #16 0x7f0f701a082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #17 0x41e928 in _start (/out/fuzz-dhcp6-client+0x41e928)
2018-09-29 03:07:29 +00:00
Evgeny Vereshchagin 45a7becfea tests: make fuzz-dhcp6-client work in containers provided by the OSS-Fuzz project
The containers come with an empty machine-id, which causes the fuzzer
to fail as soon as it starts.

See https://github.com/systemd/systemd/pull/9014#discussion_r189594104
2018-09-29 02:57:04 +00:00
Evgeny Vereshchagin d89a400ed6 fuzz: add a fuzzer for dhcp6_client 2018-09-29 02:27:07 +00:00
Zbigniew Jędrzejewski-Szmek 83043e8dc8
Merge pull request #10190 from evverx/fuzz-ndisc-rs
Add a fuzzer for sd-ndisc and a reproducer for an infinite loop in ndisc_handle_datagram
2018-09-28 15:54:04 +02:00
Helmut Grohne df7cacae69 meson: use the host architecture compiler/linker for src/boot/efi
cross building systemd to arm64 presently fails, because the build
system uses plain gcc and plain ld (build architecture compiler and
linker respectively) for building src/boot/efi. These values come from
the efi-cc and efi-ld options respectively. It rather should be using
host tools here.

Fixes: b710072da4 ("add support for building efi modules")
2018-09-28 14:42:56 +02:00
Zbigniew Jędrzejewski-Szmek 22041e475f
Merge pull request #10186 from yuwata/fix-10149
network: Fix memleaks found by test
2018-09-28 14:20:12 +02:00
Zbigniew Jędrzejewski-Szmek b87dadcdb2 networkd-routing-policy-rule.c: drop unnecessary check
set_get() already does that.
2018-09-27 18:14:56 +02:00
Yu Watanabe 431a4bc8c0 dhcp6: fix memleak
Let's drop client_set_lease() because just writing what it does in both
places is simpler.

Fixes #10157.
2018-09-27 18:14:19 +02:00
Lennart Poettering 2f3db9c907 uft8: add comment, requested by @keszybz 2018-09-27 17:21:18 +02:00
Yu Watanabe cb1bdeaf56 dhcp6: fix buffer size checking 2018-09-27 23:48:51 +09:00