Commit Graph

2126 Commits

Author SHA1 Message Date
Simon Kelley
1de6bbc108 Fix FTBS on FreeBSD due to Linux-specific optimisation of if_nametoindex() 2021-03-19 22:24:08 +00:00
Simon Kelley
023ace8e54 Merge branch 'random-port' 2021-03-17 20:42:21 +00:00
Simon Kelley
74d4fcd756 Use random source ports where possible if source addresses/interfaces in use.
CVE-2021-3448 applies.

It's possible to specify the source address or interface to be
used when contacting upstream nameservers: server=8.8.8.8@1.2.3.4
or server=8.8.8.8@1.2.3.4#66 or server=8.8.8.8@eth0, and all of
these have, until now, used a single socket, bound to a fixed
port. This was originally done to allow an error (non-existent
interface, or non-local address) to be detected at start-up. This
means that any upstream servers specified in such a way don't use
random source ports, and are more susceptible to cache-poisoning
attacks.

We now use random ports where possible, even when the
source is specified, so server=8.8.8.8@1.2.3.4 or
server=8.8.8.8@eth0 will use random source
ports. server=8.8.8.8@1.2.3.4#66 or any use of --query-port will
use the explicitly configured port, and should only be done with
understanding of the security implications.
Note that this change changes non-existing interface, or non-local
source address errors from fatal to run-time. The error will be
logged and communiction with the server not possible.
2021-03-17 20:39:33 +00:00
Simon Kelley
9eaa91bfc3 Teach --bogus-nxdomain and --ignore-address to take a subnet argument. 2021-03-17 20:31:06 +00:00
Petr Menšík
484bd75ce4 tftp warning fix.
At least on Fedora 32 with GCC 10.2.1, dnsmasq compilation emits warning:

tftp.c: In function ‘tftp_request’:
tftp.c:754:3: warning: ‘strcpy’ source argument is the same as
destination [-Wrestrict]
  754 |   strcpy(daemon->namebuff, file);

And indeed it is the same source always on line 477, sometimes also on
571 in tftp.c

Attached patch fixes the warning and possible undefined behaviour on
tftp error.
2021-03-17 14:40:04 +00:00
Simon Kelley
4c30e9602b Only log changes to DNS listeners when --log-debug is set. 2021-03-12 22:09:14 +00:00
Simon Kelley
b260d222af Add --log-debug option and MS_DEBUG flag to my_syslog(). 2021-03-12 21:57:57 +00:00
Simon Kelley
6528d62cd2 Merge i18n message files. 2021-03-11 23:46:45 +00:00
Simon Kelley
b7cf754f6f Add --dynamic-host option.
A and AAAA records which take their
network part from the network of a local interface. Useful
for routers with dynamically prefixes.
2021-03-11 23:39:33 +00:00
Simon Kelley
14e3f6ba19 Bump version in Debian changelog. 2021-03-02 21:41:04 +00:00
Petr Menšík
a8c1474562 Obtain MTU of interface only when it would be used
MTU were obtained early during iface_allowed check. But often it
returned from the function without ever using it. Because calls to
kernel might be costy, move fetching it only when it would be assigned.
2021-03-02 21:38:02 +00:00
Petr Menšík
8b8a4148ec Move flags to recvmsg function in netlink
netlink_multicast used 3 calls to fcntl in order to set O_NONBLOCK on
socket. It is possible to pass MSG_DONTWAIT flag just to recvmsg function,
without setting it permanently on socket. Save few kernel calls and use
recvmsg flags.

It is supported since kernel 2.2, should be fine for any device still
receiving updates.
2021-03-02 21:36:45 +00:00
Simon Kelley
9e147480ed Always use <poll.h>
Previously we were always using <sys/poll.h> since
HAVE_POLL_H is never set. This looks like an autoconfism
that has crept in, but we don't use autoconf.

poll.h is the correct header file, as far as I can tell.
2021-03-02 21:17:28 +00:00
Petr Menšík
4c0aecc685 Correct occasional --bind-dynamic synchronization break
Request only one re-read of addresses and/or routes

Previous implementation re-reads systemd addresses exactly the same
number of time equal number of notifications received.
This is not necessary, we need just notification of change, then re-read
the current state and adapt listeners. Repeated re-reading slows netlink
processing and highers CPU usage on mass interface changes.

Continue reading multicast events from netlink, even when ENOBUFS
arrive. Broadcasts are not trusted anyway and refresh would be done in
iface_enumerate. Save queued events sent again.

Remove sleeping on netlink ENOBUFS

With reduced number of written events netlink should receive ENOBUFS
rarely. It does not make sense to wait if it is received. It is just a
signal some packets got missing. Fast reading all pending packets is required,
seq checking ensures it already. Finishes changes by
commit 1d07667ac7.

Move restart from iface_enumerate to enumerate_interfaces

When ENOBUFS is received, restart of reading addresses is done. But
previously found addresses might not have been found this time. In order
to catch this, restart both IPv4 and IPv6 enumeration with clearing
found interfaces first. It should deliver up-to-date state also after
ENOBUFS.

