Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6132904iog; Thu, 23 Jun 2022 12:02:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vEBb2Lo7mPFcZXYlEKtd8fzieuyTZBn3amRGOoz2jf8PaHARdw44iEXlJRomuDTkyh/IZn X-Received: by 2002:a17:90a:bb91:b0:1ec:7062:32cc with SMTP id v17-20020a17090abb9100b001ec706232ccmr5464951pjr.231.1656010971215; Thu, 23 Jun 2022 12:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010971; cv=none; d=google.com; s=arc-20160816; b=woAsLKeokzwtUy5CtLbiwdji1TnVTtdlR5gXpvF3vJ7LLix0mVbGeGN2uLgJ25yEmy qR2MM4dB2To52AURjZlam8RAOcVS0+GQ5HkrvWzZ8ho3dk+gVmpmeG1LH0SJUg+TuYEw dK6sBtviXD5CpaLu4/isBrog8lUzJkfRiBJX5psyh1iwMJElT9sGsFeeZMfvdLrbYLMN gkJwSWiaOd3PVuLCe4lf5XPogq+yhbn/a1kwCGFIII0j/JC15WFOtKHWJOYxTu06/M3l N3Qv+ZMHK78gH+siHRoYsQcDlnnHtvydpmlN6xZ04rTI3mFCXAi7lv2Wpx62ZAxE91Gl gXAQ== 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=BS1BTESdvU4YwlvcSznhFFY4dshXOzDzJa04RN/W1hakiWHxvsLzJB6UNaZ4OyEv6T i5icv/FcuFMEO0QBZUNfzbdRTyMjCp2rF/v6Nml9ZDJktnd2Gt77wkDueuLVV5Sx4LN0 2g8PvzFfXzt77j6Zn/iJwZLkF4nl1GLKws5+n8uLm5wenTlwS6Hq/WoWR2HNOyO94lFU Yz7tIYQac7ePBhnrpEUstyqqfDu7Iu18tIrsTcrfpYiQ42fJGj+FiT/r/cHFLWDz99e5 /6tr/1aIvwlGZcDL6Y/usShbbWHtoe8IOWbHp8TXHmZbmx7I591e6Oar9Y8vV2unXphH SBMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oGF6iT8z; 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 w15-20020a63fb4f000000b0039cb8fe4bddsi27708167pgj.259.2022.06.23.12.02.39; Thu, 23 Jun 2022 12:02:51 -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=oGF6iT8z; 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 S236354AbiFWSKV (ORCPT + 99 others); Thu, 23 Jun 2022 14:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbiFWSGI (ORCPT ); Thu, 23 Jun 2022 14:06:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C0160C65; Thu, 23 Jun 2022 10:18:13 -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 4EFDE61DB6; Thu, 23 Jun 2022 17:18:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22732C3411B; Thu, 23 Jun 2022 17:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004692; bh=ubl00wQY+xv98jqQqIiGIqc9PiUm+TumNEpqlkQaCZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oGF6iT8zaO4KcofqRaZM143OtUapN7h4FV3OcNBku6QbVZNnO9Mv2opW0PUfFyiS3 W1NeuRiQLW3o6hutXyjqdn61HsETBpud1SqrVIwvNMzRHSsaetKn58f62i5vot8Nqi 2hvI0YKgLokx3vsK4dCZt668P7q0AzTQAsSNE9pk= 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.19 082/234] random: fix locking in crng_fast_load() Date: Thu, 23 Jun 2022 18:42:29 +0200 Message-Id: <20220623164345.378724094@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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; }