From nobody Thu Mar 13 10:22:52 2025 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 4ZD3V44l8fz5qRNv; Thu, 13 Mar 2025 10:22:52 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZD3V43nBqz3qHl; Thu, 13 Mar 2025 10:22:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741861372; 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=n4h68tlN/fPsGuxATYa43UBejjKcXKYwpoSarEalsB4=; b=lbGr9rm3YEhRm1iSe7NZYcJ5h3G/XDwBCLjuZeySmae4CmEbP+cxIS9Fy2Xj4YSmf8rPaQ 7attaYHZ5JsJ8pZOWtI5gcS2bSvjUmFI5nagRfoZS/6ZiBKHjrIRMR6erRB3twae3CfzKx L95ratYjqyVP9ZLkpFwxt+6tmL5BAU/sGfo4oi2NVsEmWCtNSdMrykSrumDD+D564P0eOn YOkpHmnSp685iuNAhSyU6XCcMt5u7ITtvxvtuCB4RsuZpJoioUkvOFeetx8Rwd/JWjDq6W alvOM5ogsXDBh/UfOfhHucICllBBCkdqMk5qro191qge25O1ll+BaEN+iSWCaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741861372; a=rsa-sha256; cv=none; b=LB0X8YoMB6TQk+VVj/019/OycNX/+4+mjElkcNbrNQMI72wsE91tWYOy3f/sXWXTQ9Z0pU KXBolpmouFZ90KftIbBLY05A2Lqaz09WtDcEanf9F0zc26Rk9ZiCU+FSS8nF0+UWUI2LfO MJiX19WBGoKQWdRZJtyjzFE0mmFuM0Eky31Hfz55ca17Q31zd9F2ncsIZOidUbZCNEd3Te KYJimNJh5RpVAXtD0qAuhdkBnDEnriSUxDO1CBNrSSxhAs+eCSDMXL70Wk5V2zC0/bfa0C 1OEbV5+OdivmPdjUMr1ajD6HJp+jNHmBzipFiLiJmlXrqc4ZKL9leqMAvBqUBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741861372; 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=n4h68tlN/fPsGuxATYa43UBejjKcXKYwpoSarEalsB4=; b=ozUNJ/ytLJe5zzb0V0cIXbyiJF3OKe8Y5iMylHD2KNzzVuhz7y1WBk+4nyzimAEFFYmzpy eKzr3gHhV7f1vk2OxyRofQihLjUXkrDZC+RkurvoBVQefDMmde743alDbAOGt3HJs2mB2U 8W83MlNn9xKHhSCLDwS5IIwf3bouDjl3kbpxUmm0EDlNPpAST22ARDF3cD3GsxmhNP2pHE 23SIGQink1c/B5OUcVj6lshnCb4rWnE/KAKDEYiTskGYenhhxUKoTjM6sSNPjf+Z1p7/b7 Sv1HDm2y/bU9MFtPFP5Mg28HqZ+NsQFmzOfxgcFQRc34up1i7Cxt/r+GIP2dRw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZD3V42Rqnztxw; Thu, 13 Mar 2025 10:22:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 52DAMqfH010407; Thu, 13 Mar 2025 10:22:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 52DAMqn5010404; Thu, 13 Mar 2025 10:22:52 GMT (envelope-from git) Date: Thu, 13 Mar 2025 10:22:52 GMT Message-Id: <202503131022.52DAMqn5010404@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Andrey V. Elsukov" Subject: git: 72e2ebf64212 - stable/14 - pfkey2: use correct value for a key length List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ae X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 72e2ebf642125efb74479fd038f45f49a3e846e4 Auto-Submitted: auto-generated The branch stable/14 has been updated by ae: URL: https://cgit.FreeBSD.org/src/commit/?id=72e2ebf642125efb74479fd038f45f49a3e846e4 commit 72e2ebf642125efb74479fd038f45f49a3e846e4 Author: Andrey V. Elsukov AuthorDate: 2025-03-06 12:18:59 +0000 Commit: Andrey V. Elsukov CommitDate: 2025-03-13 10:21:30 +0000 pfkey2: use correct value for a key length The length of key data is specified via sadb_key_bits field. Use specified size for buffer allocation and key copying. Also add a check that the value of sadb_key_bits is not zero, as explicitly required in RFC 2367. PR: 241010 Submitted by: jean-francois.hren at stormshield eu (cherry picked from commit 04207850a9b988d3c04e904cb5783f33da7fe184) --- sys/netipsec/key.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 5458d189c7bf..b550182b581b 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -674,7 +674,7 @@ static struct mbuf *key_setsadbxsa2(u_int8_t, u_int32_t, u_int32_t); static struct mbuf *key_setsadbxsareplay(u_int32_t); static struct mbuf *key_setsadbxpolicy(u_int16_t, u_int8_t, u_int32_t, u_int32_t); -static struct seckey *key_dup_keymsg(const struct sadb_key *, size_t, +static struct seckey *key_dup_keymsg(const struct sadb_key *, struct malloc_type *); static struct seclifetime *key_dup_lifemsg(const struct sadb_lifetime *src, struct malloc_type *); @@ -3437,6 +3437,9 @@ key_setsaval(struct secasvar *sav, const struct sadb_msghdr *mhp) if (len == PFKEY_ALIGN8(sizeof(struct sadb_key)) && sav->alg_auth != SADB_X_AALG_NULL) error = EINVAL; + if (key0->sadb_key_bits == 0 || (sizeof(struct sadb_key) + + (key0->sadb_key_bits >> 3)) > len) + error = EINVAL; break; case SADB_X_SATYPE_IPCOMP: default: @@ -3449,7 +3452,7 @@ key_setsaval(struct secasvar *sav, const struct sadb_msghdr *mhp) goto fail; } - sav->key_auth = key_dup_keymsg(key0, len, M_IPSEC_MISC); + sav->key_auth = key_dup_keymsg(key0, M_IPSEC_MISC); if (sav->key_auth == NULL ) { ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__)); @@ -3475,7 +3478,12 @@ key_setsaval(struct secasvar *sav, const struct sadb_msghdr *mhp) error = EINVAL; break; } - sav->key_enc = key_dup_keymsg(key0, len, M_IPSEC_MISC); + if (key0->sadb_key_bits == 0 || (sizeof(struct sadb_key) + + (key0->sadb_key_bits >> 3)) > len) { + error = EINVAL; + break; + } + sav->key_enc = key_dup_keymsg(key0, M_IPSEC_MISC); if (sav->key_enc == NULL) { ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__)); @@ -4097,13 +4105,14 @@ key_setsadbxpolicy(u_int16_t type, u_int8_t dir, u_int32_t id, u_int32_t priorit * OUT: NULL no more memory */ struct seckey * -key_dup_keymsg(const struct sadb_key *src, size_t len, - struct malloc_type *type) +key_dup_keymsg(const struct sadb_key *src, struct malloc_type *type) { struct seckey *dst; + size_t len; dst = malloc(sizeof(*dst), type, M_NOWAIT); if (dst != NULL) { + len = src->sadb_key_bits >> 3; dst->bits = src->sadb_key_bits; dst->key_data = malloc(len, type, M_NOWAIT); if (dst->key_data != NULL) {