Commit Graph

1655 Commits

Author SHA1 Message Date
Yu Watanabe 0c2c0fd256 resolve: fix use after free in DnsAnswer
This fixes a bug introduced by ae45e1a383.

The set DnsAnswer::set_items contains the reference to the array in
DnsAnswer. So, the set must be reconstructed when we realloc() the
object.

Fixes #18132.
2021-01-08 19:06:00 +01:00
Lennart Poettering c2bc710b24 string-util: imply NULL termination of strextend() argument list
The trailing NULL in the argument list is now implied (similar to
what we already have in place in strjoin()).
2021-01-06 17:24:46 +01:00
Yu Watanabe ae45e1a383 resolve: slightly optimize dns_answer_add()
Previously, dns_answer_add() was O(n^2).
With this change dns_packet_extract() becomes ~15 times faster for some
extremal case.

Before:
```
$ time ./fuzz-dns-packet ~/downloads/clusterfuzz-testcase-minimized-fuzz-dns-packet-5631106733047808
/home/watanabe/downloads/clusterfuzz-testcase-minimized-fuzz-dns-packet-5631106733047808... ok

real    0m15.453s
user    0m15.430s
sys     0m0.007s
```

After:
```
$ time ./fuzz-dns-packet ~/downloads/clusterfuzz-testcase-minimized-fuzz-dns-packet-5631106733047808
/home/watanabe/downloads/clusterfuzz-testcase-minimized-fuzz-dns-packet-5631106733047808... ok

real    0m0.831s
user    0m0.824s
sys     0m0.006s
```

Hopefully fixes oss-fuzz#19227.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19227
2020-12-30 04:14:22 +09:00
Yu Watanabe b652cccab9 resolve: field size in dns resource record may be zero 2020-12-30 04:14:22 +09:00
Yu Watanabe cd70fc373d resolve: do not compare key twice 2020-12-30 01:22:59 +09:00
Yu Watanabe 600864921b resolve: slightly shorten dns_resource_key_compare_func() 2020-12-30 01:22:59 +09:00
Yu Watanabe e9665ac2a2 resolve: fix typo 2020-12-30 01:22:56 +09:00
Lennart Poettering 5777c6130b resolved: always take a timestamp when first seeing a packet
This is later useful if we want to adjust the TTLs of packets we want to
propagate to clients.
2020-12-16 14:20:49 +01:00
Ondrej Mosnacek 7b87bece5d resolved: create stub-resolv.conf symlink with correct security label
Use symlink_atomic_label() instead of symlink_atomic() as the symlink
may need a different label than the parent directory.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2020-12-15 14:12:08 +01:00
Zbigniew Jędrzejewski-Szmek 3c94f71472 Drop compat "gateway" name
Back in 5248e7e1f1 (July 2017) we moved over to
"_gateway", with the old name declared to be temporary measure. Since we're
doing a bunch of changes to resolved now, it seems to be a good moment to make
this simplification and not add support for the compat name in new code.
2020-12-10 20:44:41 +01:00
Lennart Poettering 877884fc0d resolved: synthesize NODATA instead of NXDOMAIN if gateway exists, but of other protocol
Fixes: #11192
2020-12-03 23:23:11 +01:00
Lennart Poettering 6c0bacc146 resolved: improve log message when we use TCP a bit
DNS-over-TLS being in use isn't precisely the same as "UDP not
supported". Let's make this clearer.
2020-12-03 22:46:59 +01:00
Lennart Poettering 565147b7bb stub: don't ever respond to datagrams coming in on non-localhost addreses, on the stub 2020-12-03 09:35:40 +09:00
Lennart Poettering 9ca875e80c resolved: beef up logic for suppressing "localhost" entry in /etc/hosts
Either suppress the entry entirely, or not at all. But do not suppress
the "localhost" names we recognize, leaving the ones we do not in place.

