From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796290429; b=bUC+FabDc7KdbHWoGORAQcdreyvVSS3Osh9GaV4bUnWicXP43bh/qg3tjGj9+herDl4v hN6uSQbYdhVzD307cnFWVxvPUEyXyc2Q1VKE3i0VsLodKY/A13yoGZBXD3XMIy3gy6SAo x+qAEU97nau+BtbZ7PYDdhBJtdpXe06q3JwLIDH3IiyiXQfThcvvPNv+mAWXQkab71YOY Um+yOGWtIuO/07wT06WypEN2WvwdpQbbmxbvGHSXNgvZv5bJDHH018EVym6TDccGhtVzV MIDyf2jZ4Ya+giB3Tms6VrplMs5haldPLRgBZqHTAYpse5uiBR2yuquEbNldJiUaZtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796290429; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=+gxIyDiQaFXMk25Mjp8tmsGfm7SIozVw4RduxBviVRc=; b=zqy0IpKLc08shMiS6hQ6ndB8dFs5vrHJWMV6LP7gjukiMm8TbFQy79dvLIzQtxM5AuSI RurgEEpfomXSMyLHVERVijeiYUefBQW71U44gKvN4UzDXFBqHoNY50ntBQTNr2tZiG2GF u1zvXDy7bAl+jFWyyAKIJkAzntMvDUtz05bXgN162mIdDmesZ9egVScut2yiDh8Y7psJs JwqmIIycsYn1uPQwciIwfDj44x7G1A2XssmG95m0UuOI/BgkuyeQ+lao5CCSA8vwYWAG1 ZWklicLJhNW5kndGJkwEf6N1YYaU3p0HDRLJqqV0CYimTfmpTj/cdWniglb2aMYKdcQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C49IS3mo; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D6DD606A332 for ; Thu, 3 Dec 2026 09:33:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5D6DD606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C49IS3mo DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796290428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+gxIyDiQaFXMk25Mjp8tmsGfm7SIozVw4RduxBviVRc=; b=C49IS3moWeODHRjc9WF9lPdMyP0ahAIowhfKe2JZpn3PFwuBSJ9liHkF3nQxeKvP63ELsb UHg+AIRsLBGrYAHkb7ZMR6U+ZK3sx4tMwMcOaZiNRNkl0+gc6y09o+dODvg9blcmTl0WN0 sTsZXzUcbkBC/BNtdFRlsw4EjxiOJQQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-bY66gBTNPbGB_tCnxSCgiA-1; Thu, 3 Dec 2026 09:33:29 +0000 X-MC-Unique: bY66gBTNPbGB_tCnxSCgiA-1 X-Mimecast-MFC-AGG-ID: bY66gBTNPbGB_tCnxSCgiA_1796290408 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED5B41964CD8; Thu, 3 Dec 2026 09:33:27 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5F9AB82; Thu, 3 Dec 2026 09:33:25 +0000 (UTC) From: Thomas Huth To: Herbert Xu , linux-crypto@vger.kernel.org Cc: "David S. Miller" , Eric Biggers , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 3/4] crypto: fips - Add back the lost key length check to the hmac(sha256) algorithm Date: Thu, 3 Dec 2026 10:33:15 +0100 Message-ID: <20261203093316.97847-4-thuth@redhat.com> In-Reply-To: <20261203093316.97847-1-thuth@redhat.com> References: <20261203093316.97847-1-thuth@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 The generic code in hmac_setkey() in crypto/hmac.c rejects keys with less than 112 bits in FIPS-compliance mode. However, this check got lost when the hmac(sha224) and hmac(sha256) algorithms were implemented via the crypto library. Let's restore the same behavior from kernel v6.16 and earlier by adding the key length check to the crypto/sha256.c file, too. Cc: stable@vger.kernel.org # 6.19+, see https://lore.kernel.org/all/20261201202148.GA501764@google.com/ Fixes: e0cd371691038 ("crypto: sha256 - Wrap library and add HMAC support") Signed-off-by: Thomas Huth --- crypto/sha256.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crypto/sha256.c b/crypto/sha256.c index fb81defe084c6..a27fc5ca1f92d 100644 --- a/crypto/sha256.c +++ b/crypto/sha256.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include @@ -187,6 +188,9 @@ static int crypto_sha256_import_core(struct shash_desc *desc, const void *in) static int crypto_hmac_sha224_setkey(struct crypto_shash *tfm, const u8 *raw_key, unsigned int keylen) { + if (fips_hmac_keylen_disallowed(keylen)) + return -EINVAL; + hmac_sha224_preparekey(HMAC_SHA224_KEY(tfm), raw_key, keylen); return 0; } @@ -254,6 +258,9 @@ static int crypto_hmac_sha224_import_core(struct shash_desc *desc, static int crypto_hmac_sha256_setkey(struct crypto_shash *tfm, const u8 *raw_key, unsigned int keylen) { + if (fips_hmac_keylen_disallowed(keylen)) + return -EINVAL; + hmac_sha256_preparekey(HMAC_SHA256_KEY(tfm), raw_key, keylen); return 0; } -- 2.56.1