From nobody Mon May 08 16:13:54 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QFRDf4mGsz4B4sv; Mon, 8 May 2023 16:13:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QFRDf40k1z3Qbm; Mon, 8 May 2023 16:13:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683562434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oBnfjOlyIo/4w8RnJKeF2CjJYVcbAzG9H0O23qkCefQ=; b=iiCsoaY+j1ZroLHuOTsJ80T4fV5dlK6Q3Lm2UxCqlpbNE3iRPVaMgtHByUFW22v2GOk5aX 8bM+of5EQJiiSsle2sTxhoXt7vCLTNnEXxEkQ2Ip568sSc4MEWIudzV2EB+4Urx+sIG5Cy mTiqCuth1+eCcOBLYeSwjxMPhCS/1R9F3GVHstH1lqDcBO0NiPKOvFyArYSc2xHcuLI+Yo J6/12QTtz0ixi8ENCn3k9b80Pre3hSfau6tno3j1145RgPI/wiWAihEUv4zRjIw+zvgVRJ RIoh7QGTSgU6WaKGr67mFIaeXTYRMsE97m3FWBpEcQ2V/pxHr2i5+zXEMgXrwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683562434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oBnfjOlyIo/4w8RnJKeF2CjJYVcbAzG9H0O23qkCefQ=; b=ks0tzxF0wfgevmezZDpgkj24i4W6nrdVwjZr2nXR5cDkNn1QVQpOFLPWxhAnv8Bxetb4sV lgt2PlVXWSG1wvRbulfqDX8mmRrlqrL38/ywrc1775cyQb1xc0tuu65/i/L8xwFFMwi/4N q0it4EaGeWAuIRkULYKG611cyqHoxtJ7wXwOYcccVZfjVetphSR6gv8jmFIkdLViEXaWxD 2llcUdnId6+A7fX+NsLreXHS2HRCD/bYEyltQ+ICgZletQGKLSnlmBPkxmuToOsKhDmRSV pFXDtZVCCp95FiScpWHB6yWG3Hi+v+lbR8k9omWwisRn88+aA8AxCgsrNSsorw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683562434; a=rsa-sha256; cv=none; b=FaOLiEZk3lmQFWuJBZJ8CIYyaUzogzg00dq8567l+Efx4BrPC9/YP0D21FGTuIsQNtfCIX 5wez4azjYFPT4xZxPgKdSQBG/NUeMfA6zxRFPJYWaNP7a488EZsbX33XU9a8lxo5jRJ2E7 ACtR01JYGDWsJ6o6hI54S2ln3MNQ7b0eZ+1ODB3tx5gyl+SwiWd5VL+aVQZsK0leRYOkGl UaO3atRTeIiQUzGdel48gY+UlLGveEoVWYp2azher8FyOKRbdE8ulCyvEEeBWvi6Tlb1fT zzuPddHzMeXfMzzBfACh5o6nARg44jnfcSKNRBTp6j02CKaHZYXDZ1tCXESqPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QFRDf33X3z168X; Mon, 8 May 2023 16:13:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 348GDs3N026070; Mon, 8 May 2023 16:13:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 348GDsYw026069; Mon, 8 May 2023 16:13:54 GMT (envelope-from git) Date: Mon, 8 May 2023 16:13:54 GMT Message-Id: <202305081613.348GDsYw026069@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: f7ee28e75582 - main - if_ovpn: notify userspace when we've used half of the sequence numbers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f7ee28e755820375d5f441e19c1f1376a200e834 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f7ee28e755820375d5f441e19c1f1376a200e834 commit f7ee28e755820375d5f441e19c1f1376a200e834 Author: Kristof Provost AuthorDate: 2023-05-08 14:41:48 +0000 Commit: Kristof Provost CommitDate: 2023-05-08 14:43:25 +0000 if_ovpn: notify userspace when we've used half of the sequence numbers OpenVPN uses the sequence number (as well as a userspace supplied nonce) to build the IV. This means we should avoid re-using sequence numbers. However, userspace doesn't know how many packets we've sent (and thus what sequence number we're up to). Notify userspace when we've used half of the available sequence numbers to tell it that it's time for a key renegotiaton. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D39570 --- sys/net/if_ovpn.c | 33 ++++++++++++++++++++++++++++++--- sys/net/if_ovpn.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index bf07d23f0235..22723bfc34bb 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -93,6 +93,8 @@ struct ovpn_kkey_dir { * strictly higher than this. */ uint32_t rx_seq; + uint32_t tx_seq; + /* Seen packets, relative to rx_seq. bit(0) will always be 0. */ uint64_t rx_window; }; @@ -147,7 +149,6 @@ struct ovpn_kpeer { struct in6_addr vpn6; struct ovpn_kkey keys[2]; - uint32_t tx_seq; enum ovpn_del_reason del_reason; struct ovpn_keepalive keepalive; @@ -215,6 +216,7 @@ static RB_GENERATE(ovpn_kpeers, ovpn_kpeer, tree, ovpn_peer_compare); #define OVPN_OP_DATA_V2 0x09 #define OVPN_OP_SHIFT 3 +#define OVPN_SEQ_ROTATE 0x80000000 VNET_DEFINE_STATIC(struct if_clone *, ovpn_cloner); #define V_ovpn_cloner VNET(ovpn_cloner) @@ -428,6 +430,28 @@ ovpn_notify_del_peer(struct ovpn_softc *sc, struct ovpn_kpeer *peer) } } +static void +ovpn_notify_key_rotation(struct ovpn_softc *sc, struct ovpn_kpeer *peer) +{ + struct ovpn_notification *n; + + n = malloc(sizeof(*n), M_OVPN, M_NOWAIT | M_ZERO); + if (n == NULL) + return; + + n->peerid = peer->peerid; + n->type = OVPN_NOTIF_ROTATE_KEY; + + if (buf_ring_enqueue(sc->notifring, n) != 0) { + free(n, M_OVPN); + } else if (sc->so != NULL) { + /* Wake up userspace */ + sc->so->so_error = EAGAIN; + sorwakeup(sc->so); + sowwakeup(sc->so); + } +} + static void ovpn_peer_release_ref(struct ovpn_kpeer *peer, bool locked) { @@ -523,7 +547,6 @@ ovpn_new_peer(struct ifnet *ifp, const nvlist_t *nvl) peer = malloc(sizeof(*peer), M_OVPN, M_WAITOK | M_ZERO); peer->peerid = peerid; peer->sc = sc; - peer->tx_seq = 1; peer->refcount = 1; peer->last_active = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO); COUNTER_ARRAY_ALLOC(peer->counters, OVPN_PEER_COUNTER_SIZE, M_WAITOK); @@ -738,6 +761,7 @@ ovpn_create_kkey_dir(struct ovpn_kkey_dir **kdirp, kdir->cipher = cipher; kdir->keylen = keylen; + kdir->tx_seq = 1; memcpy(kdir->key, key, keylen); kdir->noncelen = ivlen; memcpy(kdir->nonce, iv, ivlen); @@ -1849,7 +1873,10 @@ ovpn_transmit_to_peer(struct ifnet *ifp, struct mbuf *m, ohdr->opcode |= key->peerid; ohdr->opcode = htonl(ohdr->opcode); - seq = atomic_fetchadd_32(&peer->tx_seq, 1); + seq = atomic_fetchadd_32(&peer->keys[OVPN_KEY_SLOT_PRIMARY].encrypt->tx_seq, 1); + if (seq == OVPN_SEQ_ROTATE) + ovpn_notify_key_rotation(sc, peer); + seq = htonl(seq); ohdr->seq = seq; diff --git a/sys/net/if_ovpn.h b/sys/net/if_ovpn.h index 1c0299940c3e..45fd0696a4ed 100644 --- a/sys/net/if_ovpn.h +++ b/sys/net/if_ovpn.h @@ -36,6 +36,7 @@ enum ovpn_notif_type { OVPN_NOTIF_DEL_PEER, + OVPN_NOTIF_ROTATE_KEY, }; enum ovpn_del_reason {