From: Eric Dumazet <edumazet@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Neal Cardwell <ncardwell@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
Simon Horman <horms@kernel.org>,
Flavius-Romeo Mazilu <flavius.mazilu@stud.acs.upb.ro>,
Michael Tuexen <tuexen@fh-muenster.de>,
netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>
Subject: [PATCH net-next 1/2] tcp: do not accept ACK of our ISS on active opens
Date: Wed, 18 Nov 2026 18:26:53 +0100 [thread overview]
Message-ID: <20261118172654.1267071-2-edumazet@kernel.org> (raw)
In-Reply-To: <20261118172654.1267071-1-edumazet@kernel.org>
Michael Tuexen asked on the tcpm list [1] whether, after a completed
handshake, a segment with SEG.ACK == ISS is a duplicate ACK or a ghost
ACK. Flavius-Romeo Mazilu answered that Linux behaves differently
depending on which side opened the connection:
- passive opens drop it and send a challenge ACK,
- active opens accept it as an old duplicate ACK.
This comes from commit 3d501dd326fb ("tcp: do not accept ACK of bytes
we never sent"), which bounds the range of acceptable old ACKs
by tp->bytes_acked.
On active opens (including Fast Open and simultaneous opens),
tp->snd_una starts at ISS and the ACK of our SYN goes through
tcp_snd_una_update(), so tp->bytes_acked counts the SYN.
On passive opens, tp->snd_una starts at ISS + 1 and the SYN-ACK
is not counted.
The SYN is not a payload byte, and no valid ACK ever carried ISS:
the lowest ACK a peer can send on a synchronized connection is ISS + 1.
Counting the SYN widens the acceptable range by one sequence number.
tp->bytes_acked is exported to user space (tcpi_bytes_acked,
bpf_tcp_sock, bpf_sock_ops) and tools/testing/selftests/bpf expects
the SYN to be counted, so leave it unchanged.
Instead, remember in a new bit that our SYN was counted,
and subtract it in the tcp_ack() check.
Mazilu's observation was confirmed by code inspection and with
packetdrill on an unmodified kernel: after an active open, a segment
with SEG.ACK == ISS is silently accepted, where a passive open
answers with a challenge ACK.
Tested with the packetdrill tests added in the following patch,
which fail on the active side before this patch, and with the other
tests in tools/testing/selftests/net/packetdrill.
[1] https://mailarchive.ietf.org/arch/msg/tcpm/ZbjDTFQSHeKSVHAToyAnKBr3TpU/
Fixes: 3d501dd326fb ("tcp: do not accept ACK of bytes we never sent")
Reported-by: Flavius-Romeo Mazilu <flavius.mazilu@stud.acs.upb.ro>
Closes: https://mailarchive.ietf.org/arch/msg/tcpm/ym6lb-UkrW2298LRnTLxCysoo0g/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
Documentation/networking/net_cachelines/tcp_sock.rst | 1 +
include/linux/tcp.h | 3 ++-
net/ipv4/tcp.c | 1 +
net/ipv4/tcp_input.c | 10 ++++++++--
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 554e8c14a401f27ec5a6c109877bb122942bade9..78f74eb7699063022adc5d4524a82466c82e4758 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -59,6 +59,7 @@ u8:2 fastopen_client_fail
u8:4 nonagle read_write tcp_skb_entail,tcp_push_pending_frames
u8:1 thin_lto
u8:1 recvmsg_inq read_mostly tcp_recvmsg
+u8:1 bytes_acked_syn read_mostly tcp_ack
u8:1 repair read_mostly tcp_write_xmit
u8:1 frto
u8 repair_queue
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index e6b79cf4798f497ea43bb987431da2c797ee3086..13a192cc3c62e219235e0610924fe460148be19c 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -235,7 +235,8 @@ struct tcp_sock {
tcp_usec_ts : 1, /* TSval values in usec */
is_sack_reneg:1, /* in recovery from loss with SACK reneg? */
is_cwnd_limited:1,/* forward progress limited by snd_cwnd? */
- recvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */
+ recvmsg_inq : 1,/* Indicate # of bytes in queue upon recvmsg */
+ bytes_acked_syn:1;/* bytes_acked includes our SYN */
#ifdef CONFIG_BPF
u32 bpf_tcp_ops_flags;
#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) \
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index d510e982dcea9830442d4c7afedb67deb3c28115..498889efe2e3323484b9d30842d9f16475165e4a 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3472,6 +3472,7 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->segs_out = 0;
tp->bytes_sent = 0;
tp->bytes_acked = 0;
+ tp->bytes_acked_syn = 0;
tp->bytes_received = 0;
tp->bytes_retrans = 0;
tp->data_segs_in = 0;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d35048c363be5cb985ba1efb9dab24c9aaab4fda..6cf6cb3336b23b065b93d747e0565475ce4c3d0c 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3712,6 +3712,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, const struct sk_buff *ack_skb,
} else {
flag |= FLAG_SYN_ACKED;
tp->retrans_stamp = 0;
+ /* tcp_snd_una_update() counted our SYN. */
+ tp->bytes_acked_syn = 1;
}
if (!fully_acked)
@@ -4333,8 +4335,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
if (before(ack, prior_snd_una)) {
u32 max_window;
- /* do not accept ACK for bytes we never sent. */
- max_window = min_t(u64, tp->max_window, tp->bytes_acked);
+ /* Do not accept ACK for bytes we never sent.
+ * Our SYN, if counted in bytes_acked, is not one of them:
+ * no valid ACK ever carried ISS.
+ */
+ max_window = min_t(u64, tp->max_window,
+ tp->bytes_acked - tp->bytes_acked_syn);
/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */
if (before(ack, prior_snd_una - max_window)) {
if (!(flag & FLAG_NO_CHALLENGE_ACK))
--
2.53.0
next prev parent reply other threads:[~2026-11-18 17:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 17:26 [PATCH net-next 0/2] tcp: do not accept ACK of our ISS on active opens Eric Dumazet
2026-11-18 17:26 ` Eric Dumazet [this message]
2026-11-18 17:26 ` [PATCH net-next 2/2] selftests/net: packetdrill: add tests for ACK of ISS Eric Dumazet
2026-11-21 1:20 ` [PATCH net-next 0/2] tcp: do not accept ACK of our ISS on active opens patchwork-bot+netdevbpf
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=20261118172654.1267071-2-edumazet@kernel.org \
--to=edumazet@kernel.org \
--cc=davem@davemloft.net \
--cc=flavius.mazilu@stud.acs.upb.ro \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tuexen@fh-muenster.de \
/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.