From nobody Sun Dec 03 17:48:18 2023 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 4SjvR72LKwz538dJ; Sun, 3 Dec 2023 17:48:19 +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 4SjvR71b4cz3Lm9; Sun, 3 Dec 2023 17:48:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701625699; 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=kKn7RQ1HraZ/j4V9xfwdsKkCCJSuMs/1piv2Bxoj/qw=; b=DHYjSbFu7vIMfuh4dYq+emY58xGlPxGSt6OF8KCl0My6dp6LcccSxycnDUUe40mV+WQqNY 9uFxq5EG8UC/Z0yLkSbOVBXa+3THK3snhN8h3IVYW9ywdVcbkbbTxl4PXho87+SqD/LIVL ita5qH13bexvUffJqJ5bDA4/p2+jaTPtVkyHdh6HWr5H4iSm5DAieBPVugHYKr/ICnJ6u1 olEOaIZVElh3Kg9CvNRXtRaFZ5Okky4bplVi1mCch0IZusTP+WTLwXLzw0NYx1gvaiyQ+D fkkA9pFvL155Q208BsJTOhdYutDOvgeEiDHuzhsRhSwVI/ltRdMt6cn0zOgNSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701625699; 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=kKn7RQ1HraZ/j4V9xfwdsKkCCJSuMs/1piv2Bxoj/qw=; b=fJu20kC8+r5SlAO1oUnB0dL3X5vh0HeNssPMGHOWEx9Lv88eCLWmRV7vlFQ+HLQ1qVGS64 oiRHFLLHDyk0h2InQr7eCQnRlKAO8L4fxb1j65ltPzk8VpEIqQAFukwahBTYgmfgiS7WVM rbEfWMzvqkVUvfLpnEXP+2Y4TmvDtrpJFfzVtG3xhgFIy/qMMEjQsf/HMGDoQhyLlmmhy1 754K7l7bFYTD3JYlvKb185BmpzqLS3WsTHXuvNe+mCT92OhenU9o59LlrDPV4pH8zuHQpG 8sjvAt5LxN0I6jrEhMwNotc70TkuTnioCmT1ACdOyHDLDBr2teiPN2fDNli7+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701625699; a=rsa-sha256; cv=none; b=um7epVjebVn/Nmz8nWjxuFKk0xH1iTrDahXA7M8aMPhgOB9usnnh6C1a+jM4+ucs6fsC73 3W6fUtPtcOkkGoQ3ZCf7E8X1WPR3kHzr9Y8SQnykVRNMSLkGOa/mkTisRBDGeCTj9z98ii PLitUb1ueVx/iojnjVHD0mGRRcxt8cWZ0mcc1Qp8YGeBHLzY2Ws0mxTDokBg6AtX7y1UVl Gd/QbtPpQnFbUmZ6jeoBVRxJTvVDLaXIvjVobg07DfD9eYFb+xl7J9d+TTMAgtPiB2Stsl 5jLVDjLHEqADAXlShJGAl3y3Lipx8b0tEV4sRALZghZHE5ohac+sjEBBZ1y0lg== 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 4SjvR70D9kz17Ps; Sun, 3 Dec 2023 17:48:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3B3HmIml022333; Sun, 3 Dec 2023 17:48:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B3HmIp5022330; Sun, 3 Dec 2023 17:48:18 GMT (envelope-from git) Date: Sun, 3 Dec 2023 17:48:18 GMT Message-Id: <202312031748.3B3HmIp5022330@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 118b866d9c39 - stable/14 - ossl: Fix some bugs in the fallback AES-GCM implementation 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 118b866d9c39da1f5a17680e2034b3eff7337988 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=118b866d9c39da1f5a17680e2034b3eff7337988 commit 118b866d9c39da1f5a17680e2034b3eff7337988 Author: Mark Johnston AuthorDate: 2023-11-29 20:08:12 +0000 Commit: Mark Johnston CommitDate: 2023-12-03 17:48:09 +0000 ossl: Fix some bugs in the fallback AES-GCM implementation gcm_*_aesni() are used when the AVX512 implementation is not available. Fix two bugs which manifest when handling operations spanning multiple segments: - Avoid underflow when the length of the input is smaller than the residual. - In gcm_decrypt_aesni(), ensure that we begin the operation at the right offset into the input and output buffers. Reviewed by: jhb Fixes: 9b1d87286c78 ("ossl: Add a fallback AES-GCM implementation using AES-NI") MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D42838 (cherry picked from commit 47d767dab54895f3ba8abac6ab2295797394659e) --- sys/crypto/openssl/amd64/ossl_aes_gcm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/crypto/openssl/amd64/ossl_aes_gcm.c b/sys/crypto/openssl/amd64/ossl_aes_gcm.c index 0d205ec3ff90..d08b2ac8a759 100644 --- a/sys/crypto/openssl/amd64/ossl_aes_gcm.c +++ b/sys/crypto/openssl/amd64/ossl_aes_gcm.c @@ -459,7 +459,7 @@ gcm_encrypt_aesni(struct ossl_gcm_context *ctx, const unsigned char *in, size_t bulk = 0, res; int error; - res = (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN; + res = MIN(len, (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN); if ((error = gcm_encrypt(ctx, in, out, res)) != 0) return error; @@ -621,12 +621,12 @@ gcm_decrypt_aesni(struct ossl_gcm_context *ctx, const unsigned char *in, size_t bulk = 0, res; int error; - res = (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN; + res = MIN(len, (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN); if ((error = gcm_decrypt(ctx, in, out, res)) != 0) return error; - bulk = aesni_gcm_decrypt(in, out, len, &ctx->aes_ks, ctx->gcm.Yi.c, - ctx->gcm.Xi.u); + bulk = aesni_gcm_decrypt(in + res, out + res, len - res, &ctx->aes_ks, + ctx->gcm.Yi.c, ctx->gcm.Xi.u); ctx->gcm.len.u[1] += bulk; bulk += res;