From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356994; b=n2S+XVRDZlDhUL49d/brvJJXO8SM2QClrh55vj9rfJ3JyH9ZW+j3hM1PDPvtBJJB2izT Jy2hpzOLx1KX03fplB/e6/n3mB6wskwMpQUemLQbN3eC+9mN1drmtnRskRGVXgO3GVHZh +nGQ9rwL5HPq3gB6udeupIDEuXrio4MWLz/2JgdPPqT9m/0PldQZy52bpuOVa2yn4QFY5 pwVWPNDU81o8ivgxIDRdRfDHvRt0fJaJA9ptkuk5R/bAOWrshOiTx9nxbKaUNwB2TKywW Uq0ffoUruGyl/iYwfRNc23Op6ry9lKkC6zMljMIhA7Z+puQAq4MFK2AizUwuIk1yFpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356994; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=DTAH3Lckwgp3giAF12zYKAhaX6nOfFOLPijqlv7FSUc=; b=DxR8nytxAmTtOrmZc+xuxe9X/Bp4FSHXGO1165RnOx8M89MKf1vHqlUSZeYTuuGmvnLR 8NlxhlBYnaH/TneXJlAPBNccSfWH/Qb755UTGkPxzByxta8E9nvzj4qify4rjtau7PRBe KFrlT3rDKNsGi8PugnMtYRcSwY/R/DtxlqaqOjxTEAutjik8HZ6T+VmwQRHI9v0Sz6zmp fm+RByQs6Yg658x+f98HNpeGTcJMX6rWO0lz0pnOOSJakHR7FrpBfQZnDdWweSzoNO0O3 yDcLm2CPFeC5YteFFkK+8CMAwbrm5viFAAej9MGQVkrUW1RnzOVVWDPsP33KpnPqq8A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iZ9kdKcH; arc=none smtp.remote-ip=209.85.219.71 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA3F606A32C for ; Fri, 4 Dec 2026 04:03:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4EA3F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iZ9kdKcH Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-920f97bcad4so7116286d6.0 for ; Thu, 03 Dec 2026 20:03:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796356993; x=1796961793; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DTAH3Lckwgp3giAF12zYKAhaX6nOfFOLPijqlv7FSUc=; b=iZ9kdKcH5NgtNDikFgktWn2r5qdAQXiKMScfCsVbovkmH8xjCUeor2v+y54JKuW9lX WlogVQd2rhB8WpjlYUKoRwTLL+mT9tE0UvYGBnPXgPAa1Nqvq/Z4qBRgbX0Cy1Nmz7fr ku3mmL6tGbHSBR9uN96kx45WWcCNQm9wF3BHp0+PFDRBVuJRFpJGrouYURoqPTxtf/Mm XNjAMWmAWGrhuJQ64QRy4gPzAQd1WnsBnQjXrt6AOoXfo4PhLtBfZm3GqkzHgHIEfb8s GWghJorOZ/n+8VdNoTCAxxST0McAuAaqrG0zvsw56RkHav/MXA9ztl6kaDkkcle9YJlU Q+LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796356993; x=1796961793; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DTAH3Lckwgp3giAF12zYKAhaX6nOfFOLPijqlv7FSUc=; b=ye5daT4trAl69GwiO6xN5PIV4567PiJUnh6H7HjZXh23eydQjEWLjBFfX01DVkAR2h F/yJ7DT/wcnd5nqIApcDbN7zIsb02HkmP0iVoNXDDhpIipMDG2QEVZzCUuEnq29iNnkq ydXAsFw79bRo9jV2RhsZWde+x3Ntr485cdRU8XNevn1s7LfvQSSulAldNzB6Y0GG78Fn Q/nS/ORUZgJadNEvOp8f/exq3mrB9hNwY24F7ANIbQgrGX5Cl/lD7MnkaxQy7wY8aO/D WOkh/FAU0oDD1n/r9ynXpHkaQN6wNoSQlMQMF2ozw+ln5dY9MrLmomJvTE6fTnhLEdC1 etDQ== X-Forwarded-Encrypted: i=1; AL+hErFvPCXCP2VGnmHJaRnNPjgg7uE9i697i5/WX3d7NIb1EBktW13z7CRYNEEeOMuzmS9FZcgNxyMUwMcts0CDP1Q=@vger.kernel.org X-Gm-Message-State: APuU4Z/QromqbTjJEzFQpa78I2vP4VHYkZzgJNfJO2fC/K0V8q3PTidf UswKe/y2Js7QHcXngrKZKOkNfqioOKqslgeQ9T3rkBefBAtBtrGnAe/Q7SC8YdEvJsi7U/fJUM8 4jAyp/IGdKw== X-Received: from qvqd2.prod.google.com ([2002:ad4:50a2:0:b0:921:6405:b9a0]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:5989:b0:921:d2af:b99e with SMTP id 6a1803df08f44-921e2471180mr11915436d6.34.1796356992893; Thu, 03 Dec 2026 20:03:12 -0800 (PST) Date: Thu, 03 Dec 2026 23:03:12 -0500 In-Reply-To: <20261127-tcp-l3mdev-exempt-ports-v3-1-f875b1184f26@nexthop.ai> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261127-tcp-l3mdev-exempt-ports-v3-0-f875b1184f26@nexthop.ai> <20261127-tcp-l3mdev-exempt-ports-v3-1-f875b1184f26@nexthop.ai> Message-ID: Subject: Re: [PATCH net-next v3 1/2] tcp: add net.ipv4.tcp_l3mdev_exempt_ports sysctl From: willemb@google.com To: Kalash Nainwal via B4 Relay , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Jonathan Corbet , Shuah Khan , Randy Dunlap , David Ahern , Ido Schimmel , Neal Cardwell , Kuniyuki Iwashima Cc: Shuah Khan , Joel Granados , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Kalash Nainwal Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes Kalash Nainwal via B4 Relay wrote: > From: Kalash Nainwal > With tcp_l3mdev_accept=1, an unbound listener also matches connections > that arrive in a VRF. If a VRF-bound listener exists on the same port > and both use SO_REUSEPORT, the lookup returns whichever is first in the > listen bucket, not the VRF-bound one. Since AF_INET and AF_INET6 > reuseport sockets are inserted at opposite ends of the bucket, the same > setup can pick the VRF-bound listener for IPv4 and the unbound one for > IPv6. > This breaks, for example, a BGP daemon with a TCP-MD5 key only on its > VRF-bound listener: IPv6 peers in the VRF reach the unbound listener > and the session comes up without MD5. > Add net.ipv4.tcp_l3mdev_exempt_ports, a per-netns port list in the > same format as ip_local_reserved_ports. For a listed port, an unbound > listener does not match connections that arrive in a VRF, so only a > listener bound to the VRF or to the receiving device can take them. > Only listener lookup changes. Other ports and default-VRF traffic are > not affected. The default is empty. > This is opt-in rather than a change to the lookup itself. With both > listeners present, existing setups get a stable result that depends on > creation order and address family; making the bound listener always > win would change that for every tcp_l3mdev_accept user. This compatibility argument does not justify adding a permanent 65536-bit port bitmap sysctl (and 8 KiB per network namespace) instead of fixing listener lookup: 1. The current behavior is explicitly documented as unspecified, not a UAPI contract. Documentation/networking/vrf.rst (commit b1165777fe0b) already warns that with tcp_l3mdev_accept=1 "it is unspecified which listening socket will be selected to handle connections for VRF traffic" and calls out this exact TCP-MD5 failure mode. 2. No deployment can meaningfully rely on the current behavior. Because inet_hash() prepends AF_INET sockets (LIFO) and appends AF_INET6 SO_REUSEPORT sockets (FIFO), the same startup order selects opposite listeners for IPv4 vs IPv6, and any daemon/VRF restart flips the winner. Worse, whenever the unbound listener sits ahead in the bucket, the VRF-bound listener is completely unreachable (it cannot match non-VRF traffic and its own VRF traffic is stolen). For non-reuseport listeners, compute_score() already prefers sk_bound_dev_if != 0. 3. Netdev precedent is to fix SO_REUSEPORT short-circuit shadowing in the lookup without a sysctl: - d894ba18d4e4 ("soreuseport: fix ordering for mixed v4/v6 sockets") - d9fbc7f6431f / 0ee58dad5b06 ("net: tcp[6]: prefer listeners bound to an address") - 8d6c414cd2fb ("net: prefer socket bound to interface when not in VRF") 4. The bitmap sysctl leaves the real bug unfixed everywhere else: every unlisted port keeps the IPv4/IPv6 divergence and MD5/AO bypass, non-VRF SO_BINDTODEVICE + unbound SO_REUSEPORT (sdif == 0) remains broken regardless of the sysctl, and UDP (udp_l3mdev_accept=1, udp[46]_lib_lookup2() when !reuseport_has_conns()) has the same early return. Please drop the sysctl and rework the series to fix device-bound listener preference in inet_lhash2_lookup() / inet6_lhash2_lookup()