Read all netlink messages before netlink restart

Before writing again into netlink socket, try fetching all pending
messages. They would be ignored, only might trigger new address
synchronization. Should ensure new try has better chance to succeed.

ENOBUFS error handling was improved. Netlink is correctly drained before
sending a new request again. It seems ENOBUFS supression is no longer
necessary or wanted. Let kernel tell us when it failed and handle it a
good way.
2021-03-02 18:21:32 +00:00
Simon Kelley
d556b8a5d5 Case error in x86-64_EFI pxe CSA 2021-02-28 21:36:03 +00:00
Simon Kelley
e7c0d7b348 dhcp-host selection fix for v4/v6.
Avoid treating a --dhcp-host which has an IPv6 address
as eligable for use with DHCPv4 on the grounds that it has
no address, and vice-versa.
2021-02-28 17:56:54 +00:00
Simon Kelley
17360439dc Clarification on dhcp-host and DNS. 2021-02-24 15:54:36 +00:00
Simon Kelley
9e169a9bea Belated CHANGELOG update. 2021-02-22 23:07:48 +00:00
Simon Kelley
305cb79c57 Simplify preceding fix.
Remove distinction between retry with same QID/SP and
retry for same query with different QID/SP. If the
QID/SP are the same as an existing one, simply retry,
if a new QID/SP is seen, add to the list to be replied to.
2021-02-18 21:50:33 +00:00
Simon Kelley
141a26f979 Fix problem with DNS retries in 2.83/2.84.
The new logic in 2.83/2.84 which merges distinct requests for the
same domain causes problems with clients which do retries as distinct
requests (differing IDs and/or source ports.) The retries just get
piggy-backed on the first, failed, request.

The logic is now changed so that distinct requests for repeated
queries still get merged into a single ID/source port, but they now
always trigger a re-try upstream.

Thanks to Nicholas Mu for his analysis.
2021-02-17 23:56:32 +00:00
Simon Kelley
cfcafdd27c Tweak f1204a875e
This gets, eg, v2.65test1 and v2.65test11 in the correct order.
2021-02-01 23:46:43 +00:00
Simon Kelley
f1204a875e Tweak sort order of tags in get-version.
We want to sort such that the most recent/relevant tag is first
and gets used to set the compiled-in version.

The solution is far from general, but works for the tag formats
used by dnsmasq. v2.84 sorts before v2.83, but v2.83 sorts
before v2.83rc1 and 2.83rc1 sorts before v2.83test1
2021-01-29 23:20:06 +00:00
Simon Kelley
20295012b8 Fix possible free-memory ref in e75069f79a 2021-01-24 22:25:13 +00:00
Simon Kelley
807e82343a Bump Debian changelog version. 2021-01-24 22:02:56 +00:00
Simon Kelley
c8e8f5c204 Bump copyright notices for 2021. Happy New Year! 2021-01-24 21:59:37 +00:00
Simon Kelley
a69b017902 Change HAVE_NETTLEHASH compile-time to HAVE_CRYPTOHASH.
HAVE_NETTLEHASH is retained for backwards compatibility, but deprecated.
2021-01-24 21:53:28 +00:00
Simon Kelley
e75069f79a Tidy initialisation in hash_questions.c 2021-01-22 22:50:25 +00:00
Simon Kelley
3f535da79e Fix for 12af2b171d 2021-01-22 22:26:25 +00:00
Simon Kelley
8ebdc364af Optimise sort_rrset for the case where the RR type no canonicalisation. 2021-01-22 18:50:43 +00:00
Simon Kelley
12af2b171d Fix to 75e2f0aec33e58ef5b8d4d107d821c215a52827c 2021-01-22 18:24:03 +00:00
Simon Kelley
04490bf622 Move fd into frec_src, fixes 15b60ddf93
If identical queries from IPv4 and IPv6 sources are combined by the
new code added in 15b60ddf93 then replies
can end up being sent via the wrong family of socket. The ->fd
should be per query, not per-question.

In bind-interfaces mode, this could also result in replies being sent
via the wrong socket even when IPv4/IPV6 issues are not in play.
2021-01-22 17:30:27 +00:00
Simon Kelley
327bbc92bc Changed priority to high in Debian changelog. 2021-01-17 23:35:24 +00:00
Simon Kelley
cc0b4489c7 Update to new struct frec fields in conntrack code. 2021-01-15 22:21:52 +00:00
Simon Kelley
9212ad284f Update Debian changelog. 2021-01-15 22:17:30 +00:00
Simon Kelley
503f68dbc4 Fix warning message logic. 2021-01-15 21:53:29 +00:00
Simon Kelley
e01e09c712 Add CVE numbers to security update descriptions in CHANGELOG 2021-01-08 22:50:03 +00:00
Simon Kelley
6a6e06fbb0 Small cleanups in frec_src datastucture handling. 2020-12-16 15:49:03 +00:00
Petr Menšík
2024f97297 Support hash function from nettle (only)
Unlike COPTS=-DHAVE_DNSSEC, allow usage of just sha256 function from
nettle, but keep DNSSEC disabled at build time. Skips use of internal
hash implementation without support for validation built-in.
2020-12-16 15:49:03 +00:00
Simon Kelley
25e63f1e56 Handle caching with EDNS options better.
If we add the EDNS client subnet option, or the client's
MAC address, then the reply we get back may very depending on
that. Since the cache is ignorant of such things, it's not safe to
cache such replies. This patch determines when a dangerous EDNS
option is being added and disables caching.

