From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9488031CA42; Mon, 27 Oct 2025 19:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591744; cv=none; b=OqexhKAB0mVObKzyPdf4DyIeWOiUxM1XWIhCV57kchRQrG+42UncmS4mnHd5LmEWDGAupWsK78/b2LpKZdqmJQ4YXKE+6Wwuh/GAWS9HBXXwEVVukLoDjijQJZtCaJAoZ+V7W+YH6G/XAWaqddOw0wUtCvbUWglQ6w9Dda1sWt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591744; c=relaxed/simple; bh=BkdFrpAZygrlRbKIEbAFDY9JDtG5cgfPHMmAGr3fR1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vf1F7q8EwMKOEPdbxrFTf92n6AeBOLWhgjmOq++4lqSAI6sP1UIrrrslap4sPPGIuqX/6Nw67YCcFb06iG9y9aYOd6MDQpp8lgFlS9hRsYqaicHJxjeKfm9bjbQTXEThah5TTUNxx6BVW4IZ9Q0Q9amCEZwVXxX/+DVXedhAwXA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LjHaM3+B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LjHaM3+B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2763FC4CEF1; Mon, 27 Oct 2025 19:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591744; bh=BkdFrpAZygrlRbKIEbAFDY9JDtG5cgfPHMmAGr3fR1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjHaM3+ByiQm4HR/BFNRw6wN1m+kK9hhNENWw1x0srYWKOjQVg8lh/ro35Hnd/qGT AIFgkVRVgYbY9NHKTCjKcutZupE2f9d8Gua0aiUOgUWcbFuYTCC9lQLL028Qgh1Dme 45K6nHK2+ujcHsqh7Uzo8CVud0Ae+0gDFdHnIxN8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Biggers , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 5.10 315/332] KEYS: trusted_tpm1: Compare HMAC values in constant time Date: Mon, 27 Oct 2025 19:36:08 +0100 Message-ID: <20251027183533.178936248@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers [ Upstream commit eed0e3d305530066b4fc5370107cff8ef1a0d229 ] To prevent timing attacks, HMAC value comparison needs to be constant time. Replace the memcmp() with the correct function, crypto_memneq(). [For the Fixes commit I used the commit that introduced the memcmp(). It predates the introduction of crypto_memneq(), but it was still a bug at the time even though a helper function didn't exist yet.] Fixes: d00a1c72f7f4 ("keys: add new trusted key-type") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen [ replaced crypto/utils.h include with crypto/algapi.h ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- security/keys/trusted-keys/trusted_tpm1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -248,7 +249,7 @@ int TSS_checkhmac1(unsigned char *buffer if (ret < 0) goto out; - if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE)) + if (crypto_memneq(testhmac, authdata, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: kfree_sensitive(sdesc); @@ -341,7 +342,7 @@ static int TSS_checkhmac2(unsigned char TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0); if (ret < 0) goto out; - if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) { + if (crypto_memneq(testhmac1, authdata1, SHA1_DIGEST_SIZE)) { ret = -EINVAL; goto out; } @@ -350,7 +351,7 @@ static int TSS_checkhmac2(unsigned char TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0); if (ret < 0) goto out; - if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE)) + if (crypto_memneq(testhmac2, authdata2, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: kfree_sensitive(sdesc);