From nobody Mon Nov 16 17:43: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 4jSwFh68qtz70QdL for ; Mon, 16 Nov 2026 17:43:36 +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 4jSwFh5LVDz3PNm for ; Mon, 16 Nov 2026 17:43:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794851016; 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=rpjhtwbWTwCoFU5Y64z371bJMSm2uMt2MYb9PL/juXA=; b=WGYOJ1nr/GMGY3ufDqGOJN0nsnzM6oZ2JKHOd7bML2uGdWdThG2EUmZ/DxpiJLzZC+Ks/8 3IQuayV1tRYMnFG7+STALGnyH++R2Pf1iGdpAUnCF+aA5VcK5Mb+rECp/0DP/wmJha61mQ Ad2szh0z0z/3s8gz8CrYsBpwy/rvQMYAkOL6DBxOpBvO/sJtRP6Mx3amu0mc5QvwGciwu/ JNag4AaqiyyyFezx0byDS3Pahti7yuuHvfkKI6+IfmLGHPzwhsDRZgiDHidQC2U9CWRFj5 v872JGBFaQZHjKgZjizEcMsmPa9/XkulVj2eQcy40h937tdJDJGUGFlaOmLIzg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794851016; b=fqd6AwSA8xekXa3DWIT0N4YwvHC8lbjY/3vLoNDBN/JlR3c8bC+uBYe7KWOczkL834LWlk IYRMz672U/48RipEXOclh3RFe0PIKzbSVc5R/GlpcJWtAwKTSBqFbcHRoClaFhTVEY/RV0 Om5BPh9hSUX6BPvA/lZ4/69AfVqeEv2z9636NHbPAreoWJx5G07chISeqScJ/SLK3Nv0++ itjNcv4CeVCy4BedDH+jzsjIT+NTvo/nbgBKzH23/+Pde7nHCl+gqTBV84lUMP/YzyPTI5 Y0XCtr31wNFLx1HxB7mDH0ET+LXSdKBaj/OIX2i96vh5oqhRnTs63QDM3JPeAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794851016; 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=rpjhtwbWTwCoFU5Y64z371bJMSm2uMt2MYb9PL/juXA=; b=tOeZ/b67xV4Qx8DgwDXP7dbdASR+TvG2qrjdN2fCVTT3HafCh6L10i+SkYn8vk7QsKuEDE jDdGFUq2xZaC/3+nfQpTzIinc/Xt58nbSO2JSgt5ohymjyrzw49+Isacez3t4ow0HkJSLC dCx54KnI0BUGpr53RQfOISgZg7BvRB9JPx4x9McaOMpr3FFxmXw9wushgEkrb2AfvaDh+5 M4KxhQtfIqCKnLDLBfy3zkLwyR4uTV/5HEGuybcNY/3/RJP/uDEbxQVkl1s9JfnggVEp6h dGuKGr3NKStdB/aO6nM1ph2UN0a1khtu4C4evoE+PaiWi+C1L/5zVm+H316HAw== 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 4jSwFh506Sz14H7 for ; Mon, 16 Nov 2026 17:43:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1327a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 16 Nov 2026 17:43: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: b9e45c2dca5c - main - netipsec: Clear the crypto error before dispatching a request again 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: b9e45c2dca5cf003bb999dffba5eb3c8ed053e51 Auto-Submitted: auto-generated Date: Mon, 16 Nov 2026 17:43:36 +0000 Message-Id: <6afb40c8.1327a.243fa3a3@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=b9e45c2dca5cf003bb999dffba5eb3c8ed053e51 commit b9e45c2dca5cf003bb999dffba5eb3c8ed053e51 Author: R. Christian McDonald AuthorDate: 2026-11-16 17:41:39 +0000 Commit: R. Christian McDonald CommitDate: 2026-11-16 17:42:49 +0000 netipsec: Clear the crypto error before dispatching a request again When a crypto driver unregisters, a request on one of its sessions completes with EAGAIN. The ESP, AH and IPComp callbacks then move the SA to the new session and pass the same request to crypto_dispatch() again, with crp_etype still set to EAGAIN. crypto_dispatch() requires a request without an error. A kernel with INVARIANTS panics there with "incoming crp with error". The other consumers that dispatch a request again after EAGAIN clear the field first. The six callbacks prepare the request for the retry with the same code. Move that code to a new function, ipsec_crypto_retry(), and clear the error there. ipsec_updateid() has no other callers and becomes static. The callbacks still dispatch the request themselves, because the input callbacks have to release the sahtree lock first. Reviewed by: markj, kib Fixes: c03414326909 ("Refactor driver and consumer...") MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D61515 --- sys/netipsec/ipsec.c | 19 ++++++++++++++++++- sys/netipsec/ipsec.h | 5 ++++- sys/netipsec/xform_ah.c | 14 ++------------ sys/netipsec/xform_esp.c | 14 ++------------ sys/netipsec/xform_ipcomp.c | 14 ++------------ 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/sys/netipsec/ipsec.c b/sys/netipsec/ipsec.c index 90dcdc8c8c28..ebdd071d942e 100644 --- a/sys/netipsec/ipsec.c +++ b/sys/netipsec/ipsec.c @@ -1536,7 +1536,7 @@ ipsec_updatereplay(uint32_t seq, struct secasvar *sav) SECREPLAY_UNLOCK(replay); return (0); } -int +static int ipsec_updateid(struct secasvar *sav, crypto_session_t *new, crypto_session_t *old) { @@ -1583,6 +1583,23 @@ ipsec_updateid(struct secasvar *sav, crypto_session_t *new, return (0); } +/* + * Prepare a request that failed with EAGAIN to be dispatched again. + * The caller must release its locks before it dispatches the request. + */ +void +ipsec_crypto_retry(struct secasvar *sav, struct xform_data *xd, + struct cryptop *crp) +{ + crypto_session_t cryptoid; + + cryptoid = xd->cryptoid; + if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) + crypto_freesession(cryptoid); + xd->cryptoid = crp->crp_session; + crp->crp_etype = 0; +} + int ipsec_initialized(void) { diff --git a/sys/netipsec/ipsec.h b/sys/netipsec/ipsec.h index 260c1cd6b901..1f613df2160d 100644 --- a/sys/netipsec/ipsec.h +++ b/sys/netipsec/ipsec.h @@ -329,6 +329,7 @@ VNET_DECLARE(int, natt_cksum_policy); #define DPRINTF(x) #endif +struct cryptop; struct inpcb; struct ip; struct m_tag; @@ -336,6 +337,7 @@ struct rm_priotracker; struct secasvar; struct sockopt; struct tcphdr; +struct xform_data; union sockaddr_union; int ipsec_if_input(struct mbuf *, struct secasvar *, uint32_t, @@ -353,7 +355,8 @@ int udp_ipsec_output(struct mbuf *, struct secasvar *); int ipsec_chkreplay(uint32_t, uint32_t *, struct secasvar *); int ipsec_updatereplay(uint32_t, struct secasvar *); -int ipsec_updateid(struct secasvar *, crypto_session_t *, crypto_session_t *); +void ipsec_crypto_retry(struct secasvar *, struct xform_data *, + struct cryptop *); int ipsec_initialized(void); size_t ipsec_hdrsiz_internal(struct secpolicy *); diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c index cea329eaa827..ffab85f8128e 100644 --- a/sys/netipsec/xform_ah.c +++ b/sys/netipsec/xform_ah.c @@ -695,7 +695,6 @@ ah_input_cb(struct cryptop *crp) struct secasvar *sav; struct secasindex *saidx; caddr_t ptr; - crypto_session_t cryptoid; int authsize, rplen, ahsize, error, skip, protoff; uint8_t nxt; @@ -708,7 +707,6 @@ ah_input_cb(struct cryptop *crp) skip = xd->skip; nxt = xd->nxt; protoff = xd->protoff; - cryptoid = xd->cryptoid; ipsec_sahtree_rlock(&sahtree_tracker); if (sav->state >= SADB_SASTATE_DEAD) { /* saidx is freed */ @@ -725,10 +723,7 @@ ah_input_cb(struct cryptop *crp) /* Check for crypto errors. */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); ipsec_sahtree_runlock(&sahtree_tracker); CURVNET_RESTORE(); return (crypto_dispatch(crp)); @@ -1100,7 +1095,6 @@ ah_output_cb(struct cryptop *crp) struct secpolicy *sp; struct secasvar *sav; struct mbuf *m; - crypto_session_t cryptoid; caddr_t ptr; u_int idx; int skip, error; @@ -1112,16 +1106,12 @@ ah_output_cb(struct cryptop *crp) sav = xd->sav; skip = xd->skip; idx = xd->idx; - cryptoid = xd->cryptoid; ptr = (caddr_t) (xd + 1); /* Check for crypto errors. */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); CURVNET_RESTORE(); return (crypto_dispatch(crp)); } diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c index 618556fa84a6..ff84c6b0a000 100644 --- a/sys/netipsec/xform_esp.c +++ b/sys/netipsec/xform_esp.c @@ -520,7 +520,6 @@ esp_input_cb(struct cryptop *crp) struct xform_data *xd; struct secasvar *sav; struct secasindex *saidx; - crypto_session_t cryptoid; int hlen, skip, protoff, error, alen; SECASVAR_RLOCK_TRACKER; @@ -540,17 +539,13 @@ esp_input_cb(struct cryptop *crp) } skip = xd->skip; protoff = xd->protoff; - cryptoid = xd->cryptoid; saidx = &sav->sah->saidx; esph = sav->tdb_authalgxform; /* Check for crypto errors */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); ipsec_sahtree_runlock(&sahtree_tracker); CURVNET_RESTORE(); return (crypto_dispatch(crp)); @@ -1005,7 +1000,6 @@ esp_output_cb(struct cryptop *crp) struct secpolicy *sp; struct secasvar *sav; struct mbuf *m; - crypto_session_t cryptoid; u_int idx; int error; @@ -1016,15 +1010,11 @@ esp_output_cb(struct cryptop *crp) sp = xd->sp; sav = xd->sav; idx = xd->idx; - cryptoid = xd->cryptoid; /* Check for crypto errors. */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); CURVNET_RESTORE(); return (crypto_dispatch(crp)); } diff --git a/sys/netipsec/xform_ipcomp.c b/sys/netipsec/xform_ipcomp.c index aecaf79f39bd..87bdf9eeb8e8 100644 --- a/sys/netipsec/xform_ipcomp.c +++ b/sys/netipsec/xform_ipcomp.c @@ -289,7 +289,6 @@ ipcomp_input_cb(struct cryptop *crp) struct secasvar *sav; struct secasindex *saidx; caddr_t addr; - crypto_session_t cryptoid; int hlen = IPCOMP_HLENGTH, error, clen; int skip, protoff; uint8_t nproto; @@ -300,7 +299,6 @@ ipcomp_input_cb(struct cryptop *crp) sav = xd->sav; skip = xd->skip; protoff = xd->protoff; - cryptoid = xd->cryptoid; ipsec_sahtree_rlock(&sahtree_tracker); if (sav->state >= SADB_SASTATE_DEAD) { /* saidx is freed */ @@ -317,10 +315,7 @@ ipcomp_input_cb(struct cryptop *crp) /* Check for crypto errors */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); ipsec_sahtree_runlock(&sahtree_tracker); CURVNET_RESTORE(); return (crypto_dispatch(crp)); @@ -548,7 +543,6 @@ ipcomp_output_cb(struct cryptop *crp) struct secpolicy *sp; struct secasvar *sav; struct mbuf *m; - crypto_session_t cryptoid; u_int idx; int error, skip, protoff; @@ -560,15 +554,11 @@ ipcomp_output_cb(struct cryptop *crp) sav = xd->sav; skip = xd->skip; protoff = xd->protoff; - cryptoid = xd->cryptoid; /* Check for crypto errors */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { - /* Reset the session ID */ - if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) - crypto_freesession(cryptoid); - xd->cryptoid = crp->crp_session; + ipsec_crypto_retry(sav, xd, crp); CURVNET_RESTORE(); return (crypto_dispatch(crp)); }