No public description

PiperOrigin-RevId: 1021177488
diff --git a/quiche/common/quiche_feature_flags_list.h b/quiche/common/quiche_feature_flags_list.h
index c082a98..6ae1f1d 100644
--- a/quiche/common/quiche_feature_flags_list.h
+++ b/quiche/common/quiche_feature_flags_list.h
@@ -23,6 +23,7 @@
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_block_until_settings_received_copt, true, true, "If enabled and a BSUS connection is received, blocks server connections until SETTINGS frame is received.")
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_bundle_crypto_retransmits, false, false, "When true, retransmissions of CRYPTO frames will be bundled in a single packet when possible.")
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_clear_packet_on_serialization_failure, false, false, "If true, clear QuicPacketCreator state when serialization failure.")
+QUICHE_FLAG(bool, quiche_reloadable_flag_quic_clear_probing_data_on_reset_path_validation, false, false, "If true, clear probing_data_ in QuicPathValidator::ResetPathValidation() so a PATH_RESPONSE to a cancelled path validation can't validate a different path.")
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_client_check_blockage_before_on_can_write, false, false, "If true, quic clients will only call OnCanWrite() upon write events if the writer is unblocked.")
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_close_on_idle_timeout, false, false, "If true, closes the connection if it has exceeded the idle timeout when deciding whether to open a stream.")
 QUICHE_FLAG(bool, quiche_reloadable_flag_quic_coalesce_ping_with_last_packet, false, false, "When true, QuicConnection coalesces a PING frame of a lower encryption level with the last packet of a flight during the handshake when an earlier packet in that lower space is unacknowledged.")
diff --git a/quiche/quic/core/quic_path_validator.cc b/quiche/quic/core/quic_path_validator.cc
index 75425ef..28ba66b 100644
--- a/quiche/quic/core/quic_path_validator.cc
+++ b/quiche/quic/core/quic_path_validator.cc
@@ -10,6 +10,8 @@
 
 #include "quiche/quic/core/quic_constants.h"
 #include "quiche/quic/core/quic_types.h"
+#include "quiche/quic/platform/api/quic_flag_utils.h"
+#include "quiche/quic/platform/api/quic_flags.h"
 #include "quiche/quic/platform/api/quic_socket_address.h"
 
 namespace quic {
@@ -45,7 +47,9 @@
       clock_(clock),
       retry_timer_(alarm_factory->CreateAlarm(
           arena->New<RetryAlarmDelegate>(this, context), arena)),
-      retry_count_(0u) {}
+      retry_count_(0u),
+      clear_probing_data_on_reset_(GetQuicReloadableFlag(
+          quic_clear_probing_data_on_reset_path_validation)) {}
 
 void QuicPathValidator::OnPathResponse(const QuicPathFrameBuffer& probing_data,
                                        QuicSocketAddress self_address) {
@@ -98,6 +102,11 @@
   result_delegate_ = nullptr;
   retry_timer_->Cancel();
   retry_count_ = 0;
+  if (clear_probing_data_on_reset_) {
+    QUIC_RELOADABLE_FLAG_COUNT(
+        quic_clear_probing_data_on_reset_path_validation);
+    probing_data_.clear();
+  }
   reason_ = PathValidationReason::kReasonUnknown;
 }
 
diff --git a/quiche/quic/core/quic_path_validator.h b/quiche/quic/core/quic_path_validator.h
index b7561b8..b997d46 100644
--- a/quiche/quic/core/quic_path_validator.h
+++ b/quiche/quic/core/quic_path_validator.h
@@ -268,6 +268,10 @@
   QuicArenaScopedPtr<QuicAlarm> retry_timer_;
   size_t retry_count_;
   PathValidationReason reason_ = PathValidationReason::kReasonUnknown;
+  // Latched value of --quic_clear_probing_data_on_reset_path_validation. If
+  // true, |probing_data_| is cleared whenever path validation is reset, so a
+  // PATH_RESPONSE can only validate the path its PATH_CHALLENGE was sent on.
+  bool clear_probing_data_on_reset_;
 };
 
 }  // namespace quic
diff --git a/quiche/quic/core/quic_path_validator_test.cc b/quiche/quic/core/quic_path_validator_test.cc
index d39638c..3be7d07 100644
--- a/quiche/quic/core/quic_path_validator_test.cc
+++ b/quiche/quic/core/quic_path_validator_test.cc
@@ -5,10 +5,12 @@
 #include "quiche/quic/core/quic_path_validator.h"
 
 #include <memory>
+#include <utility>
 
 #include "quiche/quic/core/frames/quic_path_challenge_frame.h"
 #include "quiche/quic/core/quic_constants.h"
 #include "quiche/quic/core/quic_types.h"
+#include "quiche/quic/platform/api/quic_flags.h"
 #include "quiche/quic/platform/api/quic_ip_address.h"
 #include "quiche/quic/platform/api/quic_socket_address.h"
 #include "quiche/quic/platform/api/quic_test.h"
@@ -299,5 +301,109 @@
   EXPECT_FALSE(path_validator_.HasPendingPathValidation());
 }
 
