From nobody Sat Apr 23 00:24:04 2022 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id EE3AA198F2FA for ; Sat, 23 Apr 2022 00:24:06 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (glebi.us [162.251.186.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KlX860wMKz3NYQ; Sat, 23 Apr 2022 00:24:06 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.16.1/8.16.1) with ESMTPS id 23N0O4xQ063657 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 22 Apr 2022 17:24:04 -0700 (PDT) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.glebi.us (8.16.1/8.16.1/Submit) id 23N0O4BL063656; Fri, 22 Apr 2022 17:24:04 -0700 (PDT) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@freebsd.org using -f Date: Fri, 22 Apr 2022 17:24:04 -0700 From: Gleb Smirnoff To: Michael Tuexen Cc: Florian Smeets , Michael Butler , freebsd-current@freebsd.org, melifaro@freebsd.org Subject: Re: IPv6 TCP: first two SYN packets to local v6 unicast addresses ignored Message-ID: References: <131c363a-7b7d-a106-5b8a-6838e7a66567@smeets.xyz> <9679642b-5de6-28be-a64b-07375c3efeba@smeets.xyz> <7cd2e76a-c6d1-e8d7-b9fb-b8797f1ca731@smeets.xyz> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4KlX860wMKz3NYQ X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=softfail (mx1.freebsd.org: 162.251.186.162 is neither permitted nor denied by domain of glebius@freebsd.org) smtp.mailfrom=glebius@freebsd.org X-Spamd-Result: default: False [-0.77 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.83)[-0.829]; FREEFALL_USER(0.00)[glebius]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_SPAM_SHORT(0.92)[0.919]; MID_RHS_MATCH_FROM(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; DMARC_NA(0.00)[freebsd.org]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-0.76)[-0.759]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MLMMJ_DEST(0.00)[freebsd-current]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Michael, On Sat, Apr 23, 2022 at 01:54:25AM +0200, Michael Tuexen wrote: M> > here is a patch that should help with the IPv6 problem. I'm not M> > yet committing it, it might be not final. M> M> when I was looking at the code, I was also wondering if it would make M> more sense to check for M_LOOP. M> M> However, isn't the rcvif wrong for the first two received packets? I M> would expect it always to be the loopback interface. Is that expectation M> wrong? The IPv6 has a special feature of calling (ifp->if_output)(origifp, ... I don't fully understand it, but Alexander does. What I can observe is that it works differently for the original packet, its first retransmit and second retransmit. Still unclear to me why. Here is how to observe it: dtrace -n 'fbt::ip6_output:entry { printf("ro %p ifp %p\n", args[2], args[2]->ro_nh ? args[2]->ro_nh->nh_ifp : 0); }' -n 'fbt::ip6_output_send:entry { printf("ifp %p origifp %p\n", args[1], args[2]); }' And you will see this: 1 45625 ip6_output:entry ro fffff800122c19a0 ifp 0 1 22539 ip6_output_send:entry ifp fffff800027cb800 origifp fffff800020db000 0 45625 ip6_output:entry ro fffff800122c19a0 ifp fffff800027cb800 0 22539 ip6_output_send:entry ifp fffff800027cb800 origifp fffff800020db000 0 45625 ip6_output:entry ro fffff800122c19a0 ifp fffff800027cb800 0 22539 ip6_output_send:entry ifp fffff800027cb800 origifp fffff800027cb800 So, on packet three (second retransmit) the origifp is equal to ifp (is lo0) and now packet passes validation. However, the more I read it, the more it seems to me that actually packet three is incorrect and first two are correct :) To cope with this self inflicted damage of (ifp->if_output)(origifp, IPV6 introduced M_LOOP and uses it internally. Looks like a quick solution for IPv6 is to use it. However, I will commit it only once we got understanding why the hell a second retransmit is different. M> I also have an additional question: M> Why is this check protected by an (ia != NULL) condition? It does not make M> any use of ia? It is a host protection feature, so checks only packets that are destined to us. This allows to do basic antispoof checks for a host not equipped with any firewall. For a machine acting as a router better behavior is not to drop anything routed through unless explicitly told so by a filtering policy. -- Gleb Smirnoff