From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=S2jjxcSt; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C08505A0265 for ; Thu, 14 May 2026 06:23:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778732577; bh=Pf3JjN2SDy959hHOdpBbXjyW/CRV44Qe4WjKevaO+Go=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S2jjxcSt6hlgwAgZjn+gxth82NwV3Cpwl15ugXCtl6KRqnSGmPKvC8BJiHldGs7AN keCRW7shLUxdrui4D9R+JZ5KJNwC3u5l80CRq+B07+dT0funYHrExppr/8gZEHEbY8 cT9Kr3FdtPjAM4ka13W9R+aFPwMZm73pzm46pWfH1XekKZxcVH4BU9qPATCqg0rwXv 8Ls2MwhGG6cF9OzjMFUcRpxujybY6364klDxLw97i1iqUAz31vp722ZExbevEZN+9P EziaKt/RTmfSdRRg72FbYUs2MTfgxP2r44F1W5zubBAETupVbD/6xsabgExJY1DpWw j3F6hEyXgEQ8g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gGHHj4yb4z4wSZ; Thu, 14 May 2026 14:22:57 +1000 (AEST) Date: Thu, 14 May 2026 14:22:51 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH RFT] fwd: Only do inbound IPv6 NAT to map_host_loopback / map_guest_addr with matching scope Message-ID: References: <20260507043149.1989693-1-sbrivio@redhat.com> <20260514010816.5ccc02de@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="+BMZNRQpvu/rAsN+" Content-Disposition: inline In-Reply-To: <20260514010816.5ccc02de@elisabeth> Message-ID-Hash: 3C33UED35OHROJCHUSITPH2NX5DK6QL7 X-Message-ID-Hash: 3C33UED35OHROJCHUSITPH2NX5DK6QL7 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.8 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: --+BMZNRQpvu/rAsN+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 14, 2026 at 01:08:16AM +0200, Stefano Brivio wrote: > On Wed, 13 May 2026 15:04:35 +1000 > David Gibson wrote: >=20 > > On Thu, May 07, 2026 at 06:31:49AM +0200, Stefano Brivio wrote: > > > I'm sharing this mostly for debugging / investigation of: > > >=20 > > > https://github.com/containers/container-libs/pull/755#issuecomment-= 4390420134 > > >=20 > > > even though the change is probably correct and needed regardless of > > > that. > > >=20 > > > If we have map_guest_addr or map_host_loopback addresses set for IPv6, > > > before using them for inbound NAT from the host, make sure they match > > > the scope of the original packet, otherwise we might unexpectedly > > > turn global unicast addresses into link-local ones for packets coming > > > from the host itself. > > >=20 > > > Link: https://github.com/containers/container-libs/pull/755#issuecomm= ent-4390420134 > > > Signed-off-by: Stefano Brivio =20 > >=20 > > There's a real problem here. However, I don't think this patch really > > addresses it. Details below. > >=20 > > > --- > > > fwd.c | 20 ++++++++++++++++++-- > > > 1 file changed, 18 insertions(+), 2 deletions(-) > > >=20 > > > diff --git a/fwd.c b/fwd.c > > > index 0697435..d224c0a 100644 > > > --- a/fwd.c > > > +++ b/fwd.c > > > @@ -974,6 +974,20 @@ uint8_t fwd_nat_from_splice(const struct fwd_rul= e *rule, uint8_t proto, > > > return PIF_HOST; > > > } > > > =20 > > > +/** > > > + * fwd_scope6_match() - Check if the IPv6 scope of two addresses mat= ch > > > + * @a: First address > > > + * @b: Second address > > > + * > > > + * Return: true for two IPv6 link-local or both not link-local, fals= e otherwise > > > + * > > > + * NOTE: This currently ignores any other difference in scope > > > + */ =20 > >=20 > > Nit: we probably want this helper (or ones like it) in ip.h and/or inan= y.h. > >=20 > > > +bool fwd_scope6_match(const struct in6_addr *a, const struct in6_add= r *b) > > > +{ > > > + return IN6_IS_ADDR_LINKLOCAL(a) =3D=3D IN6_IS_ADDR_LINKLOCAL(b); = =20 > >=20 > > This considers only linklocal vs. not linklocal. Officially those are > > the only two scopes for unicast IPv6. But... site-local unicast used > > to exist, and while it's deprecated we have once seen it in the wild. > > There's also host-local scope which I'm not sure is a term used by > > IPv6, but is used by kernel netlinkg, and kind of exists in practice > > (::1 and nothing else is host local). >=20 > Yes, see the NOTE above. I was trying to find out if this was in any > way useful (and it looks like it wasn't, at least from the current > progress of https://github.com/containers/container-libs/pull/755). Ok. > > > +} > > > + > > > /** > > > * nat_inbound() - Apply address translation for inbound (HOST to TA= P) > > > * @c: Execution context > > > @@ -993,13 +1007,15 @@ bool nat_inbound(const struct ctx *c, const un= ion inany_addr *addr, > > > /* Specifically 127.0.0.1, not 127.0.0.0/8 */ > > > *translated =3D inany_from_v4(c->ip4.map_host_loopback); > > > } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.map_host_loopback) && > > > - inany_equals6(addr, &in6addr_loopback)) { > > > + inany_equals6(addr, &in6addr_loopback) && > > > + fwd_scope6_match(&addr->a6, &c->ip6.map_host_loopback)) { =20 > >=20 > > This test will always be false: we just checked that addr =3D=3D ::1, > > which is not link-local (it's host-local, if we're admitting that > > category). >=20 > Oh, right, I didn't actually test this case. >=20 > > > translated->a6 =3D c->ip6.map_host_loopback; > > > } else if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.map_guest_addr) && > > > inany_equals4(addr, &c->ip4.addr)) { > > > *translated =3D inany_from_v4(c->ip4.map_guest_addr); > > > } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.map_guest_addr) && > > > - inany_equals6(addr, &c->ip6.addr)) { > > > + inany_equals6(addr, &c->ip6.addr) && > > > + fwd_scope6_match(&addr->a6, &c->ip6.map_guest_addr)) { =20 > >=20 > > This may be usually be right in practice, but it's kind of by > > accident. > >=20 > > The problem with both these checks is that they compare the scope of a > > host side address (addr) with the scope of a guest side address > > (c->map_*). >=20 > Note that inany_equals6(addr, &c->ip6.addr) is pre-existing. Right - that's the confusing but necessary semantics of --map-guest-addr. It's a translation for the thing on the outside that has the same address as the guest does on the inside. What I didn't spot before is that makes the scope check equivalent to: fwd_scope6_match(&c->ip6.addr, &c->ip6.map_guest_addr) which we should be able to implement at conf() time (someday at address update time). > Further, this "mismatch" is actually intended (see commit message and > Podman's pull request I mentioned above), as I was trying to (quickly) > make sure that we don't turn a global unicast request into a link-local > one. Ok, I had misunderstood the problem somewhat. Looking at that github comment, I'm still pretty confused TBH :/. > > That's not what matters: what matters is that source and > > destination on the tap side have the same scope. >=20 > Not for this particular issue: again, I was just trying to make sure > that a global unicast request doesn't get translated to a link-local > one. Hrm. It's not really clear to me why that's bad. > This can probably checked in an indirect and more correct way "at the > source". >=20 > > In flow table terms, > > that is, on a single flowside oaddr and eaddr must have the same > > scope (or must they? see later). > >=20 > > The scopes on one side of the flow don't need to match the scopes on > > the other side of the flow. In fact we need to allow them to be > > different: --map-host-loopback is *always* transforming a host-scope > > flow on the outside to something else on the inside (either link-scope > > or global-scope will work, as long as it's the same for both > > addresses). We don't do it yet, but I can imagine cases where it > > would be useful to translate a flow that's global-scope on the outside > > to local-scope on the inside (because for some reason we want to or > > have to hide the external peer's address from the guest). Or from > > local-scope on the outside to global-scope on the inside (because the > > outside flow is using local-scope addresses which are not meaningful > > to the guest). >=20 > Yes, definitely, that might actually be a feature, I just think we > don't want to do that by default / mistake. I mean, --map-host-loopback is kind of already this. > In this case we had an inbound request to a global unicast address that > was translated for some reason (we didn't really investigate) to a > link-local destination address. Hrm, ok. I really want to understand why that happened. What was the source address? This seems like it would be handled by the selection of the guest side eaddr in fwd_nat_from_host(), which explicitly tries to match scope with the (translated) source address. > But if it's explicit it should be allowed, by all means. >=20 > > This has some tricky implications for what we do about assigning > > addresses for "local mode" or any future variant where we need to > > assign a guest address, but can't take one from the host. If we > > assign a link-local address, as was our plan, that implies under this > > assumption that the guest can only talk to link-local machines. In > > practice that would mean only the host (via -map-*) or in future > > things we added explicit NATs, where the guest side address is > > link-local. The guest would have no ability to contact the internet > > at large. >=20 > I don't think that's desirable. Neither do I, but how to avoid it is not obvious to me. > > At least once we have the netlink monitor, maybe that's ok. While the > > host has no address, the guest has only link local, so it can only > > talk to the host (or explicitly configured forwards/NATs). But the > > host has no connectivity anyway, so there's nothing else to talk to > > anyway. When the host gets connectivity we add a global-scope guest > > address, so it gets connectivity too. > >=20 > > If that's not good enough, I can only see two approaches, neither of > > which look great. > >=20 > > a) For incoming connections from the world, to a guest with only an > > LL address, we NAT *both* source and destination address (ugh, the > > bookkeeping). >=20 > The bookkeeping is already in place though. Well.. we can DNAT easily enough, but to match scope we also need to SNAT. That means picking a link-local source address (guest oaddr) for each incoming flow. Maybe we can use our_tap_ll for that? But that means all incoming connections will appear to come from there regardless of whether they are actually the same peer or not. If the guest is talking to enough peers we risk running out of source ports. Or for UDP, where we preserve source port, we risk collision between flows that are separate on the outside. Theoretically, we could avoid this by assigning a distinct, link-local, guest side address for each peer. Doing _that_ is a lot of new bookkeeping which is what I was thinking of. > > Outgoing connections to the world are only possible for targets > > where we've preconfigured a NAT. > >=20 > > b) We _do_ allow different scopes on the two guest-side addresses. > > This implies that the guest *expects and requires* their gateway > > (us) to SNAT them. > >=20 > > I suspect that the guest simply won't allow (b) to work for IPv6, but > > it might for IPv4, since most things don't actually look for RFC3927 > > addresses, and NAT is much more expected in general. >=20 > I think it's rather complicated to define this before having played > with the netlink monitor implementation itself, but again, this is well > beyond the scope of this patch. Maybe. >=20 > The idea here is that *if* we have a global unicast address in a > container, the mere fact that we have a link-local address in > --map-guest-addr (not actually the case, it seems, but we haven't > investigated further), shouldn't cause inbound traffic to be mapped to > that link-local address. Indeed it should not, but I don't yet see why that's happening. > But note that I'm not sure if it's an actual problem or if it's even > happening at all, at this stage. --=20 David Gibson (he or they) | 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 --+BMZNRQpvu/rAsN+ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoFTg0ACgkQzQJF27ox 2GcNWg//Q+3fQ8SQFe0o6TJMm156A2KMb9F6Lev71lM+k+3sTrh2CbGSMijOcfk8 u5/v3p5vZz+w2M0GNR2iTZQXd42tQK8kTG1Q3Q0MXi8/2c95L8wBgEM4Gg1znnI3 NgYOYHZi4FxTLE0foT/mX/oU8ZpYTbJQgpwHcOAPXQhBfopIdT+firne9Y6sf9fx PxYAINXHdc+w/OR2ahICqgw39i80I/BC4N+GmJ2mTlWOBTHxVWECviUMyDG72tBp f3bPLeCjVvmhmHAAoTkzFz/3uu+YBdFgNqw4d8YWVL66OZoKCD1AekEdsUQ9n1HY bexDjpm3domQ4g2PK50fsfeG7Eqh4n1V8wIvO8yRr6NZHNQY45YcX7jca3JqceHF Ur4UMzQVaBaPwSJHWrxxfv83DHcZQedG537I2ItQ7sKk8+EqcdlaPBTXdRfnuMLL Vz5X/ZV5/9tuM3XiKUtS4Dp5j8mm2ZFoXLU1KlH5oOI1XeFDReTC8YGYs/E6QU3W ELD5epIECI6Enn3nPkpJuI3zwRtw5KcL8ZfbT2e0zR6NRY0AYEnhjiZvpEcAqMr3 omL5UqqX7otwCI+Ll1bqsRww4cLyCWu45ngiak7TIV1bu/fVhbD1Sh4PUY/hOQpO QwnSbe8/HSUSM5U24vJ1GbXlOc0osCSOdm845tld6ldKLJ/ys8E= =ADDk -----END PGP SIGNATURE----- --+BMZNRQpvu/rAsN+--