Received: by 10.192.165.148 with SMTP id m20csp4184694imm; Mon, 30 Apr 2018 13:24:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpRXS/fMsHyP5SkFxpZfpV764uS0XPLdv8d0qeY0Axm9gJ1AA1YNB7bzrL1LB1Z+4SNqLrQ X-Received: by 2002:a63:b70b:: with SMTP id t11-v6mr10755779pgf.193.1525119890038; Mon, 30 Apr 2018 13:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119889; cv=none; d=google.com; s=arc-20160816; b=lkuyNcTPtrO76kiL5oE/pLoxcW/gVyrSzuoWWLXfbJZkbob6xEHS0R9AVGHTakB0ia tFC2bJs/bhmO2465mUphew+Gdvo4JlJOsbzEdnN5V78nw05TNUVhi5NePTJlwDV7iYs9 8TetBi4At3kk7nN+w8+56CMVFRUgxA8sDQugTjokgNcta0Dp21PsrdEUctZZlN90W9nu 6+AuUsha8maqherrCjuaXUb/e+DmLWiDpNCYkS+y56cRpyP1lItHZnoHkK57GdhS2dxh XcuwdrJhUCLTQ5zW0lDO9mXuc4bx+0V9b92ft6PP49shIYHfpeUMQ44tXH4lgN6B5V62 EmDg== 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=iN3znSC4mXzkuvUP0rXRHAOdiswIjtGPd88kNp+9yVo=; b=a4U7lb9WiPj0JMvndUzG67LtNredv4G3LUyIV5Eq2bQP5qgUE/iNffuSB8JPIpKjaX i+/RilOKuKZi1iVMOTgK4WkS8u/91ibvMMRl+07erZ2f/TGO+3lqIl5/P6j77fbPHHLS CNboBFzIJQ8aF8RC/PVaCgtbMgSS27kR6bWkHdegjqJuWDLnJU2KG/gR9EtcL90gqXiR 3/E9YmzlkleEHPqd0mKIhu+Z0r9rn52Y0ifmTmXk9n3cXLSDDOrSuyKYEmkROoVecb1s uQ8Fu8oN+73q0ocNs+DLiCrKyeCZnhxQ2Y0xZ9JqZGfPLPTmXqQssHsrOfT07acg2f/6 /0wA== 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 73si7807718pfb.204.2018.04.30.13.24.35; Mon, 30 Apr 2018 13:24:49 -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 S1755802AbeD3UXR (ORCPT + 99 others); Mon, 30 Apr 2018 16:23:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:60464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755249AbeD3T0h (ORCPT ); Mon, 30 Apr 2018 15:26:37 -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 7059922DAE; Mon, 30 Apr 2018 19:26:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7059922DAE 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.9 07/61] random: rate limit unseeded randomness warnings Date: Mon, 30 Apr 2018 12:24:10 -0700 Message-Id: <20180430183951.929979021@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@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.9-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 | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -259,6 +259,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,16 @@ static void _crng_backtrack_protect(stru __u8 tmp[CHACHA20_BLOCK_SIZE], int used); static void process_random_ready_list(void); +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 @@ -886,6 +897,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; + } } spin_unlock_irqrestore(&crng->lock, flags); } @@ -1699,6 +1722,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); @@ -1766,9 +1793,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);