git: d7ad56decf8f - releng/15.0 - wg(4): Check for crypto operation errors

Mark Johnston <[email protected]> Wed, 29 Jul 2026 17:50:07 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a6a3d4f.3af54.7b9ec193__28768.5795266711$1785347618$gmane$org@gitrepo.freebsd.org>
The branch releng/15.0 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=d7ad56decf8f6302be6ecda9652a039c8e3c8e11

commit d7ad56decf8f6302be6ecda9652a039c8e3c8e11
Author:     John Baldwin <[email protected]>
AuthorDate: 2026-07-27 15:36:55 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-07-28 17:34:59 +0000

    wg(4): Check for crypto operation errors
    
    In particular, handle authentication errors due to bad MACs when
    decrypting packets.
    
    Since the current dispatch code assumes synchronous OCF sessions by
    design, explicitly reject any created OCF session that is not
    synchronous.  Software sessions are always synchronous in practice, so
    this should be a nop.
    
    Approved by:    so
    Security:       FreeBSD-SA-26:52.if_wg
    Security:       CVE-2026-58085
    Reviewed by:    markj
    Sponsored by:   Chelsio Communications
---
 sys/dev/wg/wg_crypto.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/dev/wg/wg_crypto.c b/sys/dev/wg/wg_crypto.c
index 53441ef25b40..82b80c7fd451 100644
--- a/sys/dev/wg/wg_crypto.c
+++ b/sys/dev/wg/wg_crypto.c
@@ -230,6 +230,8 @@ chacha20poly1305_encrypt_mbuf(struct mbuf *m, const uint64_t nonce,
 	crp.crp_cipher_key = key;
 	crp.crp_callback = crypto_callback;
 	ret = crypto_dispatch(&crp);
+	if (ret == 0)
+		ret = crp.crp_etype;
 	crypto_destroyreq(&crp);
 	return (ret);
 }
@@ -253,6 +255,8 @@ chacha20poly1305_decrypt_mbuf(struct mbuf *m, const uint64_t nonce,
 	crp.crp_cipher_key = key;
 	crp.crp_callback = crypto_callback;
 	ret = crypto_dispatch(&crp);
+	if (ret == 0)
+		ret = crp.crp_etype;
 	crypto_destroyreq(&crp);
 	if (ret)
 		return (ret);
@@ -270,9 +274,14 @@ crypto_init(void)
 		.csp_cipher_klen = CHACHA20POLY1305_KEY_SIZE,
 		.csp_flags = CSP_F_SEPARATE_AAD | CSP_F_SEPARATE_OUTPUT
 	};
-	int ret = crypto_newsession(&chacha20_poly1305_sid, &csp, CRYPTOCAP_F_SOFTWARE);
+	int ret = crypto_newsession(&chacha20_poly1305_sid, &csp,
+	    CRYPTOCAP_F_SOFTWARE);
 	if (ret != 0)
 		return (ret);
+	if (!CRYPTO_SESS_SYNC(chacha20_poly1305_sid)) {
+		crypto_freesession(chacha20_poly1305_sid);
+		return (ENXIO);
+	}
 	return (0);
 }