From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 17B405A0265 for ; Thu, 3 Nov 2022 07:43:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667457827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0HasvUctUs+Hs0ihAd5HHnCX3ECqnjxecThPpIidArg=; b=R5ChA1swCkL4SEbKcKRwC/D/ckriHiI0YEKehKps52WZw6QyWJI44vRQYbjC6dnh93V3hQ pFFRslu3ABFKWpl+IOV4SRdBoIVMl+P/3gOlMMttVU4ANMlZtj+jcA4NzTU5JTb3/0X5JL rftCC4I0fK+wVgSpdpxZmfzRJh+pc7I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-GbhT5jXRPZ2V13JdnqwHTw-1; Thu, 03 Nov 2022 02:43:44 -0400 X-MC-Unique: GbhT5jXRPZ2V13JdnqwHTw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9B94185A7B0; Thu, 3 Nov 2022 06:43:44 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-31.brq.redhat.com [10.40.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F485492B06; Thu, 3 Nov 2022 06:43:44 +0000 (UTC) Date: Thu, 3 Nov 2022 07:42:51 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 3/3] udp: Check for answers to forwarded DNS queries before handling local redirects Message-ID: <20221103074251.60b2898b@elisabeth> In-Reply-To: References: <20221102230443.377446-1-sbrivio@redhat.com> <20221102230443.377446-4-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YO4IFOGNWWWYSMDJEIC2FPJS4YD53FB3 X-Message-ID-Hash: YO4IFOGNWWWYSMDJEIC2FPJS4YD53FB3 X-MailFrom: sbrivio@redhat.com 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: On Thu, 3 Nov 2022 14:42:13 +1100 David Gibson wrote: > On Thu, Nov 03, 2022 at 12:04:43AM +0100, Stefano Brivio wrote: > > Now that we allow loopback DNS addresses to be used as targets for > > forwarding, we need to check if DNS answers come from those targets, > > before deciding to eventually remap traffic for local redirects. > > > > Otherwise, the source address won't match the one configured as > > forwarder, which means that the guest or the container will refuse > > those responses. > > > > Signed-off-by: Stefano Brivio > > --- > > udp.c | 17 ++++++++--------- > > 1 file changed, 8 insertions(+), 9 deletions(-) > > > > 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 = ntohl(b->s_in.sin_addr.s_addr); > > src_port = ntohs(b->s_in.sin_port); > > > > - if (src >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET || > > - src == INADDR_ANY || src == ntohl(c->ip4.addr_seen)) { > > + if (c->ip4.dns_fwd && src == htonl(c->ip4.dns[0]) && src_port == 53) { > > I guess this is not a newly introduced bug, but for the case of > multiple host nameservers, don't you need to check against everything > in the ip4.dns[] array, not just entry 0? No, because that's the only one we're using as target for forwarded queries -- and DNS answers we want to check here are only the forwarded ones. -- Stefano