Since cited commits moved up TCP_NEW_SYN_RECV handling in tcp_v4_err() and tcp_v6_err(), ICMP messages bypass IP_MINTTL and IPV6_MINHOPCOUNT checks. The minimal repro is: --ip_version=ipv6 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_IPV6, 73, [255], 4) = 0 +0 bind(3, ..., ...) = 0 +0 listen(3, 10) = 0 +0 < (ttl 255) S 0:0(0) win 65535 +0 > S. 0:0(0) ack 1 +0 < (ttl 1) icmp unreachable port_unreachable [0:0(0)] +0 < (ttl 255) . 1:1(0) ack 1 win 65535 +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 accept(3, ..., ...) = 4 +0 %{assert tcpi_state == TCP_ESTABLISHED}% Let's restore IP_MINTTL/IPV6_MINHOPCOUNT for reqsk. Fixes: 26e3736090e1 ("ipv4: tcp: handle ICMP messages on TCP_NEW_SYN_RECV request sockets") Fixes: 2215089b2244 ("ipv6: tcp: handle ICMP messages on TCP_NEW_SYN_RECV request sockets") Signed-off-by: Kuniyuki Iwashima --- net/ipv4/tcp_ipv4.c | 19 +++++++++++-------- net/ipv6/tcp_ipv6.c | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index bf8542368032..fd9588bba967 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -516,6 +516,17 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) inet_twsk_put(inet_twsk(sk)); return 0; } + + if (static_branch_unlikely(&ip4_min_ttl)) { + /* min_ttl can be changed concurrently from do_ip_setsockopt() */ + if (unlikely(ip_hdr(skb)->ttl < + READ_ONCE(inet_sk(sk_to_full_sk(sk))->min_ttl))) { + __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); + sock_gen_put(sk); + return 0; + } + } + seq = ntohl(th->seq); if (sk->sk_state == TCP_NEW_SYN_RECV) { tcp_req_err(sk, seq, type == ICMP_PARAMETERPROB || @@ -544,14 +555,6 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; - if (static_branch_unlikely(&ip4_min_ttl)) { - /* min_ttl can be changed concurrently from do_ip_setsockopt() */ - if (unlikely(ip_hdr(skb)->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) { - __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); - goto out; - } - } - tp = tcp_sk(sk); /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ fastopen = rcu_dereference(tp->fastopen_rsk); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 8691d220cf94..0f1523fff939 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -433,6 +433,17 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, inet_twsk_put(inet_twsk(sk)); return 0; } + + if (static_branch_unlikely(&ip6_min_hopcount)) { + /* min_hopcount can be changed concurrently from do_ipv6_setsockopt() */ + if (ipv6_hdr(skb)->hop_limit < + READ_ONCE(tcp_inet6_sk(sk_to_full_sk(sk))->min_hopcount)) { + __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); + sock_gen_put(sk); + return 0; + } + } + seq = ntohl(th->seq); fatal = icmpv6_err_convert(type, code, &err); if (sk->sk_state == TCP_NEW_SYN_RECV) { @@ -452,14 +463,6 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; - if (static_branch_unlikely(&ip6_min_hopcount)) { - /* min_hopcount can be changed concurrently from do_ipv6_setsockopt() */ - if (ipv6_hdr(skb)->hop_limit < READ_ONCE(tcp_inet6_sk(sk)->min_hopcount)) { - __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); - goto out; - } - } - tp = tcp_sk(sk); /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ fastopen = rcu_dereference(tp->fastopen_rsk); -- 2.56.0.679.gc527c65306-goog