Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp622629imu; Thu, 13 Dec 2018 01:20:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vi+ZcAnjvshGEM0r6bWj0Qtks7wSGFKkK6fSkjmjWEvTIaztjGuEVSNVaqcGsclxhhRzeS X-Received: by 2002:a62:32c4:: with SMTP id y187mr24277589pfy.195.1544692847820; Thu, 13 Dec 2018 01:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544692847; cv=none; d=google.com; s=arc-20160816; b=cV2bNxfj/97MgIyUbpiGq4OupGHuzTIkFNhCIp5OYY/xOEqELXoNzmk0Oc3kAgtzD5 llC+dy/ays3QTTWKkUy8g2VZHbyFyREH8fbqgif6dpK1daU65OuRUtoLcb46ipWB5dFF iQ3BuBzPzQkmUfY4X+8KSn0oFkAGtHDtd+lUBZIBuPo0WH/LcqnfvghTWiCuiLzXLtaO LyjcDLkA78Y0wt2tZGWNiCjI8yo0KosoEuyheVf13xbIu7XovQp5SO/GppF5QJoqZ9EM dGwxzIuhACvS7FWj/ROBFTjWspiZagmtru0cPuD/JGsmmVxkaj3vnctekEoh/lOLRzv9 mZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=LNSa3KiH1ZL0pwlhIbt5LEsdkwR+MuAQ2Tqqh2Nb6jk=; b=pTQcl1OvklRgifqlfATiyPeSlyG+Tl9LUOO1DMuETT7AUrnHwV2FwOOJ2fePcCDWKA FBqORbbcvSXMi+hypKMqoL19G+651FRGMWGD3A8GE+4uIJhwGNWQ1ozAvk+2Nr35oxio doV3ac5U1DyVxziSZztGa6fxq9lC8L1jqOogVjDZQ9+wB+f4MJ3zLu5Ae9a+I6tVbf0k 6ozheDgpuYS6fYOyZ2FYTMgEWaN/VuzKyl+/4I6LXOIGg/aEumFOlZiVg7a7N2BO9Efl G6RfvoDNsPKrvCMfo/3HYunN1Ir4GJjf0eisr7pMKaR+zNySs2vspDGMiWXTp21vdvXd RI1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="D5+Xz1G/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si1091091pgi.513.2018.12.13.01.20.33; Thu, 13 Dec 2018 01:20:47 -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; dkim=pass header.i=@chromium.org header.s=google header.b="D5+Xz1G/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbeLMJS4 (ORCPT + 99 others); Thu, 13 Dec 2018 04:18:56 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37570 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727063AbeLMJS4 (ORCPT ); Thu, 13 Dec 2018 04:18:56 -0500 Received: by mail-pg1-f195.google.com with SMTP id 80so775976pge.4 for ; Thu, 13 Dec 2018 01:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=LNSa3KiH1ZL0pwlhIbt5LEsdkwR+MuAQ2Tqqh2Nb6jk=; b=D5+Xz1G/TtOhctI8i9iw6O01K4ZlYJYuxze9D25tctDp6gDiz4p5U3EUp2IOTXFYtP IUISvHL1n1L4bmE5RQa2qb1rp1exwRt2CZendLiY5luv9aRL6z76zwtHWlEzybY0iAy1 qH3v96jyaE4Hex9kCfyItkkpYcslnvQs+Hbgk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LNSa3KiH1ZL0pwlhIbt5LEsdkwR+MuAQ2Tqqh2Nb6jk=; b=pSP0ppbI6vm1XGlil6oxCOD0MRJV8S++ohk+YHNxQDv8KEEb/c5tU7GgXDvIat2zX7 OJ75sQlDzQ1aCh32YSyi6sWBtgTKmzOXEg3c48kDvLOMCJJNlJU+y07icBxI5VD67HHl +REigRY43gNfbggTuN6v+K798S7UfHwuxs1SbVFXNn1qbimSawurbWdTcObZmvxxD9bY tUW0i3/DhH00WPvy64M0Fcxl8XRuZKd+W6FMJ34RuF9HQ3QGc00E8hHARdCtJPO5sCz8 cgpRjUvghQsaqFC0NDx7iRjkWuccqD8JBgXDUuQbgZZQ5vRDT+L2T79SfpbHw3mKVucA J1+g== X-Gm-Message-State: AA+aEWYQpU3CiHJazn+n1LiBTqF2r/iit7QeVxWBV6qcGFtlZK3WNdQI Qnii2zHQQCU0Hay8UAGf66hHaW4heiY= X-Received: by 2002:a63:9749:: with SMTP id d9mr18209125pgo.415.1544692734840; Thu, 13 Dec 2018 01:18:54 -0800 (PST) Received: from excession.tpe.corp.google.com ([2401:fa00:1:10:b167:8a11:31b5:8daa]) by smtp.gmail.com with ESMTPSA id i123sm2683186pfg.164.2018.12.13.01.18.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Dec 2018 01:18:54 -0800 (PST) From: Louis Collard To: linux-crypto@vger.kernel.org Cc: Matt Mackall , Herbert Xu , Arnd Bergmann , Greg Kroah-Hartman , Gary R Hook , Michael Buesch , PrasannaKumar Muralidharan , Louis Collard , "Michael S . Tsirkin" , linux-kernel@vger.kernel.org, apronin@chromium.org, jarkko.sakkinen@linux.intel.com, linux@mniewoehner.de, david.bild@xaptum.com, tytso@mit.edu Subject: [PATCH v2] Allow hwrng to initialize crng. Date: Thu, 13 Dec 2018 17:18:48 +0800 Message-Id: <20181213091848.81327-1-louiscollard@chromium.org> X-Mailer: git-send-email 2.13.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 95be7228f327..7736e1a96321 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,19 @@ 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 = min_t(size_t, + 2*CHACHA20_KEY_SIZE, + rng_buffer_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) -- 2.13.5