Commit d8b4072cad for openssl.org

commit d8b4072cadf3cc50b0e6c301dc20baf6f7957b88
Author: Alexandr Nedvedicky <sashan@openssl.org>
Date:   Mon Nov 2 15:35:14 2026 +0100

    test/radix/quic_tests.c: add corrupted version negotiation check

    Add a test that verifies that the reception of a QUIC protocol version
    negotiation packet does not abort client connection attempt.
    The connection attempt must time out even if the invalid version
    negotiation packet is received.  The invalid packet comes
    with wrong/unexpected destination connection id.

    References: Anthropic's OSS Scanner (finding ANT-2026-6CXTP19B)
    Co-authored-by: Andrew Dinh <andrewd@openssl.org>
    Reviewed-by: Andrew Dinh <andrewd@openssl.org>
    Reviewed-by: Bob Beck <beck@openssl.org>
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Merge-date: Mon Nov 23 13:31:28 2026
    Merged-from: https://github.com/openssl/openssl/pull/33490

diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h
index aa3b335764..2ae0f848e6 100644
--- a/include/internal/quic_channel.h
+++ b/include/internal/quic_channel.h
@@ -556,6 +556,12 @@ uint64_t ossl_quic_channel_get_path_response_count(const QUIC_CHANNEL *ch);
  * of NEW_CONNECTION_ID.
  */
 uint64_t ossl_quic_channel_get_on_new_conn_id_handled(const QUIC_CHANNEL *ch);
+/**
+ * ossl_quic_channel_get_init_dcid() is just for testing purposes
+ * @param ch pointer to channel which initial connection id is to be retrieved
+ * @returns pointer to initial destination connection id used by connect()
+ */
+const QUIC_CONN_ID *ossl_quic_channel_get_init_dcid(const QUIC_CHANNEL *ch);
 #endif

 #endif
diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c
index b9784fa9f7..bf22a7b995 100644
--- a/ssl/quic/quic_channel.c
+++ b/ssl/quic/quic_channel.c
@@ -4429,3 +4429,8 @@ uint64_t ossl_quic_channel_get_on_new_conn_id_handled(const QUIC_CHANNEL *ch)
 {
     return ch->on_new_conn_id_handled;
 }
+
+const QUIC_CONN_ID *ossl_quic_channel_get_init_dcid(const QUIC_CHANNEL *ch)
+{
+    return &ch->init_dcid;
+}
diff --git a/test/radix/quic_tests.c b/test/radix/quic_tests.c
index baeb111b36..ca8df8e05e 100644
--- a/test/radix/quic_tests.c
+++ b/test/radix/quic_tests.c
@@ -4795,6 +4795,27 @@ DEF_SCRIPT(script_74, "Version negotiation: QUIC_VERSION_1 ignored")
 #define BIO_TYPE_SCRIPT_75_FILTER (0x80 | BIO_TYPE_FILTER)
 static BIO_METHOD *script_75_filter_meth;
 static uint32_t script_75_word0;
+static const QUIC_CONN_ID *init_dcid;
+
+DEF_FUNC(get_init_dcid)
+{
+    int ok = 0;
+    SSL *client;
+    QUIC_CHANNEL *ch;
+
+    REQUIRE_SSL(client);
+    ch = ossl_quic_conn_get_channel(client);
+    if (!TEST_ptr(ch))
+        goto err;
+
+    init_dcid = ossl_quic_channel_get_init_dcid(ch);
+    if (!TEST_ptr(init_dcid))
+        goto err;
+
+    ok = 1;
+err:
+    return ok;
+}

 static int script_75_sendmmsg(BIO *b, BIO_MSG *msg, size_t stride,
     size_t num_msg, uint64_t flags, size_t *msgs_processed)
@@ -4813,8 +4834,8 @@ static int script_75_sendmmsg(BIO *b, BIO_MSG *msg, size_t stride,
         hdr.version = 0;
         hdr.fixed = 1;
         hdr.dst_conn_id.id_len = 0;
-        hdr.src_conn_id.id_len = 8;
-        memset(hdr.src_conn_id.id, 0x55, 8);
+        hdr.src_conn_id.id_len = init_dcid->id_len;
+        memcpy(hdr.src_conn_id.id, init_dcid->id, init_dcid->id_len);

         if (!TEST_true(WPACKET_init_static_len(&wpkt, msg[0].data,
                 msg[0].data_len, 0)))
@@ -4898,6 +4919,8 @@ DEF_SCRIPT(script_75, "Version negotiation: Unknown version causes connection ab
     OP_FUNC(script_75_arm_version_neg);

     OP_NEW_SSL_C(C);
+    OP_SELECT_SSL(0, C);
+    OP_FUNC(get_init_dcid);
     OP_SET_PEER_ADDR_FROM(C, L);
     OP_CONNECT_WAIT_OR_FAIL(C);

@@ -6293,6 +6316,40 @@ DEF_SCRIPT(new_connid_retrans, "verify remote peer ignores retransmitted NEW_CON
     OP_WRITE_B(S, "banana");
 }

+DEF_FUNC(corrupt_dcid)
+{
+    static QUIC_CONN_ID corrupt_dcid;
+
+    memcpy(&corrupt_dcid, init_dcid, sizeof(QUIC_CONN_ID));
+    corrupt_dcid.id[0] = corrupt_dcid.id[0] ^ 0x55;
+    init_dcid = &corrupt_dcid;
+
+    return 1;
+}
+
+DEF_SCRIPT(ver_neg_check_dcid, "version negotiation must come with matching dcid")
+{
+    OP_NEW_SSL_L_LISTEN(L);
+
+    OP_SELECT_SSL(0, L);
+    OP_FUNC(script_75_arm_version_neg);
+
+    OP_NEW_SSL_C(C);
+    OP_SELECT_SSL(0, C);
+    OP_FUNC(get_init_dcid);
+    OP_FUNC(corrupt_dcid);
+    OP_SET_PEER_ADDR_FROM(C, L);
+    OP_CONNECT_WAIT(C);
+    OP_SET_DEFAULT_STREAM_MODE(C, SSL_DEFAULT_STREAM_MODE_NONE);
+
+    OP_ACCEPT_CONN_WAIT_ND(L, S, 0);
+
+    OP_NEW_STREAM(C, Ca, 0);
+    OP_WRITE(Ca, "apple", 5);
+    OP_ACCEPT_STREAM_WAIT(S, Sa, 0);
+    OP_READ_EXPECT(Sa, "apple", 5);
+}
+
 /*
  * List of Test Scripts
  * ============================================================================
@@ -6422,4 +6479,5 @@ static SCRIPT_INFO *const scripts[] = {
     USE(new_connid_retrans),
     USE(forbidden_frame_types),
     USE(key_update_retained_keys),
+    USE(ver_neg_check_dcid),
 };