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
This commit is contained in:
John Baldwin authored and Mark Johnston committed 2026-07-29 17:45:02 +00:00
1 parent 98bbfef2ea
commit 3427182452
1 file changed
+10 -1
+10 -1
View File
@@ -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);
}