From nobody Fri Apr 29 20:55:02 2022 X-Original-To: dev-commits-src-branches@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 F3EC819941EE; Fri, 29 Apr 2022 20:55:02 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kql9f5ZM6z3FDj; Fri, 29 Apr 2022 20:55:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651265702; 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=OoYnnPaNPg+lIhGIsBknYfXMXu8kRtmOmVkK6CPaimY=; b=LZRRSS8YqKKKvUwIw64cvqqwy0kdwI1CLSFW0EFqkXQYKmMO3hYLjckmLA1OTvEb9sdZD+ WtVBqRPSQVz5p+3n/NGynonbvwYxqcaQkEHELZu7eyb6jsIxM2iqZZRpHUNI0QX+UjClRs HsrZBiUijcQ5+xY2XSPO/0l1YHs/xRcHL1ybV2yxysRi4at80+vwypNY64edC8jzGWjJCv rmU5+RN146mODzHoDbF8z9gpC6lNFheWJDCf0Hr8HLnkXB9RO3RxKpWt8rBvNYzXOGN3gL pdl7P+JwMQXtBognWr4wpJ5ydinUKvy+YpNSAR0huS5gzd86eQf75m+R2rMVFg== 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 50F2C13BFF; Fri, 29 Apr 2022 20:55:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23TKt2Vt055110; Fri, 29 Apr 2022 20:55:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23TKt2at055109; Fri, 29 Apr 2022 20:55:02 GMT (envelope-from git) Date: Fri, 29 Apr 2022 20:55:02 GMT Message-Id: <202204292055.23TKt2at055109@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: a41ff1661bc0 - stable/13 - crypto: Validate AES-GCM IV length in check_csp(). List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a41ff1661bc019abbfbc3d6df2ad7e58126cc4ef Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651265702; 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=OoYnnPaNPg+lIhGIsBknYfXMXu8kRtmOmVkK6CPaimY=; b=fA++tSrdcg+9vRgtpz9bYFgj9vDdDl6fQ/1Nygzs3zONsaUvhuo4ZE9ueJwDDxM+Grruc0 Ya6W0L4tiaFlANWB1v0zGcNbuNj2pmlXhmvonbw8qJuDBtIMnbsGo+QYWwBUWgLkVWsF29 KaD2j1sMpLn+CJhyoMXz+FqXwUxdGLXjWwponsqrQLnHfbmDnDyGwv86d3ekau+hPSkcWf ++tL4OL5P/iz+gBNRzYnoAibSXBenuJEsyoLKhsoLFcrDXQQ8mkxF1WscryqD2QotdoO1a uOwu5sNfAShd5jKzEkklwNXTfdvZK+Ggh12ka9Fz2ODSDcpuaQWEWSSZJU1Yqw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651265702; a=rsa-sha256; cv=none; b=uV1dJo3zYXIFFnS2AZbvYCe1wf0fHSKsrTi7WVIa2souuwwyrLNYkQyI2Dv1c1Pq73SESM GDWY/WERDPwOnsftpsgboysY6eWLB2VZ5ENjXkHKska8FIMtE6tyg8SmaGW5yx0vPF3n0C WuvOpSkARp38DrB8Z+r61xH80h6HAiapiYDOHD2PkblE8Lw+nliuzPSlo/TBx2aUIWcLLD rF5lXYc7NCwayLOuNJuaHtfeS9ATai3P7b8kP6+H71eKcVKNwikE2hmCHGfarOzO+Mn0O+ CZmFXPDPB1PaQdnrZSGQDpoR4V+eeagzoicMQ1hcSFbVBvaXlSXUMFveNXW/vA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a41ff1661bc019abbfbc3d6df2ad7e58126cc4ef commit a41ff1661bc019abbfbc3d6df2ad7e58126cc4ef Author: John Baldwin AuthorDate: 2021-12-09 19:52:41 +0000 Commit: John Baldwin CommitDate: 2022-04-29 20:50:04 +0000 crypto: Validate AES-GCM IV length in check_csp(). This centralizes the check for valid nonce lengths for AES-GCM. While here, remove some duplicate checks for valid AES-GCM tag lengths from ccp(4) and ccr(4). Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33194 (cherry picked from commit 6e17a2e00d62fd3041e0bb511fe925079ad1c0d7) --- sys/crypto/aesni/aesni.c | 3 +-- sys/crypto/armv8/armv8_crypto.c | 2 -- sys/crypto/ccp/ccp.c | 5 ----- sys/dev/cxgbe/crypto/t4_crypto.c | 6 ------ sys/dev/qat/qat.c | 2 -- sys/dev/safexcel/safexcel.c | 3 --- sys/opencrypto/crypto.c | 5 ++++- sys/opencrypto/cryptosoft.c | 3 --- 8 files changed, 5 insertions(+), 24 deletions(-) diff --git a/sys/crypto/aesni/aesni.c b/sys/crypto/aesni/aesni.c index de797abd1af5..eea32532131f 100644 --- a/sys/crypto/aesni/aesni.c +++ b/sys/crypto/aesni/aesni.c @@ -305,8 +305,7 @@ aesni_probesession(device_t dev, const struct crypto_session_params *csp) if (csp->csp_auth_mlen != 0 && csp->csp_auth_mlen != GMAC_DIGEST_LEN) return (EINVAL); - if (csp->csp_ivlen != AES_GCM_IV_LEN || - !sc->has_aes) + if (!sc->has_aes) return (EINVAL); break; case CRYPTO_AES_CCM_16: diff --git a/sys/crypto/armv8/armv8_crypto.c b/sys/crypto/armv8/armv8_crypto.c index 077667a4bb2a..18b0870f380b 100644 --- a/sys/crypto/armv8/armv8_crypto.c +++ b/sys/crypto/armv8/armv8_crypto.c @@ -217,8 +217,6 @@ armv8_crypto_probesession(device_t dev, case CRYPTO_AES_NIST_GCM_16: if (!sc->has_pmul) return (EINVAL); - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return (EINVAL); if (csp->csp_auth_mlen != 0 && csp->csp_auth_mlen != GMAC_DIGEST_LEN) return (EINVAL); diff --git a/sys/crypto/ccp/ccp.c b/sys/crypto/ccp/ccp.c index 7cc38b14f3fd..2b059dcee2ca 100644 --- a/sys/crypto/ccp/ccp.c +++ b/sys/crypto/ccp/ccp.c @@ -378,11 +378,6 @@ ccp_probesession(device_t dev, const struct crypto_session_params *csp) case CSP_MODE_AEAD: switch (csp->csp_cipher_alg) { case CRYPTO_AES_NIST_GCM_16: - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return (EINVAL); - if (csp->csp_auth_mlen < 0 || - csp->csp_auth_mlen > AES_GMAC_HASH_LEN) - return (EINVAL); if ((sc->hw_features & VERSION_CAP_AES) == 0) return (EINVAL); break; diff --git a/sys/dev/cxgbe/crypto/t4_crypto.c b/sys/dev/cxgbe/crypto/t4_crypto.c index 7c233897dff6..325aba60a742 100644 --- a/sys/dev/cxgbe/crypto/t4_crypto.c +++ b/sys/dev/cxgbe/crypto/t4_crypto.c @@ -2542,12 +2542,6 @@ ccr_probesession(device_t dev, const struct crypto_session_params *csp) case CSP_MODE_AEAD: switch (csp->csp_cipher_alg) { case CRYPTO_AES_NIST_GCM_16: - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return (EINVAL); - if (csp->csp_auth_mlen < 0 || - csp->csp_auth_mlen > AES_GMAC_HASH_LEN) - return (EINVAL); - break; case CRYPTO_AES_CCM_16: break; default: diff --git a/sys/dev/qat/qat.c b/sys/dev/qat/qat.c index b5d3f4d9629a..dddfe4da1083 100644 --- a/sys/dev/qat/qat.c +++ b/sys/dev/qat/qat.c @@ -1900,8 +1900,6 @@ qat_probesession(device_t dev, const struct crypto_session_params *csp) case CSP_MODE_AEAD: switch (csp->csp_cipher_alg) { case CRYPTO_AES_NIST_GCM_16: - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return EINVAL; break; default: return EINVAL; diff --git a/sys/dev/safexcel/safexcel.c b/sys/dev/safexcel/safexcel.c index 242f1bcfb90a..16978632a1be 100644 --- a/sys/dev/safexcel/safexcel.c +++ b/sys/dev/safexcel/safexcel.c @@ -2304,9 +2304,6 @@ safexcel_probesession(device_t dev, const struct crypto_session_params *csp) case CSP_MODE_AEAD: switch (csp->csp_cipher_alg) { case CRYPTO_AES_NIST_GCM_16: - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return (EINVAL); - break; case CRYPTO_AES_CCM_16: break; default: diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index 576382406d88..5332ab5f07ce 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -881,7 +881,10 @@ check_csp(const struct crypto_session_params *csp) return (false); break; case CRYPTO_AES_NIST_GCM_16: - if (csp->csp_auth_mlen > 16) + if (csp->csp_auth_mlen > AES_GMAC_HASH_LEN) + return (false); + + if (csp->csp_ivlen != AES_GCM_IV_LEN) return (false); break; case CRYPTO_CHACHA20_POLY1305: diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 567a0f4748d5..b6c964b540bc 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -1308,9 +1308,6 @@ swcr_setup_gcm(struct swcr_session *ses, struct swcr_auth *swa; struct auth_hash *axf; - if (csp->csp_ivlen != AES_GCM_IV_LEN) - return (EINVAL); - /* First, setup the auth side. */ swa = &ses->swcr_auth; switch (csp->csp_cipher_klen * 8) {