On Fedora, where "localhost4.localdomain4" is among those listed in
/etc/hosts for 127.0.0.1 we'd thus otherwise drop the "localhost" but
keep the "localhost4.localdomain4" and then on reverse lookups only
return that, which is highly confusing.
2020-12-03 09:06:27 +09:00
Lennart Poettering 36d892b7e6 resolved: use stat_inode_unmodified() to detect /etc/hosts changes 2020-12-03 08:58:45 +09:00
Lennart Poettering fbbc72189f resolved: never allow _gateway lookups to go to the network
Make them rather fail than go to the network.

Previously we'd filter them on LLMNR (explicitly) and MDNS (implicitly,
because it doesn't have .local suffix), but not on DNS.

In order to make _gateway truly reliable, let's not allow it to go to
DNS either, and keep it local.

This is particular relevant, as clients can now request lookups without
local RR synthesis, where we'd rather have NXDOMAIN returned for
_gateway than have it hit the network.
2020-12-03 08:56:27 +09:00
Lennart Poettering 19bcef9dc3 resolved: lower SERVFAIL cache timeout from 30s to 10s
Apparently 30s is a bit too long for some cases, see #5552. But not
caching SERVFAIL at all also breaks stuff, see explanation in
201d99584e.

Let's try to find some middle ground, by lowering the cache timeout to
10s. This should be ample for the problem
201d99584e attackes, but not as long as
half a miute, as #5552 complains.

Fixes: #5552
2020-12-03 08:52:27 +09:00
Yu Watanabe 34f80876f8
Merge pull request #17807 from poettering/bindtodevice
use SO_BINDTOIFINDEX while connect()
2020-12-03 08:50:43 +09:00
Lennart Poettering 0a489d3f5d resolved: insert large dgram size into EDNS0 only when in LARGE UDP mode
Specifically, in TLS-DO there's no reason to set the exotic dgram size.
2020-12-03 08:49:58 +09:00
Lennart Poettering 90df0fbea8 resolved: automatically flush caches on clock change
DNSSEC validation takes the system clock into account to validate
signatures. This means if we had incorrect time and the time is then
changed to the correct one we should flush out everything and
re-validate taking the new time into account.

(This logic will also trigger after system suspend, which is not bad
either, given that quite possibly we are connected to a different
network, and thus would get different DNS data, without us noticing
otherwise via link beat).
2020-12-03 07:25:17 +09:00
Lennart Poettering 0b261ac5be resolved: log when a bus client changes per-link DNS info
Fixes: #16298
2020-12-03 07:08:07 +09:00
Zbigniew Jędrzejewski-Szmek 4cbd28af60
Merge pull request #17804 from poettering/write-resolve-conf-less
write resolv.conf less often
2020-12-02 16:56:52 +01:00
Lennart Poettering 7e8a93b77c resolved: properly check per-link NTA list
We need to check for parent domains too. We did this correctly for the
system-wide NTA list, but not for the per-link one. Let's fix that.
2020-12-02 16:56:11 +01:00
Lennart Poettering d301c52383 resolved: bind socket to interface during connect()
Apparently, IF_UNICAST_IF does not influence the routing decisions done
during connect(). But SO_BINDTODEVICE/SO_BINDTOINDEX does, which however
brings a lot of other semantics with it, we are not so interested in
(i.e. it doesn't not allow packets from any other iface to us, even if
routing otherwise allows it).

Hence, let's bind to the ifindex immediately before the connect() and
unbind right after again, so that we get the semantics we want, but not
the ones we don't.

