Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1042942iob; Fri, 13 May 2022 20:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx+nMbOxij11q0h0pkdw+Ut0m7ACKfWY4Iv/7gJQJzbJg4RT+hc+PywA2r0JqDLzuYaXje X-Received: by 2002:a05:6000:1110:b0:20a:e113:8221 with SMTP id z16-20020a056000111000b0020ae1138221mr6035301wrw.271.1652500137402; Fri, 13 May 2022 20:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500137; cv=none; d=google.com; s=arc-20160816; b=HhhJj1e7G3nWJKlsUUQiLYgc3MLR40R5B1gxkE+awgWEQcbrvmZqsR2ANc3vR8Yxzd 8mJgN5VrK8AeRazQ70DOw49gxF8SkR5RROCidRZrSvJ26RcXgdFXJRzvLm7Po5WRMcX+ yGNe3HAXfKP+9mtFILwVwb6HwxfFoPjnFULPvoaSWuSAfaII9EYElUaK7RAFM0HZsP4s dJrJRauUzVABZI6tZ18OxeqH2drLUfA7nLSSki7JXdHv0Z1oJlaa6AYYf8aU85PtP9K7 iElmV5kvm4/0cFgO4PEAJDi4E357K2G1H510WHiCrG6Shve23TBFdh4Aozk6PrsoKqb5 ieWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8oam4uQpj40FXUylUvCQDj4pkGlt2TutOpdMK9XnVVA=; b=JhaFGGqYNbjAHrv8z/bsTdwstwRM2b14amTwJhypCpK2vfoEyvh09e2WSlWiGEubNN NuQaGktSrnh3Rdm1wnJnqfCPhjXJO4FloK8BhG3kYPMgzGHrc0CXWDOx7NB4WFILjSgF Q+EPgFund8mKfSmX+IZaZoFw15/Ty9CgrYMDDSrpC2RPDiOxUscwkXxw7JoWmR0aBC8f O7sj50P6MQrv1Tq3BDfPVEFDq2WCtJo3EXG90zo7CWJThWaA8v4Zk+7aYwlKf9UZ0R/x aROKrLvqOoaPPficqv8EPHcKBPntWPHpjX82rF+mVUfA4ErxuYQJgjGlBMMA37YJnPxW /Yzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=p0hyA9bC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i14-20020adfdece000000b0020c4e71bedbsi3439238wrn.916.2022.05.13.20.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:48:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=p0hyA9bC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A1E21471172; Fri, 13 May 2022 17:22:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379473AbiEMKYH (ORCPT + 99 others); Fri, 13 May 2022 06:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379422AbiEMKXi (ORCPT ); Fri, 13 May 2022 06:23:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E99D178560 for ; Fri, 13 May 2022 03:23:19 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2D61AB82D74 for ; Fri, 13 May 2022 10:23:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E211C34100; Fri, 13 May 2022 10:23:16 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="p0hyA9bC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1652437394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8oam4uQpj40FXUylUvCQDj4pkGlt2TutOpdMK9XnVVA=; b=p0hyA9bCLfWirBqsLr28cFLNt3fvOgsRbfypam++KexYG4fYHBEQXjs4DgkYpD99uIgxLB A/7U+xhG6rJIo3gSiJrFkEs0Eo7ZkM37oJyvmva5U5696Mixq9D104yuY1Xfov3+I84mVZ 5ym9BWS+x7TtUwImc3qt+GcgfNQ91kQ= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 4506914a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 13 May 2022 10:23:14 +0000 (UTC) Date: Fri, 13 May 2022 12:23:13 +0200 From: "Jason A. Donenfeld" To: Dominik Brodowski Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] random: avoid init'ing twice in credit race Message-ID: References: <20220509121409.529788-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Dominik, On Fri, May 13, 2022 at 08:23:40AM +0200, Dominik Brodowski wrote: > Am Mon, May 09, 2022 at 02:14:08PM +0200 schrieb Jason A. Donenfeld: > > Since all changes of crng_init now go through credit_init_bits(), we can > > fix a long standing race in which two concurrent callers of > > credit_init_bits() have the new bit count >= some threshold, but are > > doing so with crng_init as a lower threshold, checked outside of a lock, > > resulting in crng_reseed() or similar being called twice. > > Sidenote: crng_reseed() did manage quite fine if called twice in short > order. With regards to crng_finialize, it did, but not with regards to prematurely emptying patches and all that. IOW, buggy but not that bad. > > > In order to fix this, we can use the original cmpxchg value of the bit > > count, and only change crng_init when the bit count transitions from > > below a threshold to meeting the threshold. > > > > Cc: Dominik Brodowski > > Signed-off-by: Jason A. Donenfeld > > Reviewed-by: Dominik Brodowski > > Thanks, > Dominik Jason