From nobody Fri Nov 20 20:27:36 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 4jWRj51P9bz6w1MP for ; Fri, 20 Nov 2026 20:27:37 +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 4jWRj44KTqz4HJb for ; Fri, 20 Nov 2026 20:27:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795206456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OOe/uSOHyazedJSt7NNkvSzLZymKI/n/Ch0uBxKemjk=; b=s7dhf+JYA3ghRSZlezLpL9iPqF91H0ONhX+ueF/z1BKS1sb2DOLNpNPk7x2d4oohX2rWMl 0/mrlGOcdr3/PUk+piyCDM3ByBxDe70ioT41mB2AYE2JVNnuWLJqvJkghaET04Y/9UXCGX c+xRqX70yH0qAYL5iJ5Bdi5ncZBSdDCit9apd+CjPC7bp+7bcoOAgexWFwHe53C6GISiz+ RbiOBli6eGTsnV6FQJ78EL+9NfGrqBSN9m1++B4/Acn3gpWyEBEKQLwEpq3TZUaH+XQZpC w5nJgTxuXUJeApgXE7Kn/KG4AvObcL3ktoVOLjF6hYwnoYJADdbpea3kiC3xtA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795206456; b=MYaPTPJwiFnaeqb2wC4US2C9dH9eIXos9+GGu0ihMtsDdEK9MmkZvR4g//rjYU8LLw1bZz ARfXYaB1HvpnjvOyX1fTReIRfieNvnVJkLnMmDy+iR8UikGGTDA+gWJMDY50AhACYG+T75 TpWqhmPYx8KaYc3VsccYVBeBETc9w0Sf+hxQctioCI04XcaFLpSRvZCNL85kj+CWnGincn bnyDb73KvyEx+RhKdUfgeosF4LAn2EPFlsbCWJA4t45z0Anq2mhcdnjs8Xy7ubh2m7/vDg 5wxy372t5v9Rplt20lyLkFSzaI/JH3BsW05iYolbjycWWWZm6lo+dpCjuMZ91Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795206456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OOe/uSOHyazedJSt7NNkvSzLZymKI/n/Ch0uBxKemjk=; b=fTU+bIWACS1zhtDLUPWH5Egl4ChO2Fa3aKQ6JXMoSQ9935cjEoHNQiuXP5nokrO7Uxz7Fa l8ENV/5+It7vuBkPVm9ctZVQ5FrWejoRKCTt04d0Cqwzj8EJZfYVe7VGcOpD6BEAhHpFzA tvkFk+pCRdATF6p08ErEpFDO08gHyelNg8kU/T3Qv0DDNuItygmOilhCS5Uv+0frgyynhj NY9MLyf6viy30eMbq5KlO1rMcZSU14LG0s/u4YIc4ecIXot+ex+HcnPEehsXGJG6+uoO6s v+id51a4ETCikwtBEFTJMnlS3Gc1bkq4JrYv+tgciDuMsMxnl/mHLHdJuMNdlg== 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 4jWRj43jV9z13dh for ; Fri, 20 Nov 2026 20:27:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 108b6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 20 Nov 2026 20:27:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: R. Christian McDonald Subject: git: d40d299bd1f5 - main - netipsec: Send the packet when the rest of a bundle is skipped 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: rcm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d40d299bd1f54a8f5906a77209dfb62e9a9e74e4 Auto-Submitted: auto-generated Date: Fri, 20 Nov 2026 20:27:36 +0000 Message-Id: <6b00ad38.108b6.68aec82f@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=d40d299bd1f54a8f5906a77209dfb62e9a9e74e4 commit d40d299bd1f54a8f5906a77209dfb62e9a9e74e4 Author: R. Christian McDonald AuthorDate: 2026-11-20 13:50:24 +0000 Commit: R. Christian McDonald CommitDate: 2026-11-20 20:27:30 +0000 netipsec: Send the packet when the rest of a bundle is skipped A policy can bundle several requests, for example an ESP tunnel and an AH transport request. A request at level "use" that has no SA is skipped (as is "default", which the net.inet.ipsec.*_deflev and net.inet6.ipsec6.*_deflev sysctls make "use" by default), and the packet is meant to leave with the transforms of the other requests. ipsec_process_done() applies the next request of a bundle once a transform completes. When all remaining requests are skipped, ipsec{4,6}_perform_request() returns EJUSTRETURN and leaves the packet to its caller, but ipsec_process_done() returned that to the transform, which does not send the packet or free it. Keep the references to the SP and the SA across the call, and on EJUSTRETURN send the packet with the transforms applied so far, after the UDP encapsulation of the last SA applied. ipcomp_output() calls ipsec_process_done() directly for packets below the compression threshold and passed the EJUSTRETURN on to ip_output(), which then went on with a packet that tunnel mode encapsulation had already changed. It no longer sees one. Reviewed by: kib, ae Fixes: 9e3bdede0f3d ("Correct IPsec behaviour with a 'use'...") MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D61638 --- sys/netipsec/ipsec_output.c | 28 ++++++++++++----- tests/sys/netipsec/tunnel/Makefile | 1 + tests/sys/netipsec/tunnel/bundle.sh | 63 +++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 8 deletions(-) diff --git a/sys/netipsec/ipsec_output.c b/sys/netipsec/ipsec_output.c index 0a35a6edf0d9..218556aa016b 100644 --- a/sys/netipsec/ipsec_output.c +++ b/sys/netipsec/ipsec_output.c @@ -998,22 +998,29 @@ ipsec_process_done(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, * doing further processing. */ if (++idx < sp->tcount) { + /* + * The request consumes a reference to the SP. Keep ours and + * the SA: when none of the remaining requests has an SA and + * none requires one, the request returns EJUSTRETURN and + * leaves the packet to be sent here, with the transforms + * applied so far. + */ switch (saidx->dst.sa.sa_family) { #ifdef INET case AF_INET: - key_freesav(&sav); + key_addref(sp); IPSECSTAT_INC(ips_out_bundlesa); - return (ipsec4_perform_request(NULL, m, ip, sp, NULL, - idx, 0)); - /* NOTREACHED */ + error = ipsec4_perform_request(NULL, m, ip, sp, NULL, + idx, 0); + break; #endif #ifdef INET6 case AF_INET6: - key_freesav(&sav); + key_addref(sp); IPSEC6STAT_INC(ips_out_bundlesa); - return (ipsec6_perform_request(NULL, m, sp, NULL, - idx, 0)); - /* NOTREACHED */ + error = ipsec6_perform_request(NULL, m, sp, NULL, + idx, 0); + break; #endif /* INET6 */ default: DPRINTF(("%s: unknown protocol family %u\n", __func__, @@ -1021,6 +1028,11 @@ ipsec_process_done(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, error = EPFNOSUPPORT; goto bad; } + if (error != EJUSTRETURN) { + key_freesav(&sav); + key_freesp(&sp); + return (error); + } } #ifdef INET6 /* diff --git a/tests/sys/netipsec/tunnel/Makefile b/tests/sys/netipsec/tunnel/Makefile index de1b56c4cc0b..b3946dc2e9d2 100644 --- a/tests/sys/netipsec/tunnel/Makefile +++ b/tests/sys/netipsec/tunnel/Makefile @@ -11,6 +11,7 @@ ATF_TESTS_SH+= empty \ aesni_aes_cbc_256_hmac_sha2_256 \ aesni_aes_gcm_128 \ aesni_aes_gcm_256 \ + bundle \ chacha20_poly1305 \ esp_iv \ flowlabel \ diff --git a/tests/sys/netipsec/tunnel/bundle.sh b/tests/sys/netipsec/tunnel/bundle.sh new file mode 100755 index 000000000000..f4865c6a4c8e --- /dev/null +++ b/tests/sys/netipsec/tunnel/bundle.sh @@ -0,0 +1,63 @@ + +. $(atf_get_srcdir)/utils.subr + +KEY="12345678901234567890" + +# bundle_use 4|6: ipsecA's outbound policy bundles a required ESP tunnel +# with an AH transport request at level "use", and only the ESP SAs exist. +# The AH request is skipped, so the packets must leave with ESP alone; +# ipsecB has a plain ESP tunnel and drops anything else. +bundle_use() +{ + af=$1 + if [ ${af} = 4 ]; then + lan_a=192.0.2.0/30; lan_b=203.0.113.0/30; target=203.0.113.1 + gw_a=198.51.100.2; gw_b=198.51.100.6 + else + lan_a=2001:db8:1::/64; lan_b=2001:db8:45::/64; target=2001:db8:45::1 + gw_a=2001:db8:23::2; gw_b=2001:db8:34::2 + fi + sas="add ${gw_a} ${gw_b} esp 0x1000 -m tunnel -E aes-gcm-16 \"${KEY}\"; +add ${gw_b} ${gw_a} esp 0x1001 -m tunnel -E aes-gcm-16 \"${KEY}\";" + + ist_init + ist_labsetup + ist_v${af}_setup + cat > ${TMPDIR}/ipsec.ipsecA.conf <<-EOF + flush; + spdflush; + spdadd ${lan_a} ${lan_b} any -P out ipsec esp/tunnel/${gw_a}-${gw_b}/require ah/transport//use; + spdadd ${lan_b} ${lan_a} any -P in ipsec esp/tunnel/${gw_b}-${gw_a}/require; + ${sas} + EOF + cat > ${TMPDIR}/ipsec.ipsecB.conf <<-EOF + flush; + spdflush; + spdadd ${lan_a} ${lan_b} any -P in ipsec esp/tunnel/${gw_a}-${gw_b}/require; + spdadd ${lan_b} ${lan_a} any -P out ipsec esp/tunnel/${gw_b}-${gw_a}/require; + ${sas} + EOF + atf_check -s exit:0 -o ignore jexec ipsecA setkey -f ${TMPDIR}/ipsec.ipsecA.conf + 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 3 -i 0.2 ${target} +} + +atf_test_case "use_v4" "cleanup" +use_v4_head() +{ + atf_set descr 'A bundled request at level use without an SA is skipped (IPv4)' + atf_set require.user root +} +use_v4_body() +{ + bundle_use 4 +} +use_v4_cleanup() +{ + ist_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case "use_v4" +}