Netdev List
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: Eric Dumazet <edumazet@kernel.org>
Cc: Neal Cardwell <ncardwell@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org,
	 Stephen Hemminger <stephen@networkplumber.org>,
	stephen hemminger <shemminger@vyatta.com>
Subject: Re: [PATCH v1 net 2/8] tcp: Don't use inner IP TTL for IP_MINTTL in tcp_v4_err().
Date: Tue, 17 Nov 2026 23:35:50 +0000	[thread overview]
Message-ID: <avzjoLDBf-bkj6J5@google.com> (raw)
In-Reply-To: <CAL4WiiqEnTF0RCv4+Vp_WXG8jrwhsAakbXTzU+vfLq+d4WTAqw@mail.gmail.com>

On Tue, 17 Nov 2026 09:42:02 +0100, Eric Dumazet wrote:
> Le mar. 17 nov. 2026 à 06:35, Kuniyuki Iwashima <kuniyu@google.com> a écrit :
> >
> > 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 <kuniyu@google.com>
> > ---
> > Cc: Stephen Hemminger <stephen@networkplumber.org>
> > Cc: stephen hemminger <shemminger@vyatta.com>
> > ---
> >  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;
> >                 }
> 
> Linux sends ICMP errors with the default TTL (64), so locally
> generated errors are now dropped for any min_ttl above 64.
> 
> For the strict GTSM case (min_ttl == 255) there is no router between
> the peers, so nothing else changes.
> 
> But IP_MINTTL is also used with lower values for multi-hop sessions
> ("ttl-security hops N"). There, an ICMP from an intermediate router
> using an initial TTL of 64 was accepted before this patch (the quoted
> TTL is the one we sent, minus the hops to that router), and is dropped
> after.
> 
> I think this is the right thing to do, since the inner TTL is under
> the sender's control, but I would mention this in the changelog.

Will add it to changelog.

Thanks !

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

Thread overview: 22+ 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 [this message]
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 ` [PATCH v1 net 5/8] tcp: Check ip_sk_accept_pmtu() in tcp_v4_err() Kuniyuki Iwashima
2026-11-17  8:54   ` 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

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=avzjoLDBf-bkj6J5@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=shemminger@vyatta.com \
    --cc=stephen@networkplumber.org \
    /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