Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6048316iog; Thu, 23 Jun 2022 10:14:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vKZ1qVFbT1URM5yAaLwKr+pOSZmEsQ0ks+EQfAz77OgfnFjgjBtdvTcPcyt7JyNuMeVrcV X-Received: by 2002:a17:907:9490:b0:722:e9ee:fbc7 with SMTP id dm16-20020a170907949000b00722e9eefbc7mr9251405ejc.338.1656004456844; Thu, 23 Jun 2022 10:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656004456; cv=none; d=google.com; s=arc-20160816; b=TOTHxnISCf6HC2s2ayUgt5BTN5PSgBGWQuvUPSKMH9TCFv/ZvFe5d9FhK2HbBVRFO6 0Y63lpVCmw4nQqpniRD3TJrX2wxtlxFe5tPDTl1bu2wB8ax7aU8weAK+Pa2ItKAmH742 6IEyQEeu+HF6Xdh1iShyhzoXYlW6PSUBuLjJ93qhOP3WqKGTISo6ytN/g0bDJHSLdjjP 2azK62h6rZ75SDzqG0y54Vhot+5A56pS1I9uqKfgx40OOGXpm/CeNAGAuFjThfrL5sTK UCDXzDLTDuNvuNxv8nFXxVjRkPxgREcp6e1JuqOLmGw5R7GQKLxB5yZDisq0dTP7P4ne vvxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QWozpLbeH1FP6UIEpPWIfoaFjqUT+HWfNX2e03hLksk=; b=sREFNSCKmD5SrRhpmthvveNjAmk52pItdaal9YV1K/HCCR+n26M4lDTyKa2BEdR8G4 JWUt/1G+8bK3YfQkM2w0QeGApjdaxDOeehF2NRnE6+XagptsjEu7AZr04e/JIYhvhOlZ Eil5dVXVP8rJKpSr7LFXI0woGIU7qKpHxtEr/giDs/DlpzFOPWd+dPGwd9kJnSWbcPO7 B6trNJ+jGOu9cbAGmh5e0gMb1Zk/XZ0fw/FZYa2PL3wQpPqgnWCDIYytpEhTC6gJeDX7 Mpw5Q0XNpSmGOvCU6LScxoxSW1SwNdgKzCkjtJEy2mmkCOOJ1myxwpiCAKtngdKUGY/1 VXDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sXKDuCqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p23-20020a50cd97000000b004357d9b78cesi87956edi.514.2022.06.23.10.13.51; Thu, 23 Jun 2022 10:14:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sXKDuCqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233202AbiFWQy6 (ORCPT + 99 others); Thu, 23 Jun 2022 12:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233896AbiFWQvu (ORCPT ); Thu, 23 Jun 2022 12:51:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E86A18347; Thu, 23 Jun 2022 09:51:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D82D961F99; Thu, 23 Jun 2022 16:51:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1584C3411B; Thu, 23 Jun 2022 16:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003064; bh=ubl00wQY+xv98jqQqIiGIqc9PiUm+TumNEpqlkQaCZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXKDuCqRZ9FRuy0zQ0lOnWt4coKOUV8rLlN22rdQhVXW5CF+VNLZBUxFjX9fya57A ElOGj0HvMswINy1efD33F1JxGcuZyYW8aIq+0H6iKz4fp+H0D87Gim0mN8GuTQTAts 38VK5JLU6J9eUb/MOEaz2AfCIcwlBPvgAzcyOfWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 4.9 117/264] random: fix locking in crng_fast_load() Date: Thu, 23 Jun 2022 18:41:50 +0200 Message-Id: <20220623164347.378827219@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dominik Brodowski commit 7c2fe2b32bf76441ff5b7a425b384e5f75aa530a upstream. crng_init is protected by primary_crng->lock, so keep holding that lock when incrementing crng_init from 0 to 1 in crng_fast_load(). The call to pr_notice() can wait until the lock is released; this code path cannot be reached twice, as crng_fast_load() aborts early if crng_init > 0. Signed-off-by: Dominik Brodowski Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -647,12 +647,13 @@ static size_t crng_fast_load(const u8 *c p[crng_init_cnt % CHACHA20_KEY_SIZE] ^= *cp; cp++; crng_init_cnt++; len--; ret++; } - spin_unlock_irqrestore(&primary_crng.lock, flags); if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { invalidate_batched_entropy(); crng_init = 1; - pr_notice("fast init done\n"); } + spin_unlock_irqrestore(&primary_crng.lock, flags); + if (crng_init == 1) + pr_notice("fast init done\n"); return ret; }