From nobody Tue Dec 05 18:27:34 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 4Sl8CV4z9Dz53JML; Tue, 5 Dec 2023 18:27:34 +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 4Sl8CV1fwyz3Ywl; Tue, 5 Dec 2023 18:27:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701800854; 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=wKPKruljpt9WBpEtB4V8Db9TwVNv7ekdRdPJUX1zDg8=; b=TiTIuHGUTPcCXmf1O8XVqlYF+JuX674IDaNnbo+XkLNAKZuBPu6UnVrKY+8qMLe7/oC1iP uvhNmTejPZcvT0a9OZmC93zehHRI1+R4q6YS5guutrm0sc/hLUb2n4BNoB2R3aHC0Dp0C7 FI+P4ISBqeLzSfytDxqQR2V8Kt4ZkM7OGHfSJb/EINYGBI+VaNP3OYIy4jmlmSbjkBIC4O 1jnTPP+5e2f+AVXhLSqKr06UpscxhraQFnZLx4DuL33vqRlKXlivPGs/0B+YEG3mwXATdl OCu3R6RD5rQ+sAwWX+0fFOB8+K/fAgmfSYIBCVmw9aaYKxZ6J2cPLQJyhXPe0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701800854; a=rsa-sha256; cv=none; b=eVW+h4i4V2qfSKIfHk7dwgYBSqHvf9Cs2ZCiYWhyI/CoGSZf17r8Aury0OZjp59w7uN6QD VA5YboLw22cNoFkMFBb5odpDnSmwyvsMamTOJDdtl14Oi6/gvMzQelLvOUdLUDai4whzk8 CE53jd3SrdM1mUg0HsnYw63uVGr3477JT1We68PjDhJdlKMqXujmSoNaUei4HRRIXHAjg6 gcw7CkJaQHd/vRdf7550ajlk3mOAm5Y9cLvPoFCTaKIRcFZa6ETlXRALazh9dUuQzMTDa3 ZiNA/ug2Ujp/PAI4OaCkKLDw/rDcIa9ha2xPUciWstIu1c8BnSw1KA0/7J45uA== 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=1701800854; 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=wKPKruljpt9WBpEtB4V8Db9TwVNv7ekdRdPJUX1zDg8=; b=JBA+hrHkakiKm+qIaYG5IA5mHXe5djIOQ9BYQs2HIGGK5j5tuh9rgYsxj1D7zxcL8MyG7H cJQC1xVAXBE1pwdOh6vDKIUPElLfKBxbyzMES1UicBcKyk4JI7Gs08VgLjSFVKwA43UMho h8IW864eEbSkQhGY2JfaDOyzDOr8Sp7ugA0HEH9D4L+gDv3IahsOnaV+Ul6CDzJu69pKh/ x7HeVWCQhY1mXSpK88mZG6L7WaC+5PZcpZxZbhGEguKPlNU8HMH6zCx3NPnd1tbmjkkjUA IgCU/PJt076e6cQNlxIHnBeq0aopSxdhna0rjAiBmZ9DVklDL9QF+6yFTsf14A== 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 4Sl8CV0ftxz59w; Tue, 5 Dec 2023 18:27:34 +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 3B5IRY5M009249; Tue, 5 Dec 2023 18:27:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B5IRYfn009246; Tue, 5 Dec 2023 18:27:34 GMT (envelope-from git) Date: Tue, 5 Dec 2023 18:27:34 GMT Message-Id: <202312051827.3B5IRYfn009246@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: 433fe061fc59 - releng/14.0 - 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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 433fe061fc5954fe00b33ed9d850a655920f0a2d Auto-Submitted: auto-generated The branch releng/14.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=433fe061fc5954fe00b33ed9d850a655920f0a2d commit 433fe061fc5954fe00b33ed9d850a655920f0a2d Author: Mark Johnston AuthorDate: 2023-11-29 20:08:12 +0000 Commit: Mark Johnston CommitDate: 2023-12-04 14:02:28 +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 Approved by: so Security: FreeBSD-EN-23:17.ossl (cherry picked from commit 47d767dab54895f3ba8abac6ab2295797394659e) (cherry picked from commit 118b866d9c39da1f5a17680e2034b3eff7337988) --- 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;