Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3905139pxp; Wed, 23 Mar 2022 07:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIQkMuW8VXQpF6ySC/KDYqIGPH+jlBIUHAf8NWKwWgi8n+JvE6j5BmgT7BFnkMisiRzqRb X-Received: by 2002:a17:903:1c7:b0:154:1831:1f76 with SMTP id e7-20020a17090301c700b0015418311f76mr376073plh.0.1648047456745; Wed, 23 Mar 2022 07:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648047456; cv=none; d=google.com; s=arc-20160816; b=aZqMZetBOSgQVuJ+9cfyrxgMreGC/x2l/8OSiXJB4vNDPkXxcP6pL/uIlFRo5T05ES ugxvkm0pV3k7VVCjWWQTM3mLxf+S/UUYpJ1/5P5WeOcGbg8eHC8YiWiCu2w2YgFPfwUN 0yTUP2GDveXlPOb4HqKq8hTW0DPe/v3NdY1evb5LnbSwOO5ObD6Ih15Lbv3xTy6enykP FP5bb6xlysuVep789lpVM0jfKvV0po8WtQ0Z6BFmoXllt55I2EI21jXdPY72Q03Vse1V cVjcEUylKJr6RDulTKUEqgjfF2uSL10i4oUxypcbwZykr6fe9HSjB5csZ5RISl2w+ZVc 5sGA== 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=kC3rlTX6IZ1qsGZ7LbDOlnDblc/s2ccWEzBAw4VZMDc=; b=SEHpq7S+9mrToBr0EX1HhdDfpDprZVj2NNSnG9VynOTkR02G/bqbqSMpffGmTszMa8 Mz3ePQDWhDk/Ayi2l7RRRRbYqweiVsIIfhk7f7a7cqsplS25scVfc8u6vFC0YhxowT0Z ljkvMqJiohGpNMtNb28cfh/U2bHlngVZ5qeC3BzzulHggSuflbZQ0Z0NlS9pJ3yYT+BV KO7RUEQxBt3A8mtj/a+tycOPkOv75P/6LucZaRT2ZvMeIWMVt4J5Wnm7uWjetoQYXb+5 J+v0uOPAYAGrSvvoZXXPQsz2gyUs386ofDXE+4NUtemPBk5GcJSoxw+rY8LZXGlhf/Ek Bhig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=f7++ytaT; 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=NONE sp=NONE 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 v9-20020a17090a634900b001c6f6602dcasi5501542pjs.73.2022.03.23.07.57.19; Wed, 23 Mar 2022 07:57:36 -0700 (PDT) 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=f7++ytaT; 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=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234340AbiCVSU6 (ORCPT + 99 others); Tue, 22 Mar 2022 14:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240234AbiCVSU4 (ORCPT ); Tue, 22 Mar 2022 14:20:56 -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 3DF786FF6B; Tue, 22 Mar 2022 11:19:28 -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 BAE84B81D57; Tue, 22 Mar 2022 18:19:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CB13C340EC; Tue, 22 Mar 2022 18:19:22 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="f7++ytaT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1647973161; 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=kC3rlTX6IZ1qsGZ7LbDOlnDblc/s2ccWEzBAw4VZMDc=; b=f7++ytaT+H4u8qIP3z8QM4EFX6FAMoDH590KSUK64ZOpOrVJ5PuZLQuBMwkGrSFTEN1k/a d05Aa9C/shaEo0E+EIQY7x2vghRnB6o4FvQbDIhwvvXfNkxlVtbdf2zIVQKm0FLTxA2H1K /o8yXOT4AC4cjLQqpX6LcrKPdfygCxQ= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 262f21e8 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 22 Mar 2022 18:19:20 +0000 (UTC) Date: Tue, 22 Mar 2022 12:19:16 -0600 From: "Jason A. Donenfeld" To: Guenter Roeck Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-arch@vger.kernel.org, Dinh Nguyen , Nick Hu , Max Filippov , Palmer Dabbelt , "David S . Miller" , Yoshinori Sato , Michal Simek , Borislav Petkov , Guo Ren , Geert Uytterhoeven , Joshua Kinard , David Laight , Dominik Brodowski , Eric Biggers , Ard Biesheuvel , Arnd Bergmann , Thomas Gleixner , Andy Lutomirski , Kees Cook , Lennart Poettering , Konstantin Ryabitsev , Linus Torvalds , Greg Kroah-Hartman , Theodore Ts'o Subject: Re: [PATCH v1] random: block in /dev/urandom Message-ID: References: <20220217162848.303601-1-Jason@zx2c4.com> <20220322155820.GA1745955@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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,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-crypto@vger.kernel.org Hi Guenter, On Tue, Mar 22, 2022 at 10:56:44AM -0700, Guenter Roeck wrote: > Everything - including the various root file systems - is at > git@github.com:groeck/linux-build-test.git. Look into rootfs/ for the > various boot tests. I'll be happy to provide some qemu command lines > if needed. Thanks. It looks like the "problem" is with this shell script: init_rng() { if check_file_size; then printf 'Initializing random number generator: ' dd if="$URANDOM_SEED" bs="$pool_size" of=/dev/urandom count=1 2> /dev/null status=$? if [ "$status" -eq 0 ]; then echo "OK" else echo "FAIL" fi return "$status" fi } save_random_seed() { printf 'Saving random seed: ' if touch "$URANDOM_SEED" 2> /dev/null; then old_umask=$(umask) umask 077 dd if=/dev/urandom of="$URANDOM_SEED" bs="$pool_size" count=1 2> /dev/null status=$? umask "$old_umask" if [ "$status" -eq 0 ]; then echo "OK" else echo "FAIL" fi else status=$? echo "SKIP (read-only file system detected)" fi return "$status" } case "$1" in start|restart|reload) # Carry a random seed from start-up to start-up # Load and then save the whole entropy pool init_rng && save_random_seed;; This code is actually problematic for a number of reasons. (And Linus, I'm not saying "userspace is wrong" to justify breaking it or something, don't worry.) The first `dd if="$URANDOM_SEED" bs="$pool_size" of=/dev/urandom count=1` will write the seed into the input pool, but: - It won't credit the entropy from that seed, so the pool won't actually initialize. (You need to use the ioctl to credit it.) - Because the pool doesn't initialize, subsequent reads from /dev/urandom won't actually use that seed. The first point is why we had to revert this patch. But the second one is actually a bit dangerous: you might write in a perfectly good seed to /dev/urandom, but what you read out for the subsequent seed may be complete deterministic crap. This is because the call to write_pool() goes right into the input pool and doesn't touch any of the "fast init" stuff, where we immediately mutate the crng key during early boot. As far as I can tell, this has been the behavior for a really long time, making the above innocuous pattern a pretty old thing that's broken. So I could perhaps say, "this behavior is so old now, that your userspace code is just plain broken," but I think I might actually have a very quick unobtrusive fix for this. I'll mull some things over for rc2 or later in rc1. But, anyway, this only fixes the second point mentioned above. The first one -- which resulted in the revert -- remains a stumper for now. Jason