Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72FB8CA6004 for ; Wed, 7 Oct 2026 21:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Type:Cc:Reply-To:From: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:Message-ID:References:In-Reply-To:To:Date:Sender: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=alxwAg+nErT4y7xtLA35UnIlyuW8z7CaweWnGDVvi+s=; b=eGYGvEOKx+Ns4rlsTDCxT0btDv GvA7JFqVw6Z8E9k1w48z97Y4cL2loRP31ITGNqNiHUV1JsDn253fPsluzSoqrZzijTGWKXbzeIPGB n7hWvSnRgqBFX5ocVCH5RVrxNc+pSOQhbaxNO9jtaqEnI93hpy1gqZAWaQK8XTZSlMiU=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1xEZIX-0005gR-BM; Wed, 07 Oct 2026 21:35:38 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1xEZIV-0005gA-L0 for openvpn-devel@lists.sourceforge.net; Wed, 07 Oct 2026 21:35:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:Subject:References:In-Reply-To:List-Unsubscribe:List-Id: Cc:To:Date:From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Help:List-Subscribe :List-Post:List-Owner:List-Archive; bh=9iDQj4qOalRv1WIsenCJk1qQv5GXBVw8uiYhPboT37I=; b=ShQAHN8rNffV3bhZSiJCoPs6Pg yv6exsYdx/0Z7fCfCCl2raCaDiKSbFxkgt4ekGg2B1x712AprSWyoZIWkLtfCIybkYIbxL08iYSQf iY0X5j5CA5SMA41WQJVBnPxVEbSl2OQCYnu+3O77/uq+WjY5dewB/bkxw0Jdbyu/5frE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: Subject:References:In-Reply-To:List-Unsubscribe:List-Id:Cc:To:Date:From: Sender:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=9iDQj4qOalRv1WIsenCJk1qQv5GXBVw8uiYhPboT37I=; b=c 9BW77ixuAA+oIEwjeVREQmwzB5Lnp/V2sXckMDn6MPuA5hKdgs+g5O6f9Fv0ovPs8Gc7LdvD9cWpG 46+G/FiYxkoc6qv0ZFHkTFJuHrwiQ3v6f3TTpNRXJa3wsYIuWY+z0hjjQkAE2lfhIOP12789d8hrq uU9IK+bR7cx4Gh2k=; Received: from mail-wm1-f44.google.com ([209.85.128.44]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1xEZIT-000684-09 for openvpn-devel@lists.sourceforge.net; Wed, 07 Oct 2026 21:35:36 +0000 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a1698ea378so19936635e9.2 for ; Wed, 07 Oct 2026 14:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1791408926; x=1792013726; darn=lists.sourceforge.net; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references:in-reply-to:list-unsubscribe:list-id :auto-submitted:cc:to:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=9iDQj4qOalRv1WIsenCJk1qQv5GXBVw8uiYhPboT37I=; b=Yjwfo0mZIYbEU+PyZfk2IehuPwD9KMqcdJsxTV1p7AlVcmYidohb+YEmuGL14BdV/O DLcABIhsVPgSXAdivqzqhd7DlqMS3ZIc3YsqCr9ymqkRtH9XYUSV71i/ztlb2ZxJAo1f 1XveHGAjWPfi3AoHzLHBE8+QDjRl/Vp369L1qpboiulYivSYlSPV3bCIjQSMI2xVTFqc KcIHFcKtZ9UmMyoNdeon6dxboXz1FPNj1iWgnWLWOeb6gDxxV6cww+G7zrR4RftJ5Vei 6WaVbVZmGoh1tnup9ZLxMfRCtzGPgB0vIOS5jVcjBJrHt5QmVUgltekuXkMabJp1fwVv AsdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791408926; x=1792013726; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references:in-reply-to:list-unsubscribe:list-id :auto-submitted:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=9iDQj4qOalRv1WIsenCJk1qQv5GXBVw8uiYhPboT37I=; b=xulirebw2KKBufWGsn5qUsZ6HGdOhp2A8I6wZp/v/62+08DDIjoONtu7QAqa6xgIpe NgCowIr3zahi51lhch4JoXT5IuHwSoi3e51Oe7d0cvllqpUJEe/pS4xu0a0tvnjrnTHN XwXAOIwZaErxsMXaNTqtRY8djYXb9prWEdez27F5auHK9zvu1MJ1xgJkhomn+aX2ijE8 zOejAqk1RdJZ2uZlgUZJf1wUtQRIlfyDKCfXACgqZ8sxSGAK0sCZykR3vqwm3+f/qJmv If0sZhHoMnRFle5HmumJJnrVtvfhh6IAPAt4d83aFk7ysv3JnJS97DkcAI7C2iHTERUK h9CA== X-Forwarded-Encrypted: i=1; AKwUvBy5KfF0OGp+Nb/4Fe1Nq2cz7lvVaDifxApCHF6Z/01fnYm6GhEZ0dZth9P1uj6nvzua9ZsWSjwpVRWDWImw@lists.sourceforge.net X-Gm-Message-State: AFuF++lJ14AG1I5lEU2xlOGD5vBATXs2dVx2GH/0IpjCSjuJtj5gcwrj iEsVzUuRv8LyI5dvr9sZ+MqYSkz+Ur58OvVKFDXd3P2Mes+4HILdTQN9koU2f66+gnCLL2ge5Dw RqQFqhGr838YLJLEgZqU281KbRzw5mngPa/FR/u51iCQG+e+l5QAOifaU14zLc+bjFyZA X-Gm-Gg: AYBFou3ayHK9pEJGSFKA83mByGCC2tyL8QGj7kQ/866eCF4MxeT3TIFJOR+cLhBcS3e qUmcDMlW1qVHCzCjmOYXGRYfAMpzhpKj2EtiFvbtTLzRRjWVZFv2/ylg6OVDFPV8O8IaBDVbZ0C QgooV3xRHaMgfVkRLk+Le5F4XgTo6Dfg7Za/cfIY+P/E63sVo2llT0L2O4KPtaEjGfWP2Q2biRv e1bvYXzR0X0EMqV9lQRMAW9KCYhZeg0/QWYwaUxRdauXyPaTtjfaD8c8iurJYked4TxhJ6/ZdOO oG1KPC71NePRqn+9I7qpSb4I6YTt+inOYZ7bY7zTV3UkbCJR5/QzFYFWFkLJjtwd/axL+g3ERCi E5aHqzLQcKvbb3FsUKAawJgA0WJAzSQdr1GhzQkYMUdXVpBaC2vGaK7AyLb+Z3+vBbmO6owL+hQ obbzvdQTLF8WqhrEOwIV8wACQwiObOfzOP3d1ctsIPPIgdHH0NGiDDQotVnnkFVZWZIM1tSDmXO q0lO0U+0JJiNCZ5bNamrk9abwxpi1DOZkLUjzBdX4FvyApZuEuV+E0fEktSdvHZnNXYuwDqv9BR Fcgc5Emjcnh5HzpgdQjei+R9pzi6409U6e+FtqFrN+nVGu3k+o7vPJ8G1fxq X-Received: by 2002:a05:600c:4e43:b0:4a0:108:3b54 with SMTP id 5b1f17b1804b1-4a1804557camr53328915e9.32.1791408926231; Wed, 07 Oct 2026 14:35:26 -0700 (PDT) Received: from ip-10-18-1-162.eu-central-1.compute.internal (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a1842a3f55sm20664635e9.2.2026.10.07.14.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2026 14:35:25 -0700 (PDT) X-Google-Original-From: "Gert Doering (Code Review)" Date: Wed, 7 Oct 2026 21:35:25 +0000 To: =?UTF-8?Q?R=C4=83zvan_Cojocaru?= Auto-Submitted: auto-generated X-Gerrit-MessageType: merged X-Gerrit-PatchSet: 4 X-Gerrit-Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03 X-Gerrit-Change-Number: 1899 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 3a78bd3912607e5a62dad0453d5fc8bc37619073 In-Reply-To: References: Thread-Index: PGdlcnJpdC4xNzg4NzY1NzgxMDAwLklhZjY4YWJmMGQyNTc1ZWU0Y2QzMGRjNGYzZWY2MjdmNmIyMmVjYjAzQGdlcnJpdC5vcGVudnBuLm5ldD4= Message-ID: <13f5777b930ab0ad2fe41fbf2156cb45b02060e8-HTML@gerrit.openvpn.net> MIME-Version: 1.0 User-Agent: Gerrit/3.14.2 X-Headers-End: 1xEZIT-000684-09 Subject: [Openvpn-devel] [L] Change in openvpn[master]: reliable: characterize the packet id comparisons before rewriting them X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "Gert Doering \(Code Review\) via Openvpn-devel" Reply-To: gert@greenie.muc.de, arne-openvpn@rfc2549.org, razvanc@mailbox.org, openvpn-devel@lists.sourceforge.net Cc: "Gert Doering \(Code Review\)" , openvpn-devel , Arne Schwabe Content-Type: multipart/mixed; boundary="===============9053758991921046927==" Errors-To: openvpn-devel-bounces@lists.sourceforge.net --===============9053758991921046927== Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="2GPQ8wRuf30="; charset=UTF-8 --2GPQ8wRuf30= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Gert Doering has submitted this change=2E ( https://gerrit=2Eopenvpn=2Enet/= c/openvpn/+/1899?usp=3Demail ) Change subject: reliable: characterize the = packet id comparisons before rewriting them =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E reliable: characterize the packet id compar= isons before rewriting them The comparisons are about to lose their 2^31 h= orizon helpers=2E Pin the accepted id set at each site first, by sweeping a= nchors and offsets across the 0/2^32 wrap and the 0x80000000 midpoint again= st reference implementations of the current behaviour=2E reliable_not_repl= ay(), reliable_wont_break_sequentiality(), the three scans for the oldest u= nacknowledged entry and the ASSERT in reliable_mark_active_incoming() had n= o coverage at all=2E The receive path is characterized as the verdict ssl= =2Ec produces (drop / ack-only / store) rather than as two predicates, beca= use a replay is still acknowledged while a sequentiality break is not=2E It= s sweep splits at 2^31: reliable_wont_break_sequentiality() compares in abs= olute terms, so above that base its accepted set shifts=2E Change-Id: Iaf6= 8abf0d2575ee4cd30dc4f3ef627f6b22ecb03 Signed-off-by: Razvan Cojocaru Acked-by: Arne Schwabe Gerri= t URL: https://gerrit=2Eopenvpn=2Enet/c/openvpn/+/1899 Message-Id: <2026100= 7172007=2E23382-1-gert@greenie=2Emuc=2Ede> URL: https://www=2Email-archive= =2Ecom/openvpn-devel@lists=2Esourceforge=2Enet/msg39760=2Ehtml Signed-off-b= y: Gert Doering --- M tests/unit_tests/openvpn/te= st_packet_id=2Ec 1 file changed, 348 insertions(+), 2 deletions(-) diff= --git a/tests/unit_tests/openvpn/test_packet_id=2Ec b/tests/unit_tests/ope= nvpn/test_packet_id=2Ec index dc77553=2E=2Eaabb555 100644 --- a/tests/unit_= tests/openvpn/test_packet_id=2Ec +++ b/tests/unit_tests/openvpn/test_packet= _id=2Ec @@ -516,6 +516,344 @@ reliable_free(rel); } +/* + * Referen= ce implementations of the packet id comparisons as they behave today=2E + *= The sweeps below assert reliable=2Ec agrees with them at the anchors swept= , so + * a change to an accepted id set there fails a test=2E Keep them sta= ndalone: + * expressing them in terms of reliable=2Ec would make the sweeps= tautologies=2E + */ + +/* "p1 < p2" with the 2^31 horizon, i=2Ee=2E ((int3= 2_t)(p1 - p2) < 0) */ +static bool +ref_pid_min(packet_id_type p1, packet_i= d_type p2) +{ + return (packet_id_type)(p1 - p2) >=3D 0x80000000u; +} + = +/* one short of RELIABLE_CAPACITY, which is what the code accepts today */= +#define CHARACTERIZED_SEND_WINDOW 11 + +/* TLS_RELIABLE_N_SEND_BUFFERS an= d P_CONTROL_V1, from ssl_pkt=2Eh, which this + * test binary does not pull = in */ +#define CHAR_N_SEND_BUFFERS 6 +#define CHAR_OPCODE_CONTROL_V1 4 += +static bool +ref_pid_in_send_window(const struct reliable *rel, packet_id= _type pid) +{ + const packet_id_type dist =3D (packet_id_type)(rel->pack= et_id - pid); + + return dist >=3D 1 && dist <=3D CHARACTERIZED_SEND_WIN= DOW; +} + +static bool +ref_wont_break_sequentiality(const struct reliable = *rel, packet_id_type id) +{ + const packet_id_type base =3D rel->packet_= id; + const packet_id_type extent =3D (packet_id_type)rel->size; + + = /* char_anchors and char_anchors_high stay clear of the overflow, where + = * reliable_pid_in_range2() used a 0x80000000 bias instead */ + assert= _true(base + extent >=3D base); + + return id < base + extent; +} + +sta= tic bool +ref_not_replay(const struct reliable *rel, packet_id_type id) +{ = + if (ref_pid_min(id, rel->packet_id)) + { + return false; + = } + + for (int i =3D 0; i < rel->size; ++i) + { + if (rel->a= rray[i]=2Eactive && rel->array[i]=2Epacket_id =3D=3D id) + { + = return false; + } + } + + return true; +} + +/* The rece= ive path verdict as ssl=2Ec produces it: stored only if both checks + * pas= s, a replay still ACKed, a sequentiality break dropped without an ACK=2E */= +enum recv_verdict +{ + RECV_DROP, + RECV_ACK_ONLY, + RECV_STORE = +}; + +static enum recv_verdict +recv_filter(const struct reliable *rel, pa= cket_id_type id) +{ + if (!reliable_wont_break_sequentiality(rel, id)) += { + return RECV_DROP; + } + + return reliable_not_replay(r= el, id) ? RECV_STORE : RECV_ACK_ONLY; +} + +static enum recv_verdict +ref_r= ecv_filter(const struct reliable *rel, packet_id_type id) +{ + if (!ref_= wont_break_sequentiality(rel, id)) + { + return RECV_DROP; + }= + + return ref_not_replay(rel, id) ? RECV_STORE : RECV_ACK_ONLY; +} + += /* Anchors for rel->packet_id=2E reliable_wont_break_sequentiality() compar= es id + * against rel->packet_id + rel->size in absolute terms, so its acce= pted set + * depends on where rel->packet_id sits: up to 2^31 that leaves t= he composite + * verdict unchanged, above it it does not, hence the split= =2E Bases past + * 0xFFFFFFF3 are excluded, rel->packet_id + rel->size over= flowing there=2E */ +static const packet_id_type char_anchors[] =3D { + = 0x00000000, + 0x00000001, + 0x00000005, + 0x0000000B, + 0x00000= 00C, + 0x0000000D, + 0x000001F4, + 0x7FFFFFF4, + 0x7FFFFFFF, + = 0x80000000, +}; + +static const packet_id_type char_anchors_high[] =3D {= + 0x80000001, + 0x8000000C, + 0xFFFFFFF0, + 0xFFFFFFF3, +}; + = +/* offsets applied below and above each anchor */ +static const packet_id_= type char_offsets[] =3D { + 0, + 1, + 2, + 10, + 11, + 12= , + 13, + 14, + 100, + 0x3FFFFFFF, + 0x40000000, + 0x7FFF= FFFE, + 0x7FFFFFFF, + 0x80000000, + 0x80000001, + 0x80000002, += 0xFFFFFFF4, + 0xFFFFFFFE, + 0xFFFFFFFF, +}; + +static void +sweep= _recv_filter(const packet_id_type *anchors, size_t n_anchors, + = enum recv_verdict (*oracle)(const struct reliable *, packet_id_type))= +{ + for (size_t a =3D 0; a < n_anchors; a++) + { + for (size= _t o =3D 0; o < SIZE(char_offsets); o++) + { + /* probe b= oth below and above the anchor */ + const packet_id_type ids[] = =3D { + (packet_id_type)(anchors[a] - char_offsets[o]), + = (packet_id_type)(anchors[a] + char_offsets[o]), + }= ; + + for (size_t i =3D 0; i < SIZE(ids); i++) + { + = struct reliable rel =3D { 0 }; + rel=2Esize = =3D RELIABLE_CAPACITY; + rel=2Epacket_id =3D anchors[a]; + += assert_int_equal(oracle(&rel, ids[i]), recv_filter(&rel, id= s[i])); + + /* with the id already in a receive slot it can = only be + * acknowledged or dropped, never stored again */ = + rel=2Earray[3]=2Eactive =3D true; + rel=2Ea= rray[3]=2Epacket_id =3D ids[i]; + + assert_int_equal(oracle(= &rel, ids[i]), recv_filter(&rel, ids[i])); + assert_int_not_= equal(RECV_STORE, recv_filter(&rel, ids[i])); + } + } + = } +} + +/* bases at or below 2^31, where old and new agree; never to chan= ge */ +static void +test_recv_filter_characterization(void **state) +{ + = sweep_recv_filter(char_anchors, SIZE(char_anchors), ref_recv_filter); +} += +/* bases above 2^31, where they diverge, kept apart so a change confined = + * there touches one test */ +static void +test_recv_filter_high_base(void= **state) +{ + sweep_recv_filter(char_anchors_high, SIZE(char_anchors_hi= gh), ref_recv_filter); +} + +static void +sweep_send_window(const packet_id= _type *anchors, size_t n_anchors) +{ + for (size_t a =3D 0; a < n_anchor= s; a++) + { + for (size_t o =3D 0; o < SIZE(char_offsets); o++) += { + const packet_id_type ids[] =3D { + (p= acket_id_type)(anchors[a] - char_offsets[o]), + (packet_id_t= ype)(anchors[a] + char_offsets[o]), + }; + + for (siz= e_t i =3D 0; i < SIZE(ids); i++) + { + struct rel= iable rel =3D { 0 }; + rel=2Esize =3D CHAR_N_SEND_BUFFERS; += rel=2Epacket_id =3D anchors[a]; + + assert_i= nt_equal(ref_pid_in_send_window(&rel, ids[i]), + = validate_packet_id_window(&rel, ids[i]) !=3D 0); + } + = } + } +} + +/* a pure distance test, so identical at every base */ += static void +test_send_window_characterization(void **state) +{ + sweep_= send_window(char_anchors, SIZE(char_anchors)); + sweep_send_window(char_= anchors_high, SIZE(char_anchors_high)); +} + +/* reliable_send() picks the = oldest eligible entry, across the wrap and the + * signed midpoint */ +stat= ic void +test_reliable_send_picks_oldest(void **state) +{ + now =3D 1000= ; + + struct reliable rel =3D { 0 }; + rel=2Esize =3D CHAR_N_SEND_BUF= FERS; + rel=2Einitial_timeout =3D 2; + rel=2Epacket_id =3D 3; + + = /* 6, 2 and 1 below rel->packet_id; the first sits exactly on the window + = * edge, where rel->size still admits it */ + const packet_id_type wr= apped[] =3D { 0xFFFFFFFD, 1, 2 }; + + for (size_t i =3D 0; i < SIZE(wrap= ped); i++) + { + rel=2Earray[i]=2Eactive =3D true; + rel= =2Earray[i]=2Epacket_id =3D wrapped[i]; + rel=2Earray[i]=2Etimeout = =3D 2; + rel=2Earray[i]=2Enext_try =3D 0; + } + + int opcode = =3D 0; + assert_ptr_equal(&rel=2Earray[0]=2Ebuf, reliable_send(&rel, &op= code)); + + /* same across the signed midpoint */ + struct reliable r= el2 =3D { 0 }; + rel2=2Esize =3D CHAR_N_SEND_BUFFERS; + rel2=2Einitia= l_timeout =3D 2; + rel2=2Epacket_id =3D 0x80000002; + + const packet_= id_type midpoint[] =3D { 0x7FFFFFFF, 0x80000000, 0x80000001 }; + + for (= size_t i =3D 0; i < SIZE(midpoint); i++) + { + rel2=2Earray[i]=2E= active =3D true; + rel2=2Earray[i]=2Epacket_id =3D midpoint[i]; + = rel2=2Earray[i]=2Etimeout =3D 2; + rel2=2Earray[i]=2Enext_try = =3D 0; + } + + assert_ptr_equal(&rel2=2Earray[0]=2Ebuf, reliable_send= (&rel2, &opcode)); +} + +/* reliable_get_buf_output_sequenced() stops issui= ng ids once rel->packet_id is + * a full window ahead of the oldest unackno= wledged one */ +static void +test_get_buf_output_sequenced_boundary(void **= state) +{ + struct reliable *rel =3D test_reliable_new(); + + rel->ar= ray[0]=2Eactive =3D true; + rel->array[0]=2Epacket_id =3D 100; + + /*= distance 7 < size 8: still allowed */ + rel->packet_id =3D 107; + as= sert_non_null(reliable_get_buf_output_sequenced(rel)); + + /* distance 8= =3D=3D size 8: refused */ + rel->packet_id =3D 108; + assert_null(re= liable_get_buf_output_sequenced(rel)); + + /* same boundary across the w= rap */ + rel->array[0]=2Epacket_id =3D 0xFFFFFFFC; + rel->packet_id = =3D 3; + assert_non_null(reliable_get_buf_output_sequenced(rel)); + + = rel->packet_id =3D 4; + assert_null(reliable_get_buf_output_sequenced(r= el)); + + reliable_free(rel); +} + +/* Ids at or just ahead of rel->pack= et_id are accepted */ +static void +test_mark_active_incoming_accepts_windo= w(void **state) +{ + struct reliable rel =3D { 0 }; + rel=2Esize =3D = RELIABLE_CAPACITY; + rel=2Epacket_id =3D 10; + + reliable_mark_active= _incoming(&rel, &rel=2Earray[0]=2Ebuf, 10, CHAR_OPCODE_CONTROL_V1); + as= sert_true(rel=2Earray[0]=2Eactive); + assert_int_equal(10, rel=2Earray[0= ]=2Epacket_id); + + reliable_mark_active_incoming(&rel, &rel=2Earray[1]= =2Ebuf, 10 + RELIABLE_CAPACITY - 1, + CHAR= _OPCODE_CONTROL_V1); + assert_true(rel=2Earray[1]=2Eactive); +} + +/* Id= s below rel->packet_id abort=2E The far-ahead case is left unpinned: caller= s + * cannot produce it, and the bound may legitimately tighten=2E + * + * = NOTE: expect_assert_failure() does not work with MSVC=2E It catches the ASS= ERT + * by longjmp()ing out of assert_failed(), and MSVC's longjmp() unwind= s the + * intervening frames through RtlUnwindEx() instead of just restorin= g the + * registers, which faults=2E */ +#ifndef _MSC_VER +static void +tes= t_mark_active_incoming_rejects_past_ids(void **state) +{ + struct reliab= le rel =3D { 0 }; + rel=2Esize =3D RELIABLE_CAPACITY; + rel=2Epacket_= id =3D 10; + + expect_assert_failure( + reliable_mark_active_inco= ming(&rel, &rel=2Earray[0]=2Ebuf, 5, CHAR_OPCODE_CONTROL_V1)); + expect_= assert_failure( + reliable_mark_active_incoming(&rel, &rel=2Earray[1= ]=2Ebuf, 0xFFFFFFFF, CHAR_OPCODE_CONTROL_V1)); +} +#endif /* ifndef _MSC_VE= R */ + + int main(void) { @@ -541,8 +879,16 @@ cmocka_unit_test= (test_packet_id_window), cmocka_unit_test(test_reliable_backoff_is= _bounded), cmocka_unit_test(test_reliable_purge_ignores_forged_ack= s), - cmocka_unit_test(test_reliable_purge_legitimate_ack) - + = cmocka_unit_test(test_reliable_purge_legitimate_ack), + cmocka_uni= t_test(test_recv_filter_characterization), + cmocka_unit_test(test_r= ecv_filter_high_base), + cmocka_unit_test(test_send_window_character= ization), + cmocka_unit_test(test_reliable_send_picks_oldest), + = cmocka_unit_test(test_get_buf_output_sequenced_boundary), + cmoc= ka_unit_test(test_mark_active_incoming_accepts_window), +#ifndef _MSC_VER += cmocka_unit_test(test_mark_active_incoming_rejects_past_ids), +#end= if }; return cmocka_run_group_tests_name("packet_id tests", tes= ts, NULL, NULL); -- To view, visit https://gerrit=2Eopenvpn=2Enet/c/openv= pn/+/1899?usp=3Demail To unsubscribe, or for help writing mail filters, vis= it https://gerrit=2Eopenvpn=2Enet/settings?usp=3Demail Gerrit-MessageType:= merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iaf= 68abf0d2575ee4cd30dc4f3ef627f6b22ecb03 Gerrit-Change-Number: 1899 Gerrit-Pa= tchSet: 4 Gerrit-Owner: R=C4=83zvan Cojocaru Gerrit= -Reviewer: Arne Schwabe Gerrit-CC: openvpn-dev= el --2GPQ8wRuf30= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Gert Doering submitted this change=2E

View Change

reliable: characterize the packet =
id comparisons before rewriting them

The comparisons are about to lo= se their 2^31 horizon helpers=2E Pin the
accepted id set at each site fi= rst, by sweeping anchors and offsets across
the 0/2^32 wrap and the 0x80= 000000 midpoint against reference
implementations of the current behavio= ur=2E

reliable_not_replay(), reliable_wont_break_sequentiality(), th= e three scans
for the oldest unacknowledged entry and the ASSERT in
r= eliable_mark_active_incoming() had no coverage at all=2E

The receive= path is characterized as the verdict ssl=2Ec produces
(drop / ack-only = / store) rather than as two predicates, because a replay is
still acknow= ledged while a sequentiality break is not=2E Its sweep splits at
2^31: r= eliable_wont_break_sequentiality() compares in absolute terms, so
above = that base its accepted set shifts=2E

Change-Id: Iaf68abf0d2575ee4cd3= 0dc4f3ef627f6b22ecb03
Signed-off-by: Razvan Cojocaru <razvanc@mailbox= =2Eorg>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549=2Eorg>
= Gerrit URL: https://gerrit=2Eopenvpn=2Enet/c/openvpn/+/1899
Message-Id: = <20261007172007=2E23382-1-gert@greenie=2Emuc=2Ede>
URL: https://ww= w=2Email-archive=2Ecom/openvpn-devel@lists=2Esourceforge=2Enet/msg39760=2Eh= tml
Signed-off-by: Gert Doering <gert@greenie=2Emuc=2Ede>
---M tests/unit_tests/openvpn/test_packet_id=2Ec
1 file changed, 348 inse= rtions(+), 2 deletions(-)

diff --git a/tests/unit_tests/op=
envpn/test_packet_id=2Ec b/tests/unit_tests/openvpn/test_packet_id=2Ec
index dc77553=2E=2Eaabb555 100644
--- a/tests/u= nit_tests/openvpn/test_packet_id=2Ec
+++ b/tests/unit_tests= /openvpn/test_packet_id=2Ec
@@ -516,6 +516,344 @@ reliable_free(rel);
}
=
+/*
+ * Reference implementations of the packe= t id comparisons as they behave today=2E
+ * The sweeps below assert reliable=2Ec agrees with th= em at the anchors swept, so
+ * a change to an accepted id set there fails a test=2E Keep them s= tandalone:
+ * expres= sing them in terms of reliable=2Ec would make the sweeps tautologies=2E
+ */
+
+/* "p1 < p2" with the 2^31 horizon, i=2Ee=2E = ((int32_t)(p1 - p2) < 0) */
+static bool
+{
+ return (packet_id_type)(p1 - p2) >=3D 0x80000000u;
+}
+
+/* one short of RELIABLE_CAPACITY, which is what the code = accepts today */
+#de= fine CHARACTERIZED_SEND_WINDOW 11
+
+/* TL= S_RELIABLE_N_SEND_BUFFERS and P_CONTROL_V1, from ssl_pkt=2Eh, which this
+ * test binary does no= t pull in */
+#define= CHAR_N_SEND_BUFFERS 6
+#define CHAR_OPCODE_CONTROL_V1 4
+
+= static bool
+ref_pid_= in_send_window(const struct reliable *rel, packet_id_type pid)
+{

+ const packet_id_type dist =3D (packet_id_type)= (rel->packet_id - pid);
+
+ return d= ist >=3D 1 && dist <=3D CHARACTERIZED_SEND_WINDOW;
= +}
+
+static bool
+= ref_wont_break_sequentiality(const struct reliable *rel, packet_id_type id)=
+{
+ const packet_id_type base =3D rel= ->packet_id;
+ = const packet_id_type extent =3D (packet_id_type)rel->size;
+

+ /* char_anchors and char_anchors_high stay clear= of the overflow, where
+ * reliable_pid_in_range2() used a 0x80000000 bias instead */
+ assert_true(base + ex= tent >=3D base);
+=
+ return id < = base + extent;
+}
+
+static bool
+ref_not_replay(const struct reliable *rel, packet= _id_type id)
+{
+ if (ref_pid_min(id, r= el->packet_id))
+ = {
+ return = false;
+ }<= br>+
+ for (int i =3D 0; i < rel->size; ++i= )
+ {
+ if (rel->array[i]=2Ea= ctive && rel->array[i]=2Epacket_id =3D=3D id)

+ {
+ return false;
+ }
+ }
+
+ retur= n true;
+}
= +
+/* The receive path verdict as ssl=2Ec produces i= t: stored only if both checks
+ * pass, a replay still ACKed, a sequentiality break dropped with= out an ACK=2E */
+enu= m recv_verdict
+{
+ RECV_DROP,+ RECV_ACK_ONLY,+ RECV_STORE
+};

+
+static enum recv_verdict
+recv_filter(const struct reliable *rel, packet_id_type id)=
+{
+ if (!reliable_wont_break_sequentiality(r= el, id))
+ {
+ return RECV_DROP;=
+ }
+

+ return reliable_not_replay(rel, id) ? RECV_STORE= : RECV_ACK_ONLY;
+}<= /span>
+
+static enum recv_verdict
+ref_recv_filter(const struct relia= ble *rel, packet_id_type id)

+{
+ if (!= ref_wont_break_sequentiality(rel, id))
+ {
+ return RECV_DROP;
+ }
+
+ return ref_not_rep= lay(rel, id) ? RECV_STORE : RECV_ACK_ONLY;
+}
+
+/* Anchors for= rel->packet_id=2E reliable_wont_break_sequentiality() compares id
+ * against rel->packet= _id + rel->size in absolute terms, so its accepted set
+ * depends on where rel->packet_id= sits: up to 2^31 that leaves the composite
+ * verdict unchanged, above it it does not, hence t= he split=2E Bases past
+static = const packet_id_type char_anchors[] =3D {
+ 0x00000000,
+ 0x00000001,
+ 0x00000005,
+ 0x0000000B,
+ 0x0000000C,
+ 0x0000000D,
+ = 0x000001F4,
+ 0x= 7FFFFFF4,
+ 0x7FFF= FFFF,
+ 0x80000000= ,
+};
+

+static const packet_id_type char_anchors_high[] =3D {<= /span>
+ 0x80000001,
+ 0x8000000C,+ 0xFFFFFFF0,
+ 0xFFFFFFF3,

+};
+
+static const packet_id_type char_offsets[= ] =3D {
+ 0,
+ 1,
+ 2,
+ 10,
+ 11,
+= 12,
+ 13,
+ 14,
+ 100,
+ 0x3FFFFFFF,
+ 0x40000000,
+ 0x7FFFFFFE,
+ 0x7FFFFFFF,
+ 0x80000000,
+ 0x80000001,
+ 0x80000002,
+= 0xFFFFFFF4,
+ = 0xFFFFFFFE,
+ 0xFF= FFFFFF,
+};+
+static void
+sweep_recv_filter(const packet_id_type *anchors, size_t = n_anchors,
+ = enum recv_verdict (*oracle)(const struct reliable *, packet_id_typ= e))
+{
+ for (size_t a =3D 0; a < n_= anchors; a++)

+ {<= /span>
+ for (size_t = o =3D 0; o < SIZE(char_offsets); o++)
+ {
+ /* probe both below and above the anchor */+ const packet_id_= type ids[] =3D {
+ = (packet_id_type)(anchors[a] - char_offsets[o]),
+ (packet_id_type)(a= nchors[a] + char_offsets[o]),

+ };
+
+ fo= r (size_t i =3D 0; i < SIZE(ids); i++)
+ {
+ struct reliable rel =3D { 0 };
+ rel=2Esize =3D R= ELIABLE_CAPACITY;

+ = rel=2Epacket_id =3D anchors[a];
+
+ assert_int_equal(oracle(&rel, ids[i]), recv_filt= er(&rel, ids[i]));
+ = /* with the id already in a receive slot it can only be
+ * acknowledged or drop= ped, never stored again */
+ rel=2Earray[3]=2Eactive =3D true;
+ rel=2Earray[3]=2Epacke= t_id =3D ids[i];
+
+ assert= _int_equal(oracle(&rel, ids[i]), recv_filter(&rel, ids[i]));=
+ assert_int= _not_equal(RECV_STORE, recv_filter(&rel, ids[i]));
+ }
+ }
+ }
+}
+
+/* bases at or below 2^31, where= old and new agree; never to change */

