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 EF6415A0082 for ; Thu, 10 Nov 2022 08:59:34 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N7Dkq0xSkz4xZ0; Thu, 10 Nov 2022 18:59:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668067171; bh=uUds/od2NK+iKQ3D6wwBywGTOawohnO0EMmr/fdS19c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hbVSjg5Sg/7KF205oP/yznY3pYq7V3JLXa3tHSb+OJerdHBeQn/ofhDJfUJaEUsmw PJaOfnq/zWUNX9+kQpqtTHFAsEAYW/Ap2Wwa67ee8V5C+/HVdKgviDIvG5eBFladAU 9tdSQxMNvwz8LtuNXkkR3adeKL6SiBIie9QC7fh0= Date: Thu, 10 Nov 2022 15:30:58 +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> <20221108072222.73615076@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TX/Vir2zCXdgSbSF" Content-Disposition: inline In-Reply-To: <20221108072222.73615076@elisabeth> Message-ID-Hash: JAH3B3QX2JZC4J65O7S4WKHUDKBGEFJU X-Message-ID-Hash: JAH3B3QX2JZC4J65O7S4WKHUDKBGEFJU 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: --TX/Vir2zCXdgSbSF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 08, 2022 at 07:22:22AM +0100, Stefano Brivio wrote: > On Tue, 8 Nov 2022 16:51:35 +1100 > David Gibson wrote: >=20 > > 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: =20 > > > > > 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 wr= ote: =20 > > > > > > > > > Now that we allow loopback DNS addresses to be used as ta= rgets for > > > > > > > > > forwarding, we need to check if DNS answers come from tho= se targets, > > > > > > > > > before deciding to eventually remap traffic for local red= irects. > > > > > > > > >=20 > > > > > > > > > Otherwise, the source address won't match the one configu= red as > > > > > > > > > forwarder, which means that the guest or the container wi= ll refuse > > > > > > > > > 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(co= nst 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.ad= dr_seen)) { > > > > > > > > > + if (c->ip4.dns_fwd && src =3D=3D htonl(c->ip4.dns[0]) &= & src_port =3D=3D 53) { =20 > > > > > > > >=20 > > > > > > > > I guess this is not a newly introduced bug, but for the cas= e of > > > > > > > > multiple host nameservers, don't you need to check against = everything > > > > > > > > in the ip4.dns[] array, not just entry 0? =20 > > > > > > >=20 > > > > > > > No, because that's the only one we're using as target for for= warded > > > > > > > queries -- and DNS answers we want to check here are only the= forwarded > > > > > > > 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 a= t all? > > > > > > 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. Othe= r naming > > > > > 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 > > >=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 s= ome > > > obscure use case. =20 > >=20 > > 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). >=20 > Rather hypothetical: you don't want the guest/container to use a given > address as resolver. You know that that address might be in its > resolv.conf(5) because you don't have control over the image, wish to > override it if possible, and at the same time keep a safety net. Yeah, I guess. Seems pretty contrived. > Slightly unrelated: we're talking about this in the perspective of > getting rid of an explicit @dns_fwd/@dns_match. This would become a > flag, indicating we should forward queries originally directed to > 1. dns[0]... or 2. anything in dns[]? >=20 > If it's just about 1. dns[0], we're forcing that address to be the first > advertised resolver. >=20 > If it's about 2. dns[], we're not giving anymore the possibility of > forwarding queries originally directed to one a single address. Hmm... yes, those are fair points. --=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 --TX/Vir2zCXdgSbSF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNsfnwACgkQgypY4gEw YSKTZg//f8FaoaYJ/afWW65tt44TrRWaMP9eRDtP48kWN6YA3DDR+GlIZBjaniVe wwM/gilMgmWnXFhini2i15bRKPgt3pPGFy4FFh+e/qm+Ztc1F1Vi2u9pVxr7HPWG Ztfb2BVr5d4dPeZ91TglqP4unVAeKNR7et4skH/ERdB6fJ7bReokalBTTStU6cbk rZsb6JThlyP33YWxni7sX15iYx1Kj/SaJSz5KpTFRCiMzf2IjtGAU8g2St3k/C83 hYhS5J1NKfsFk66uCL9SAWOMog6WkYqEwdfbJ2KgdOQ0WDqOjL9rYlqpv2OPsENo DySl9F4AKsoK81h7OWHX6jH7Lr3vWW47zcVQhvjjLnG5knV0kbwg+Veu5JBbsnOp /wKy4PGMnCttbj61gNtUFD8kb+IHOI42cqrP/M5unuoD/4hzcphR9hfeK51TFGIp w7iQpS+CJ7Nc0NYWDTiWn6urZ0aDlMV4PHZBOmzqDBGr8IIqRQX+Rkv0wXcDv1tQ xyaPXn6XEQcLmkZ2HDEPoXVp88o6osBPDBrmnTAUOh39ODvRnpYTpRWx/7dOMn0J 3UvjVshaPNIF+46C8yw/q8b2btAa0QY3Vx9MRBHPxdw7s7KnOKvB3kBhnLmKiWMj WPT46HC/ACjqlY+qyy8rBC+z+lfz/JOrDZxX/DXOPrBrbZBu9y4= =e73G -----END PGP SIGNATURE----- --TX/Vir2zCXdgSbSF--