Netdev List
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: Eric Dumazet <edumazet@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	 "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH v2 net 3/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_rcv().
Date: Sat, 28 Nov 2026 08:06:15 +0000	[thread overview]
Message-ID: <20261128080700.3828378-4-kuniyu@google.com> (raw)
In-Reply-To: <20261128080700.3828378-1-kuniyu@google.com>

The cited commit added TCP_NEW_SYN_RECV handling just before
the GTSM check in tcp_v[46]_rcv().

Without this patch, we cannot see SYN+ACK in the script below
because the ACK with TTL 10 completes 3WHS.

  --ip_version=ipv4
   0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
  +0 setsockopt(3, SOL_IP, IP_MINTTL, [250], 4) = 0
  +0 bind(3, ..., ...) = 0
  +0 listen(3, 10) = 0
  +0 < (ttl 255) S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
  +0 > S. 0:0(0) ack 1 <...>
  +0 < (ttl 10) . 1:1(0) ack 1 win 65535
  +1 > S. 0:0(0) ack 1 <...>

Let's restore GTSM check for reqsk in tcp_v[46]_rcv().

Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 net/ipv4/tcp_ipv4.c | 10 ++++++++--
 net/ipv6/tcp_ipv6.c |  9 +++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index fe9cc5b66b97..4b6bc7812cb1 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2135,12 +2135,18 @@ int tcp_v4_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
+
+		if (static_branch_unlikely(&ip4_min_ttl) &&
+		    iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl)) {
+			__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
+			drop_reason = SKB_DROP_REASON_TCP_MINTTL;
+		} else if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
 			drop_reason = SKB_DROP_REASON_XFRM_POLICY;
-		else
+		} else {
 			drop_reason = tcp_inbound_hash(sk, req, skb,
 						       &iph->saddr, &iph->daddr,
 						       AF_INET, dif, sdif);
+		}
 		if (unlikely(drop_reason)) {
 			sk_drops_skbadd(sk, skb);
 			reqsk_put(req);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 90426ea9e073..7c17162160ad 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1792,12 +1792,17 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
+		if (static_branch_unlikely(&ip6_min_hopcount) &&
+		    hdr->hop_limit < READ_ONCE(tcp_inet6_sk(sk)->min_hopcount)) {
+			__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
+			drop_reason = SKB_DROP_REASON_TCP_MINTTL;
+		} else if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
 			drop_reason = SKB_DROP_REASON_XFRM_POLICY;
-		else
+		} else {
 			drop_reason = tcp_inbound_hash(sk, req, skb,
 						       &hdr->saddr, &hdr->daddr,
 						       AF_INET6, dif, sdif);
+		}
 		if (drop_reason) {
 			sk_drops_skbadd(sk, skb);
 			reqsk_put(req);
-- 
2.56.1.839.g22a8290db9-goog


  parent reply	other threads:[~2026-11-28  8:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  8:06 [PATCH v2 net 0/8] tcp: Misc fixes for tcp_v[46]_err() and tcp_v[46]_rcv() Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 1/8] tcp: Don't use inner IP TTL for IP_MINTTL in tcp_v4_err() Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 2/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_err() Kuniyuki Iwashima
2026-11-28  8:06 ` Kuniyuki Iwashima [this message]
2026-11-28  8:06 ` [PATCH v2 net 4/8] tcp: Fix reqsk abort condition on ICMP errors Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err() Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 6/8] selftest: net: packetdrill: Add ICMP and ICMPv6 tests Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 7/8] tcp: Pass inet_sdif() to __inet_lookup_established() in tcp_v4_err() Kuniyuki Iwashima
2026-11-28  8:06 ` [PATCH v2 net 8/8] tcp: Pass inet6_iif() to __inet6_lookup_established() in tcp_v6_err() Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128080700.3828378-4-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox