git: 0df9a2d94988 - main - netipsec: Copy the offload interface name to a cloned SA
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Nov 2026 14:47:09 UTC
The branch main has been updated by rcm:
URL: https://cgit.FreeBSD.org/src/commit/?id=0df9a2d9498891977823d27b60071adbca29b796
commit 0df9a2d9498891977823d27b60071adbca29b796
Author: R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-23 14:45:27 +0000
Commit: R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-23 14:45:27 +0000
netipsec: Copy the offload interface name to a cloned SA
When SADB_UPDATE changes the addresses of an SA, key_updateaddresses()
replaces the SA with a clone. For an SA that names an offload interface
it allocated a buffer for the clone's copy of the name, and then called
strncpy() with the arguments swapped. The clone was left with an
uninitialized name, and the name of the old SA was overwritten with the
contents of the new buffer.
Copy the name from the old SA to the new one.
Also, the clone starts as a bcopy() of the old SA, so its natt and
accel_ifname pointers refer to memory owned by the old SA until they are
replaced. If one of the offload allocations failed, the error path freed
that memory, and key_cleansav() freed it again with the last reference
to the old SA. Clear both pointers right after the copy.
Reported by: llm-postcr
Reviewed by: kib
Fixes: ef2a572bf6bd ("ipsec_offload: kernel infrastructure")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61899
---
sys/netipsec/key.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index c440624536b7..923c4a3aca92 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -5428,9 +5428,18 @@ key_updateaddresses(struct socket *so, struct mbuf *m,
/* Clone SA's content into newsav */
SAV_INITREF(newsav);
bcopy(sav, newsav, offsetof(struct secasvar, chain));
+ /*
+ * The copy still points at the old SA's NAT-T config and offload
+ * interface name. Those stay with the old SA, and key_cleansav()
+ * frees them with its last reference. Clear them before anything
+ * can fail, so that the error path frees only what belongs to
+ * newsav.
+ */
+ newsav->natt = NULL;
#ifdef IPSEC_OFFLOAD
CK_LIST_INIT(&newsav->accel_ifps);
newsav->accel_forget_tq = 0;
+ newsav->accel_ifname = NULL;
newsav->accel_lft_sw = uma_zalloc_pcpu(ipsec_key_lft_zone,
M_NOWAIT | M_ZERO);
if (newsav->accel_lft_sw == NULL) {
@@ -5446,20 +5455,15 @@ key_updateaddresses(struct socket *so, struct mbuf *m,
error = ENOBUFS;
goto fail;
}
- strncpy(__DECONST(char *, sav->accel_ifname),
- newsav->accel_ifname,
+ strncpy(__DECONST(char *, newsav->accel_ifname),
+ sav->accel_ifname,
sizeof(xof.sadb_x_if_hw_offl_if));
}
#endif
- /*
- * We create new NAT-T config if it is needed.
- * Old NAT-T config will be freed by key_cleansav() when
- * last reference to SA will be released.
- */
- newsav->natt = NULL;
newsav->sah = sah;
newsav->state = SADB_SASTATE_MATURE;
+ /* Create a new NAT-T config if one is needed. */
error = key_setnatt(newsav, mhp);
if (error != 0)
goto fail;