* [PATCH v2 net 1/8] tcp: Don't use inner IP TTL for IP_MINTTL in tcp_v4_err().
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 ` 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
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev,
Stephen Hemminger
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 with the default
TTL 64, and an ICMP from intermediate routers with the initial TTL
will be dropped too, 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 <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
Cc: Stephen Hemminger <stephen@networkplumber.org>
v2: Mention ICMP could be dropped if sent with the default 64 TTL
---
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 2fc92a7884fc..e001c54cdc4b 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.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 2/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_err().
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 ` Kuniyuki Iwashima
2026-11-28 8:06 ` [PATCH v2 net 3/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_rcv() Kuniyuki Iwashima
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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 <mss 1440,nop,nop,sackOK>
+0 > S. 0:0(0) ack 1 <mss 1440,nop,nop,sackOK>
+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 in
tcp_v[46]_err().
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 <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
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 e001c54cdc4b..fe9cc5b66b97 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 5c7ed38f1f56..90426ea9e073 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.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 3/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_rcv().
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
2026-11-28 8:06 ` [PATCH v2 net 4/8] tcp: Fix reqsk abort condition on ICMP errors Kuniyuki Iwashima
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 4/8] tcp: Fix reqsk abort condition on ICMP errors.
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
` (2 preceding siblings ...)
2026-11-28 8:06 ` [PATCH v2 net 3/8] tcp: Don't bypass GTSM check for reqsk in tcp_v[46]_rcv() Kuniyuki Iwashima
@ 2026-11-28 8:06 ` Kuniyuki Iwashima
2026-11-28 8:06 ` [PATCH v2 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err() Kuniyuki Iwashima
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
TCP_SYN_SENT and TCP_SYN_RECV sockets treat ICMP soft errors
as hard errors as mentioned in RFC 5461 Section 4.1.
Commit 9cf7490360bf ("tcp: do not drop syn_recv on all icmp
reports") introduced the abort arg to tcp_req_err() to avoid
aborting TCP_NEW_SYN_RECV reqsk on ICMP_REDIRECT and
ICMP_FRAG_NEEDED.
However, tcp_v4_err() only checks ICMP_NET_UNREACH and
ICMP_HOST_UNREACH under ICMP_DEST_UNREACH and ignores other
codes such as ICMP_PORT_UNREACH.
For example, we can see SYN+ACK retransmitted after receiving
hard error:
--ip_version=ipv4
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 bind(3, ..., ...) = 0
+0 listen(3, 10) = 0
+0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
+0 < icmp unreachable port_unreachable [0:0(0)]
+1 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK>
Similarly, tcp_v6_err() passes fatal from icmpv6_err_convert()
and ignores soft errors such as ICMPV6_TIME_EXCEED, ICMPV6_NOROUTE,
and ICMPV6_ADDR_UNREACH.
Let's abort reqsk on ICMP_DEST_UNREACH (except ICMP_FRAG_NEEDED),
ICMP_TIME_EXCEEDED, and ICMP_PARAMETERPROB (and their IPv6
equivalents) to match TCP_SYN_SENT and TCP_SYN_RECV.
Fixes: 9cf7490360bf ("tcp: do not drop syn_recv on all icmp reports")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
v2: Change not to ignore hard error instead of following RFC 1122
---
net/ipv4/tcp_ipv4.c | 3 +--
net/ipv6/tcp_ipv6.c | 7 ++++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 4b6bc7812cb1..f7fef1dd8780 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -532,8 +532,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
tcp_req_err(sk, seq, type == ICMP_PARAMETERPROB ||
type == ICMP_TIME_EXCEEDED ||
(type == ICMP_DEST_UNREACH &&
- (code == ICMP_NET_UNREACH ||
- code == ICMP_HOST_UNREACH)));
+ code != ICMP_FRAG_NEEDED));
return 0;
}
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 7c17162160ad..8ec0f2707502 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -414,7 +414,6 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
struct tcp_sock *tp;
__u32 seq, snd_una;
struct sock *sk;
- bool fatal;
int err;
sk = __inet6_lookup_established(net, &hdr->daddr, th->dest,
@@ -445,9 +444,11 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
}
seq = ntohl(th->seq);
- fatal = icmpv6_err_convert(type, code, &err);
+ icmpv6_err_convert(type, code, &err);
if (sk->sk_state == TCP_NEW_SYN_RECV) {
- tcp_req_err(sk, seq, fatal);
+ tcp_req_err(sk, seq, type == ICMPV6_PARAMPROB ||
+ type == ICMPV6_TIME_EXCEED ||
+ type == ICMPV6_DEST_UNREACH);
return 0;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err().
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
` (3 preceding siblings ...)
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 ` Kuniyuki Iwashima
2026-11-28 8:06 ` [PATCH v2 net 6/8] selftest: net: packetdrill: Add ICMP and ICMPv6 tests Kuniyuki Iwashima
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev,
Hannes Frederic Sowa
Currently, tcp_v4_mtu_reduced() checks ip_sk_accept_pmtu()
after calling inet_csk_update_pmtu(), which is too late.
Even if we configure a socket not to perform Path MTU
Discovery with IP_PMTUDISC_INTERFACE, ICMP_FRAG_NEEDED
can overwrite MTU.
The last getsockopt() returns 1200 MTU:
--ip_version=ipv4
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0
+0 < S 0:0(0) win 65535 <mss 1460,sackOK,nop,nop,nop,wscale 8>
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 9>
+0 < . 1:1(0) ack 1 win 257
+0 accept(3, ..., ...) = 4
+0 setsockopt(4, SOL_IP, IP_MTU_DISCOVER, [4], 4) = 0
+0 getsockopt(4, SOL_IP, IP_MTU, [1500], [4]) = 0
+0 write(4, ..., 1000) = 1000
+0 > P. 1:1001(1000) ack 1
+0 < icmp unreachable frag_needed mtu 1200 [1:1001(1000)]
+0 getsockopt(4, SOL_IP, IP_MTU, [1500], [4]) = 0
Let's check ip_sk_accept_pmtu() in tcp_v4_err() as done
in tcp_v6_err().
Note that inet_sk(sk)->pmtudisc is configured locklessly,
so we do not recheck it in tcp_v4_mtu_reduced(). This is
same with tcp_v6_mtu_reduced() too.
Fixes: 482fc6094afa ("ipv4: introduce new IP_MTU_DISCOVER mode IP_PMTUDISC_INTERFACE")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
net/ipv4/tcp_ipv4.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index f7fef1dd8780..767f84d94aaa 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -391,7 +391,6 @@ void tcp_v4_mtu_reduced(struct sock *sk)
WRITE_ONCE(sk->sk_err_soft, EMSGSIZE);
if (inet->pmtudisc != IP_PMTUDISC_DONT &&
- ip_sk_accept_pmtu(sk) &&
inet_csk(sk)->icsk_pmtu_cookie > dmtu) {
tcp_sync_mss(sk, dmtu);
@@ -587,6 +586,9 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
if (sk->sk_state == TCP_LISTEN)
goto out;
+ if (!ip_sk_accept_pmtu(sk))
+ goto out;
+
WRITE_ONCE(tp->mtu_info, info);
if (!sock_owned_by_user(sk)) {
tcp_v4_mtu_reduced(sk);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 6/8] selftest: net: packetdrill: Add ICMP and ICMPv6 tests.
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
` (4 preceding siblings ...)
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 ` 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
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
tcp_icmp_ipv4.pkt and tcp_icmp_ipv6.pkt cover the scenarios
fixed by the preceding patches.
tcp_v6_err() already checks the outer hop limit and
ip6_sk_accept_pmtu(), so Test 1 and 4 in tcp_icmp_ipv6.pkt
pass without the series.
ICMP and ICMPv6 behaviour are unlikely to change, so splitting
into multiple files per test case is not worth it.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
v2:
* Remove tests for v1's patch 1
* Cover more ICMP errors
* Use IP_TTL symbol w/ a new packetdrill (NIPA already
support this : https://github.com/linux-netdev/nipa/pull/143
---
.../net/packetdrill/tcp_icmp_ipv4.pkt | 124 ++++++++++++++++++
.../net/packetdrill/tcp_icmp_ipv6.pkt | 124 ++++++++++++++++++
2 files changed, 248 insertions(+)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_icmp_ipv4.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_icmp_ipv6.pkt
diff --git a/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv4.pkt b/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv4.pkt
new file mode 100644
index 000000000000..0e98f713a451
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv4.pkt
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+--ip_version=ipv4
+
+`./defaults.sh`
+
+// Test 1: Client with IP_MINTTL checks outer IP TTL in tcp_v4_err()
+// An ICMP with outer TTL < min_ttl (250) must be dropped, while outer TTL >= min_ttl
+// must be accepted even though the quoted inner IP header has lower TTL (64).
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_IP, IP_MINTTL, [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) <...>
+ // Outer TTL 10 < min_ttl (250): dropped, socket stays in TCP_SYN_SENT
+ +0 < (ttl 10) icmp unreachable host_unreachable [0:0(0)]
+ +1 > S 0:0(0) <...>
+ // Outer TTL 255 >= min_ttl (250): accepted, socket aborts
+ +0 < (ttl 255) icmp unreachable host_unreachable [0:0(0)]
+ +0 %{ assert tcpi_state == TCP_CLOSE }%
+ +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [EHOSTUNREACH], [4]) = 0
+ +0 close(3) = 0
+
+// Test 2: Listener with IP_MINTTL checks TTL before reqsk handling
+// An incoming ICMP or 3rd ACK with outer TTL < min_ttl (255) must not abort or
+// complete TCP_NEW_SYN_RECV, while outer TTL >= min_ttl (255) must be accepted.
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 setsockopt(3, SOL_IP, IP_MINTTL, [255], 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 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer TTL 10 < min_ttl (255) on ICMP: dropped in tcp_v4_err(), reqsk survives
+ +0 < (ttl 10) icmp unreachable port_unreachable [0:0(0)]
+ +1 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer TTL 10 < min_ttl (255) on 3rd ACK: dropped in tcp_v4_rcv(), reqsk survives
+ +0 < (ttl 10) . 1:1(0) ack 1 win 65535
+ +2 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer TTL 255 >= min_ttl (255): accepted, ICMP aborts reqsk
+ +0 < (ttl 255) icmp unreachable port_unreachable [0:0(0)]
+ +0 < (ttl 255) . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+
+// Test 3: Server in TCP_NEW_SYN_RECV ignores ICMP_FRAG_NEEDED, but aborts on
+// other ICMP_DEST_UNREACH codes, ICMP_TIME_EXCEEDED, and ICMP_PARAMETERPROB.
+ // 3a: ICMP_FRAG_NEEDED must not abort reqsk, ICMP_HOST_UNREACH must abort
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable frag_needed mtu 1200 [0:0(0)]
+ +1 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable host_unreachable [0:0(0)]
+ // Remote sends 3rd ACK: listener responds with RST because reqsk was aborted
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3b: ICMP_NET_UNREACH must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable net_unreachable [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3c: ICMP_TIME_EXCEEDED must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp time_exceeded [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3d: ICMP_PARAMETERPROB must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp parameter_problem [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3e: ICMP_PORT_UNREACH must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable port_unreachable [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+
+// Test 4: Socket with IP_PMTUDISC_INTERFACE ignores ICMP_FRAG_NEEDED
+// Socket configured with IP_PMTUDISC_INTERFACE must not overwrite MTU
+// upon receiving ICMP_DEST_UNREACH with code ICMP_FRAG_NEEDED.
+ +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+ +0 < S 0:0(0) win 65535 <mss 1460,sackOK,nop,nop,nop,wscale 8>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < . 1:1(0) ack 1 win 257
+ +0 accept(3, ..., ...) = 4
+ +0 setsockopt(4, SOL_IP, IP_MTU_DISCOVER, [IP_PMTUDISC_INTERFACE], 4) = 0
+ +0 getsockopt(4, SOL_IP, IP_MTU, [1500], [4]) = 0
+ +0 write(4, ..., 1000) = 1000
+ +0 > P. 1:1001(1000) ack 1 <...>
+ +0 < icmp unreachable frag_needed mtu 1200 [1:1001(1000)]
+ +0 getsockopt(4, SOL_IP, IP_MTU, [1500], [4]) = 0
+ +0 close(4) = 0
+ +0 close(3) = 0
diff --git a/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv6.pkt b/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv6.pkt
new file mode 100644
index 000000000000..d1a44af7297b
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_icmp_ipv6.pkt
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+--ip_version=ipv6
+
+`./defaults.sh`
+
+// Test 1: Client with IPV6_MINHOPCOUNT checks outer IPv6 hop_limit in tcp_v6_err()
+// An ICMPv6 with outer hop_limit < min_hopcount (250) must be dropped, while outer
+// hop_limit >= min_hopcount must be accepted even though the quoted inner hop_limit is 64.
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_IPV6, IPV6_MINHOPCOUNT, [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) <...>
+ // Outer hop_limit 10 < min_hopcount (250): dropped, socket stays in TCP_SYN_SENT
+ +0 < (ttl 10) icmp unreachable address_unreachable [0:0(0)]
+ +1 > S 0:0(0) <...>
+ // Outer hop_limit 255 >= min_hopcount (250): accepted, socket aborts
+ +0 < (ttl 255) icmp unreachable address_unreachable [0:0(0)]
+ +0 %{ assert tcpi_state == TCP_CLOSE }%
+ +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [EHOSTUNREACH], [4]) = 0
+ +0 close(3) = 0
+
+// Test 2: Listener with IPV6_MINHOPCOUNT checks hop_limit before reqsk handling
+// An incoming ICMPv6 or 3rd ACK with outer hop_limit < min_hopcount (255) must not abort or
+// complete TCP_NEW_SYN_RECV, while outer hop_limit >= min_hopcount (255) must be accepted.
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 setsockopt(3, SOL_IPV6, IPV6_MINHOPCOUNT, [255], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < (ttl 255) S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer hop_limit 10 < min_hopcount (255) on ICMPv6: dropped in tcp_v6_err(), reqsk survives
+ +0 < (ttl 10) icmp unreachable port_unreachable [0:0(0)]
+ +1 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer hop_limit 10 < min_hopcount (255) on 3rd ACK: dropped in tcp_v6_rcv(), reqsk survives
+ +0 < (ttl 10) . 1:1(0) ack 1 win 65535
+ +2 > (ttl 64) S. 0:0(0) ack 1 <...>
+ // Outer hop_limit 255 >= min_hopcount (255): accepted, ICMPv6 aborts reqsk
+ +0 < (ttl 255) icmp unreachable port_unreachable [0:0(0)]
+ +0 < (ttl 255) . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+
+// Test 3: Server in TCP_NEW_SYN_RECV ignores ICMPV6_PKT_TOOBIG, but aborts on
+// ICMPV6_DEST_UNREACH, ICMPV6_TIME_EXCEED, and ICMPV6_PARAMPROB.
+ // 3a: ICMPV6_PKT_TOOBIG must not abort reqsk, ICMPV6_ADDR_UNREACH must abort
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp packet_too_big mtu 1280 [0:0(0)]
+ +1 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable address_unreachable [0:0(0)]
+ // Remote sends 3rd ACK: listener responds with RST because reqsk was aborted
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3b: ICMPV6_TIME_EXCEED must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp time_exceeded [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3c: ICMPV6_HDR_FIELD parameter problem must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp parameter_problem header_field [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3d: ICMPV6_UNK_NEXTHDR parameter problem must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp parameter_problem unknown_next_header [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+ // 3e: ICMPV6_PORT_UNREACH must abort reqsk
+ +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 10) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,nop,nop,sackOK>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < icmp unreachable port_unreachable [0:0(0)]
+ +0 < . 1:1(0) ack 1 win 65535
+ +0 > R 1:1(0)
+ +0 close(3) = 0
+
+// Test 4: Socket with IPV6_PMTUDISC_INTERFACE ignores ICMPV6_PKT_TOOBIG
+// Socket configured with IPV6_PMTUDISC_INTERFACE must not overwrite MTU
+// upon receiving ICMPV6_PKT_TOOBIG.
+ +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+ +0 < S 0:0(0) win 65535 <mss 1440,sackOK,nop,nop,nop,wscale 8>
+ +0 > S. 0:0(0) ack 1 <...>
+ +0 < . 1:1(0) ack 1 win 257
+ +0 accept(3, ..., ...) = 4
+ +0 setsockopt(4, SOL_IPV6, IPV6_MTU_DISCOVER, [IPV6_PMTUDISC_INTERFACE], 4) = 0
+ +0 getsockopt(4, SOL_IPV6, IPV6_MTU, [1520], [4]) = 0
+ +0 write(4, ..., 1000) = 1000
+ +0 > P. 1:1001(1000) ack 1 <...>
+ +0 < icmp packet_too_big mtu 1280 [1:1001(1000)]
+ +0 getsockopt(4, SOL_IPV6, IPV6_MTU, [1520], [4]) = 0
+ +0 close(4) = 0
+ +0 close(3) = 0
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 7/8] tcp: Pass inet_sdif() to __inet_lookup_established() in tcp_v4_err().
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
` (5 preceding siblings ...)
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 ` 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
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev,
David Ahern
tcp_v4_err() passes 0 sdif to __inet_lookup_established().
So, ICMP error coming from VRF can be leaked to a socket not
bound to the device.
For example, this test fails at the last assert because the
socket receives ICMP error:
--ip_version=ipv4
0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+0 > S 0:0(0) <...>
+0 `ip link add vrf0 type vrf table 10`
+0 `ip link set vrf0 up`
+0 `ip link set dev tun0 master vrf0`
+0 `ip route add 192.0.2.0/24 dev tun0 table 10`
+0 < icmp unreachable port_unreachable [0:0(0)]
+0 %{ assert tcpi_state == TCP_SYN_SENT, tcpi_state }%
Let's pass inet_sdif() to __inet_lookup_established().
Fixes: 3fa6f616a7a4 ("net: ipv4: add second dif to inet socket lookups")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: David Ahern <dsahern@kernel.org>
---
net/ipv4/tcp_ipv4.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 767f84d94aaa..ffc521c2b701 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -504,7 +504,8 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
int err;
sk = __inet_lookup_established(net, iph->daddr, th->dest, iph->saddr,
- ntohs(th->source), inet_iif(skb), 0);
+ ntohs(th->source), inet_iif(skb),
+ inet_sdif(skb));
if (!sk) {
__ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
return -ENOENT;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 net 8/8] tcp: Pass inet6_iif() to __inet6_lookup_established() in tcp_v6_err().
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
` (6 preceding siblings ...)
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 ` Kuniyuki Iwashima
7 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-28 8:06 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
tcp_v6_err() passes skb->dev->ifindex to __inet6_lookup_established().
When ICMP is sent to a local address not on loopback device,
ip6_rt_get_dev_rcu() sets dst->dev to lo and ip6_rt_copy_init()
sets rt6i_idev to the actual device.
In ip6_rcv_core(), skb->dev is still lo, but IP6CB(skb)->iif
is set to ip6_dst_idev(skb_dst(skb))->dev->ifindex.
So skb->dev->ifindex is 1 while inet6_iif(skb) points to the
actual device.
Since tcp_v6_err() passes the wrong ifindex, such an ICMP error
is not delivered.
For example, this script creates a socket bound to tun0 and
generates ICMPv6 Port Unreachable to it, but the socket cannot
receive it and getsockopt() fails:
--ip_version=ipv6
0 `ip link set lo up`
+0 `ip6tables -A OUTPUT -p tcp -j REJECT`
+0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+0 setsockopt(3, SOL_SOCKET, SO_BINDTODEVICE, "tun0", 4) = 0
+0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+0 getsockopt(3, SOL_SOCKET, SO_ERROR, [ECONNREFUSED], [4]) = 0
Let's pass inet6_iif() to __inet6_lookup_established().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
---
net/ipv6/tcp_ipv6.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 8ec0f2707502..9fbb0d97fbc7 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -418,7 +418,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
sk = __inet6_lookup_established(net, &hdr->daddr, th->dest,
&hdr->saddr, ntohs(th->source),
- skb->dev->ifindex, inet6_sdif(skb));
+ inet6_iif(skb), inet6_sdif(skb));
if (!sk) {
__ICMP6_INC_STATS(net, __in6_dev_get(skb->dev),
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread