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 CDADDC79FA3 for ; Mon, 7 Sep 2026 07:23:25 +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:To:Date:Sender: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=JSyV6vRzVi4baxm7F4ZVuFmP28S4hVP6vO53QWiBL3k=; b=cmVlDwas1pF0Hf O726KFTBYyg3E6mEr3B/jbpX/zSoK4PVmy35+R/lGKGvYpuHjfSePfOlLSudYildBeuo6YPsC24kj rtBV7o7/J4HJSESSZ+T08nh5LivLqoAZ0O9YU306tHrwhbjSNT9f6bMmfqyX35r8IoWOWUuZCyr7I qww=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1x3ThJ-0001BA-KJ; Mon, 07 Sep 2026 07:23:19 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1x3ThH-0001B1-LG for openvpn-devel@lists.sourceforge.net; Mon, 07 Sep 2026 07:23:17 +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: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:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bQ+RJ+2zeL5P45IF329nNkrnClZELx1UbIaKDfnyklU=; b=j/A5k8vlBjZ4A/MseZIU8IWiUA TykuoMQOsvV4X/bqebnTwyeVk49C7pgYUU6JLxWWu/p1Y+Mbkqisw6gNcc+wm1lh4txAQjspbzNug 0lik4KJWd+sGazyqpKmsp8WueayLDzZCOFwfcNb4Kb3I39wBaxCbw2mTKczkQ3s/QU4M=; 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: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:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=bQ+RJ+2zeL5P45IF329nNkrnClZELx1UbIaKDfnyklU=; b=L lfULm6qaBFDQ77S/kHqliKZS2NAT085Jz9NgpxNnDJQKdzuS2U/4/06qqsNilhNkSB5DU+f+Uwo0x ArobarektLvMasNGRQ6K6pfowOaJruFAFsHbSwKF2dNwemnwkt/e8oF6gFXwRFI59/8X54HLZWgmQ oBF1oUqjJid27FfI=; Received: from mail-wm1-f42.google.com ([209.85.128.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1x3ThC-0007NM-7P for openvpn-devel@lists.sourceforge.net; Mon, 07 Sep 2026 07:23:17 +0000 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-49d05d51553so12073585e9.2 for ; Mon, 07 Sep 2026 00:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1788765788; x=1789370588; darn=lists.sourceforge.net; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references:list-unsubscribe:list-id:auto-submitted:cc :to:date:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bQ+RJ+2zeL5P45IF329nNkrnClZELx1UbIaKDfnyklU=; b=Xd+kK/VJQqsc9o2aEpKHKq9Pe4sMQlXc1GhB0YBXgaBSPnHk3MGj79pxLlL5zRUtEV 5/NGjqreFgjXXwKi3KrIdoQwj2F8JtBaCm5vTPzjbuEtERe5NTBYDYNvblXvUVR7nT7C G/gi5zkYgKeia/sI7Oi8JTlj2wumv26JuNCpxNRe2NV/2aUhLVDsj/5z5zehTFhhrINy R+QTjphOwu3fVWCxMEBSq7MtVUDpOTq2Qa3v4uahvU/3bg0YK3x8q/v+1uSJg5hKEnbJ p4SXmA3w+rJ+3d6Yl2HencnxMudU3PO/mFzD+D3Gm//JY0ZBoOn48zyUcz3jOyM9dfl0 Z1PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788765788; x=1789370588; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references: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=bQ+RJ+2zeL5P45IF329nNkrnClZELx1UbIaKDfnyklU=; b=DR+FfBFywojDURACdTruIaQiubtF2o5MHGupuCsUn65CiAvxby1hx3kBVIvtP1msQo POYeWaQGtQkiA/Vi3No/xx4KSzqo28SKjAzongsV8pW5oJP1l842Dm4KdRnRE/qx7wdo uEDbn4qLS5kV7ugAns07wlcYycPMNIUlCfAhDRGdAc0okWVUmwzHJAY4iNt9S7PzbwYj qYqYQdnsPx3Y+ZoB0JxI3kcm2wkCJUbZ8aslyzAZZlyKcKgPw8rRyA/yZHlRTfvfedcc 16khhytMqEufGOcvhSs+JJyZ/o42xEv+50w/mPk2KsdNlDPy2yXMxv/04nrIvkNbZbXj 2tmQ== X-Gm-Message-State: AFuF++mK2wvlLoo793CocYIHZlyPwTKtvrO1PIQAcPY7pcy0ySQIAaA3 31Rhkhh5/Zd0kkKdFt1FJoF89QrWHquoBZKkX6MhUZ4IyVtp65NZB/edrO2+QirdabZRWfl1szQ +OOTyEUgMsqZke8QEOgitBsfrMfUuRLmrE1BRftLat8uHiEeMoRH3BimQKGKBlSPqTqxx/c9d4u YNvGnt3w== X-Gm-Gg: AYBFou1FN2fh2eWxdsnKbT5Zv1QPLiGrA0LuKPA8TAp1RIiWIfdNpqUiLpBT0HMlp7C nKDdVuvvR2vnMc3clEMX9ycVIWaojib+oCgWPVpT8XeZH7mPEDEa3LEB09jhhcgBcx2rmFDbS21 IEHTSOVGHc+tPoIfkyAASn0xtSxdOVRamuOXk3pJMqhHfv7B2c0DAXWBxmLwdGXsigf1Bz3nJ7Q IKY2fX/opogk4s2c4b5eXtDvdtN3Hj1z++FhhEBlI2l9RWYeqvrcgXOtv5jZVaPp7DgoKgOb800 vv7m9uf7dAEqyy2NFlQg855gu1e6XxO9bbCy1Tta8GUBt4z0EvO1BujycErioIyiyXNJID2Fswl Uaolhlwh8AIm73W3NxdzN3VuvajaneQINMRm2lxsKr6QUWjmnSynAQdM3v18K09WKqoE5MQ9iqR 2NGh62Oh+sF/Q4I31mhKHmkwWg4cYM6jwWUo49Bhc3V/GbCRaFfw+1NO+CLZ+I5Rix15JhXY29I bWh2rn8C2QbF0nQ22NlprfEUA5p+Dh57XBkskHK+k3H/Uw/gZKFGi3BCw48tULXeCXxvvGmpxjJ 60Sa70WQT9FpIfmWuPm125dt+lLta8qsHWYGUppNpDJG053A1pk= X-Received: by 2002:a05:600c:a05:b0:49c:fc6e:a3dc with SMTP id 5b1f17b1804b1-49cfc6ea772mr176401815e9.27.1788765787171; Mon, 07 Sep 2026 00:23:07 -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-49d00a5b19dsm218327785e9.2.2026.09.07.00.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2026 00:23:06 -0700 (PDT) X-Google-Original-From: "razvanc (Code Review)" Date: Mon, 7 Sep 2026 07:23:06 +0000 To: plaisthos Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-PatchSet: 1 X-Gerrit-Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03 X-Gerrit-Change-Number: 1899 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 93495f90cf625486a2d071ee04a7c7eeefca1870 References: Thread-Index: PGdlcnJpdC4xNzg4NzY1NzgxMDAwLklhZjY4YWJmMGQyNTc1ZWU0Y2QzMGRjNGYzZWY2MjdmNmIyMmVjYjAzQGdlcnJpdC5vcGVudnBuLm5ldD4= Message-ID: <0b0d2331375eee59fa01a02cc9828e0b375961ad-HTML@gerrit.openvpn.net> MIME-Version: 1.0 User-Agent: Gerrit/3.11.5 X-Headers-End: 1x3ThC-0007NM-7P 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: "razvanc \(Code Review\) via Openvpn-devel" Reply-To: razvanc@mailbox.org, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net Cc: "razvanc \(Code Review\)" , openvpn-devel Content-Type: multipart/mixed; boundary="===============7283245295048083595==" Errors-To: openvpn-devel-bounces@lists.sourceforge.net --===============7283245295048083595== Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="p9cwW3uDm9w="; charset=UTF-8 --p9cwW3uDm9w= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos=2E Hello plaisthos, I'd l= ike you to do a code review=2E Please visit http://gerrit=2Eopenvpn=2E= net/c/openvpn/+/1899?usp=3Demail to review the following change=2E Chang= e subject: reliable: characterize the packet id comparisons before rewritin= g 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 reli= able: characterize the packet id comparisons before rewriting them The com= parisons are about to lose their 2^31 horizon helpers=2E Pin the accepted i= d set at each site first, by sweeping anchors and offsets across the 0/2^32= wrap and the 0x80000000 midpoint against reference implementations of the = current behaviour=2E reliable_not_replay(), reliable_wont_break_sequential= ity(), the three scans for the oldest unacknowledged entry and the ASSERT i= n reliable_mark_active_incoming() had no coverage at all=2E The receive pa= th is characterized as the verdict ssl=2Ec produces (drop / ack-only / stor= e) rather than as two predicates, because a replay is still acknowledged wh= ile a sequentiality break is not=2E Its sweep splits at 2^31: reliable_wont= _break_sequentiality() compares in absolute terms, so above that base its a= ccepted set shifts=2E Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03= Signed-off-by: Razvan Cojocaru --- M tests/unit_te= sts/openvpn/test_packet_id=2Ec 1 file changed, 330 insertions(+), 1 deletio= n(-) git pull ssh://gerrit=2Eopenvpn=2Enet:29418/openvpn refs/changes/= 99/1899/1 diff --git a/tests/unit_tests/openvpn/test_packet_id=2Ec b/tests= /unit_tests/openvpn/test_packet_id=2Ec index dc77553=2E=2E9b62444 100644 --= - a/tests/unit_tests/openvpn/test_packet_id=2Ec +++ b/tests/unit_tests/open= vpn/test_packet_id=2Ec @@ -516,6 +516,329 @@ reliable_free(rel); } = +/* + * Reference implementations of the packet id comparisons as they beha= ve today=2E + * The sweeps below assert reliable=2Ec agrees with them at th= e anchors swept, so + * a change to an accepted id set there fails a test= =2E Keep them standalone: + * expressing them in terms of reliable=2Ec woul= d make the sweeps tautologies=2E + */ + +/* "p1 < p2" with the 2^31 horizon= , i=2Ee=2E ((int32_t)(p1 - p2) < 0) */ +static bool +ref_pid_min(packet_id_= type p1, packet_id_type p2) +{ + return (packet_id_type)(p1 - p2) >=3D 0= x80000000u; +} + +/* one short of RELIABLE_CAPACITY, which is what the code= accepts today */ +#define CHARACTERIZED_SEND_WINDOW 11 + +/* TLS_RELIABLE_= N_SEND_BUFFERS and P_CONTROL_V1, from ssl_pkt=2Eh, which this + * test bina= ry does not pull in */ +#define CHAR_N_SEND_BUFFERS 6 +#define CHAR_OPCO= DE_CONTROL_V1 4 + +static bool +ref_pid_in_send_window(const struct reliabl= e *rel, packet_id_type pid) +{ + const packet_id_type dist =3D (packet_i= d_type)(rel->packet_id - pid); + + return dist >=3D 1 && dist <=3D CHARA= CTERIZED_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)r= el->size; + + /* char_anchors and char_anchors_high stay clear of the ov= erflow, where + * reliable_pid_in_range2() used a 0x80000000 bias inste= ad */ + assert_true(base + extent >=3D base); + + return id < base + = extent; +} + +static bool +ref_not_replay(const struct reliable *rel, packe= t_id_type id) +{ + if (ref_pid_min(id, rel->packet_id)) + { + = return false; + } + + for (int i =3D 0; i < rel->size; ++i) + { + = if (rel->array[i]=2Eactive && rel->array[i]=2Epacket_id =3D=3D id) += { + return false; + } + } + + return true; = +} + +/* The receive path verdict as ssl=2Ec produces it: stored only if bo= th checks + * pass, a replay still ACKed, a sequentiality break dropped wit= hout an ACK=2E */ +enum 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_sequenti= ality(rel, id)) + { + return RECV_DROP; + } + + return reli= able_not_replay(rel, id) ? RECV_STORE : RECV_ACK_ONLY; +} + +static enum re= cv_verdict +ref_recv_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_seque= ntiality() compares id + * against rel->packet_id + rel->size in absolute t= erms, 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 the split=2E Bases past + * 0xFFFFFFF3 are excluded, rel->packet_id += rel->size overflowing there=2E */ +static const packet_id_type char_anchor= s[] =3D { + 0x00000000, + 0x00000001, + 0x00000005, + 0x0000000= B, + 0x0000000C, + 0x0000000D, + 0x000001F4, + 0x7FFFFFF4, + = 0x7FFFFFFF, + 0x80000000, +}; + +static const packet_id_type char_ancho= rs_high[] =3D { + 0x80000001, + 0x8000000C, + 0xFFFFFFF0, + 0xF= FFFFFF3, +}; + +/* offsets applied below and above each anchor */ +static c= onst packet_id_type char_offsets[] =3D { + 0, + 1, + 2, + 10, += 11, + 12, + 13, + 14, + 100, + 0x3FFFFFFF, + 0x400000= 00, + 0x7FFFFFFE, + 0x7FFFFFFF, + 0x80000000, + 0x80000001, + = 0x80000002, + 0xFFFFFFF4, + 0xFFFFFFFE, + 0xFFFFFFFF, +}; + +sta= tic void +sweep_recv_filter(const packet_id_type *anchors, size_t n_anchors= , + enum recv_verdict (*oracle)(const struct reliable *, p= acket_id_type)) +{ + for (size_t a =3D 0; a < n_anchors; a++) + { + = 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_off= sets[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 an= chors[a]; + + assert_int_equal(oracle(&rel, ids[i]), recv_fi= lter(&rel, ids[i])); + + /* with the id already in a receive= slot it can only be + * acknowledged or dropped, never sto= red again */ + rel=2Earray[3]=2Eactive =3D true; + = rel=2Earray[3]=2Epacket_id =3D ids[i]; + + assert_int_= equal(oracle(&rel, ids[i]), recv_filter(&rel, ids[i])); + as= sert_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 **s= tate) +{ + sweep_recv_filter(char_anchors, SIZE(char_anchors), ref_recv_= filter); +} + +/* bases above 2^31, where they diverge, kept apart so a cha= nge confined + * there touches one test */ +static void +test_recv_filter_h= igh_base(void **state) +{ + sweep_recv_filter(char_anchors_high, SIZE(ch= ar_anchors_high), ref_recv_filter); +} + +static void +sweep_send_window(co= nst packet_id_type *anchors, size_t n_anchors) +{ + for (size_t a =3D 0;= a < n_anchors; a++) + { + for (size_t o =3D 0; o < SIZE(char_off= sets); o++) + { + 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_SE= ND_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); + = } + } + } +} + +/* a pure distance test, so identical at ev= ery 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 midp= oint */ +static void +test_reliable_send_picks_oldest(void **state) +{ + = now =3D 1000; + + struct reliable rel =3D { 0 }; + rel=2Esize =3D CH= AR_N_SEND_BUFFERS; + 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 pac= ket_id_type wrapped[] =3D { 0xFFFFFFFD, 1, 2 }; + + for (size_t i =3D 0;= i < SIZE(wrapped); 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; + } + + i= nt 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_SEND_BUFFERS; + rel= 2=2Einitial_timeout =3D 2; + rel2=2Epacket_id =3D 0x80000002; + + con= st packet_id_type midpoint[] =3D { 0x7FFFFFFF, 0x80000000, 0x80000001 }; + = + for (size_t i =3D 0; i < SIZE(midpoint); i++) + { + rel2=2Ea= rray[i]=2Eactive =3D true; + rel2=2Earray[i]=2Epacket_id =3D midpoin= t[i]; + rel2=2Earray[i]=2Etimeout =3D 2; + rel2=2Earray[i]=2E= next_try =3D 0; + } + + assert_ptr_equal(&rel2=2Earray[0]=2Ebuf, reli= able_send(&rel2, &opcode)); +} + +/* reliable_get_buf_output_sequenced() st= ops issuing ids once rel->packet_id is + * a full window ahead of the oldes= t unacknowledged one */ +static void +test_get_buf_output_sequenced_boundar= y(void **state) +{ + struct reliable *rel =3D test_reliable_new(); + + = rel->array[0]=2Eactive =3D true; + rel->array[0]=2Epacket_id =3D 100; = + + /* distance 7 < size 8: still allowed */ + rel->packet_id =3D 107= ; + assert_non_null(reliable_get_buf_output_sequenced(rel)); + + /* d= istance 8 =3D=3D size 8: refused */ + rel->packet_id =3D 108; + asser= t_null(reliable_get_buf_output_sequenced(rel)); + + /* same boundary acr= oss the wrap */ + rel->array[0]=2Epacket_id =3D 0xFFFFFFFC; + rel->pa= cket_id =3D 3; + assert_non_null(reliable_get_buf_output_sequenced(rel))= ; + + rel->packet_id =3D 4; + assert_null(reliable_get_buf_output_seq= uenced(rel)); + + reliable_free(rel); +} + +/* Ids at or just ahead of r= el->packet_id are accepted, ids below it abort=2E The + * far-ahead case is= left unpinned: callers cannot produce it, and the bound + * may legitimate= ly tighten=2E */ +static void +test_mark_active_incoming_rejects_past_ids(v= oid **state) +{ + struct reliable rel =3D { 0 }; + rel=2Esize =3D REL= IABLE_CAPACITY; + rel=2Epacket_id =3D 10; + + reliable_mark_active_in= coming(&rel, &rel=2Earray[0]=2Ebuf, 10, CHAR_OPCODE_CONTROL_V1); + asser= t_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); + + expe= ct_assert_failure( + reliable_mark_active_incoming(&rel, &rel=2Earra= y[2]=2Ebuf, 5, CHAR_OPCODE_CONTROL_V1)); + expect_assert_failure( + = reliable_mark_active_incoming(&rel, &rel=2Earray[3]=2Ebuf, 0xFFFFFFFF, C= HAR_OPCODE_CONTROL_V1)); +} + + int main(void) { @@ -541,7 +864,13 @@ = cmocka_unit_test(test_packet_id_window), cmocka_unit_test(t= est_reliable_backoff_is_bounded), cmocka_unit_test(test_reliable_p= urge_ignores_forged_acks), - cmocka_unit_test(test_reliable_purge_le= gitimate_ack) + cmocka_unit_test(test_reliable_purge_legitimate_ack)= , + cmocka_unit_test(test_recv_filter_characterization), + cm= ocka_unit_test(test_recv_filter_high_base), + cmocka_unit_test(test_= send_window_characterization), + cmocka_unit_test(test_reliable_send= _picks_oldest), + cmocka_unit_test(test_get_buf_output_sequenced_bou= ndary), + cmocka_unit_test(test_mark_active_incoming_rejects_past_id= s) }; -- To view, visit http://gerrit=2Eopenvpn=2Enet/c/openvpn/= +/1899?usp=3Demail To unsubscribe, or for help writing mail filters, visit = http://gerrit=2Eopenvpn=2Enet/settings?usp=3Demail Gerrit-MessageType: new= change Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iaf6= 8abf0d2575ee4cd30dc4f3ef627f6b22ecb03 Gerrit-Change-Number: 1899 Gerrit-Pat= chSet: 1 Gerrit-Owner: razvanc Gerrit-Reviewer: pla= isthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --p9cwW3uDm9w= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos=2E

razvanc would like plaisthos to = review this change=2E

View Change

=
reliable: characterize the packet id comparisons before rewriting them
<= br>The comparisons are about to lose their 2^31 horizon helpers=2E Pin the<= br>accepted id set at each site first, by sweeping anchors and offsets acro= ss
the 0/2^32 wrap and the 0x80000000 midpoint against reference
impl= ementations of the current behaviour=2E

reliable_not_replay(), relia= ble_wont_break_sequentiality(), the three scans
for the oldest unacknowl= edged entry and the ASSERT in
reliable_mark_active_incoming() had no cov= erage at all=2E

The receive path is characterized as the verdict ssl= =2Ec produces
(drop / ack-only / store) rather than as two predicates, b= ecause a replay is
still acknowledged while a sequentiality break is not= =2E Its sweep splits at
2^31: reliable_wont_break_sequentiality() compar= es in absolute terms, so
above that base its accepted set shifts=2E
<= br>Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03
Signed-off-by: R= azvan Cojocaru <razvanc@mailbox=2Eorg>
---
M tests/unit_tests/o= penvpn/test_packet_id=2Ec
1 file changed, 330 insertions(+), 1 deletion(= -)

git pull ssh://gerrit=2Eopenvpn=2Enet:29418/o=
penvpn refs/changes/99/1899/1
diff --git a/tests/unit_tests/openvpn=
/test_packet_id=2Ec b/tests/unit_tests/openvpn/test_packet_id=2Ecindex dc77553=2E=2E9b62444 100644
--- a/tests/unit_t= ests/openvpn/test_packet_id=2Ec
+++ b/tests/unit_tests/open= vpn/test_packet_id=2Ec
@@ -516,6 +516,329 @@
reliable_free(rel);
}

<= span style=3D"color: hsl(120, 100%, 40%);">+/*
+ * Reference implementations of the packet id co= mparisons as they behave today=2E
+ * The sweeps below assert reliable=2Ec agrees with them at t= he anchors swept, so
= + * a change to an accepted id set there fails a test=2E Keep them standalo= ne:
+ * expressing th= em 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
+ref_= pid_min(packet_id_type p1, packet_id_type p2)
+{
+ return (packet_id_type)(p1 - p2) >=3D 0x80000000u;+}
+
+/* one short of RELIABLE_CAPACITY, which is what the code accepts = today */
+#define CHA= RACTERIZED_SEND_WINDOW 11
+
+/* TLS_RELIAB= LE_N_SEND_BUFFERS and P_CONTROL_V1, from ssl_pkt=2Eh, which this
= + * test binary does not pull i= n */
+#define CHAR_N_= SEND_BUFFERS 6
+#d= efine CHAR_OPCODE_CONTROL_V1 4
+
+static b= ool
+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);
+<= /span>
+ return dist >= =3D 1 && dist <=3D CHARACTERIZED_SEND_WINDOW;
+}
+
+= static bool
+ref_wont= _break_sequentiality(const struct reliable *rel, packet_id_type id)<= br>+{
+ const packet_id_type base =3D rel->pac= ket_id;
+ const pa= cket_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);

+<= br>+ return id < base + e= xtent;
+}
<= span style=3D"color: hsl(120, 100%, 40%);">+
+static bool
+ref_not_replay(const struct reliable *rel, packet_id_type = id)
+{
+ if (ref_pid_min(id, rel->pa= cket_id))
+ {

+ return false;
+ }
+
+ for (int i =3D 0; i < rel->size; ++i)<= br>+ {
+ if (rel->array[i]=2Eactive &am= p;& rel->array[i]=2Epacket_id =3D=3D id)
+ {
+ return false;
+ }
+ }
+=
+ return true;
+}
+
+/* The receive path verdict as ssl=2Ec produces it: stored = only if both checks
+= * pass, a replay still ACKed, a sequentiality break dropped without an ACK= =2E */
+enum recv_ver= dict
+{
+ RECV_DROP,

+ RECV_ACK_ONLY,
+ RECV_STORE
+};
+
+stati= c enum recv_verdict
+= recv_filter(const struct reliable *rel, packet_id_type id)
+{
+ if (!reliable_wont_break_sequentiality(rel, id))
+ {
+ return RECV_DROP;
+ }
+
+ return reliable_not_replay(rel, id) ? RECV_STORE : RECV_= ACK_ONLY;
+}+
+static enum recv_verdict
+ref_recv_filter(const struct reliable *re= l, packet_id_type id)
+{
+ if (!ref_won= t_break_sequentiality(rel, id))
+ {
+ = return RECV_DROP;
+ }
++ return ref_not_replay(rel= , id) ? RECV_STORE : RECV_ACK_ONLY;
+}
+
+/* Anchors for rel-&g= t;packet_id=2E reliable_wont_break_sequentiality() compares id
+ * against rel->packet_id + r= el->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 the spli= t=2E Bases past
+ * 0= xFFFFFFF3 are excluded, rel->packet_id + rel->size overflowing there= =2E */
+static const = packet_id_type char_anchors[] =3D {
+ 0x00000000,
+ 0x00000001,
+ 0x00000005,
+ 0x0000000B,
+= 0x0000000C,
+ = 0x0000000D,
+ 0x00= 0001F4,
+ 0x7FFFFF= F4,
+ 0x7FFFFFFF,<= /span>
+ 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,
<= span style=3D"color: hsl(120, 100%, 40%);">+ 1,
+ 2,
+ 10,
+ 11,
+ 12= ,
+ 13,
= + 14,
+ 100,
+ 0x3FFFFFFF,
+ 0x40000000,
+ 0x7FFFFFFE,
+ 0x7FFFFFFF,
+ 0x80000000,
+ = 0x80000002,
+ 0= xFFFFFFF4,
+ 0xFFF= FFFFE,
+ 0xFFFFFFF= F,
+};
+
+static void
+sweep_recv_filter(const packet_id_type *anchors, size_t n_anc= hors,
+ = enum recv_verdict (*oracle)(const struct reliable *, packet_id_type))
+{
+ for (size_t a =3D 0; a < n_ancho= rs; a++)
+ {
+ 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)(anchor= s[a] + char_offsets[o]),
+ };
+=
+ for (si= ze_t i =3D 0; i < SIZE(ids); i++)
+ {
+ struct reliable rel =3D { 0 };
+ rel=2Esize =3D RELIAB= LE_CAPACITY;
+ = rel=2Epacket_id =3D anchors[a];
+
+ assert_int_equal(oracle(&rel, ids[i]), recv_filter(&a= mp;rel, ids[i]));
+
+ /* wi= th the id already in a receive slot it can only be
+ * acknowledged or dropped, = never stored again */
+ rel=2Earray[3]=2Eactive =3D true;
+ rel=2Earray[3]=2Epacket_i= d =3D ids[i];
+
+ assert_in= t_equal(oracle(&rel, ids[i]), recv_filter(&rel, ids[i]));+ assert_int_no= t_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 diverg= e, 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_ancho= rs_high), ref_recv_filter);
+}
++static void
+sweep_send_window(const packet_id_typ= e *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++)+ {
+ 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_SEN= D_BUFFERS;
+ = rel=2Epacket_id =3D anchors[a];
+
+= assert_int_equal(ref_pid_in_send_window(&rel, ids[i]),<= /span>
+ = validate_packet_id_window(&rel, ids[i]) !=3D 0);+ }
+ }

