Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp290964rwb; Fri, 18 Nov 2022 01:15:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NwlGXAKYHqSNycgzLGL+05XFR2HwUqOyKI2vMKF3GlFb5584Oik2jJhxB3rJ0jZyTqOES X-Received: by 2002:a17:906:375a:b0:7a9:a59c:4be with SMTP id e26-20020a170906375a00b007a9a59c04bemr5197943ejc.556.1668762938513; Fri, 18 Nov 2022 01:15:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668762938; cv=none; d=google.com; s=arc-20160816; b=cXbN+VGmXjli7oDcCXhdTKS1aWWpGAahFZgW1Zs8VTbKFK7F7NVOeguXN7nOH4Mvhn LSdiWPOaKhQ82G/a02/23CLX9UM9qBlQ9yf4zinbWUEjVR8pXDNFUmez/0jP+VEddTij pzvxPRLuZFzFlXPUvX8l1BKzXKINvEuLtL17JVLb1YFgtzZTwpmdK3GoFmR+RcdmjJg7 LiYBlukxMaqA1xVmHoFlP4NGVvcfbJBEjeYEIgYgFl0uib8L87muB+nMZsCJdOGaB15m 33n/f1NLAN4BSqo/u0mUDyRy94d6tB12FnHOsy2FdqRicp9C7dzuXRBNjhppSsyRoo+n GeBw== 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; bh=Rxa1MdoaZPQq28QfQrBbwl/aydumX7CR4L17mdvxfMk=; b=NJ5+hjxsHqp9Mar5jDNDlTGG6YOcS1YrFgaRcF4wbQwIYs5UpuNitxejX1ITfPYYmb 5bsTnXM57SV05IfGZzueBUc/xM3PBTeoQylp1XVYt0jXaUyqYYOu919Ec+DoJ3VbvrbW iTTRNedOVUAmlhXdpqIPMye5VrG88HgVff/VAXe4bw5vl71ps8ivq9Cb8/kkUCaYmY5Z 1o/a5L0FE6wHsMRW5X/7UL4SsQFTKDztBIU9b5u1wqUrsiMNje+Ty1MfHfj1R4uYNGJF aaHNdYOitJrlqL4d3qIYm7KpPog/O221fN+JLIxpl5yDH7uQm30YaaFFdkNUbw2aBOjL +VLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 17-20020a170906059100b007a1084820f6si2173806ejn.230.2022.11.18.01.15.12; Fri, 18 Nov 2022 01:15:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241718AbiKRJKK (ORCPT + 99 others); Fri, 18 Nov 2022 04:10:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240700AbiKRJKJ (ORCPT ); Fri, 18 Nov 2022 04:10:09 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8776F35C for ; Fri, 18 Nov 2022 01:10:07 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1ovxNq-00FYN7-RO; Fri, 18 Nov 2022 17:10:03 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 18 Nov 2022 17:10:02 +0800 Date: Fri, 18 Nov 2022 17:10:02 +0800 From: Herbert Xu To: "Jason A. Donenfeld" Cc: linux-crypto@vger.kernel.org, Dominik Brodowski , Ard Biesheuvel Subject: Re: [PATCH v2] hw_random: treat default_quality as a maximum and default to 1024 Message-ID: References: <20221107122455.6169-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221107122455.6169-1-Jason@zx2c4.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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-crypto@vger.kernel.org On Mon, Nov 07, 2022 at 01:24:55PM +0100, Jason A. Donenfeld wrote: > Most hw_random devices return entropy which is assumed to be of full > quality, but driver authors don't bother setting the quality knob. Some > hw_random devices return less than full quality entropy, and then driver > authors set the quality knob. Therefore, the entropy crediting should be > opt-out rather than opt-in per-driver, to reflect the actual reality on > the ground. > > For example, the two Raspberry Pi RNG drivers produce full entropy > randomness, and both EDK2 and U-Boot's drivers for these treat them as > such. The result is that EFI then uses these numbers and passes the to > Linux, and Linux credits them as boot, thereby initializing the RNG. > Yet, in Linux, the quality knob was never set to anything, and so on the > chance that Linux is booted without EFI, nothing is ever credited. > That's annoying. > > The same pattern appears to repeat itself throughout various drivers. In > fact, very very few drivers have bothered setting quality=1024. > > Looking at the git history of existing drivers and corresponding mailing > list discussion, this conclusion tracks. There's been a decent amount of > discussion about drivers that set quality < 1024 -- somebody read and > interepreted a datasheet, or made some back of the envelope calculation > somehow. But there's been very little, if any, discussion about most > drivers where the quality is just set to 1024 or unset (or set to 1000 > when the authors misunderstood the API and assumed it was base-10 rather > than base-2); in both cases the intent was fairly clear of, "this is a > hardware random device; it's fine." > > So let's invert this logic. A hw_random struct's quality knob now > controls the maximum quality a driver can produce, or 0 to specify 1024. > Then, the module-wide switch called "default_quality" is changed to > represent the maximum quality of any driver. By default it's 1024, and > the quality of any particular driver is then given by: > > min(default_quality, rng->quality ?: 1024); > > This way, the user can still turn this off for weird reasons (and we can > replace whatever driver-specific disabling hacks existed in the past), > yet we get proper crediting for relevant RNGs. > > Cc: Dominik Brodowski > Cc: Ard Biesheuvel > Cc: Herbert Xu > Signed-off-by: Jason A. Donenfeld > --- > Changes v1->v2: > - Expand commit message a bit. > - Account for erroneous quality=1000 and quirky devices too. > > arch/um/drivers/random.c | 1 - > drivers/char/hw_random/cavium-rng-vf.c | 1 - > drivers/char/hw_random/cn10k-rng.c | 1 - > drivers/char/hw_random/core.c | 9 +++------ > drivers/char/hw_random/mpfs-rng.c | 1 - > drivers/char/hw_random/npcm-rng.c | 1 - > drivers/char/hw_random/s390-trng.c | 1 - > drivers/char/hw_random/timeriomem-rng.c | 2 -- > drivers/char/hw_random/virtio-rng.c | 1 - > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 1 - > drivers/crypto/atmel-sha204a.c | 1 - > drivers/crypto/caam/caamrng.c | 1 - > drivers/firmware/turris-mox-rwtm.c | 1 - > drivers/s390/crypto/zcrypt_api.c | 6 ------ > drivers/usb/misc/chaoskey.c | 1 - > include/linux/hw_random.h | 2 +- > 16 files changed, 4 insertions(+), 27 deletions(-) Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt