Commit graph

21180 commits

Author SHA1 Message Date
Iwan Timmer 98767d75d7 resolved: longlived TCP connections
Keep DNS over TCP connection open until it's closed by the server or after a timeout.
2018-06-11 20:17:51 +02:00
Zbigniew Jędrzejewski-Szmek 65be7e0652 pid1: do not reset subtree_control on already-existing units with delegation
Fixes #8364.

Reproducer:
$ sudo systemd-run -t -p Delegate=yes bash
# mkdir /sys/fs/cgroup/system.slice/run-u6958.service/supervisor
# echo $$ > /sys/fs/cgroup/system.slice/run-u6958.service/supervisor/cgroup.procs
# echo +memory > /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
# cat /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
memory
# systemctl daemon-reload
# cat /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
(empty)

With patch, the last command shows 'memory'.
2018-06-11 18:12:30 +02:00
Zbigniew Jędrzejewski-Szmek 86ab333d00 basic/path-util: fix ordering in error message
Jun 11 14:29:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: = path is not normalizedWorkingDirectory: /../../etc
   ↓
Jun 11 14:32:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: WorkingDirectory= path is not normalized: /../../etc
2018-06-11 17:06:23 +02:00
Zbigniew Jędrzejewski-Szmek bbac65bcc2
Merge pull request #9157 from poettering/unit-config-load-error
introduce a new "bad-setting" unit load state in order to improve "systemctl status" output when bad settings are used
2018-06-11 14:37:10 +02:00
Lennart Poettering 7590ebc5e7
Merge pull request #9185 from marckleinebudde/can
networkd: add support to configure CAN devices
2018-06-11 12:58:55 +02:00
xginn8 a98f7575ae Add counter for socket unit refuse events (#9217)
core: add counter for socket unit rejection events
2018-06-11 12:56:26 +02:00
Lennart Poettering 6f40aa4547 core: add a couple of more error cases that should result in "bad-setting"
This changes a number of EINVAL cases to ENOEXEC, so that we enter
"bad-setting" state if they fail.
2018-06-11 12:53:12 +02:00
Lennart Poettering 9a0abfa8aa systemctl: load_error is a string, don't compare it with 0
Using isempty() is nicer anyway.
2018-06-11 12:53:12 +02:00
Lennart Poettering c4555ad8f6 core: introduce a new load state "bad-setting"
Since bb28e68477 parsing failures of
certain unit file settings will result in load failures of units. This
introduces a new load state "bad-setting" that is entered in precisely
this case.

With this addition error messages on bad settings should be a lot more
explicit, as we don't have to show some generic "errno" error in that
case, but can explicitly say that a bad setting is at fault.

Internally this unit load state is entered as soon as any configuration
loader call returns ENOEXEC. Hence: config parser calls should return
ENOEXEC now for such essential unit file settings. Turns out, they
generally already do.

Fixes: #9107
2018-06-11 12:53:12 +02:00
Lennart Poettering 8ace1db703 core: rework manager_load_startable_unit_or_warn() on top of unit_validate_load_state()
These functions do very similar work, let's unify common code.
2018-06-11 12:53:12 +02:00
Lennart Poettering fd1e3fd8de core: use bus_unit_validate_load_state() for generating LoadError unit bus property
The load_error is only valid in some load_state cases, lets generate
prettier messages for other cases too, by reusing the
bus_unit_validate_load_state() call which does jus that.

Clients (such as systemctl) ignored LoadError unles LoadState was
"error" before. With this change they could even show LoadError in other
cases and it would show a useful name.
2018-06-11 12:53:12 +02:00
Lennart Poettering e49da001c4 core: rename (and modernize) bus_unit_check_load_state() → bus_unit_validate_load_state()
Let's use a switch() statement, cover more cases with pretty messages.
Also let's rename it to "validate", as that's more specific that
"check", as it implies checking for a "valid"/"good" state, which is
what this function does.
2018-06-11 12:53:12 +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
Lennart Poettering 0b491556ac resolved: rework NSEC covering tests
This makes two changes: first of all we will now explicitly check
whether a domain to test against an NSEC record is actually below the
signer's name. This is relevant for NSEC records that chain up the end
and the beginning of a zone: we shouldn't alow that NSEC record to match
against domains outside of the zone.

This also fixes how we handle NSEC checks for domains that are prefixes
of the NSEC RR domain itself, fixing #8164 which triggers this specific
case. The non-wildcard NSEC check is simplified for that, we can
directly make our between check, there's no need to find the "Next
Closer" first, as the between check should not be affected by additional
prefixes. For the wild card NSEC check we'll prepend the asterisk in
this case to the NSEC RR itself to make a correct check.

Fixes: #8164
2018-06-11 10:43:14 +02:00
Zbigniew Jędrzejewski-Szmek cfc01c1e02 basic/format-table: remove parameter with constant value 2018-06-11 10:04:10 +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
Yu Watanabe 1c73b60b4d util-lib: reject too long path for timedate_is_valid()
This should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8827.
2018-06-11 12:38:34 +09:00
Hiram van Paassen 06828bb617 networkd-link: add support to configure CAN interfaces
This patch adds support for kind "can". Fixes: #4042.
2018-06-09 15:12:31 +02:00
Marc Kleine-Budde bd5038f8b7 networkd-link: link_up_can(): move function upwards
This patch is a preparation patch, to avoid forward declarations in the
next patch.
2018-06-09 15:12:31 +02:00
Marc Kleine-Budde 93ea77505e networkd-link: link_configure(); factor out link_configure_can() into separate function 2018-06-09 15:12:31 +02:00
Marc Kleine-Budde c07b23ca7e conf-parser: add config_parse_permille() 2018-06-09 15:12:31 +02:00
Marc Kleine-Budde 958acea18b parse-util: add permille parser + tests 2018-06-09 15:12:31 +02:00
Zbigniew Jędrzejewski-Szmek 294a3121aa basic/utf8: add ascii_is_valid_n() 2018-06-09 13:41:24 +02:00
Lennart Poettering b5cbe199c7
Merge pull request #9240 from poettering/ds-validate
resolved: fix DNSKEY validation by DS RR
2018-06-08 20:44:01 +02:00
Ivan Shapovalov ee73a176a2 mymachines: fix getgrnam()
getgrnam() was returning input gid instead of the mapped one. Fix that.
2018-06-08 17:52:18 +02:00
Susant Sahani 194c03c839 networkd: tunnel ignore wrong conf rather than assert
Closes #9234
2018-06-08 16:09:19 +02:00
Zbigniew Jędrzejewski-Szmek 5e55cde9b8 resolved: fix typo in macro name 2018-06-08 16:05:18 +02:00
Filipe Brandenburger df560cf6b1 analyze: use _cleanup_ for struct unit_times
This introduces a has_data boolean field in struct unit_files which can
be used to detect the end of the array.

Use a _cleanup_ for struct unit_files in acquire_time_data and its
callers. Code for acquire_time_data is also simplified by replacing
goto's with straight returns.

Tested: By running the commands below, also checking them under valgrind.
  - build/systemd-analyze blame
  - build/systemd-analyze critical-chain
  - build/systemd-analyze plot

Fixes: Coverity finding CID 996464.
2018-06-08 15:46:07 +02:00
Lennart Poettering 6d67385fcd test: add www.dnssec-bogus.sg to list of domains to test in DNSSEC complex test 2018-06-08 15:40:32 +02:00
Lennart Poettering c910c520cf resolved: fix DNSKEY validation against DS
Let's use the wireformat name, not the text version.

Fixes: #8901
2018-06-08 15:40:32 +02:00
Zbigniew Jędrzejewski-Szmek 89278d96dc
Merge pull request #9221 from poettering/bus-track-destroy
add sd_bus_track and sd_event_source destroy callbacks too
2018-06-08 15:35:45 +02:00
Lennart Poettering 63b1219130 resolved: whenever a link starts/stops being relevant flush global DNS caches
Let's add some protection for split horizon setups, where different
zones are visible on the same global DNS servers depending on where you
come from.

Fixes: #9196
2018-06-08 15:16:10 +02:00
Filipe Brandenburger 3ad9705824 scsi_id: use _cleanup_free_ on buffer allocated by get_file_options
This simplifies the code a bit and hopefully fixes Coverity finding
CID 1382966. There was not actually a resource leak here (Coverity
seemed to be confused by thinking log_oom() could actually return 0),
but the fix doesn't hurt and should make this code more resilient to
future refactorings.

Tested: builds fine, manually called scsi_id, seems to work ok.
2018-06-08 15:15:02 +02:00
Lennart Poettering 0323073878
Merge pull request #9213 from poettering/copy-mount
copy() mount detection fixes
2018-06-08 12:09:23 +02:00
Filipe Brandenburger d23c3e4c28 lldp: check that lldp neighbor raw data size is in expected range
This fixes an insecure use of tainted data as argument to functions that
allocate memory and read from files, which could be tricked into getting
networkctl to allocate a large amount of memory and fill it with file
data.

This was uncovered by Coverity. Fixes CID 1393254.
2018-06-08 08:54:25 +02:00
Filipe Brandenburger 15b8332e7c networkd: add missing _cleanup_ in prefix_new
This should fix a leak of the allocated Prefix if sd_radv_prefix_new
fails for some reason.

The code was already initializing prefix to NULL and using TAKE_PTR to
return it, so only the _cleanup_ was missing.

Fixes Coverity finding CID 1382976.
2018-06-08 00:48:41 +02:00
Filipe Brandenburger 9d635f50b8 udev-builtin-usb_id: Check full range of size returned by read()
This shouldn't be necessary, since read() should never return a size
larger than the size of the buffer passed in, but Coverity doesn't seem
to understand that.

We could possibly fix this with a model file for Coverity, but given
changing the code is not that much of a biggie, let's just do that
instead.

Fixes CID 996458: Overflowed or truncated value (or a value computed
from an overflowed or truncated value) `pos` used as array index.

Tested: `ninja -C build/ test`, builds without warnings, test cases pass.
2018-06-08 00:46:44 +02:00
Filipe Brandenburger fffafb2b5e udev: fix usage of udev_device_new_from_stat_rdev() in journalctl
The refactor in #9200 inadvertently dropped the variable assignment to
traverse the device and its hierarchy in add_matches_for_device().

This was uncovered by Coverity (CID #1393310).

Fix that by restoring the assignment.

Tested: `journalctl /dev/sda` now filters journalctl output again.
2018-06-08 00:45:22 +02:00
Lennart Poettering 3ceca73a59
Merge pull request #9200 from poettering/device-state-fix
core: rework device state serialization/enumeration
2018-06-07 17:04:57 +02:00
Lennart Poettering ce3ec07f41
Merge pull request #9165 from ssahani/networkd-netdevsim
networkd: introduce netdev "Netdevsim" Driver
2018-06-07 16:56:32 +02:00
Lennart Poettering cb209a0489 swap: trivial log message improvements 2018-06-07 15:29:17 +02:00
Lennart Poettering a7f8be01aa core: be a bit stricter when validating SYSTEMD_ALIAS udev props 2018-06-07 15:29:17 +02:00
Lennart Poettering b8b846d7b4 tree-wide: fix a number of log calls that use %m but have no errno set
This is mostly fall-out from d1a1f0aaf0,
however some cases are older bugs.

There might be more issues lurking, this was a simple grep for "%m"
across the tree, with all lines removed that mention "errno" at all.
2018-06-07 15:29:17 +02:00
Lennart Poettering 04eb582acc core: enumerate perpetual units in a separate per-unit-type method
Previously the enumerate() callback defined for each unit type would do
two things:

1. It would create perpetual units (i.e. -.slice, system.slice, -.mount and
   init.scope)

2. It would enumerate units from /proc/self/mountinfo, /proc/swaps and
   the udev database

With this change these two parts are split into two seperate methods:
enumerate() now only does #2, while enumerate_perpetual() is responsible
for #1. Why make this change? Well, perpetual units should have a
slightly different effect that those found through enumeration: as
perpetual units should be up unconditionally, perpetually and thus never
change state, they should also not pull in deps by their state changing,
not even when the state is first set to active. Thus, their state is
generally initialized through the per-device coldplug() method in
similar  fashion to the deserialized state from a previous run would be
put into place. OTOH units found through regular enumeration should
result in state changes (and thus pull in deps due to state changes),
hence their state should be put in effect in the catchup() method
instead. Hence, given this difference, let's also separate the
functions, so that the rule is:

1. What is created in enumerate_perpetual() should be started in
   coldplug()

2. What is created in enumerate() should be started in catchup().
2018-06-07 15:29:17 +02:00
Lennart Poettering 244f805549 core: tighten when we unset the sysfs path of device units
Make sure that whenever we enter "dead" state we unset the sysfs path,
not just when we are changing to it due to "found" mask changes.
2018-06-07 15:29:17 +02:00
Lennart Poettering 66f3fdbb07 core: rework how device units get set up
This reworks how device units are "powered on".

This makes sure that any device changes that might have happened while
we were restarting/reloading will be noticed properly. For that we'll
now properly serialize/deserialize both the device unit state and the
device "found" flags, and restore these initially in the "coldplug"
phase of the manager deserialization. While enumerating the udev devices
during startup we'll put together a new "found" flags mask, which we'll
the switch to in the "catchup" phase of the manager deserialization,
which follows the "coldplug" phase.

Note that during the "coldplug" phase no unit state change events are
generated, which is different for the "catchall" phase which will do
that. Thus we correctly make sure that the deserialized state won't pull
in new deps, but any device's change while we were reloading would.

Fixes: #8832
Replaces: #8675
2018-06-07 15:29:17 +02:00
Lennart Poettering 69ce73d18d device: simplify device_found_to_string_many() a tiny bit
No need to maintain a NULL marker at the end of the table if we know the
size of the array anyway.
2018-06-07 15:28:50 +02:00
Lennart Poettering f0831ed2a0 core: add a new unit method "catchup()"
This is very similar to the existing unit method coldplug() but is
called a bit later. The idea is that that coldplug() restores the unit
state from before any prior reload/restart, i.e. puts the deserialized
state in effect. The catchup() call is then called a bit later, to
catch up with the system state for which we missed notifications while
we were reloading. This is only really useful for mount, swap and device
mount points were we should be careful to generate all missing unit
state change events (i.e. call unit_notify() appropriately) for
everything that happened while we were reloading.
2018-06-07 15:28:50 +02:00
Lennart Poettering 62b0cbb358 core: use safe_fclose() where appropriate 2018-06-07 13:36:19 +02:00
Lennart Poettering 159f1e7666 core: split out early-boot preset logic into a function of its own 2018-06-07 13:36:19 +02:00