Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp233754imm; Tue, 25 Sep 2018 20:25:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV635ToI9kdGv2BjQW2Xurm3stUuqul8CkiGOtoe/kBxkz4qoQ7grj7Uly0xA8Ct6CJ3bvWym X-Received: by 2002:a62:1c06:: with SMTP id c6-v6mr4086370pfc.41.1537932343237; Tue, 25 Sep 2018 20:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537932343; cv=none; d=google.com; s=arc-20160816; b=tSC1dJ9Bbp5qU5rMUR9mwaxnycU8Nyxq3nq90CfdhLL4DFKFxuD6wACUeT/7RyKFFs L/fA5F7+aHwhBDUjPe0CATtTGOlgZCwykpC+JqTQ5+u9Z5hRIRGqRy+/8kOLLjSaTOXg XQVC1FqULBaniFsiAQjV6sIPvo/zdhjOViI/x9TSTPHT8i+38s0/FIaYdn458oa6Fhj3 BiKHFBJ9CYiJMrL/sncf2bfSp4L6JvTtNe0xOuvNE1DZ2UQwMdZ53fxM211N6i3WAARm LFq/DeFukPUwFnFc8taHn1v88ZxNL4ePKrmyvVVKFL8GR06AdEL+ebampmKSXEb8tnZA Yijw== 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=zZBmsP5oO4UuC2hC+KXG/IKvs6WIY2otf7jRBtBAZ8E=; b=01hQU29x+WSkDtwmA4Lku5J6yEY9LUybuw/vwwfELUJmtJLXGlAllbrm24Tm3zCVXW uQnKHuVxmkw7KaNAUgOarvo0kNXhilGw0tn5tqNU4NP+vOWACR5ngjO0WCLH+QeKAbsT e0zGD1EgvFVCSXh7wIVpZ2lwMA/W37ZZB7BxYLg0mBROsi09znZ5CQsLnzcU/TxT4D0D LAW2LFj3krDy0ZtrTlzuVklH+ZyMmB14lz4c3/s55M+45McSJX23wIkBbZZG3a0567+7 J3j0GnX6WrsRXcL5pvHHw656a60m68iXcFFGI1NlIkdGhEpPgIodTGetmJBS+mroIITM l3pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="F+f/LTpn"; 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 a20-v6si4068342pgi.184.2018.09.25.20.25.25; Tue, 25 Sep 2018 20:25:43 -0700 (PDT) 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="F+f/LTpn"; 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 S1726369AbeIZJgE (ORCPT + 99 others); Wed, 26 Sep 2018 05:36:04 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43147 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbeIZJgE (ORCPT ); Wed, 26 Sep 2018 05:36:04 -0400 Received: by mail-pf1-f193.google.com with SMTP id j26-v6so12615424pfi.10 for ; Tue, 25 Sep 2018 20:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=zZBmsP5oO4UuC2hC+KXG/IKvs6WIY2otf7jRBtBAZ8E=; b=F+f/LTpnl8QT+P8uhnkPgBWN+k8ow+V1na64InfTfzwNsPLkO+QEracGOvwAtY7/jU 2l1p7u+CvRlBZEkxbeqtpZehWJR4AeHWugZoaKiDfNiNrecOATfAyRR/AC9DT4iuwAA2 n6vHKwhUZFvhSLtSswmCUw/cQ3Tpv4J9toHgA= 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=zZBmsP5oO4UuC2hC+KXG/IKvs6WIY2otf7jRBtBAZ8E=; b=tAvOroxse7eoBo70AvfhwLEpeJwAF+7rEP2+2prUMRbeQwK75ENqSsGJFlFjDl9R28 tnX6+AIeNXWp/lrfBHzqS64Z1rg2Cb/0/pvo0YPK4eptkQUVE45YV9t19538OgWtbmLT B1JdkqixIALNF0VDZ/RGDH2bjzQ5tKqojXp4T6ZmQXLeBdEHvWjtT3HRucfMp+XahVcN 7J31VPgZsWcLVZGw4QoPLtq1WdA9aGLvzxbXtvQ3NvQPLlwpR6hFAxvFswmUsm+v8jjY Hk+rT6N1Xvlp32003SAH1SBQtV+tEc0Wuj643CA3lCenj+zVzxQRYD91x+9uRY1i66Na DetA== X-Gm-Message-State: ABuFfohzQCzmg9GqAoeqVNPTAjfNzreCk+df8bP4om4H8JRaMumTxh8S 3M/yX6cV5cnKw14JEyctOujFamrgmYc= X-Received: by 2002:a62:5343:: with SMTP id h64-v6mr4041255pfb.226.1537932318541; Tue, 25 Sep 2018 20:25:18 -0700 (PDT) Received: from excession.tpe.corp.google.com ([2401:fa00:1:10:199d:5882:860a:4adb]) by smtp.gmail.com with ESMTPSA id c80-v6sm4262620pfc.109.2018.09.25.20.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Sep 2018 20:25:17 -0700 (PDT) From: Louis Collard To: linux-integrity@vger.kernel.org Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jarkko Sakkinen , apronin@chromium.org, Jason Gunthorpe , david.bild@xaptum.com Subject: [PATCH] Allow hwrng to initialize crng. Date: Wed, 26 Sep 2018 11:24:55 +0800 Message-Id: <20180926032455.224600-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 --- 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) -- 2.13.5