+static void
+test_recv_filter_characterization(void **state)
+{
+ sweep_recv_filter(char_anchors, SIZE(char_anchors)= , ref_recv_filter);
+= }
+
+/* bases above 2^31, where they diver= ge, kept apart so a change confined
+ * there touches one test */
+static void
+test_recv_filter_high_base(void **state)
+{
+ sweep_recv_filter(char_anchors_high, SIZE(char_anch= ors_high), ref_recv_filter);
+}
++static void
+sweep_send_window(const packet_id_ty= pe *anchors, size_t n_anchors)
+{
+ for= (size_t a =3D 0; a < n_anchors; a++)
+ {
+ for (size_t o =3D 0; o < SIZE(char_offsets); o++)<= br>+ {
+ const packet_id_type ids[= ] =3D {
+ = (packet_id_type)(anchors[a] - char_offsets[o]),
+ (packet_id_type)(anchors[= a] + char_offsets[o]),
+
+ for (size= _t i =3D 0; i < SIZE(ids); i++)
+ {
+ struct reliable rel =3D { 0 };
+ rel=2Esize =3D CHAR_N_S= END_BUFFERS;
+ = rel=2Epacket_id =3D anchors[a];
+
+ assert_int_equal(ref_pid_in_send_window(&rel, ids[i])= ,
+ = validate_packet_id_window(&rel, ids[i]) !=3D 0);<= br>+ }
+ }

+ }
+}
+
+/* a pure distanc= e test, so identical at every base */
+static void
+test_send_window_characterization(void **state)
+{
+ sweep_send_window(char_anchors, SIZE(char_anchors))= ;
+ sweep_send_win= dow(char_anchors_high, SIZE(char_anchors_high));
+}
+
+/* relia= ble_send() picks the oldest eligible entry, across the wrap and the<= br>+ * signed midpoint */
+static void
+test_reliable_send_picks_oldest(v= oid **state)

+{
+ now =3D 1000;<= br>+
+ struct reliable rel =3D { 0 };
<= span style=3D"color: hsl(120, 100%, 40%);">+ rel=2Esize =3D CHAR_N_SEND_= BUFFERS;

+ rel=2Ei= nitial_timeout =3D 2;
+ rel=2Epacket_id =3D 3;
+
+ /* 6, = 2 and 1 below rel->packet_id; the first sits exactly on the window
+ * edge, where rel-&g= t;size still admits it */
+ const packet_id_type wrapped[] =3D { 0xFFFFFFFD, 1, 2 };+
+ for (size_t i =3D 0; i < SIZE(wrapped); = i++)
+ {+ rel=2Earray[i]=2Eacti= ve =3D true;
+ = rel=2Earray[i]=2Epacket_id =3D wrapped[i];
+ rel=2Earray[i]=2Etimeout =3D 2;
<= span style=3D"color: hsl(120, 100%, 40%);">+ rel=2Earray[i]=2Enext_t= ry =3D 0;

+ }
+
+ int opcode =3D 0;
+ assert_ptr_equal(&rel=2Earray[0= ]=2Ebuf, reliable_send(&rel, &opcode));
+
+ /* same across the signed midpoint */
+ struct reliable rel2 =3D { 0 };+ rel2=2Esize =3D CHAR_N_S= END_BUFFERS;
+ rel= 2=2Einitial_timeout =3D 2;
+ rel2=2Epacket_id =3D 0x80000002;
+
+ const packet_id_type midpoint[] =3D { 0x7FFFFFFF, 0x80000000, 0x80= 000001 };
++ for (size_t i =3D 0; i &l= t; SIZE(midpoint); i++)
+ {
+ re= l2=2Earray[i]=2Eactive =3D true;
+ rel2=2Earray[i]=2Epacket_id =3D midpoint[i];+ rel2=2Earray[i]=2Etim= eout =3D 2;
+ = rel2=2Earray[i]=2Enext_try =3D 0;
+ }
+=
+ assert_ptr_equa= l(&rel2=2Earray[0]=2Ebuf, reliable_send(&rel2, &opcode));
+}
+
+/* reliable_get_buf_output_sequenced() stops issuing ids onc= e rel->packet_id is
+static void
+test_get_buf_output_sequenced_boundary(vo= id **state)
+{=
+ struct reliable *rel = =3D test_reliable_new();
+
+ rel->ar= ray[0]=2Eactive =3D true;
+ rel->array[0]=2Epacket_id =3D 100;
+
+ /* distance 7 < size 8: still allowed */
+ rel->packet_id =3D 107;<= br>+ assert_non_null(reliabl= e_get_buf_output_sequenced(rel));
+
+ /= * distance 8 =3D=3D size 8: refused */
+ rel->packet_id =3D 108;
+ assert_null(reliable_get_buf_output_seque= nced(rel));
+<= br>+ /* same boundary across= the wrap */
+ rel= ->array[0]=2Epacket_id =3D 0xFFFFFFFC;
+ rel->packet_id =3D 3;
+ assert_non_null(reliable_get_buf_output_= sequenced(rel));
+
+ rel->packet_id = =3D 4;
+ assert_nu= ll(reliable_get_buf_output_sequenced(rel));
+
+ reliable_free(rel);
+}
++/* Ids at or just ahead of r= el->packet_id are accepted */
+static void
+test_mark_active_incoming_accepts_window(void **state)
+{

+ struct reliable rel =3D { 0 };
+ rel=2Esize =3D RELIABLE_CAPACITY;<= /span>
+ rel=2Epacket_id = =3D 10;
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ reliable_mark_active_incomi= ng(&rel, &rel=2Earray[0]=2Ebuf, 10, CHAR_OPCODE_CONTROL_V1);
=
+ assert_true(rel=2Earra= y[0]=2Eactive);
+ = assert_int_equal(10, rel=2Earray[0]=2Epacket_id);
+
+ reliable_mark_active_incoming(&rel, &rel=2Earray[1]= =2Ebuf, 10 + RELIABLE_CAPACITY - 1,
+ CHAR_OPCODE_CONTROL_V1);<= /span>
+ assert_true(rel= =2Earray[1]=2Eactive);
+
+/* Ids below rel->packet_id abo= rt=2E The far-ahead case is left unpinned: callers

+ * cannot produce it, and the bound may legi= timately tighten=2E
+= *
+ * NOTE: expect_a= ssert_failure() does not work with MSVC=2E It catches the ASSERT
= + * by longjmp()ing out of asse= rt_failed(), and MSVC's longjmp() unwinds the
+ * intervening frames through RtlUnwindEx() i= nstead of just restoring the
+ * registers, which faults=2E */
+#ifndef _MSC_VER
+static void
+test_mark_active_incoming_rejects_past_ids(void **state)<= br>+{
+ struct reliable rel =3D { 0 };
= + rel=2Esize =3D RELIABLE_CA= PACITY;
+ rel=2Epa= cket_id =3D 10;
+
+ expect_assert_failu= re(
+ reliable= _mark_active_incoming(&rel, &rel=2Earray[0]=2Ebuf, 5, CHAR_OPCODE_C= ONTROL_V1));
+ exp= ect_assert_failure(
+= reliable_mark_active_incoming(&rel, &rel=2Earray[1]=2Ebuf, = 0xFFFFFFFF, CHAR_OPCODE_CONTROL_V1));
+}
+= #endif /* ifndef _MSC_VER */
+
+ int
main(void)
{
= @@ -541,8 +879,16 @@
cmocka_unit_test(test_packet_= id_window),
cmocka_unit_test(test_reliable_backoff= _is_bounded),
cmocka_unit_test(test_reliable_purge= _ignores_forged_acks),
= - cmocka_unit_test(test_reliable_purge_legitimate_ack)
-

+ cmocka_unit_test(test_reliable_purge_legitimat= e_ack),
+ cmoc= ka_unit_test(test_recv_filter_characterization),
+ cmocka_unit_test(test_recv_filter_high= _base),
+ cmoc= ka_unit_test(test_send_window_characterization),
+ cmocka_unit_test(test_reliable_send_pi= cks_oldest),
+ = cmocka_unit_test(test_get_buf_output_sequenced_boundary),
+ cmocka_unit_test(test_mark_a= ctive_incoming_accepts_window),
+#ifndef _MSC_VER
+ cmocka_unit_test(test_mark_active_incoming_rejects_past_id= s),
+#endif };

return cmocka_run_gro= up_tests_name("packet_id tests", tests, NULL, NULL);

To view, visit change 1899=2E To unsubscribe, or for help writing m= ail filters, visit settings=2E

Gerrit-MessageType: = merged
Gerrit-Project: openvpn
<= div style=3D"display:none"> Gerrit-Branch: master
Gerrit-Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03
Gerrit-Change-Number: 1899
Gerrit-PatchSet: 4
= Gerrit-Owner: R=C4=83zvan Cojocaru <razvanc@mailbox=2Eorg>
Gerrit-Reviewer: Arne Schwabe <arne-openvpn@rf= c2549=2Eorg>
Gerrit-CC: openvpn-deve= l <openvpn-devel@lists=2Esourceforge=2Enet>
--2GPQ8wRuf30=-- --===============9053758991921046927== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============9053758991921046927== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel --===============9053758991921046927==--