Skip to content

transport: Client resets PTO backoff on Initial ACKs, probing every RTT indefinitely #4359

Open

Description

@larseggert

Related: #3662, #1605

A neqo client resets its PTO backoff on every ACK it receives in an Initial packet, which RFC 9002 Section 6.2.1 forbids. A peer that only acknowledges the client's Initials can therefore make it send a full-size 1232-byte Initial probe once per round trip, with no exponential backoff and no end at the idle timeout. The attached reproducer shows 386 datagrams in 20 simulated seconds at a 50 ms round trip, against 14 when nothing comes back. There is no memory-safety impact, and the server role is not affected.

The reset is the unconditional self.pto_state = None at the end of Loss::on_ack_received() in neqo-transport/src/recovery/mod.rs (around line 734). It checks neither pn_space nor the role, since Loss does not know whether it is a client or a server. Because the Initial-space PTO timer stays armed after the first flight is acknowledged (the handshake-deadlock special case in pto_base_time()), each probe is acknowledged, the count drops back to zero, and the next probe fires about 1 ms after the ACK arrives. Each such ACK also restarts the idle timer, so the probing continues until the client discards the Initial space. In the reproducer, the client was still probing after 90 s and had sent about 2.1 MB.

The benign trigger is the case the RFC rule exists for: a server that acknowledges Initials promptly but is slow or overloaded in continuing the handshake. That server then receives one full-size datagram per round trip from every such client. The same ACKs can be forged by anyone who sees the client's first datagram and can spoof the server's address, since Initial keys derive from that datagram. Each 66-byte forged ACK makes the client send 1232 bytes to the real server, about 19 to 1, at a rate the forger chooses. In one test, forged ACKs that arrived first also caused the real server's first reply to be discarded as a duplicate, and the client kept probing. Later server retransmissions were not tested.

This is separate from the documented, deliberate deviation in Loss::discard(), which runs once per packet number space. The reset in on_ack_received() runs on every ACK and has no such comment. The behaviour dates from 0b72a5381cc2 ("Handshake recovery improvements", 2020-07-15) and first shipped in v0.4.9. A patch that keeps the count for client Initial-space ACKs is attached.

Details

Loss::on_ack_received() clears the PTO count for every ACK frame that acknowledges something new, in either
role and in every packet number space. RFC 9002, Section 6.2.1 makes one exception to that reset: "To protect
such a server from repeated client probes, the PTO backoff is not reset at a client that is not yet certain that
the server has finished validating the client's address. That is, a client does not reset the PTO backoff factor
on receiving acknowledgments in Initial packets."

The effect on the wire: test_fixture::default_client() starts a connection and gets back nothing but Initial
packets that hold one ACK frame, each 50 ms after the client flight it acknowledges. Over 20 simulated seconds:

what comes back datagrams the client sends sent at (ms) Stats::pto_counts
nothing 14 0, 300, 900, 2100, 4500, 9300, 18900 (two each) [0, 0, 0, 0, 0, 1, 0, …]
Initial ACKs only 386 0, 0, 150, 275, 381, 473, 555, … then one every 51 ms until the end [384, 0, 0, …]

Unanswered, the client doubles its probe interval. Acknowledged, it fires 384 PTOs and not one of them is the
second in a row: every probe goes out with the backoff at its start value, each one a 1232-byte Initial
datagram.

The reset is the last thing on_ack_received() does:

// neqo-transport/src/recovery/mod.rs:734
if self.pto_state.is_some() {
    qlog::loss_timer_cancelled(&mut self.qlog, now);
}
self.pto_state = None;

pto_state holds the PTO count that pto_period_inner() (recovery/mod.rs:854) turns into the 2^count
factor; None means a factor of 1. The reset does not look at pn_space, and Loss does not know whether it
belongs to a client or a server. The function is reached from Connection::handle_ack()
(neqo-transport/src/connection/mod.rs:3707) for an ACK frame in any space, and returns before the reset only
when the space has been discarded or the frame acknowledges nothing new (recovery/mod.rs:664, :671).

