From decc56edfdfbb9f0b66f3bf568e0d6ab25e9f791 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 27 Jul 2026 15:36:55 +0000 Subject: [PATCH 1/2] 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); } From b181583a807e094dc1369c85269bf39f386395ec Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 27 Jul 2026 15:36:22 +0000 Subject: [PATCH 2/2] OCF: Add a fail point to inject EBADMSG decryption errors Approved by: so Security: FreeBSD-SA-26:52.if_wg Security: CVE-2026-58085 Reviewed by: markj Sponsored by: Chelsio Communications --- sys/opencrypto/crypto.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index c3ae5e8a9ff8..9fa017902a19 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,9 @@ static struct mtx crypto_q_mtx; SYSCTL_NODE(_kern, OID_AUTO, crypto, CTLFLAG_RW, 0, "In-kernel cryptography"); +static SYSCTL_NODE(_debug_fail_point, OID_AUTO, crypto, CTLFLAG_RW, 0, + "OCF fail points"); + /* * Taskqueue used to dispatch the crypto requests submitted with * crypto_dispatch_async . @@ -1666,6 +1670,17 @@ crypto_clonereq(struct cryptop *crp, crypto_session_t cses, int how) void crypto_done(struct cryptop *crp) { + if (crp->crp_etype == 0) { + switch (crp->crp_session->csp.csp_mode) { + case CSP_MODE_DIGEST: + case CSP_MODE_AEAD: + if ((crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) != 0) + KFAIL_POINT_CODE(_debug_fail_point_crypto, + inject_badmsg, crp->crp_etype = EBADMSG); + break; + } + } + if (crp->crp_etype != 0) CRYPTOSTAT_INC(cs_errs);