Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6140749iog; Thu, 23 Jun 2022 12:11:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tAXgFkkkrNVAYNF7aZ5L0I7VMjdoD/wUMbfPcwa+cczKE7Jvc5IRZKYPNcMQuQrTsdB32D X-Received: by 2002:a17:906:58cf:b0:722:e4e1:c174 with SMTP id e15-20020a17090658cf00b00722e4e1c174mr9697702ejs.85.1656011494105; Thu, 23 Jun 2022 12:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011494; cv=none; d=google.com; s=arc-20160816; b=n/PVIPyYawsC+WW6l//QND8HV9Zs0IeJPbtrMiY7SxIS102Hx5fYqC9hGvT4w+EE60 jiKVuOF1cWcvbq2jcF/FhjQN9Dp4ayddeJ64y+S95Jkh1RJH7Y/ypojc9y9bxAcdTW3k DqlQ7Cq/Vn7eSmIbs66OEXvxY8YqQatOriwVnhojw2WAp1Wdxw4mpY/x9xCGqGIGYhZ+ zX6xmcXtadjzZAV9iMpHqXbLxQ3WNLVvGwcAVHcHN1+hAxNmeCV2LKXgZJLMrnx0MrYp FhtU4jUNw8fiQwSnzBzXzycK+egm5lvlU+692nXudxRzfG7Xltu4JujtJdBRRDBz5gHR D3UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kzblqb0veU6cX/wMBOCG7CCOAwstN/U6MLcz6jzaPkE=; b=SN/W8SR/oQdd40rDf+DEhA0p6T5Z0Rv5mNHSLI7djf+9ep0tL2ecNewoUOw9BVSX9I gsxROLLnw83Pct7KhV+trP+CYatmxwFYBBT059tZVQQ2pdCB0QQnB5BEDpM0UtJlTn62 jCmuUO7Vcw5vYVyPpzKL2PtedakgOwUFQt9OilEgVgvF/tegkDhWHtDFt+FR4eaCEKvD YajEGFoTzS/CXpf3OWTGMmR/T9GMvb/rhn8pWnNSuKiSpnLeFV7ZqWvg9GduyTQEnqHR lX+jS/9rFAykRWMdB14WyKJEmckYw9X7zzkjo3fqwp8RVeDqBbJIE/PGFBFPDSRcGgGx /2aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hJ9yZjUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ha25-20020a170906a89900b007262a4865e0si1857296ejb.931.2022.06.23.12.11.07; Thu, 23 Jun 2022 12:11:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hJ9yZjUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236672AbiFWSTo (ORCPT + 99 others); Thu, 23 Jun 2022 14:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236819AbiFWSQn (ORCPT ); Thu, 23 Jun 2022 14:16:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C95EB7F5; Thu, 23 Jun 2022 10:23:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B656D61EA7; Thu, 23 Jun 2022 17:23:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DB4EC3411B; Thu, 23 Jun 2022 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004986; bh=UrZM801TqwRIICsVfAzJac2y0NOGz5tf/BvbH6vMcOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJ9yZjUgJCzv4rQDbU3j7PCZNUi9Y4W9rC/AJNYr1Dgc0/SfnFkCnZBSQwxzoIswG 2+rBfYFv2ACZ9Oq81Si/qnlZnUXOtu2FgWnkT06wTykHTIWPYY0S0qnGYHnID0qVQU 115MQgttCmod4OeheV5l70ozzupf8Mcn3UMtwS5k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Mueller , Herbert Xu , "Jason A. Donenfeld" Subject: [PATCH 4.19 172/234] crypto: drbg - always seeded with SP800-90B compliant noise source Date: Thu, 23 Jun 2022 18:43:59 +0200 Message-Id: <20220623164347.919133423@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Stephan M?ller" commit 97f2650e504033376e8813691cb6eccf73151676 upstream. As the Jitter RNG provides an SP800-90B compliant noise source, use this noise source always for the (re)seeding of the DRBG. To make sure the DRBG is always properly seeded, the reseed threshold is reduced to 1<<20 generate operations. The Jitter RNG may report health test failures. Such health test failures are treated as transient as follows. The DRBG will not reseed from the Jitter RNG (but from get_random_bytes) in case of a health test failure. Though, it produces the requested random number. The Jitter RNG has a failure counter where at most 1024 consecutive resets due to a health test failure are considered as a transient error. If more consecutive resets are required, the Jitter RNG will return a permanent error which is returned to the caller by the DRBG. With this approach, the worst case reseed threshold is significantly lower than mandated by SP800-90A in order to seed with an SP800-90B noise source: the DRBG has a reseed threshold of 2^20 * 1024 = 2^30 generate requests. Yet, in case of a transient Jitter RNG health test failure, the DRBG is seeded with the data obtained from get_random_bytes. However, if the Jitter RNG fails during the initial seeding operation even due to a health test error, the DRBG will send an error to the caller because at that time, the DRBG has received no seed that is SP800-90B compliant. Signed-off-by: Stephan Mueller Signed-off-by: Herbert Xu Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- crypto/drbg.c | 26 +++++++++++++++++++------- include/crypto/drbg.h | 6 +----- 2 files changed, 20 insertions(+), 12 deletions(-) --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1087,10 +1087,6 @@ static void drbg_async_seed(struct work_ if (ret) goto unlock; - /* If nonblocking pool is initialized, deactivate Jitter RNG */ - crypto_free_rng(drbg->jent); - drbg->jent = NULL; - /* Set seeded to false so that if __drbg_seed fails the * next generate call will trigger a reseed. */ @@ -1168,7 +1164,23 @@ static int drbg_seed(struct drbg_state * entropylen); if (ret) { pr_devel("DRBG: jent failed with %d\n", ret); - goto out; + + /* + * Do not treat the transient failure of the + * Jitter RNG as an error that needs to be + * reported. The combined number of the + * maximum reseed threshold times the maximum + * number of Jitter RNG transient errors is + * less than the reseed threshold required by + * SP800-90A allowing us to treat the + * transient errors as such. + * + * However, we mandate that at least the first + * seeding operation must succeed with the + * Jitter RNG. + */ + if (!reseed || ret != -EAGAIN) + goto out; } drbg_string_fill(&data1, entropy, entropylen * 2); @@ -1493,6 +1505,8 @@ static int drbg_prepare_hrng(struct drbg if (list_empty(&drbg->test_data.list)) return 0; + drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); + INIT_WORK(&drbg->seed_work, drbg_async_seed); drbg->random_ready.notifier_call = drbg_schedule_async_seed; @@ -1511,8 +1525,6 @@ static int drbg_prepare_hrng(struct drbg return err; } - drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); - /* * Require frequent reseeds until the seed source is fully * initialized. --- a/include/crypto/drbg.h +++ b/include/crypto/drbg.h @@ -184,11 +184,7 @@ static inline size_t drbg_max_addtl(stru static inline size_t drbg_max_requests(struct drbg_state *drbg) { /* SP800-90A requires 2**48 maximum requests before reseeding */ -#if (__BITS_PER_LONG == 32) - return SIZE_MAX; -#else - return (1UL<<48); -#endif + return (1<<20); } /*