How that becomes one probe per round trip:

  1. The ACK for the first flight leaves nothing outstanding in the Initial space, but the PTO timer stays armed
    there from last_ack_eliciting to avoid a handshake deadlock (LossRecoverySpace::pto_base_time(),
    recovery/mod.rs:197). That is correct and is what makes the client probe at all.
  2. The timer expires, fire_pto() (recovery/mod.rs:908) sets the count to 1 and the client sends a probe.
  3. The peer acknowledges the probe. on_ack_received() takes an RTT sample from it (recovery/mod.rs:684) and
    then drops pto_state, so the next period is the base srtt + max(4 * rttvar, 1 ms)
    (neqo-transport/src/rtt.rs:158) again, counted from the time the probe was sent.
  4. All samples are the same, so rttvar shrinks and the period settles at one round trip plus 1 ms: the
    timer expires 1 ms after the ACK has arrived, and step 2 repeats.

The probe rate is therefore set by how fast the acknowledgments come back, not by the client. With the same
test and other round-trip times the client sends 93 datagrams in 20 s at 200 ms, 3330 at 5 ms and 10001 at 1 ms.

Each of these ACK packets is a valid packet, so it also restarts the idle timer
(connection/mod.rs:1870). Run for 90 s instead of 20 s, the acknowledged client is still probing at the end
(1759 datagrams, 2,167,088 bytes), while the unanswered one has sent its 14 datagrams and is in
Closed(Transport(IdleTimeout)). The probing ends when the client sends its first Handshake packet and discards
the Initial space (connection/mod.rs:2961).

Loss::discard() clears the count as well, and says that it departs from the specification on purpose
(recovery/mod.rs:792):

// We just made progress, so discard PTO count.
// The spec says that clients should not do this until confirming that
// the server has completed address validation, but ignore that.

That one runs once per packet number space. The reset in on_ack_received() has no such comment and runs for
every ACK. The behaviour was introduced in 0b72a5381cc2 ("Handshake recovery improvements", 2020-07-15) and
first shipped in release v0.4.9.

Impact

A client that receives Initial acknowledgments but no ServerHello sends a 1232-byte Initial probe once per
round trip, for as long as the acknowledgments keep coming, instead of backing off exponentially: 386 datagrams
in 20 s against 14 at a 50 ms round trip, growing linearly with time and not bounded by the idle timeout. The
peer that produces such ACKs without any ill intent is a server that acknowledges Initial packets at once but is
overloaded or slow to continue the handshake, which is the case the RFC rule is written for; it receives one
full-size datagram per round trip from every such client. The same ACKs can be forged by anyone who saw the
client's first datagram and can spoof the server's address, because Initial keys are derived from that datagram.
The real server's reply does not necessarily end this: when forged ACKs reach the client first, the forger has
already used the packet numbers of the server's first reply, so the client discards that reply as a duplicate
and keeps probing (409 more datagrams in the next 4.5 s in a test; later retransmissions from the server were
not tested). The probes go to the address the client is already connecting to, so this is not a reflection
vector by destination, but each 66-byte forged ACK makes the client send 1232 bytes to the real server, about
19 to 1, at a rate the forger chooses. It is a protocol violation with a load effect on the server,
on the client code path; there is no memory-safety impact and the server role is not affected.

Suggested fix

The attached patch keeps the PTO count when a client processes an ACK in the Initial space, in
Loss::on_ack_received() (neqo-transport/src/recovery/mod.rs):

@@ -731,10 +733,15 @@ impl Loss {
             &mut self.stats.borrow_mut(),
         );
 
-        if self.pto_state.is_some() {
-            qlog::loss_timer_cancelled(&mut self.qlog, now);
+        // A client does not reset the PTO backoff on receiving acknowledgments in
+        // Initial packets, as the server might not have validated its address yet
+        // and needs protecting from repeated probes (RFC 9002, Section 6.2.1).
+        if self.role == Role::Server || pn_space != PacketNumberSpace::Initial {
+            if self.pto_state.is_some() {
+                qlog::loss_timer_cancelled(&mut self.qlog, now);
+            }
+            self.pto_state = None;
         }
-        self.pto_state = None;
 
         (acked_packets, lost)
     }

