RFC 5082 introduced Generalized TTL Security Mechanism (GTSM), and IP_MINTTL and IPV6_MINHOPCOUNT follow that. If an incoming IPv4 packet has TTL less than inet_sk(sk)->min_ttl configured via IP_MINTTL, the packet is dropped. However, tcp_v4_err() checks the TTL extracted from the ICMP payload, not the one in the outer IP header. The minimal repro is: --ip_version=ipv4 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_IP, 21, [250], 4) = 0 +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) +0 > S 0:0(0) <...> +0 < (ttl 10) icmp unreachable host_unreachable [0:0(0)] +0 %{assert tcpi_state == TCP_SYN_SENT}% Let's check ip_hdr(skb)->ttl. Now GTSM is applied to locally generated ICMP errors, but this behaviour matches tcp_v6_err(). Note that tcp_v6_err() properly checks ipv6_hdr(skb)->hop_limit. Fixes: 97e3ecd112ba ("TCP: check min TTL on received ICMP packets") Signed-off-by: Kuniyuki Iwashima --- Cc: Stephen Hemminger Cc: stephen hemminger --- net/ipv4/tcp_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 7d58f522068d..bf8542368032 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -546,7 +546,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) if (static_branch_unlikely(&ip4_min_ttl)) { /* min_ttl can be changed concurrently from do_ip_setsockopt() */ - if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) { + if (unlikely(ip_hdr(skb)->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) { __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); goto out; } -- 2.56.0.679.gc527c65306-goog