Received: by 10.192.165.148 with SMTP id m20csp4175716imm; Mon, 30 Apr 2018 13:13:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZmm6dn0USuRlEZXoAd4SUlzZjzuQD9GIQv9HqDuX56GJTwqFus2rXOWT8eGRjQkqdE2vv X-Received: by 10.167.128.141 with SMTP id v13mr13079988pff.147.1525119200679; Mon, 30 Apr 2018 13:13:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119200; cv=none; d=google.com; s=arc-20160816; b=dD6gWnLPtujdAUUxG7OkTVjoezqpEgdDXjDxPLS36JJ5MfqLgz37MzQBcmw6kkjUOz XnGPdY4Ilnj7R94HQYr2yyZfRUQYhPP25ETzmRQdORH/aY35d6nli3GT1ffju9CAktxi V0Vw0O7BZPxpMeLQM96wcwYoos15XhTjQEcnnGJ6/c6SX66pSV/SBi0VWGgqA/uLw7Ks f9k2UQyC999hLoOVtNeSF4A02B0KqRV27TqMPe3mwEc4ogH3hdcXqcPXWhzcYxUpZMUr Jq3/1e6ROvjoYDmK2iKncRznZajr2ap2kbx5ylcyc3xY+pYaTERkClhsPLo/+D8tZFT6 DJvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=WSgUP3V4vupqVuj4rxpQ7x2Jn6/TRs17Akmn9oKG/v8=; b=NbXlBgkAKbRCdLvP7NEHPmjaUGbQ3tapq2xf2TIJFpIZs2Vhpm57Is4CfCgzw8sKc/ qI0aLfGjQora2wKN7VQEHv1R8TkBeHV4C+d6As6Kjcz6gky3YvBIXI+NQoew84RyrOfo jTLKmLklxULAF3Fd4JWvauJvGkHO2DSLps/7mDIEMQeiBdpRWD+35BoNO1EFACeVp3D0 T35HNqh+Y6e2XSRiO4FoCWAYS4xCd257iCKeM2X1uYKukLyQ0T/0ukjqSLfKahzZ0I1T csXp66s5F8wzzJY46bpIiNy2DPwD0jHM++rk/5EZELqOG0QcVqFEEqRE+Ce+0rWZoAiu hMfg== ARC-Authentication-Results: i=1; mx.google.com; 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 b23si1270776pfi.40.2018.04.30.13.13.06; Mon, 30 Apr 2018 13:13:20 -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; 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 S1755867AbeD3T1L (ORCPT + 99 others); Mon, 30 Apr 2018 15:27:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:33306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932148AbeD3T1J (ORCPT ); Mon, 30 Apr 2018 15:27:09 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5DDB922DC0; Mon, 30 Apr 2018 19:27:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DDB922DC0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso Subject: [PATCH 4.14 08/91] random: rate limit unseeded randomness warnings Date: Mon, 30 Apr 2018 12:23:50 -0700 Message-Id: <20180430184004.649780470@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 4e00b339e264802851aff8e73cde7d24b57b18ce upstream. On systems without sufficient boot randomness, no point spamming dmesg. Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -261,6 +261,7 @@ #include #include #include +#include #include #include #include @@ -438,6 +439,16 @@ static void _crng_backtrack_protect(stru static void process_random_ready_list(void); static void _get_random_bytes(void *buf, int nbytes); +static struct ratelimit_state unseeded_warning = + RATELIMIT_STATE_INIT("warn_unseeded_randomness", HZ, 3); +static struct ratelimit_state urandom_warning = + RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3); + +static int ratelimit_disable __read_mostly; + +module_param_named(ratelimit_disable, ratelimit_disable, int, 0644); +MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression"); + /********************************************************************** * * OS independent entropy store. Here are the functions which handle @@ -931,6 +942,18 @@ static void crng_reseed(struct crng_stat process_random_ready_list(); wake_up_interruptible(&crng_init_wait); pr_notice("random: crng init done\n"); + if (unseeded_warning.missed) { + pr_notice("random: %d get_random_xx warning(s) missed " + "due to ratelimiting\n", + unseeded_warning.missed); + unseeded_warning.missed = 0; + } + if (urandom_warning.missed) { + pr_notice("random: %d urandom warning(s) missed " + "due to ratelimiting\n", + urandom_warning.missed); + urandom_warning.missed = 0; + } } } @@ -1574,8 +1597,9 @@ static void _warn_unseeded_randomness(co #ifndef CONFIG_WARN_ALL_UNSEEDED_RANDOM print_once = true; #endif - pr_notice("random: %s called from %pS with crng_init=%d\n", - func_name, caller, crng_init); + if (__ratelimit(&unseeded_warning)) + pr_notice("random: %s called from %pS with crng_init=%d\n", + func_name, caller, crng_init); } /* @@ -1769,6 +1793,10 @@ static int rand_initialize(void) init_std_data(&blocking_pool); crng_initialize(&primary_crng); crng_global_init_time = jiffies; + if (ratelimit_disable) { + urandom_warning.interval = 0; + unseeded_warning.interval = 0; + } return 0; } early_initcall(rand_initialize); @@ -1836,9 +1864,10 @@ urandom_read(struct file *file, char __u if (!crng_ready() && maxwarn > 0) { maxwarn--; - printk(KERN_NOTICE "random: %s: uninitialized urandom read " - "(%zd bytes read)\n", - current->comm, nbytes); + if (__ratelimit(&urandom_warning)) + printk(KERN_NOTICE "random: %s: uninitialized " + "urandom read (%zd bytes read)\n", + current->comm, nbytes); spin_lock_irqsave(&primary_crng.lock, flags); crng_init_cnt = 0; spin_unlock_irqrestore(&primary_crng.lock, flags);