From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 68A145A0082 for ; Tue, 8 Nov 2022 06:58:17 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N5y7n6PJDz4xYD; Tue, 8 Nov 2022 16:58:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1667887093; bh=fAXd9wTIWg+7qrTOCFqR+Z0k+OKLClujQziIpQCcQ44=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JGfZGxrXr21nuygeuQjasbv9tjNB/ZdWk9HGJF5DbrFzR2i8++YGmLn6+a/2HLpVZ tIFp+0P3b/m0FnphbzT67RhcGvkAhk0MvIEaunGC3btQznB9ph2e3ESijfGJXzNSve m9k+Z7I5c9JvVAu54slfVk7wAh1tFzQhfAMHd1ys= Date: Tue, 8 Nov 2022 16:51:35 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/3] udp: Check for answers to forwarded DNS queries before handling local redirects Message-ID: References: <20221102230443.377446-1-sbrivio@redhat.com> <20221102230443.377446-4-sbrivio@redhat.com> <20221103074251.60b2898b@elisabeth> <20221105082223.4a447ac5@elisabeth> <20221107105121.37735a0b@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="j3QKCHC7l9MEK3+0" Content-Disposition: inline In-Reply-To: <20221107105121.37735a0b@elisabeth> Message-ID-Hash: D2WBF5EZBLZSSFTXHDYHITXLDTH76FZJ X-Message-ID-Hash: D2WBF5EZBLZSSFTXHDYHITXLDTH76FZJ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Paul Holzinger X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: <> Archived-At: List-Archive: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --j3QKCHC7l9MEK3+0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 07, 2022 at 10:51:21AM +0100, Stefano Brivio wrote: > On Mon, 7 Nov 2022 12:08:59 +1100 > David Gibson wrote: >=20 > > On Sat, Nov 05, 2022 at 08:22:23AM +0100, Stefano Brivio wrote: > > > On Sat, 5 Nov 2022 12:19:55 +1100 > > > David Gibson wrote: > > > =20 > > > > On Thu, Nov 03, 2022 at 07:42:51AM +0100, Stefano Brivio wrote: =20 > > > > > On Thu, 3 Nov 2022 14:42:13 +1100 > > > > > David Gibson wrote: > > > > > =20 > > > > > > On Thu, Nov 03, 2022 at 12:04:43AM +0100, Stefano Brivio wrote:= =20 > > > > > > > Now that we allow loopback DNS addresses to be used as target= s for > > > > > > > forwarding, we need to check if DNS answers come from those t= argets, > > > > > > > before deciding to eventually remap traffic for local redirec= ts. > > > > > > >=20 > > > > > > > Otherwise, the source address won't match the one configured = as > > > > > > > forwarder, which means that the guest or the container will r= efuse > > > > > > > those responses. > > > > > > >=20 > > > > > > > Signed-off-by: Stefano Brivio > > > > > > > --- > > > > > > > udp.c | 17 ++++++++--------- > > > > > > > 1 file changed, 8 insertions(+), 9 deletions(-) > > > > > > >=20 > > > > > > > diff --git a/udp.c b/udp.c > > > > > > > index 4b201d3..7c77e09 100644 > > > > > > > --- a/udp.c > > > > > > > +++ b/udp.c > > > > > > > @@ -680,8 +680,10 @@ static void udp_sock_fill_data_v4(const = struct ctx *c, int n, > > > > > > > src =3D ntohl(b->s_in.sin_addr.s_addr); > > > > > > > src_port =3D ntohs(b->s_in.sin_port); > > > > > > > =20 > > > > > > > - if (src >> IN_CLASSA_NSHIFT =3D=3D IN_LOOPBACKNET || > > > > > > > - src =3D=3D INADDR_ANY || src =3D=3D ntohl(c->ip4.addr_s= een)) { > > > > > > > + if (c->ip4.dns_fwd && src =3D=3D htonl(c->ip4.dns[0]) && sr= c_port =3D=3D 53) { =20 > > > > > >=20 > > > > > > I guess this is not a newly introduced bug, but for the case of > > > > > > multiple host nameservers, don't you need to check against ever= ything > > > > > > in the ip4.dns[] array, not just entry 0? =20 > > > > >=20 > > > > > No, because that's the only one we're using as target for forward= ed > > > > > queries -- and DNS answers we want to check here are only the for= warded > > > > > ones. =20 > > > >=20 > > > > *thinks* .. ok, that makes sense. But if that's the case, won't > > > > ip4.dns[0] be the only entry in ip4.dns[] we use for anything at al= l? > > > > Can we drop the table and just keep one entry? =20 > > >=20 > > > Now that we have ip{4,6}.dns_send[], yes. =20 > >=20 > > Right, that's what I meant. > >=20 > > > We could rename .dns_send[] back to .dns[] and change the current =20 > >=20 > > Right, I think dns[] is a better name for it. > >=20 > > > .dns[] to .own_dns, or .fwd_dns_target, something like that. Other na= ming > > > ideas welcome. =20 > >=20 > > Yeah, I find the current dns_fwd name not very illuminating either. > >=20 > > *thinks* does it even make sense for dns_fwd not to be in dns_send? > > We're intercepting queries the guest sends to @dns_fwd, so surely we > > should also be advertising it to the guest. >=20 > I wouldn't be so sure of that "surely". In the Podman test case where I > hit this issue, I use Podman to write to /etc/resolv.conf directly, no > DHCP/NDP/DHCPv6 involved, and things work. >=20 > That doesn't automatically imply a use case for *not* advertising it, > but we have several ways this can work without advertising anything, so > there are also chances somebody might not want to advertise that in some > obscure use case. Right, but only the case for not advertising it matters here, and I don't see one. @dns_fwd (or @dns_match, as we discussed calling it instead) is explicitly a virtual DNS server available to the guest. Whatever method the guest does use to configure itself, we should allow it to discover this via DHCP (or DHCPv6 or NDP). > > So what about: > >=20 > > @dns: Primary DNS server advertised to guest - may be a fake > > address we'll intercept > > @dns_extra[]:Additional DNS servers advertised to guest. Must be > > real servers the guest can address without translation > > @host_dns: Host side DNS server (may be localhost or another > > address that's not guest accessible) > >=20 > > The DHCP code advertises both @dns and @dns_extra, and that's the > > *only* place @dns_extra is used. >=20 > Also NDP and DHCPv6 use that, and checking one item plus one array in > three places (difficult to share that code path) is uglier than just the > array. >=20 > > UDP intercepts outbound packets for @dns and redirects them to > > @host_dns, likewise masquerading inbound packets from @host_dns to > > appear to have come from @dns. >=20 > I see the general point, but we would still need a flag to allow users > to disable the redirection. >=20 > Given that, I'd rather go with dns, host_dns, and fwd_dns, it looks > simpler. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --j3QKCHC7l9MEK3+0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNp7k8ACgkQgypY4gEw YSKpeg/+KduNW7f2AFWFqm8vtVzH456YvetWtlUkcxIrJ8DTQ/m5i/zP+Lu0lOm7 70W/66yFpQbbR85GBpF+Ei1rE7OIXihKqZJhgHvFSLtpq6fqYhtaVkadv1Gan97V f0ZbNM6cMwpRym3/Ze67f/Gf3mNaXbUce1JBcA5PkFwaAX/Nb15mUn0R5IRVe/SE UnAHjV3HRUx9mH9k3eNlDGcBIrtfSgS4WCDCE8b7ju6agg2/eAUHQR7XCuzup4q8 1RuFBWw9GWjZKDyeU9BYGnrhEDJiuf0TGEr2OaGoEfDGLUNmGQiVlubrc8V0uUsT CqUkyROO/5q8vwA2+8iTK9ljlpLN9QO6oj7IQkKo2z3scPbAd8N+oJP47UjEd/Wq Uw5k7wy6mo/av6fG8PBxdKBCBkgDfvq2byEVc4cReU/Ece9rJs4yev8cQ/VlFbOB Yoy00+LrPwRANKahqNC04zIomVXppttvWmb/8gcwHUqRPEVYCKhxf0KwesAeNRea 7o+8GqE/YjuArM3v3rL6Mw85U91hHq4es6HOKRM0kfn2Xy0XaVcXUh8kY/riun4W 67JZSLA7w/1deDKCbxEYKBdpQoj3bFiUEBDknAQmZZvLJJvQoJEkD43LcydrLeKn HDZR2zsdvcTLG2aw4cknGCyDm0flCxEtOcjaqtH+OwzY83q2DCQ= =+wId -----END PGP SIGNATURE----- --j3QKCHC7l9MEK3+0--