Note that for much the same reason, we can't combine multiple
queries for the same question when dangerous EDNS options are
being added, and the code now handles that in the same way. This
query combining is required for security against cache poisoning,
so disabling the cache has a security function as well as a
correctness one.
2020-12-16 15:49:03 +00:00
Simon Kelley
15b60ddf93 Handle multiple identical near simultaneous DNS queries better.
Previously, such queries would all be forwarded
independently. This is, in theory, inefficent but in practise
not a problem, _except_ that is means that an answer for any
of the forwarded queries will be accepted and cached.
An attacker can send a query multiple times, and for each repeat,
another {port, ID} becomes capable of accepting the answer he is
sending in the blind, to random IDs and ports. The chance of a
succesful attack is therefore multiplied by the number of repeats
of the query. The new behaviour detects repeated queries and
merely stores the clients sending repeats so that when the
first query completes, the answer can be sent to all the
clients who asked. Refer: CERT VU#434904.
2020-12-16 15:49:02 +00:00
Simon Kelley
824461192c Add missing check for NULL return from allocate_rfd(). 2020-12-16 15:49:02 +00:00
Simon Kelley
1eb6cedb03 Fix DNS reply when asking for DNSSEC and a validated CNAME is already cached. 2020-12-16 15:49:02 +00:00
Simon Kelley
059aded070 Optimse RR digest calculation in DNSSEC.
If an RR is of a type which doesn't need canonicalisation,
bypass the relatively slow canonicalisation code, and insert
it direct into the digest.
2020-12-16 15:49:02 +00:00
Simon Kelley
2d765867c5 Use SHA-256 to provide security against DNS cache poisoning.
Use the SHA-256 hash function to verify that DNS answers
received are for the questions originally asked. This replaces
the slightly insecure SHA-1 (when compiled with DNSSEC) or
the very insecure CRC32 (otherwise). Refer: CERT VU#434904.
2020-12-16 15:49:02 +00:00
Simon Kelley
257ac0c5f7 Check destination of DNS UDP query replies.
At any time, dnsmasq will have a set of sockets open, bound to
random ports, on which it sends queries to upstream nameservers.
This patch fixes the existing problem that a reply for ANY in-flight
query would be accepted via ANY open port, which increases the
chances of an attacker flooding answers "in the blind" in an
attempt to poison the DNS cache. CERT VU#434904 refers.
2020-12-16 15:48:36 +00:00
Simon Kelley
4e96a4be68 Fix remote buffer overflow CERT VU#434904
The problem is in the sort_rrset() function and allows a remote
attacker to overwrite memory. Any dnsmasq instance with DNSSEC
enabled is vulnerable.
2020-12-16 15:47:42 +00:00
Simon Kelley
a2a7e040b1 Use the values of --min-port and --max-port in TCP connections.
Rather that letting the kernel pick source ports, do it ourselves
so that the --min-port and --max-port parameters are be obeyed.
2020-12-12 23:26:45 +00:00
Wang Shanker
4ded96209e pxe: support pxe clients with custom vendor-class
From 606d638918edb0e0ec07fe27eb68d06fb5ebd981 Mon Sep 17 00:00:00 2001
From: Miao Wang <shankerwangmiao@gmail.com>
Date: Fri, 4 Dec 2020 09:59:37 +0800
Subject: [PATCH v2] pxe: support pxe clients with custom vendor-class

According to UEFI[1] and PXE[2] specs, PXE clients are required to have
`PXEClient` identfier in the vendor-class field of DHCP requests, and
PXE servers should also include that identifier in their responses.
However, the firmware of servers from a few vendors[3] are customized to
include a different identifier. This patch adds an option named
`dhcp-pxe-vendor` to provide a list of such identifiers. The identifier
used in responses sent from dnsmasq is identical to that in the coresponding
request.

[1]: https://uefi.org/sites/default/files/resources/UEFI%20Spec%202.8B%20May%202020.pdf
[2]: http://www.pix.net/software/pxeboot/archive/pxespec.pdf
[3]: For instance, TaiShan servers from Huawei, which are Arm64-based,
       send `HW-Client` in PXE requests up to now.

Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
2020-12-06 22:48:11 +00:00
Matthias Andree
f60fea1fb0 CHANGELOG: Fix three typoes. 2020-07-19 21:54:44 +01:00
Simon Kelley
4d85e409cd Change default lease time for DHCPv6 to one day.
Also remove floor on valid and preffered times in RA when
no time is specified.
2020-07-12 22:45:46 +01:00