Received: by 10.192.165.148 with SMTP id m20csp2519904imm; Sun, 22 Apr 2018 08:43:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+VK2E6oN6JTMASPxoiROrAfDRW41jqCzxKCXQ/Ai3dG1i2lziEM/uftKbubFZZHCe9ruoU X-Received: by 10.101.99.214 with SMTP id n22mr14519590pgv.152.1524411833226; Sun, 22 Apr 2018 08:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524411833; cv=none; d=google.com; s=arc-20160816; b=OdqxGGLEjPyLU9lql/TTheizqiE2+HaZoz7sX5O10kMcRoqR/GDumL0FR6+a01GyR7 WKz2C8rfAL4QyxmHT9F35L+jVfqNWgqJCJG7KZVPDh2dufyYFl1Of89T51TY3H8xlOWf kibxQioboV09tbJ5fDfH9KqX3GZ04BQk6H4DpXzseoHIalG/OEP0XNKsipSg+BAvSJm5 rWzsMeg9+sa4+03BXLLY/igMwkdaurDJ/8CoMo5Br2zlnq46pJU+Wy2UEdOEBl9PAZHV Xy+NJxZqo/IlcLCSEPB9K33KOzwil0jYDQiSee9JkqAsuhbvCli1zkET//vAYsgq/mJj V97g== 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=YiyS+akCfS3dLayquneNw165LBcROe3T1jNOWftE5h0=; b=nK5UVrgwz4QunZk++gwfZaDpEKXCVRSlJ00vjLbQFiJ0HL3zmuCNujoihCH6Sl4qtz /DoHm16lbvf6x9v+1HCfEqPk/yX/bvEelFSJGMhHQrFgeL48/HW19Rd7E7Ry//a8rTkI 4PiXCBJ05vie/uoLyOeKD5ZY1lrCHgAxG/P8et1+7YseelRdLcqPN2W5IfptdAw3ZCvg 6xrK51US3WGE/ivPjf+6P89C0nzU0rrEtjzlsXUTUphhbpf9YaVllGtAwdMFTPP17boH pjHF5DgoQQqo36oaxDO5yHxMhrsa/ceABo2NiLq85Kl63cGJVX4d/1/2Gxz1h2AmlIim 5KfA== 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 l7-v6si10053930pls.93.2018.04.22.08.43.39; Sun, 22 Apr 2018 08:43:53 -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 S1755226AbeDVPmA (ORCPT + 99 others); Sun, 22 Apr 2018 11:42:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49136 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755024AbeDVODS (ORCPT ); Sun, 22 Apr 2018 10:03:18 -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 2E6E79C; Sun, 22 Apr 2018 14:03:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Theodore Tso , stable@kernel.org Subject: [PATCH 4.16 163/196] random: fix crng_ready() test Date: Sun, 22 Apr 2018 15:53:03 +0200 Message-Id: <20180422135112.655853962@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@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 43838a23a05fbd13e47d750d3dfd77001536dd33 upstream. The crng_init variable has three states: 0: The CRNG is not initialized at all 1: The CRNG has a small amount of entropy, hopefully good enough for early-boot, non-cryptographical use cases 2: The CRNG is fully initialized and we are sure it is safe for cryptographic use cases. The crng_ready() function should only return true once we are in the last state. This addresses CVE-2018-1108. Reported-by: Jann Horn Fixes: e192be9d9a30 ("random: replace non-blocking pool...") Cc: stable@kernel.org # 4.8+ Signed-off-by: Theodore Ts'o Reviewed-by: Jann Horn Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -427,7 +427,7 @@ struct crng_state primary_crng = { * its value (from 0->1->2). */ static int crng_init = 0; -#define crng_ready() (likely(crng_init > 0)) +#define crng_ready() (likely(crng_init > 1)) static int crng_init_cnt = 0; #define CRNG_INIT_CNT_THRESH (2*CHACHA20_KEY_SIZE) static void _extract_crng(struct crng_state *crng, @@ -793,7 +793,7 @@ static int crng_fast_load(const char *cp if (!spin_trylock_irqsave(&primary_crng.lock, flags)) return 0; - if (crng_ready()) { + if (crng_init != 0) { spin_unlock_irqrestore(&primary_crng.lock, flags); return 0; } @@ -855,7 +855,7 @@ static void _extract_crng(struct crng_st { unsigned long v, flags; - if (crng_init > 1 && + if (crng_ready() && time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)) crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL); spin_lock_irqsave(&crng->lock, flags); @@ -1141,7 +1141,7 @@ void add_interrupt_randomness(int irq, i fast_mix(fast_pool); add_interrupt_bench(cycles); - if (!crng_ready()) { + if (unlikely(crng_init == 0)) { if ((fast_pool->count >= 64) && crng_fast_load((char *) fast_pool->pool, sizeof(fast_pool->pool))) { @@ -2214,7 +2214,7 @@ void add_hwgenerator_randomness(const ch { struct entropy_store *poolp = &input_pool; - if (!crng_ready()) { + if (unlikely(crng_init == 0)) { crng_fast_load(buffer, count); return; }