From nobody Mon Nov 23 14:47:09 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 4jY80s6hM3z6w6rV for ; Mon, 23 Nov 2026 14:47:09 +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 4jY80s5tYhz4mlm for ; Mon, 23 Nov 2026 14:47:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795445229; 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=XD6wmbuO+5yWPG0+SSJFvN9vveKY0VVGKLfHpAT4YqU=; b=mClUytNv0kXkzPhAPiB087HroAr2Br82mmJRMrT6cfnEzOkfxaNPlYe9eSh7Gp5IYNjWZX ChV7pD/yA/j13M5IEQzx55Kncj9THV+CvKQq2hjEjMKJyO2XN0jfi9O4h1YB3GcVlcBP42 3AU3cjznFKGQAmnKx33i9TYp7Tlf64h3kMu9ItRPKnSgViadqR9hVC13qASDswf46lNBzR sadtooYqMBxf5pX81F4BqCNWIM2lmsdtYiZvEKGlvAhQ1DUA0PpwQ0GPOQPkvyGTGCz1Jl 4WqBaiH511TlayaLzz78Nb4ZO2tgv1v0N7l3ChSMWPQj+VlFOjg+bII7uPHeUQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795445229; b=tfSUBaKVsrN+y8IIfrIvL/NTxuThfby6bZ6lemRL2G1R5sMIbNEuGWBKg2kGrfNd6hy840 fQYuVOJBZqKMgUvHq7FGOCmQs9yI4p/kFaWjH2F3LmHX5ud84hPoMgtZmS8wUuQAMqxMQx l04bsk4JspmTtc4Pg/STNI5UIFI2FTdXLF0XUU2K8i/7Zz/UYS0TduwK4OM4AKskM09gaU 81IIfjOoSVS1uFfJEQbzordr07CmgCHyw06a+KEe+fp+s3gAMV/Aqx6X+nRq3wNoWhVAT1 M9ynkR7UFjtGOyZblYPOjZca3a0htJIsk3Vp5ZNF9W6zMqkBOPFBQf+Jtz4sJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795445229; 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=XD6wmbuO+5yWPG0+SSJFvN9vveKY0VVGKLfHpAT4YqU=; b=qApGp47t5HWOyuni/TaymmHdSp67EQZaCMZXYm9oNeViLhd2B8L+2TMjSX4GzwIfvgmC7r awgdmhr+1Wr8wHvfnET/GTLHl6lCV+9+XoDlkpR8QhDpr3P8zVCBvzkJVsJbsLWS75WiAY JHMYw6bvhXe6D4Wtjjk+I/uGIMrXbvQTQYkVlRGYXUWKkeS57vOA0a9zK/hhTG8dHDoaZ1 xI/JvspqhgQGMDt0uty7bHo4Bzjk4F7Ets1+nSq6JwC1iLrRrND3Msyo5ndYoUjnrhjPug kdA575Eg0cMfWpYDkeyC0kv4CYf0OFbVDcLGMainH0tQSxBVt6qvyjBYT2on9Q== 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 4jY80s5DCqzwK0 for ; Mon, 23 Nov 2026 14:47:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 10783 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 23 Nov 2026 14:47:09 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: R. Christian McDonald Subject: git: 0df9a2d94988 - main - netipsec: Copy the offload interface name to a cloned SA 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: 0df9a2d9498891977823d27b60071adbca29b796 Auto-Submitted: auto-generated Date: Mon, 23 Nov 2026 14:47:09 +0000 Message-Id: <6b0451ed.10783.30ac66b7@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=0df9a2d9498891977823d27b60071adbca29b796 commit 0df9a2d9498891977823d27b60071adbca29b796 Author: R. Christian McDonald AuthorDate: 2026-11-23 14:45:27 +0000 Commit: R. Christian McDonald 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;