+ }
+}
+
+/* a pure distance te= st, 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
<= span style=3D"color: hsl(120, 100%, 40%);">+ * signed midpoint */
+static void
+test_reliable_send_picks_oldest(void = **state)
+{+ now =3D 1000;
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ struct reliable rel =3D { 0 };
+ rel=2Esize =3D CHAR_N_SEND_BUFF= ERS;
+ rel=2Einiti= al_timeout =3D 2;
+ = rel=2Epacket_id =3D 3;
+
+ /* 6, 2 an= d 1 below rel->packet_id; the first sits exactly on the window+ * edge, where rel->si= ze 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]=2Eactive = =3D true;
+ re= l=2Earray[i]=2Epacket_id =3D wrapped[i];
+ rel=2Earray[i]=2Etimeout =3D 2;
+ rel=2Earray[i]=2Enext_try = =3D 0;
+ }<= br>+
+ int opcode =3D 0;
+ assert_ptr_equal(&rel=2Earray[0]=2Eb= uf, reliable_send(&rel, &opcode));
+
+ /* same across the signed midpoint */
+ struct reliable rel2 =3D { 0 };
+ rel2=2Esize =3D CHAR_N_SEND_B= UFFERS;
+ rel2=2Ei= nitial_timeout =3D 2;
+ rel2=2Epacket_id =3D 0x80000002;
+
+= const packet_id_type midpoint[] =3D { 0x7FFFFFFF, 0x80000000, 0x8000000= 1 };
+
+ for (size_t i =3D 0; i < SI= ZE(midpoint); i++)
+ = {
+ rel2=2E= array[i]=2Eactive =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(&a= mp;rel2=2Earray[0]=2Ebuf, reliable_send(&rel2, &opcode));+}
+
+/* reliable_get_buf_output_sequenced() stops issuing ids once rel-= >packet_id is
+ * = a full window ahead of the oldest unacknowledged one */
+static void
+test_get_buf_output_sequenced_boundary(void **s= tate)
+{
+ struct reliable *rel =3D tes= t_reliable_new();
+
+ rel->array[0]= =2Eactive =3D true;
+= rel->array[0]=2Epacket_id =3D 100;
+
+ rel->packet_id =3D 107;
+ assert_non_null(reliable_get_= buf_output_sequenced(rel));

+
+ /* dist= ance 8 =3D=3D size 8: refused */
+ rel->packet_id =3D 108;
+ assert_null(reliable_get_buf_output_sequenced(r= el));
+
+ /* same boundary across the w= rap */
+ rel->a= rray[0]=2Epacket_id =3D 0xFFFFFFFC;
+ rel->packet_id =3D 3;
+ assert_non_null(reliable_get_buf_output_sequen= ced(rel));
++ rel->packet_id =3D 4;=
+ assert_null(rel= iable_get_buf_output_sequenced(rel));
+
+ = reliable_free(rel);
+
+/* Ids at or just ahead of rel->= ;packet_id are accepted, ids below it abort=2E The
+ * far-ahead case is left unpinned: callers = cannot produce it, and the bound
+ * may legitimately tighten=2E */
+static void
+test_mark_active_incoming_rejects_past_ids(void **state)=
+{
+ struct reliable rel =3D { 0 };

+ rel=2Esize =3D REL= IABLE_CAPACITY;
+ = rel=2Epacket_id =3D 10;
+
+ reliable_ma= rk_active_incoming(&rel, &rel=2Earray[0]=2Ebuf, 10, CHAR_OPCODE_CON= TROL_V1);
+ assert= _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_OPCOD= E_CONTROL_V1);
+ a= ssert_true(rel=2Earray[1]=2Eactive);
+
+ = expect_assert_failure(
+ reliable_mark_active_incoming(&rel, &rel=2Earray[2]=2E= buf, 5, CHAR_OPCODE_CONTROL_V1));
+ expect_assert_failure(
+ reliable_mark_active_incoming(&rel, &r= el=2Earray[3]=2Ebuf, 0xFFFFFFFF, CHAR_OPCODE_CONTROL_V1));
+}
+
+
int
main(void)
{

@@ -541,7 +864,13 @@
cmocka_unit_test(= test_packet_id_window),
cmocka_unit_test(test_reli= able_backoff_is_bounded),
cmocka_unit_test(test_re= liable_purge_ignores_forged_acks),
- cmocka_unit_test(test_reliable_purge_legitimate_ack)
+ cmocka_unit_t= est(test_reliable_purge_legitimate_ack),
+ cmocka_unit_test(test_recv_filter_characteriza= tion),
+ cmock= a_unit_test(test_recv_filter_high_base),
+ cmocka_unit_test(test_send_window_characteriza= tion),
+ cmock= a_unit_test(test_reliable_send_picks_oldest),
+ cmocka_unit_test(test_get_buf_output_sequ= enced_boundary),
+ = cmocka_unit_test(test_mark_active_incoming_rejects_past_ids)
};

<= br>

To view, visit change 1899=2E To unsubscribe, or for help writi= ng mail filters, visit settings=2E

Gerrit-MessageType: = newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iaf68abf0d2575ee4cd30dc4f3ef627f6b22ecb03 <= /div>
Gerrit-Change-Number: 1899
Gerrit-PatchSet: 1
Gerrit-Owner: razvanc <razvanc@mailbox=2Eorg>
Gerrit-Reviewer: plaisthos <arne-openvpn@rfc2549=2Eorg&g= t;
Gerrit-CC: openvpn-devel <openvpn= -devel@lists=2Esourceforge=2Enet>
Ge= rrit-Attention: plaisthos <arne-openvpn@rfc2549=2Eorg>
--p9cwW3uDm9w=-- --===============7283245295048083595== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============7283245295048083595== 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 --===============7283245295048083595==--