Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1634322rwb; Mon, 7 Nov 2022 04:08:07 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Gq6dj1g9PAaME+Vde6Sozl7NMKq3CjfyD0Dbhmz5HmjnKHHzJhC2Cav799T1zhyGg0yXB X-Received: by 2002:a05:6402:3c2:b0:464:61f5:6d86 with SMTP id t2-20020a05640203c200b0046461f56d86mr18820483edw.382.1667822887070; Mon, 07 Nov 2022 04:08:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667822887; cv=none; d=google.com; s=arc-20160816; b=Kbnd7bfVbYsSXixAiTwi85xi8RPjKejX1f5IpF246/TSwNP1TNxZGWSccX3Jqa9EkU cXzhEMyFPeKFbXH55/6l/lFMmdbtthIpewV4Lgwkun4Qewu7VUNK1Ah1f/HqWbkRZuqe 3QTy+afli07zwNMu+kBj+J44ehpSlLiqQaadaMkuBgzfr2FgcmUs1tXGhXkgPcI2pj9E SQxwYvkfcHp4nx00uv9cNX3PVevxw2ov/t8qRVOOyu6ygt07wbFkzRPP8F6DR05Tv4hh grAG+GOne05cEBbZ8E6oL2LRj5j+YEN5b8d5A8ZhEEs6KAUuf7QM2LAb4bpGH5b6KWHx Qa7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=x/VlGM4HifwgG8vPARHtC+BrT1VT/CRtK8URHaPVNx4=; b=MaTPXkqSVCqBcdK131KS/aRtTVrutgua1o3GMG95o/BjJn638bgRY4mL3Has1gAcZx wMX+oyYuExVyh6aESeLktRyhJvdgZeqw8Yd3EeTx5gATMKExCx4+rlNr12X5jDMVpO5p gFKbLClacqdy5zQzLjckU32YJL3IpBeCzkLENvbnsE+hDOSABYMUjxq3MuZtfLXjoidz fT5wk/Pu9pg6YvVT+jnYSZ1pla/PT9heKRsaWEkZ3Tm32GDIWRFxe/b//fm3OBq7g40k LXfqNPevSaS6pllvbPoMyqirguQ03XLacEjJYKimTBHUjv+tXQOlOU+svQ8/B1TBq13s OLMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=aONdDrYw; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt41-20020a1709072da900b007ae6f13645dsi2039461ejc.498.2022.11.07.04.07.38; Mon, 07 Nov 2022 04:08:07 -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; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=aONdDrYw; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbiKGMEm (ORCPT + 99 others); Mon, 7 Nov 2022 07:04:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbiKGMEl (ORCPT ); Mon, 7 Nov 2022 07:04:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06240186F9 for ; Mon, 7 Nov 2022 04:04:41 -0800 (PST) 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 983A860ED6 for ; Mon, 7 Nov 2022 12:04:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A523BC433D6 for ; Mon, 7 Nov 2022 12:04:39 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="aONdDrYw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1667822676; 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=x/VlGM4HifwgG8vPARHtC+BrT1VT/CRtK8URHaPVNx4=; b=aONdDrYwPITCp6LE+/g4P2esBXQzlmXsV+VMEbCrVN2MidVW4aGdCyOfbDiKkevV8DXbLH hZ5E7oA8Ji1qS2NJrbwp+ktNyTBMZnOb6CDw+tfa7rY77zrePTdm5S5okYCTs/OZfkgGxu Nq0Sndl1Ycc9k1gWEtMgB/C4CLve8RU= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3352f2c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 7 Nov 2022 12:04:36 +0000 (UTC) Received: by mail-vs1-f49.google.com with SMTP id 3so10328835vsh.5 for ; Mon, 07 Nov 2022 04:04:36 -0800 (PST) X-Gm-Message-State: ACrzQf0EpPHZOrW9Djr2wy5fF/uMC0cqZaH8vIuDMsOhtZCi0tMut9Pd pubwQBkXBuu9PA0Y2R1fNVVSX2oXrIG078mGXUg= X-Received: by 2002:a05:6102:f9a:b0:3aa:1a11:2702 with SMTP id e26-20020a0561020f9a00b003aa1a112702mr25586304vsv.73.1667822674669; Mon, 07 Nov 2022 04:04:34 -0800 (PST) MIME-Version: 1.0 References: <20221104154230.52836-1-Jason@zx2c4.com> In-Reply-To: From: "Jason A. Donenfeld" Date: Mon, 7 Nov 2022 13:04:23 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] hw_random: treat default_quality as a maximum and default to 1024 To: Dominik Brodowski Cc: herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, Ard Biesheuvel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,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 7, 2022 at 12:14 PM Jason A. Donenfeld wrote: > > Hi Dominik, > > On Mon, Nov 07, 2022 at 08:35:02AM +0100, Dominik Brodowski wrote: > > Hi Jason, > > > > Am Sun, Nov 06, 2022 at 03:40:44PM +0100 schrieb Jason A. Donenfeld: > > > On Sun, Nov 06, 2022 at 08:05:25AM +0100, Dominik Brodowski wrote: > > > > Am Fri, Nov 04, 2022 at 04:42:30PM +0100 schrieb Jason A. Donenfeld: > > > > > 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. > > > > > > > > > > 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, yet we get > > > > > proper crediting for relevant RNGs. > > > > > > > > Hm. Wouldn't we need to verify that 1024 is appropriate for all drivers > > > > where the quality currently is not set? > > > > > > No, certainly not, and I think this sort of thought belies a really > > > backwards attitude. Hardware RNGs are assumed to produce good > > > randomness. Some manufacturers provide a caveat, "actually, we're giving > > > raw entropy with only N bits quality", but for the ones who don't, the > > > overarching assumption is that the bits are fully entropic. > > > > My point is not about the 1024 as an exact value, it's more about "do the > > driver and the hardware really provide _something_ sensible or not". In the > > past, the default mode as to feed the output of hw_rng devies to some > > userspace daemon, which then tried to verify that the device works as > > expected, and then feeded the data back to the crng core. This userspace > > indirection is largely removed already (in particular by a patch of mine > > which starts up the hwrng kernel thread also for devices with quality==0) > > once the crng is fully initialized, on the rationale that even bad quality > > data will do no harm. Yet, we may need to be a tad more careful whether or > > not to trust devices for the initial seeding of the crng. > > I got your point, and I still think it's a bad one, for the reasons > already explained to you. If it's a hardware RNG, then it's sensible to > assume it provides hardware random bits, unless we have documentation > that says it provides something less than perfect. > > Now you've moved on to talking again about entropy estimation. Stop with > this nonsense. Entropy estimation is an impossible proposition that > actually results in an infoleak. With that said, a self-test to make > sure the hardware isn't completely borked would be a nice thing, but > this applies for any device no matter what assumptions are made. So if > you want to work on that, go ahead, but it's completely orthogonal to > this change here. Based on IRC discussion, following up with a v2 with a better commit message. Jason