Fixes: #11935
Replaces: #12004
2020-12-02 15:15:02 +01:00
Lennart Poettering f3e1f00d03 resolved: don't update resolv.conf snippets unnecessarily
Fixes: #17577
2020-12-02 10:32:17 +01:00
Yu Watanabe 0d5eb02134
Merge pull request #17478 from yuwata/split-network-internal
libsystemd-network: split network-internal.c
2020-11-27 09:04:19 +09:00
Pavel Sapezhko 6d8325f66a resolved: allow cache responses from local DNS servers 2020-11-27 09:03:42 +09:00
Yu Watanabe e93387f38b tree-wide: sort specifiers and move common comments to specifier.h 2020-11-25 15:12:27 +09:00
Lennart Poettering 4fab57cec5
Merge pull request #17669 from yuwata/coccinelle-update
tree-wide: shorten code a bit suggested by coccinelle
2020-11-23 22:19:52 +01:00
Lennart Poettering e3650d619a
Merge pull request #17676 from yuwata/lgtm-fixes
tree-wide: several fixes prompted by LGTM
2020-11-23 22:18:28 +01:00
Yu Watanabe 283ec78963 resolvectl: drop a condition which is always true 2020-11-20 19:39:49 +09:00
Yu Watanabe fed66db05d tree-wide: use return value of log_xxx_errno() 2020-11-20 02:58:27 +09:00
Yu Watanabe dd2e9e1d0e resolve: ignore invalid service template name
Let's fiest test the template name, and then assign it.
2020-11-18 03:32:40 +09:00
Yu Watanabe 0c949643b8 resolve: make config_parse_dnssd_service_name() accepts an empty string 2020-11-18 03:23:32 +09:00
Yu Watanabe a37eb63ffa resolve: add a short comment about difference between dnssd_render_instance_name() and config_parse_dnssd_service_name() 2020-11-18 03:22:56 +09:00
Yu Watanabe d63542bc02 resolve: wrap long line 2020-11-18 03:20:30 +09:00
Roman Beranek 07e4a8dc23 Revert "resolve: check DNSSD service name template before assigning it"
This reverts commit 34136e1503.

Having the "%H" host name specifier in a DNSSD service name template
triggers a failed assertion during name template instantiation as
specifier_dnssd_host_name expects DnssdService in its userdata
pointer but finds NULL instead.
2020-11-18 03:16:57 +09:00
Yu Watanabe d51c4fca29 tree-wide: fix "a the" or "the a" 2020-11-13 16:28:47 +09:00
Jörg Thalheim d7aa78c32f meson: add option to skip installing to $sysconfdir
This is useful for development where overwriting files out side
the configured prefix will affect the host as well as stateless
systems such as NixOS that don't let packages install to /etc but handle
configuration on their own.

Alternative to https://github.com/systemd/systemd/pull/17501

tested with:

$ mkdir inst build && cd build
$ meson \
  -Dcreate-log-dirs=false \
  -Dsysvrcnd-path=$(realpath ../inst)/etc/rc.d \
  -Dsysvinit-path=$(realpath ../inst)/etc/init.d \
  -Drootprefix=$(realpath ../inst) \
  -Dinstall-sysconfdir=false \
  --prefix=$(realpath ../inst) ..
$ ninja install
2020-11-12 11:21:46 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering eaa269484b resolved: fix non-initialized memory access
Fix for bug introduced in 1ed314087f.
2020-11-06 13:58:20 -08:00
Lennart Poettering 76f772298e resolved: slightly extend debug log output about outgoing messages 2020-11-06 14:43:05 +01:00
Lennart Poettering 088648d081 resolved: don't resolve "local." via LLMNR
It's the mDNS top-level domain, hence don't consider it for LLMNR, ever.

Fixes: #16233
2020-11-06 14:43:01 +01:00
Lennart Poettering dc194dce80 resolved: add comments for various query flags 2020-11-06 14:42:56 +01:00
Lennart Poettering 5cdcac6cf6 resolved: show all answer flags when dumping answer 2020-11-06 14:42:53 +01:00
Lennart Poettering 032b398224 resolved: add minor optimization path to dns_answer_merge() 2020-11-06 14:42:49 +01:00
Lennart Poettering 02c205359b resolved: suppress misleading debug message about ignored resolv.conf line 2020-11-06 14:42:45 +01:00
Lennart Poettering 2f4c2db20a resolved: handle RRs where we don't have a signer
If we encounter an RR that has no matching signature, then we don't know
whether it was expanded from a wildcard or not. We need to accept that
and not make the NSEC test fail, just skip over the RR.
2020-11-03 20:36:02 +01:00
Lennart Poettering de4a0138e7 resolved: drop unused family argument from manager_routable() 2020-11-03 20:35:09 +01:00
Lennart Poettering 014e8cc131 resolved: fix dumping of DnsAnswer objects 2020-11-03 20:35:09 +01:00