Received: by 10.192.165.148 with SMTP id m20csp4155902imm; Mon, 30 Apr 2018 12:50:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZokUSlEIGn9o7VUfZ72Cu/Z2XFXA3bfQNQP242sJ91SDMzO0QyVAo61mlGhDKzyRW1e65Tw X-Received: by 2002:a63:7a43:: with SMTP id j3-v6mr10900413pgn.172.1525117823346; Mon, 30 Apr 2018 12:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117823; cv=none; d=google.com; s=arc-20160816; b=VbO+BhMVwFyMc+uZ8dsPd3zbLg3s666NtBJLTaRYclQESbyoPtfY8mLRb3QOt64M5G Dl8vgY947GB8cMQ4WJAKFA+rsUspdwmD4Agd7LLlNgfE6eB6A8fzzKjc3d3jJTmD/uNn t+dcjBT0IaBfwQvA3LAiMAwcSxVSt0hV/uYsjPw0etla7zorCNgfrb+NMbeMxdHGrksY FOlFEQyLXBweb4+zHYOqXto7JjywPxX1oO8ttbzuItVuupNn4k+h6l+viV6hRqfrQjmq 2eB/iy7UbFkNjRbSXSKNHH49XVLwCfHP3zuorlCLSsGswER8FjGKRz++3ntthCso1C1Y aOyQ== 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=p3HDx6k6z3a6Xw8Pp8YooxrYnmye9VYXRevWdAySyJ8=; b=rr7pbYoIKJJNzYnHAlRLyck/+gBYcrKqk2Ot9qqMK4G82dp0i1ZbQr59KCif5ZKYrk ReSRo/NmIhusMpF3Fto9Ix9hbbNU7SYBhfurtIQZe9rgbwgU/duT9dnNaEFl1URWzvYz oTpY0hGLRL/XYGB81mEUV5q58A96J7J1NzDSqmBPWBOIA86EKAjcwvRvE/6wWJQHM71p ZUawWGFxMr5RHTBRBWxk5GktEFscR15RxwucAgf/AZ07iah9G0QmeZIcS9nFFmqOjcJw Ikx14fWfNk1IPf5iEKYcNxeNwCVAWo3A/mzjo215n9dPF4cIaMmUrTtgWRQ0P6MRwYZL r+xw== 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 g63si8113179pfd.93.2018.04.30.12.50.09; Mon, 30 Apr 2018 12:50:23 -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 S1756301AbeD3TtI (ORCPT + 99 others); Mon, 30 Apr 2018 15:49:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:35632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756220AbeD3T2M (ORCPT ); Mon, 30 Apr 2018 15:28:12 -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 AB50C22DC1; Mon, 30 Apr 2018 19:28:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB50C22DC1 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.16 008/113] random: rate limit unseeded randomness warnings Date: Mon, 30 Apr 2018 12:23:39 -0700 Message-Id: <20180430184015.422520343@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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);