From nobody Tue Nov 17 17:08:17 2026 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 4jTWQV1sl6z71SRH for ; Tue, 17 Nov 2026 17:08:18 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTWQT70xsz4MhP for ; Tue, 17 Nov 2026 17:08:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XQW61Ro5HC7a4GbTUMUG7N6Ld7mNwqB+2/dD2m5+sqE=; b=OFIl5ySV/mADQGjF00CYWRg/AFvfUKac8Z/FMyexVA4yiAnW8H6nRn09QabIklo7RUWAR6 FwlrhyHlIf/KaZ821HHceIKHD/yrMF3mZOZ2vS9xMo/ssqNcE1vEMqxTdfUub8U1vDnFYp 6Qprtd8MKOELTWQMNroysvGzY6t9x0Rt4rn61wLnkUJiNphX34X1yxxQz13ZgGvUMMARl3 RPkVeAWanheW+froLV7h9E2EgwKEzEL9X+8gSc6Uu7IaqoFWEWfZb2UIYhKRoDEEEQ615r u+YDfYebyys2NcgXWcAh9ho10tMBaYcUo/b+ROiLl0qizT1jpLlHkumsmB3/xQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935298; b=gkolAur8H8Be88VI72OByNuUzNokZWtFZvF0AGnozaY9meyLN+YJJDo1TJ+g5mDDApZMer jpMR82ZpnIDpUkLzREDfleScvHlvtac8AVYdGvI6TgnTvSHy2OYW7QYpT6AwD/Ek9b3zsv //v40ulJBQXnC2wGUhzbJdVLS3W0ECualUPR3IjQ4eY7hoECVp1bwyl4XL/bmb0oQKOgD/ v3xGQE0lduCf5Kc9lpfki4MjX3I0w/AL5WwpM21M3B2lJwBE5/fXDGOTXV7yYK1e++PMnV BCA3gI+77UHbFaq9JgZWh3VXIOx4xgEU1btzdW2W8jl3cRbE4rNOeOEj8gv/pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XQW61Ro5HC7a4GbTUMUG7N6Ld7mNwqB+2/dD2m5+sqE=; b=C6d1sW3xHPygX9frrVc8/tmuYNXdFTSckyYWcTNosL8N88hx6wumGzbxM+qNhFW6etC2eB ULeAB7EyoCQ7yRnErCMWPoAigaM74x2Uep2VAy0nA3C/rhiEZ/JRBZlE7mKkKa2Nn/ZMZe 23RZIp3EUBIto18tSa3MVK+dUy3qbzsRkbtQk3wtlDFnS087N6ess/aZsUoJo3ngAyyk5+ fJSpFY+VgcoEVk1pmJKaAHSqox1MzIwy9XVhoi0/juIAsHtC2vDr7UcDJh2A6jeqUzTpC2 oBmPt6SayarNfmykDgRnV0pGcnvU1cO7vn7l1GMaMPX6PikZikTvteeCKYkALw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTWQT6FRWzrw0 for ; Tue, 17 Nov 2026 17:08:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1fc57 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:08:17 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: R. Christian McDonald From: Mark Johnston Subject: git: 154a5e9e1844 - releng/15.1 - esp: Fix synchronization of stream cipher counter updates List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.1 X-Git-Reftype: branch X-Git-Commit: 154a5e9e184478c8b057ff350d22a1e2665d6417 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:08:17 +0000 Message-Id: <6afc8a01.1fc57.21ab5b53@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=154a5e9e184478c8b057ff350d22a1e2665d6417 commit 154a5e9e184478c8b057ff350d22a1e2665d6417 Author: R. Christian McDonald AuthorDate: 2026-11-12 18:10:09 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:21:09 +0000 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") --- sys/netipsec/xform_esp.c | 6 ++- tests/sys/netipsec/tunnel/Makefile | 3 +- tests/sys/netipsec/tunnel/esp_iv.sh | 91 +++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c index be8c18da60b3..c0026268abe0 100644 --- a/sys/netipsec/xform_esp.c +++ b/sys/netipsec/xform_esp.c @@ -829,8 +829,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); /* diff --git a/tests/sys/netipsec/tunnel/Makefile b/tests/sys/netipsec/tunnel/Makefile index c6060a790cc3..36e6a4990dc1 100644 --- a/tests/sys/netipsec/tunnel/Makefile +++ b/tests/sys/netipsec/tunnel/Makefile @@ -11,7 +11,8 @@ ATF_TESTS_SH+= empty \ aesni_aes_cbc_256_hmac_sha2_256 \ aesni_aes_gcm_128 \ aesni_aes_gcm_256 \ - chacha20_poly1305 + chacha20_poly1305 \ + esp_iv # Each test uses the same names for its jails, so they must be run serially. TEST_METADATA+= is_exclusive=true diff --git a/tests/sys/netipsec/tunnel/esp_iv.sh b/tests/sys/netipsec/tunnel/esp_iv.sh new file mode 100644 index 000000000000..f218113a5c95 --- /dev/null +++ b/tests/sys/netipsec/tunnel/esp_iv.sh @@ -0,0 +1,91 @@ +. $(atf_get_srcdir)/utils.subr + +# The explicit IV of AES-GCM, AES-CTR and ChaCha20-Poly1305 must never repeat +# under one key. esp_output() takes it from a per-SA counter that every CPU +# sending on the SA advances, so drive one tunnel from several processes at +# once, capture the ESP on the wire and look for a repeated IV per SPI. + +atf_test_case "unique" "cleanup" +unique_head() +{ + atf_set descr 'The explicit ESP IV is unique per SA under concurrent senders' + atf_set require.user root + atf_set require.progs tcpdump + atf_set timeout 600 +} + +unique_body() +{ + if [ "$(sysctl -n hw.ncpu)" -lt 2 ]; then + atf_skip "This test needs more than one CPU" + fi + + ist_init + ist_labsetup + ist_v4_setup + ist_setkey ipsecA out 4 aes-gcm-16 "12345678901234567890" + atf_check -s exit:0 -o ignore \ + jexec ipsecA setkey -f ${TMPDIR}/ipsec.ipsecA.conf + ist_setkey ipsecB in 4 aes-gcm-16 "12345678901234567890" + atf_check -s exit:0 -o ignore \ + jexec ipsecB setkey -f ${TMPDIR}/ipsec.ipsecB.conf + atf_check -s exit:0 -o ignore jexec hostA ping -c 1 203.0.113.1 + + # ESP in both directions crosses the router. + jexec router tcpdump -ni ${epair_PUB_A}b -s 64 -w ${TMPDIR}/esp.pcap esp \ + > /dev/null 2>&1 & + tcpdump_pid=$! + sleep 1 + + # Flood pings from the gateway itself, so that each one runs + # esp_output() in its own context on whatever CPU the scheduler gives + # it: many concurrent senders on the same SA each way. (Sent from + # hostA they would all arrive through one epair queue and be + # serialised before they reach IPsec.) + pids="" + for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do + jexec ipsecA ping -q -f -c 12000 -S 192.0.2.2 203.0.113.1 \ + > /dev/null 2>&1 & + pids="${pids} $!" + done + wait ${pids} + sleep 1 + kill -INT ${tcpdump_pid} + wait ${tcpdump_pid} 2>/dev/null + + # Per packet: hex of the first 48 bytes after the link header; the ESP + # header follows the IPv4 header, the explicit IV follows the 8-byte + # ESP header. Count a (SPI, IV) pair seen more than once. + tcpdump -nnr ${TMPDIR}/esp.pcap -x esp 2>/dev/null | awk ' + /^[0-9][0-9]:/ { flush(); next } + /^[ \t]*0x00[012]0:/ { line = $0; sub(/^[ \t]*0x00[0-9a-f]+:[ \t]*/, "", line); gsub(/ /, "", line); hex = hex line; next } + function flush() { + if (length(hex) >= 72) { + ihl = strtonum_hex(substr(hex, 2, 1)) * 8; + spi = substr(hex, ihl + 1, 8); iv = substr(hex, ihl + 17, 16); + n++; if (++seen[spi " " iv] == 2) dup++; + } + hex = "" + } + function strtonum_hex(c) { return index("0123456789abcdef", c) - 1 } + END { flush(); printf "%d %d\n", n, dup }' > ${TMPDIR}/esp.count + read packets dups < ${TMPDIR}/esp.count + echo "ESP packets captured: ${packets}, repeated IVs: ${dups}" + + if [ "${packets}" -lt 100000 ]; then + atf_fail "Captured only ${packets} ESP packets" + fi + if [ "${dups}" -ne 0 ]; then + atf_fail "${dups} ESP packets reused an explicit IV" + fi +} + +unique_cleanup() +{ + ist_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case "unique" +}