+TEST_F(QuicPathValidatorTest, StalePathResponseIgnoredInSubsequentValidation) {
+  SetQuicReloadableFlag(quic_clear_probing_data_on_reset_path_validation, true);
+  // The flag is latched at construction, so create a new validator.
+  QuicPathValidator path_validator(&alarm_factory_, &arena_, &send_delegate_,
+                                   &random_, &clock_, /*context=*/nullptr);
+  QuicPathFrameBuffer first_challenge_data;
+  EXPECT_CALL(send_delegate_,
+              SendPathChallenge(_, self_address_, peer_address_,
+                                effective_peer_address_, &writer_))
+      .WillOnce(testing::DoAll(testing::SaveArg<0>(&first_challenge_data),
+                               Return(true)));
+  EXPECT_CALL(send_delegate_, GetRetryTimeout(peer_address_, &writer_));
+  path_validator.StartPathValidation(
+      std::unique_ptr<QuicPathValidationContext>(context_),
+      std::unique_ptr<MockQuicPathValidationResultDelegate>(result_delegate_),
+      PathValidationReason::kMultiPort);
+  EXPECT_CALL(*result_delegate_, OnPathValidationFailure(_));
+  path_validator.CancelPathValidation(
+      PathValidationFailure::Reason::kNewerValidation);
+  EXPECT_FALSE(path_validator.HasPendingPathValidation());
+
+  clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(kInitialRttMs));
+  random_.ChangeValue();
+  auto second_result_delegate = std::make_unique<
+      testing::StrictMock<MockQuicPathValidationResultDelegate>>();
+  MockQuicPathValidationResultDelegate* second_result_delegate_ptr =
+      second_result_delegate.get();
+  QuicPathFrameBuffer second_challenge_data;
+  EXPECT_CALL(send_delegate_,
+              SendPathChallenge(_, self_address_, peer_address_,
+                                effective_peer_address_, &writer_))
+      .WillOnce(testing::DoAll(testing::SaveArg<0>(&second_challenge_data),
+                               Return(true)));
+  EXPECT_CALL(send_delegate_, GetRetryTimeout(peer_address_, &writer_));
+  const QuicTime second_start_time = clock_.Now();
+  path_validator.StartPathValidation(
+      std::make_unique<MockQuicPathValidationContext>(
+          self_address_, peer_address_, effective_peer_address_, &writer_),
+      std::move(second_result_delegate),
+      PathValidationReason::kConnectionMigration);
+  EXPECT_NE(first_challenge_data, second_challenge_data);
+
+  // A late PATH_RESPONSE matching the canceled validation must not validate
+  // the new path.
+  path_validator.OnPathResponse(first_challenge_data, self_address_);
+  ASSERT_TRUE(path_validator.HasPendingPathValidation());
+
+  EXPECT_CALL(*second_result_delegate_ptr,
+              OnPathValidationSuccess(_, second_start_time));
+  path_validator.OnPathResponse(second_challenge_data, self_address_);
+  EXPECT_FALSE(path_validator.HasPendingPathValidation());
+}
+
+TEST_F(QuicPathValidatorTest, StalePathResponseAcceptedWhenFlagFalse) {
+  SetQuicReloadableFlag(quic_clear_probing_data_on_reset_path_validation,
+                        false);
+  // The flag is latched at construction, so create a new validator.
+  QuicPathValidator path_validator(&alarm_factory_, &arena_, &send_delegate_,
+                                   &random_, &clock_, /*context=*/nullptr);
+  QuicPathFrameBuffer first_challenge_data;
+  EXPECT_CALL(send_delegate_,
+              SendPathChallenge(_, self_address_, peer_address_,
+                                effective_peer_address_, &writer_))
+      .WillOnce(testing::DoAll(testing::SaveArg<0>(&first_challenge_data),
+                               Return(true)));
+  EXPECT_CALL(send_delegate_, GetRetryTimeout(peer_address_, &writer_));
+  const QuicTime first_start_time = clock_.Now();
+  path_validator.StartPathValidation(
+      std::unique_ptr<QuicPathValidationContext>(context_),
+      std::unique_ptr<MockQuicPathValidationResultDelegate>(result_delegate_),
+      PathValidationReason::kMultiPort);
+  EXPECT_CALL(*result_delegate_, OnPathValidationFailure(_));
+  path_validator.CancelPathValidation(
+      PathValidationFailure::Reason::kNewerValidation);
+  EXPECT_FALSE(path_validator.HasPendingPathValidation());
+
+  clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(kInitialRttMs));
+  random_.ChangeValue();
+  auto second_result_delegate = std::make_unique<
+      testing::StrictMock<MockQuicPathValidationResultDelegate>>();
+  MockQuicPathValidationResultDelegate* second_result_delegate_ptr =
+      second_result_delegate.get();
+  QuicPathFrameBuffer second_challenge_data;
+  EXPECT_CALL(send_delegate_,
+              SendPathChallenge(_, self_address_, peer_address_,
+                                effective_peer_address_, &writer_))
+      .WillOnce(testing::DoAll(testing::SaveArg<0>(&second_challenge_data),
+                               Return(true)));
+  EXPECT_CALL(send_delegate_, GetRetryTimeout(peer_address_, &writer_));
+  path_validator.StartPathValidation(
+      std::make_unique<MockQuicPathValidationContext>(
+          self_address_, peer_address_, effective_peer_address_, &writer_),
+      std::move(second_result_delegate),
+      PathValidationReason::kConnectionMigration);
+  EXPECT_NE(first_challenge_data, second_challenge_data);
+
+  // When the flag is false, probing_data_ is retained across
+  // ResetPathValidation(), so the earlier PATH_RESPONSE validates the new path.
+  EXPECT_CALL(*second_result_delegate_ptr,
+              OnPathValidationSuccess(_, first_start_time));
+  path_validator.OnPathResponse(first_challenge_data, self_address_);
+  EXPECT_FALSE(path_validator.HasPendingPathValidation());
+}
+
 }  // namespace test
 }  // namespace quic