From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55278C433EF for ; Wed, 23 Mar 2022 02:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241132AbiCWCRi convert rfc822-to-8bit (ORCPT ); Tue, 22 Mar 2022 22:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241127AbiCWCRh (ORCPT ); Tue, 22 Mar 2022 22:17:37 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 32C5770056 for ; Tue, 22 Mar 2022 19:16:05 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-188-9RN3NbaTNnehPJOCmKjD3g-1; Wed, 23 Mar 2022 02:15:58 +0000 X-MC-Unique: 9RN3NbaTNnehPJOCmKjD3g-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 23 Mar 2022 02:15:55 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Wed, 23 Mar 2022 02:15:55 +0000 From: David Laight To: "'Jason A. Donenfeld'" , "linux-kernel@vger.kernel.org" , "linux-crypto@vger.kernel.org" CC: Linus Torvalds , Guenter Roeck , Dominik Brodowski , Theodore Ts'o , Jann Horn Subject: RE: [PATCH] random: allow writes to /dev/urandom to influence fast init Thread-Topic: [PATCH] random: allow writes to /dev/urandom to influence fast init Thread-Index: AQHYPiElHr6Egf4vbEGW28icqj7YNKzMOPHg Date: Wed, 23 Mar 2022 02:15:55 +0000 Message-ID: <6716f3ffefae4ed8b5fd332bfcca8a9a@AcuMS.aculab.com> References: <20220322191436.110963-1-Jason@zx2c4.com> In-Reply-To: <20220322191436.110963-1-Jason@zx2c4.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Jason A. Donenfeld > Sent: 22 March 2022 19:15 > > For as far back as I can tell, writing to /dev/urandom or /dev/random > will put entropy into the pool, but won't immediately use it, and won't > credit it either. Instead, crediting is controlled by the ioctls > RNDADDTOENTCNT and RNDADDENTROPY. If, however, this happens during early > boot before the input pool is ready, we have a dangerous situation with > seed files as commonly used by shell scripts: > > dd if=seedfile of=/dev/urandom # write seed into pool > dd if=/dev/urandom of=seedfile count=1 bs=32 # read new seed for next boot > > Since the entropy in seedfile isn't credited there, this won't cause the > RNG to transition from crng_init=0 to crng_init=2, and so when we make a > new seedfile for next boot, we'll still be getting crng_init=0-quality > randomness, which may well regress from the original seedfile. Never mind scripts that try to immediately save a new seedfile [1]. What about code run by later startup scripts that wants random numbers. They really do want the seedfile data to be used. If it isn't used then they are likely to get very weak random numbers. You can't really expect startup scripts to be issuing ioctl requests. [1] I suspect the initial 'save' is just there to ensure that the random numbers don't exactly repeat if the system crashes. The seedfile will be written again during normal shutdown. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)