Received: by 10.192.165.148 with SMTP id m20csp2480712imm; Sun, 22 Apr 2018 07:57:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Kv12POKZbAAbDeLrRHP5EjCTR2eCI8ESZoGDPABZ18FWoA/LA4lc6BToaE03QUlBXtEub X-Received: by 10.99.168.79 with SMTP id i15mr7533704pgp.367.1524409024137; Sun, 22 Apr 2018 07:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409024; cv=none; d=google.com; s=arc-20160816; b=h3xaYTfZwvoTJjfpPkpeYNb6AiKYwpkMB2qh3cYaZVCLbpPraE3LmikHo9i31Zsx80 ezXbJJo2z8oHt4E5g95XLNI2EpNg4pym3sCShe8V0yi2LnwUZgPhdzhqVB0E5ba38k5O U7l3khUJIDeoswJ89Quc10pacs5FeEzdW/GHZusZnKiNZl5uQqEPLHvG76Vjegvjv++9 mTLcUoNQ984ds+KctvGbi5uCglucpPm8TlzHWSvcm39DGB7uPUVbGWJNmj/7BJ3aPykM 5v+/u1E5quDe6riS7pFsLX8o+50RaiY/bJ2WPCRy2stqN/5ctgj8FP2EHQLAi+b3YD4M EYxw== 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=HOwRFAnqPMcEgjnB6GTeSS94OJ4fDCOsRnLEoLezHNE=; b=ot13sxf5QreNWrcOhMcAlljKYrXL5dNM143HUc2+L0KqRYRPTwH3IFkGT9J3Lo7szx F/t28ZpRiy/CxaU11sKGDPKCFgiAaEIvyJ6dONMh6EVSmNEVB/5IVcTvSW1Rgp0RWlgh Z3tdDa1q1M//oQ0PooNx4FjXT/FuQ5qVm8AYz8/eRNfbOnAsew6Qerb6X15Rk8dywCDk Y0E3YmBSC2N+DJDe14PKFJPF1au1WACHdFKheWy5nyXR3Yt0/vHOv4wQB0Ep6X3LvlUz Z399N/ICMJ4Wz78T0y+aJVwf84/SoXQ4T/A0Kn4bDpx1X5FCKx8C1yAy7FaWAOCj3L0t dGnw== 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 f9-v6si9337935plo.292.2018.04.22.07.56.49; Sun, 22 Apr 2018 07:57:04 -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 S1756934AbeDVOOI (ORCPT + 99 others); Sun, 22 Apr 2018 10:14:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56076 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756922AbeDVOOD (ORCPT ); Sun, 22 Apr 2018 10:14:03 -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 2116BCF5; Sun, 22 Apr 2018 14:14:02 +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.9 74/95] random: fix crng_ready() test Date: Sun, 22 Apr 2018 15:53:43 +0200 Message-Id: <20180422135213.452755881@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 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 @@ -434,7 +434,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, @@ -800,7 +800,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; } @@ -872,7 +872,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); @@ -1153,7 +1153,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))) { @@ -2148,7 +2148,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; }