Received: by 10.192.165.148 with SMTP id m20csp2480642imm; Sun, 22 Apr 2018 07:56:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/djiL7NjkMh/3Rca7hZEAkJYTaRVoujAYWpBxz2Zi2NS7nT1ESvNaMeawXKWbvCF5JJdn X-Received: by 10.101.78.18 with SMTP id r18mr14714138pgt.128.1524409017349; Sun, 22 Apr 2018 07:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409017; cv=none; d=google.com; s=arc-20160816; b=NFwjgz9zTqxqgZZkrbtQiF4GxRsrjhLPCWeFtXZ9OLfUHxKnHtW/6DhvF02YeUrPg3 svQHgHack3SyG7MXO/SPZhWQ8CX9CfziJ8qusvbC78qEje2IO5QeLqCFrM3MtPxypS0h h42ZukPGc1BIDQePj0WIi8hRewJ1AwIpqWlUGr/cvgEnU66VO0n4VaoN2aQjvmFQ/bjl 26Ujlv337zoBHMAQjr9eAP4Vtfl8V+uV87cKX/x7QYtX0WVV9cUXkgBMjcpL0FTvDIX8 o87Q+zpIK+mD9GMDKI9rVbnA81vPtqmBb/qLpEL37ahNqVH1bTewfM2aeJmQrp5UO/i0 HoQA== 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 :arc-authentication-results; bh=o6xEG6xzTN1ikBw2MuG3hNQMTlwxZueHO2eCbrxWkos=; b=uY2s3NBVgFXEUj/kvJCOcEacUH8BSTrP/mVV/wDcSOB5drJkNk26Y3mifEVTgobv7o B2wuhGlBBhIAOwQlF8v3YDBuL2+YIbLV5Xjwq3yeufXAvdITwjX8qjwhbERpxUBPnDTQ V/t01CV36Wce2tQcUiC9yLz4SLekXuG8JMCUjEykIFpqiQO23tI10H5gg2HznK8MzDCL Z2dA0ka67Xn+rkttFdOU5HAmHFxpwXwRYjoAPYibnVAluJUfynCGaJAfSPNeh/tVYVgE Ek9pYsnAa7qlwiH6DroMdOCnC1+hBrboF4pKbVkssm3mK/aJgOKxDjSga1kd7nKuo29R AyOA== 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 l6si8413998pgs.531.2018.04.22.07.56.43; Sun, 22 Apr 2018 07:56:57 -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 S1757497AbeDVOzk (ORCPT + 99 others); Sun, 22 Apr 2018 10:55:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56204 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756940AbeDVOOM (ORCPT ); Sun, 22 Apr 2018 10:14:12 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3734512; Sun, 22 Apr 2018 14:14:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org Subject: [PATCH 4.9 77/95] random: add new ioctl RNDRESEEDCRNG Date: Sun, 22 Apr 2018 15:53:46 +0200 Message-Id: <20180422135213.580990477@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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 d848e5f8e1ebdb227d045db55fe4f825e82965fa upstream. Add a new ioctl which forces the the crng to be reseeded. Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 13 ++++++++++++- include/uapi/linux/random.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -436,6 +436,7 @@ struct crng_state primary_crng = { static int crng_init = 0; #define crng_ready() (likely(crng_init > 1)) static int crng_init_cnt = 0; +static unsigned long crng_global_init_time = 0; #define CRNG_INIT_CNT_THRESH (2*CHACHA20_KEY_SIZE) static void _extract_crng(struct crng_state *crng, __u8 out[CHACHA20_BLOCK_SIZE]); @@ -900,7 +901,8 @@ static void _extract_crng(struct crng_st unsigned long v, flags; if (crng_ready() && - time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)) + (time_after(crng_global_init_time, crng->init_time) || + time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL))) crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL); spin_lock_irqsave(&crng->lock, flags); if (arch_get_random_long(&v)) @@ -1689,6 +1691,7 @@ static int rand_initialize(void) init_std_data(&input_pool); init_std_data(&blocking_pool); crng_initialize(&primary_crng); + crng_global_init_time = jiffies; return 0; } early_initcall(rand_initialize); @@ -1862,6 +1865,14 @@ static long random_ioctl(struct file *f, input_pool.entropy_count = 0; blocking_pool.entropy_count = 0; return 0; + case RNDRESEEDCRNG: + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + if (crng_init < 2) + return -ENODATA; + crng_reseed(&primary_crng, NULL); + crng_global_init_time = jiffies - 1; + return 0; default: return -EINVAL; } --- a/include/uapi/linux/random.h +++ b/include/uapi/linux/random.h @@ -34,6 +34,9 @@ /* Clear the entropy pool and associated counters. (Superuser only.) */ #define RNDCLEARPOOL _IO( 'R', 0x06 ) +/* Reseed CRNG. (Superuser only.) */ +#define RNDRESEEDCRNG _IO( 'R', 0x07 ) + struct rand_pool_info { int entropy_count; int buf_size;