All of lore.kernel.org
 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>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org,
	 Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: [PATCH v1 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err().
Date: Tue, 17 Nov 2026 05:35:23 +0000	[thread overview]
Message-ID: <20261117053543.84032-6-kuniyu@google.com> (raw)
In-Reply-To: <20261117053543.84032-1-kuniyu@google.com>

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>
---
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 f11e090d04fb..bc909fedda3a 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);
 
@@ -588,6 +587,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.0.679.gc527c65306-goog


  parent reply	other threads:[~2026-11-17  5:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:35 [PATCH v1 net 0/8] tcp: Misc fixes for tcp_v[46]_err() Kuniyuki Iwashima
2026-11-17  5:35 ` [PATCH v1 net 1/8] tcp: Don't accept ICMP for SND.NXT in TCP_SYN_SENT Kuniyuki Iwashima
2026-11-17  8:35   ` Eric Dumazet
2026-11-17 23:30     ` Kuniyuki Iwashima
2026-11-17  5:35 ` [PATCH v1 net 2/8] tcp: Don't use inner IP TTL for IP_MINTTL in tcp_v4_err() Kuniyuki Iwashima
2026-11-17  8:42   ` Eric Dumazet
2026-11-17 23:35     ` Kuniyuki Iwashima
2026-11-17  5:35 ` [PATCH v1 net 3/8] tcp: Don't bypass GTSM check for reqsk Kuniyuki Iwashima
2026-11-17  8:45   ` Eric Dumazet
2026-11-17 23:42     ` Kuniyuki Iwashima
2026-11-17  5:35 ` [PATCH v1 net 4/8] tcp: Fix reqsk abort condition on ICMP errors Kuniyuki Iwashima
2026-11-17  8:49   ` Eric Dumazet
2026-11-17 23:44     ` Kuniyuki Iwashima
2026-11-17  5:35 ` Kuniyuki Iwashima [this message]
2026-11-17  8:54   ` [PATCH v1 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err() Eric Dumazet
2026-11-17  5:35 ` [PATCH v1 net 6/8] selftest: net: packetdrill: Add ICMP and ICMPv6 tests Kuniyuki Iwashima
2026-11-17  8:58   ` Eric Dumazet
2026-11-17 23:45     ` Kuniyuki Iwashima
2026-11-17  5:35 ` [PATCH v1 net 7/8] tcp: Pass inet_sdif() to __inet_lookup_established() in tcp_v4_err() Kuniyuki Iwashima
2026-11-17  9:01   ` Eric Dumazet
2026-11-17  5:35 ` [PATCH v1 net 8/8] tcp: Pass inet6_iif() to __inet6_lookup_established() in tcp_v6_err() Kuniyuki Iwashima
2026-11-17  9:03   ` Eric Dumazet
2026-11-17 23:56     ` 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=20261117053543.84032-6-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hannes@stressinduktion.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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.