aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorR. Christian McDonald <rcm@FreeBSD.org>2026-11-12 18:10:09 +0000
committerMark Johnston <markj@FreeBSD.org>2026-11-16 21:17:12 +0000
commitd80b60653fb8094ec5916f643265aad153f27024 (patch)
tree5f34e88c81843a042bb2b2ebd0308fde01a2431d /sys
parent0a039d79a3ba7acd2adf3bdb96daceae26ea12fd (diff)
esp: Fix synchronization of stream cipher counter updates
After commit 0361f165f219, the counter embedded in the IV for AES-CTR, AES-GCM and ChaCha20 transforms is incremented under a shared lock, which creates the potential for nonce reuse. This can be abused by an on-path attacker to alter the ciphertext of intercepted packets, and potentially reveal the plaintext of packets whose counter values collide. Approved by: so Security: FreeBSD-SA-26:82.ipsec Security: CVE-2026-101318 Sponsored by: Rubicon Communications, LLC ("Netgate") Fixes: 0361f165f219 ("ipsec: replace SECASVAR mtx by rmlock")
Diffstat (limited to 'sys')
-rw-r--r--sys/netipsec/xform_esp.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c
index 7ad6085db87f..9c3f97355e7f 100644
--- a/sys/netipsec/xform_esp.c
+++ b/sys/netipsec/xform_esp.c
@@ -824,8 +824,12 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
SECREPLAY_UNLOCK(sav->replay);
}
cryptoid = sav->tdb_cryptoid;
+ /*
+ * The SA lock is shared by every CPU sending on the SA; the IV
+ * counter must still advance once per packet.
+ */
if (SAV_ISCTRORGCM(sav) || SAV_ISCHACHA(sav))
- cntr = sav->cntr++;
+ cntr = atomic_fetchadd_64(&sav->cntr, 1);
SECASVAR_RUNLOCK(sav);
/*