Loss needs to know its role for that. The rest of the patch is plumbing: a role: Role field in Loss, set
from a new first argument of Loss::new(), the way Streams::new() and NewTokenState::new() take it;
Connection::new(), the only non-test caller, passes its role (connection/mod.rs:468); and
neqo_common::Role is imported in recovery/mod.rs and in its tests module. The unit-test fixture in
recovery/mod.rs gains Fixture::new(role), and its Default stays Role::Server, which keeps the behaviour
its tests were written for. A new unit test, pto_backoff_kept_on_client_initial_ack, checks that the count
survives an Initial ACK at a client but is still cleared by a Handshake ACK at a client and by an Initial ACK at
a server. Servers and the Handshake and ApplicationData spaces behave as before, and the reset in
Loss::discard() is left as it is, so the backoff still ends when the client sends its first Handshake packet.

Not covered by the patch: the comments in connection/tests/recovery.rs::handshake_pto_not_primed_without_keys
still say that a server's Initial ACK clears pto_state at the client, which is no longer true (the test itself
passes unchanged); they should be updated before merging.

Proposed patches

patches/1.patch
# neqo-transport/src/recovery/mod.rs
# Keep the PTO backoff when a client receives an ACK in the Initial space (RFC 9002, Section 6.2.1);
#   recovery::Loss now knows its role
#
# Loss::on_ack_received() cleared pto_state for every new ACK in any space and either role, so a client that
#   got only Initial ACKs probed once per round trip instead of backing off, although RFC 9002, Section 6.2.1
#   says a client does not reset the backoff on acknowledgments in Initial packets. The reset is now skipped
#   for a client in the Initial space, in the function that owns the PTO count; Loss learns its role through a
#   new first argument of Loss::new(), the way Streams::new() and NewTokenState::new() take it
#   (Connection::new() is the only non-test caller). Servers and the Handshake/ApplicationData spaces behave
#   as before, and the reset in Loss::discard(), whose comment says it departs from the spec on purpose, is
#   untouched, so the backoff still ends when the client sends its first Handshake packet. The recovery test
#   fixture stays Role::Server by default and gains Fixture::new(role) for a new unit test,
#   pto_backoff_kept_on_client_initial_ack, which fails without the fix. With the patch, `cargo test --locked
#   --offline --workspace --exclude mtu` passes and `cargo +nightly fmt --check` and `cargo clippy --locked
#   --all-targets -- -D warnings` are clean. Left alone to keep the diff minimal: the comments of
#   connection/tests/recovery.rs::handshake_pto_not_primed_without_keys still say a server Initial ACK clears
#   pto_state at the client, which is no longer true (the test passes unchanged).
# reviewer: good — Fixes the reset where it lives, client and Initial space only, with a unit test that fails
#   without it; full test suite, nightly fmt and clippy -D warnings pass. Before merging, update the comments
#   in connection/tests/recovery.rs::handshake_pto_not_primed_without_keys, which still say a server Initial
#   acknowledgment clears the count at the client.
# our check: FIXED · confidence high
#
diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs
index c7261652..27008a6d 100644
--- a/neqo-transport/src/connection/mod.rs
+++ b/neqo-transport/src/connection/mod.rs
@@ -465,7 +465,7 @@ impl Connection {
             streams: Streams::new(tphandler, role, events.clone()),
             cids: ConnectionIdStore::default(),
             state_signaling: StateSignaling::Idle,
-            loss_recovery: recovery::Loss::new(stats.clone(), conn_params.get_fast_pto()),
+            loss_recovery: recovery::Loss::new(role, stats.clone(), conn_params.get_fast_pto()),
             events,
             new_token: NewTokenState::new(role),
             stats,
diff --git a/neqo-transport/src/recovery/mod.rs b/neqo-transport/src/recovery/mod.rs
index 2774d970..0fa4d756 100644
--- a/neqo-transport/src/recovery/mod.rs
+++ b/neqo-transport/src/recovery/mod.rs
@@ -18,7 +18,7 @@ use std::{
 
 use enum_map::EnumMap;
 use enumset::enum_set;
-use neqo_common::qlog::Qlog;
+use neqo_common::{Role, qlog::Qlog};
 use strum::IntoEnumIterator as _;
 pub use token::{StreamRecoveryToken, Token, Tokens};
 use tracing::{debug, info, trace, warn};
@@ -503,6 +503,7 @@ impl PtoState {
 }
 
 pub struct Loss {
+    role: Role,
     /// When the handshake was confirmed, if it has been.
     confirmed_time: Option<Instant>,
     pto_state: Option<PtoState>,
@@ -518,8 +519,9 @@ pub struct Loss {
 
 impl Loss {
     #[must_use]
-    pub fn new(stats: StatsCell, fast_pto: u8) -> Self {
+    pub fn new(role: Role, stats: StatsCell, fast_pto: u8) -> Self {
         Self {
+            role,
             confirmed_time: None,
             pto_state: None,
             spaces: LossRecoverySpaces::default(),
@@ -731,10 +733,15 @@ impl Loss {
             &mut self.stats.borrow_mut(),
         );
 
-        if self.pto_state.is_some() {
-            qlog::loss_timer_cancelled(&mut self.qlog, now);
+        // A client does not reset the PTO backoff on receiving acknowledgments in
+        // Initial packets, as the server might not have validated its address yet
+        // and needs protecting from repeated probes (RFC 9002, Section 6.2.1).
+        if self.role == Role::Server || pn_space != PacketNumberSpace::Initial {
+            if self.pto_state.is_some() {
+                qlog::loss_timer_cancelled(&mut self.qlog, now);
+            }
+            self.pto_state = None;
         }
-        self.pto_state = None;
 
         (acked_packets, lost)
     }
@@ -1101,7 +1108,7 @@ mod tests {
         time::{Duration, Instant},
     };
 
-    use neqo_common::{qlog::Qlog, to_u64};
+    use neqo_common::{Role, qlog::Qlog, to_u64};
     use test_fixture::{DEFAULT_ADDR, now};
 
     use super::{
@@ -1175,10 +1182,8 @@ mod tests {
         pub fn send_profile(&mut self, now: Instant) -> SendProfile {
             self.lr.send_profile(&self.path.borrow(), now)
         }
-    }
 
-    impl Default for Fixture {
-        fn default() -> Self {
+        pub fn new(role: Role) -> Self {
             let stats = StatsCell::default();
             let mut path = Path::temporary(
                 DEFAULT_ADDR,
@@ -1194,12 +1199,18 @@ mod tests {
             path.set_primary(true, now());
             path.rtt_mut().set_initial(TEST_RTT);
             Self {
-                lr: recovery::Loss::new(stats, FAST_PTO_SCALE),
+                lr: recovery::Loss::new(role, stats, FAST_PTO_SCALE),
                 path: Rc::new(RefCell::new(path)),
             }
         }
     }
 
+    impl Default for Fixture {
+        fn default() -> Self {
+            Self::new(Role::Server)
+        }
+    }
+
     // Most uses of the fixture only care about the loss recovery piece,
     // but the internal functions need the other bits.
     impl Deref for Fixture {
@@ -2196,6 +2207,30 @@ mod tests {
         );
     }
 
+    /// A client keeps the PTO backoff when an ACK arrives in the Initial space, as the
+    /// server might not have validated its address yet (RFC 9002, Section 6.2.1).
+    #[test]
+    fn pto_backoff_kept_on_client_initial_ack() {
+        for (role, pt, pto_count) in [
+            (Role::Client, packet::Type::Initial, 1),
+            (Role::Client, packet::Type::Handshake, 0),
+            (Role::Server, packet::Type::Initial, 0),
+        ] {
+            let mut lr = Fixture::new(role);
+            lr.on_packet_sent(
+                sent::Packet::new(pt, 0, now(), true, recovery::Tokens::new(), ON_SENT_SIZE),
+                now(),
+            );
+            let pto = lr.next_timeout().expect("PTO timer armed");
+            lr.timeout(pto);
+            assert_eq!(lr.pto_count(), 1);
+
+            let space = PacketNumberSpace::from(pt);
+            lr.on_ack_received(space, vec![0..=0], None, Duration::ZERO, pto + TEST_RTT);
+            assert_eq!(lr.pto_count(), pto_count, "{role} {space}");
+        }
+    }
+
     #[test]
     fn note_timeout_type_survives_ack() {
         let (log, contents) = test_fixture::new_neqo_qlog();

When fixing this, please carry this line into the commit message:

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HPBYXZJ1.

Activity

  1. added
    client-side
    on Nov 12, 2026
  2. added
    recovery
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

client-sidep3recovery

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions