Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2436100ioo; Sat, 28 May 2022 13:37:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoXXz+k6hyuUEtJQfzqHHBmKg92FMOac0RxBak4go0ptmM+XxN94V2zL17/ZZOgbFjDEf8 X-Received: by 2002:a17:90a:8914:b0:1dc:20c0:40f4 with SMTP id u20-20020a17090a891400b001dc20c040f4mr15137184pjn.11.1653770246995; Sat, 28 May 2022 13:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770246; cv=none; d=google.com; s=arc-20160816; b=JhQLdEfWAZVPFzsUcYX9mfm5N5UQgRFd6V0lmn/EZn4S52qDpW2FlPHDsLjTr2wORF BclTTjfaK65QrDCvNwKIpjIgaJljigQw4FW7AW/9FMXLx/zwA2Nz8gyK6SSdVa9P19Zv WFdLNCi1NhWy7jmm/0C3Uxk8RaxLxbcTV2EbSBQXQyJPZUte8IVxzl/NylHrBqCgObcZ i5AZadRLs0Cl6I8haO1CxUsYVAWt9m7n4rxffaz7c15y5EvXqZvrt16I/qH347LegU29 FlhvGgwtCtEDgwECN6AOlQi4gK0bOY21TkrogATBnDRNsJjCGNWr/4W52bePEUVv+X/d ABIQ== 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=xWuHumqdORyN4Q/ocOem7jOME2lONxw639fKAmQ3IGY=; b=vD7Is+3CB6otBI6mbA0vZI2dba/vc+y7M8/r54w+t/OAX8dLcfX+c55NBssviCOWQZ 1NUwBQ1p9/tFcK4ij51PaXzJbfnQ0cQhW056HkY0y78Y9lMoscUgToo9Zsz3ohDb9uxR nfFvGu3cWpS/F1bEAk9R3dAh8IOy6tY60W2ztg1NPA/QNUSARYjBytROwKoUOnwwzDMB HZTIHIagXNx8iKzcSJ17lJ+lQxmhcmJB2zcaM5afVayRZk0/uge0e/C2JOTJMYXXj092 hpqFFNEUqUaQ8re719fJq7otM1LndyWTEuvdq1v00cZn0f7rpb61ffEiRMZI3yFOKQDu 9CtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vNWgEuZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x9-20020a170902ec8900b001622e02a816si12301220plg.498.2022.05.28.13.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:37:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vNWgEuZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2BF9D114684; Sat, 28 May 2022 12:39:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350149AbiE0Izn (ORCPT + 99 others); Fri, 27 May 2022 04:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350181AbiE0Iyc (ORCPT ); Fri, 27 May 2022 04:54:32 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22D7D57150; Fri, 27 May 2022 01:53:15 -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 sin.source.kernel.org (Postfix) with ESMTPS id 43FE7CE23C7; Fri, 27 May 2022 08:53:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2193AC385A9; Fri, 27 May 2022 08:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641592; bh=F6HYdTu8y5D04U97NP8ICb8h5IlyZ/Zzy3gf8MAugFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vNWgEuZK358mcOI7OPFprLtUxJWYh0uUqlQ/Drme1IgHqyww8NcOgBjmfJDnE8tIo +P6WfWhOgYwEAX7iskfLzwkTy4T53uqRl2V/M7OhJW7SqWxRxslCUv78abElqldPAT 00yMJmCzP0k4Wd1Q1wDSydJPPjMV09ZPK1AsuY1Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Dominik Brodowski , "Jason A. Donenfeld" Subject: [PATCH 5.18 21/47] random: do not use batches when !crng_ready() Date: Fri, 27 May 2022 10:50:01 +0200 Message-Id: <20220527084804.890256943@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084801.223648383@linuxfoundation.org> References: <20220527084801.223648383@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=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: "Jason A. Donenfeld" commit cbe89e5a375a51bbb952929b93fa973416fea74e upstream. It's too hard to keep the batches synchronized, and pointless anyway, since in !crng_ready(), we're updating the base_crng key really often, where batching only hurts. So instead, if the crng isn't ready, just call into get_random_bytes(). At this stage nothing is performance critical anyhow. Cc: Theodore Ts'o Reviewed-by: Dominik Brodowski Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -465,10 +465,8 @@ static void crng_pre_init_inject(const v if (account) { crng_init_cnt += min_t(size_t, len, CRNG_INIT_CNT_THRESH - crng_init_cnt); - if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { - ++base_crng.generation; + if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) crng_init = 1; - } } spin_unlock_irqrestore(&base_crng.lock, flags); @@ -624,6 +622,11 @@ u64 get_random_u64(void) warn_unseeded_randomness(&previous); + if (!crng_ready()) { + _get_random_bytes(&ret, sizeof(ret)); + return ret; + } + local_lock_irqsave(&batched_entropy_u64.lock, flags); batch = raw_cpu_ptr(&batched_entropy_u64); @@ -658,6 +661,11 @@ u32 get_random_u32(void) warn_unseeded_randomness(&previous); + if (!crng_ready()) { + _get_random_bytes(&ret, sizeof(ret)); + return ret; + } + local_lock_irqsave(&batched_entropy_u32.lock, flags); batch = raw_cpu_ptr(&batched_entropy_u32);