Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp926177imu; Sat, 17 Nov 2018 12:16:54 -0800 (PST) X-Google-Smtp-Source: AJdET5eo5aIj+bavZ6wGt2ZLLloQ8j4lhEHcPq1f+Fv0j4JnJlBnee6itA80bX3QALLlSEVFbCwp X-Received: by 2002:a63:2315:: with SMTP id j21mr14759968pgj.297.1542485814471; Sat, 17 Nov 2018 12:16:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542485814; cv=pass; d=google.com; s=arc-20160816; b=F9FBZdmp7yaxlnatCCKe+QM8EzG1plAPyf+1dYCKdSJBST+Sa/3Pe+tWyjRH0EKwr1 J9qEtg1KJPJsjiDHhyQ+IAAHmN+uFSBPPJ18gItUHrP6Jmktwq8XmRYQ05LiZJjIgSFa aeNo7HsBOfcP7J1/kJmUs1OXjrq86OIdSeh1xasQzR/wmE9oWYS/MNCNYI/b1VLYNGpv juw1JAe4ffAuCD+uAKnGNBI2wAWJUEYsBTzBpJO/AJbWCyJt51RDA7oWADw38GFK7nB3 mJDDBHZFXJ0H17Jf4GKs3AP3Ro8VvWKhE/a8OPgZBO3qRHSuU+FTTsXTDztQa4qElGLt s6bQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:references:in-reply-to:cc:to:from:subject:message-id; bh=msrNFitDTuhne6hzcdz+5zKDQbarSW+zE6EKA7b+4K0=; b=hLMZWSGlaFqrF7/33XbAleXy7kx1js677LsCZRoPpGz7H8wzsjA/bjXTOv9qLjkk/+ D6VrIAZbY84Xr5A9Y6bgNpqDv7dwssLpfHofLRPZ3HKUpaBW6Vvu5gXH7f6gnLjEib6n kE466m77rZpaovmUwCQ3D2vFfvsS4WY+qmr8eh9vrIQiP09VpDQDwtZ5IWbnWw6hD32v cRVz1fa+22sDHQzOIDrGl0+txU+71RVO2/snsHdQ7+n32N5SglNKVLvYNKRgYZDIEmIc Ciubw7bMq95o2Z8+r37fv++Bn9EY+6oiXoWSQXbVqWlDIz/JxNecIuMCaIa8vlOIst++ 4Jdw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=mniewoehner.de dkim=pass dkdomain=mniewoehner.de dmarc=pass fromdomain=mniewoehner.de>); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si10139447pgv.431.2018.11.17.12.16.39; Sat, 17 Nov 2018 12:16:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=mniewoehner.de dkim=pass dkdomain=mniewoehner.de dmarc=pass fromdomain=mniewoehner.de>); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbeKRGdt (ORCPT + 99 others); Sun, 18 Nov 2018 01:33:49 -0500 Received: from sender-of-o53.zoho.com ([135.84.80.218]:21703 "EHLO sender-of-o53.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725732AbeKRGdt (ORCPT ); Sun, 18 Nov 2018 01:33:49 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1542485738; cv=none; d=zoho.com; s=zohoarc; b=c5wAj65ZHymBfCUwwXAUODUl7cbn2/KsfhGG+jEQi3euUt6hIfNwIfRjLWR/fOjH4MSJc1NOzS2ZuL+UuDts3t9m4H4iyWz+NxcuojVMlfjj733jT1BKuNPcX1JiM4KtcS3FWU/d8b+x1EZNKpIm2fkqVd/ECpq9H6TV1XIbEDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1542485738; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=msrNFitDTuhne6hzcdz+5zKDQbarSW+zE6EKA7b+4K0=; b=jZMqeqe65HKyBkHxLYiuZa+ooMhQeF0bhkrJ4QMXJfPSO0ytQfrWNpUtRvyu598twtTR6PE6Q3ObmKBDeuZxuLpHyufXo/GJBvIeGIybPfqr3cqna0+WaPwIaRTg2UtEjBNuh6ElTcvMImHh8xrPXG+7Nc1Mp45Tw67OfZiI3yo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=mniewoehner.de; spf=pass smtp.mailfrom=linux@mniewoehner.de; dmarc=pass header.from= header.from= Received: from z3r0 (31.187.91.78 [31.187.91.78]) by mx.zohomail.com with SMTPS id 1542485736387545.3812507833644; Sat, 17 Nov 2018 12:15:36 -0800 (PST) Message-ID: <568ea3447a8116ef460d191bf3599e2761bca3a5.camel@mniewoehner.de> Subject: Re: [PATCH] Allow hwrng to initialize crng. From: Michael =?ISO-8859-1?Q?Niew=F6hner?= To: Louis Collard Cc: linux-integrity@vger.kernel.org, Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jarkko Sakkinen , apronin@chromium.org, Jason Gunthorpe , david.bild@xaptum.com In-Reply-To: <20180926032455.224600-1-louiscollard@chromium.org> References: <20180926032455.224600-1-louiscollard@chromium.org> Content-Type: text/plain; charset="UTF-8" Date: Sat, 17 Nov 2018 21:15:32 +0100 Mime-Version: 1.0 X-Mailer: Evolution 3.28.5 Content-Transfer-Encoding: 7bit X-ZohoMailClient: External Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Louis, On Wed, 2018-09-26 at 11:24 +0800, Louis Collard wrote: > Some systems, for example embedded systems, do not generate > enough entropy on boot through interrupts, and boot may be blocked for > several minutes waiting for a call to getrandom to complete. > > Currently, random data is read from a hwrng when it is registered, > and is loaded into primary_crng. This data is treated in the same > way as data that is device-specific but otherwise unchanging, and > so primary_crng cannot become initialized with the data from the > hwrng. > > This change causes the data initially read from the hwrng to be > treated the same as subsequent data that is read from the hwrng if > it's quality score is non-zero. > > The implications of this are: > > The data read from hwrng can cause primary_crng to become > initialized, therefore avoiding problems of getrandom blocking > on boot. > > Calls to getrandom (with GRND_RANDOM) may be using entropy > exclusively (or in practise, almost exclusively) from the hwrng. > > Regarding the latter point; this behavior is the same as if a > user specified a quality score of 1 (bit of entropy per 1024 bits) > so hopefully this is not too scary a change to make. > > This change is the result of the discussion here: > https://patchwork.kernel.org/patch/10453893/ > > Signed-off-by: Louis Collard > Acked-by: Jarkko Sakkinen > --- > drivers/char/hw_random/core.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c > index aaf9e5afaad4..47f358aa0c3d 100644 > --- a/drivers/char/hw_random/core.c > +++ b/drivers/char/hw_random/core.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > > #define RNG_MODULE_NAME "hw_random" > > @@ -64,13 +65,17 @@ static size_t rng_buffer_size(void) > static void add_early_randomness(struct hwrng *rng) > { > int bytes_read; > - size_t size = min_t(size_t, 16, rng_buffer_size()); > + /* Read enough to initialize crng. */ > + size_t size = 2*CHACHA20_KEY_SIZE; > > mutex_lock(&reading_mutex); > bytes_read = rng_get_data(rng, rng_buffer, size, 1); > mutex_unlock(&reading_mutex); > if (bytes_read > 0) > - add_device_randomness(rng_buffer, bytes_read); > + /* Allow crng to become initialized, but do not add > + * entropy to the pool. > + */ > + add_hwgenerator_randomness(rng_buffer, bytes_read, 0); > } > > static inline void cleanup_rng(struct kref *kref) I found your patch by chance, searching for a solution for crng init delay on my headless machine. Unfortunately it hardly makes any difference for me. With the patch the system hangs for about 80s instead of 120s until the "crng init done" message.In contrast, doing a `cat /dev/hwrng >/dev/random` or running rngd initializes the crng instantly. Isn't that delay the problem this patch tries to fix? Any idea what is wrong here? Thanks! Best regards Michael