From patchwork Tue Nov 30 14:10:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 516995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12515C433EF for ; Tue, 30 Nov 2021 14:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236418AbhK3ON5 (ORCPT ); Tue, 30 Nov 2021 09:13:57 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:60350 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbhK3ONz (ORCPT ); Tue, 30 Nov 2021 09:13:55 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ADDED21891; Tue, 30 Nov 2021 14:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1638281435; h=from:from:reply-to: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=rDuo7pVZQTFs4L5N2DQh9ls5njhAaSZRsIp1d0oOqqM=; b=MycXBvQZy+GhLoWQ7GNY9rDq4mB3nDKifmrEY4aL7chFMNKTe8iWIW3Gt452qksK7xjpK8 yagjWkXKUWtHUSglmWsG292wQDVUKUak3z5rAs5nOGfJJ4RIXBmFgvYqqq5BccV9mcYDHT eFCkq8eDRIouyiWbpB9rBYjkqhMt2Zc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1638281435; h=from:from:reply-to: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=rDuo7pVZQTFs4L5N2DQh9ls5njhAaSZRsIp1d0oOqqM=; b=BdYWYQ0RA7zY45InW2ROkYg0LVk6BEQf8XrnQ4OAZwvQLijXJYqlXO6OvIkHyR4HRgRLit PIlqmbj/qs/gg3BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 91A7613D4E; Tue, 30 Nov 2021 14:10:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id K+L6IdswpmFzLgAAMHmgww (envelope-from ); Tue, 30 Nov 2021 14:10:35 +0000 From: Nicolai Stange To: =?utf-8?q?Stephan_M=C3=BCller?= , Herbert Xu , "David S. Miller" Cc: Torsten Duwe , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 1/3] crypto: drbg - ignore jitterentropy errors if not in FIPS mode Date: Tue, 30 Nov 2021 15:10:07 +0100 Message-Id: <20211130141009.6791-2-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211130141009.6791-1-nstange@suse.de> References: <20211130141009.6791-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org A subsequent patch will make the jitterentropy RNG to unconditionally report health test errors back to callers, independent of whether fips_enabled is set or not. The DRBG needs access to a functional jitterentropy instance only in FIPS mode (because it's the only SP800-90B compliant entropy source as it currently stands). Thus, it is perfectly fine for the DRBGs to obtain entropy from the jitterentropy source only on a best effort basis if fips_enabled is off. Make the DRBGs to ignore jitterentropy failures if fips_enabled is not set. Signed-off-by: Nicolai Stange Reviewed-by: Stephan Mueller --- crypto/drbg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/drbg.c b/crypto/drbg.c index 5977a72afb03..177983b6ae38 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1193,11 +1193,14 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, pr_devel("DRBG: (re)seeding with %u bytes of entropy\n", entropylen); } else { - /* Get seed from Jitter RNG */ + /* + * Get seed from Jitter RNG, failures are + * fatal only in FIPS mode. + */ ret = crypto_rng_get_bytes(drbg->jent, entropy + entropylen, entropylen); - if (ret) { + if (fips_enabled && ret) { pr_devel("DRBG: jent failed with %d\n", ret); /* From patchwork Tue Nov 30 14:10:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 519433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCFB9C433F5 for ; Tue, 30 Nov 2021 14:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236629AbhK3ON6 (ORCPT ); Tue, 30 Nov 2021 09:13:58 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:60360 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236619AbhK3ON5 (ORCPT ); Tue, 30 Nov 2021 09:13:57 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4916D212B9; Tue, 30 Nov 2021 14:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1638281437; h=from:from:reply-to: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=dnEkwdPdKAGHHGEF5tN3IGx4PVT9y27Bh+g38lvNuD8=; b=IrZVVeItAjLfU3plqmvLpiZ+EgpBKl4wr3oTUnlRawpj0tDyhxXs3KJUe/J+M1Dpf0Z4cA 2vu6d9eyAQd18otipYRqd9UT6DPI2DlZH0wmE3/fO8HPQitv0GrxvCPC3VXoOvagASd4Me JfocHcGufjJtcQLlWUt7zgQk2D7AJoc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1638281437; h=from:from:reply-to: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=dnEkwdPdKAGHHGEF5tN3IGx4PVT9y27Bh+g38lvNuD8=; b=sPNMXm29oqfapF1QVtdvr9ljx8SRLPUiqcW/RXV6fxnlJ7kFihwQJRBGgM8CKfTs4d5deO leDadFFmX4VlHsDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3139E13D4E; Tue, 30 Nov 2021 14:10:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xicGC90wpmF3LgAAMHmgww (envelope-from ); Tue, 30 Nov 2021 14:10:37 +0000 From: Nicolai Stange To: =?utf-8?q?Stephan_M=C3=BCller?= , Herbert Xu , "David S. Miller" Cc: Torsten Duwe , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 2/3] crypto: jitter - don't limit ->health_failure check to FIPS mode Date: Tue, 30 Nov 2021 15:10:08 +0100 Message-Id: <20211130141009.6791-3-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211130141009.6791-1-nstange@suse.de> References: <20211130141009.6791-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The jitterentropy's Repetition Count Test (RCT) as well as the Adaptive Proportion Test (APT) are run unconditionally on any collected samples. However, their result, i.e. ->health_failure, will only get checked if fips_enabled is set, c.f. the jent_health_failure() wrapper. I would argue that a RCT or APT failure indicates that something's seriously off and that this should always be reported as an error, independently of whether FIPS mode is enabled or not: it should be up to callers whether or not and how to handle jitterentropy failures. Make jent_health_failure() to unconditionally return ->health_failure, independent of whether fips_enabled is set. Note that fips_enabled isn't accessed from the jitterentropy code anymore now. Remove the linux/fips.h include as well as the jent_fips_enabled() wrapper. Signed-off-by: Nicolai Stange --- crypto/jitterentropy-kcapi.c | 6 ------ crypto/jitterentropy.c | 4 ---- crypto/jitterentropy.h | 1 - 3 files changed, 11 deletions(-) diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c index e8a4165a1874..2d115bec15ae 100644 --- a/crypto/jitterentropy-kcapi.c +++ b/crypto/jitterentropy-kcapi.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include @@ -60,11 +59,6 @@ void jent_zfree(void *ptr) kfree_sensitive(ptr); } -int jent_fips_enabled(void) -{ - return fips_enabled; -} - void jent_panic(char *s) { panic("%s", s); diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index 788d90749715..24e087c3f526 100644 --- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c @@ -298,10 +298,6 @@ static int jent_stuck(struct rand_data *ec, __u64 current_delta) */ static int jent_health_failure(struct rand_data *ec) { - /* Test is only enabled in FIPS mode */ - if (!jent_fips_enabled()) - return 0; - return ec->health_failure; } diff --git a/crypto/jitterentropy.h b/crypto/jitterentropy.h index c83fff32d130..b7397b617ef0 100644 --- a/crypto/jitterentropy.h +++ b/crypto/jitterentropy.h @@ -2,7 +2,6 @@ extern void *jent_zalloc(unsigned int len); extern void jent_zfree(void *ptr); -extern int jent_fips_enabled(void); extern void jent_panic(char *s); extern void jent_memcpy(void *dest, const void *src, unsigned int n); extern void jent_get_nstime(__u64 *out); From patchwork Tue Nov 30 14:10:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 516994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBEACC43217 for ; Tue, 30 Nov 2021 14:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236814AbhK3ON7 (ORCPT ); Tue, 30 Nov 2021 09:13:59 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:60380 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236613AbhK3ON6 (ORCPT ); Tue, 30 Nov 2021 09:13:58 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B78D521892; Tue, 30 Nov 2021 14:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1638281438; h=from:from:reply-to: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=hQhE8yGgIftiH52A4CWTfhYlnu/uKm6rar23ZjE1g3o=; b=aeJVE1FSV0RHgteozLe3XORqMLb6MMqMztrFgX6zfnf1E23LZRpbBUl60rNhTY2DqlDIH7 DNuYrsxOUBPBykeUyx7NEjtye1nCRpPgeqLOv7VxVcsLTXUdxHGxyivPx9GymTa6Wpvb0s tH8PX5f6yqdKx7SgLgTUfktObnQgIhU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1638281438; h=from:from:reply-to: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=hQhE8yGgIftiH52A4CWTfhYlnu/uKm6rar23ZjE1g3o=; b=c6M2CeKp2xc7kB3QI2ga49txlMS65eLPFlgQg+z/aN1iMAmltVyyAQ8ecvDtbwWnGDGz/w 0zPwpkJGbaOVtODw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A366213D4E; Tue, 30 Nov 2021 14:10:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id p/XRJt4wpmF5LgAAMHmgww (envelope-from ); Tue, 30 Nov 2021 14:10:38 +0000 From: Nicolai Stange To: =?utf-8?q?Stephan_M=C3=BCller?= , Herbert Xu , "David S. Miller" Cc: Torsten Duwe , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 3/3] crypto: jitter - quit sample collection loop upon RCT failure Date: Tue, 30 Nov 2021 15:10:09 +0100 Message-Id: <20211130141009.6791-4-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211130141009.6791-1-nstange@suse.de> References: <20211130141009.6791-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The jitterentropy collection loop in jent_gen_entropy() can in principle run indefinitely without making any progress if it only receives stuck measurements as determined by jent_stuck(). After 31 consecutive stuck samples, the Repetition Count Test (RCT) would fail anyway and the jitterentropy RNG instances moved into ->health_failure == 1 state. jent_gen_entropy()'s caller, jent_read_entropy() would then check for this ->health_failure condition and return an error if found set. It follows that there's absolutely no point in continuing the collection loop in jent_gen_entropy() once the RCT has failed. Make the jitterentropy collection loop more robust by terminating it upon jent_health_failure() so that it won't continue to run indefinitely without making any progress. Signed-off-by: Nicolai Stange Reviewed-by: Stephan Mueller --- crypto/jitterentropy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index 24e087c3f526..8f5283f28ed3 100644 --- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c @@ -547,7 +547,7 @@ static void jent_gen_entropy(struct rand_data *ec) /* priming of the ->prev_time value */ jent_measure_jitter(ec); - while (1) { + while (!jent_health_failure(ec)) { /* If a stuck measurement is received, repeat measurement */ if (jent_measure_jitter(ec)) continue;