From owner-svn-src-all@freebsd.org Tue Sep 3 14:07:51 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 772A2DD27E; Tue, 3 Sep 2019 14:06:59 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N8030Q1Cz4Q6Z; Tue, 3 Sep 2019 14:06:59 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 20D1A1AE93; Tue, 3 Sep 2019 14:06:24 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 324BE69BA; Tue, 16 Apr 2019 23:28:52 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4E2BB852EF; Tue, 16 Apr 2019 23:28:51 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1DA35694F; Tue, 16 Apr 2019 23:28:51 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 69816694C; Tue, 16 Apr 2019 23:28:48 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1319A852E5; Tue, 16 Apr 2019 23:28:48 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-3.local (unknown [IPv6:2601:648:8880:1e30:50e5:2fcc:d66f:cb37]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 56F4D17853; Tue, 16 Apr 2019 23:28:47 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: svn commit: r346250 - in head: share/man/man4 share/man/man9 sys/dev/random sys/kern sys/libkern sys/sys To: cem@freebsd.org Cc: src-committers , svn-src-all , svn-src-head References: <201904151840.x3FIeaEQ009242@repo.freebsd.org> <457a2c63-f062-8fc6-15d4-6f5b93981930@FreeBSD.org> From: John Baldwin Openpgp: preference=signencrypt Autocrypt: addr=jhb@FreeBSD.org; keydata= mQGiBETQ+XcRBADMFybiq69u+fJRy/0wzqTNS8jFfWaBTs5/OfcV7wWezVmf9s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Q6qdljeaRqeR6zFus7EZTwtX sNzs5bP8y51PSUDJbeiy2RNCNKWFMndM22TZnk3GNG45nQd4OwYK0RZVrikalmJY5Q6m7Z16 4yrZgIXFdKj2t8F+x613/SJW1lIr9/bDp4U9tw0V1g3l2dFtD3p3ZrQ3hpoDtoK70ioIAjjH aIXIAcm3FGZFXy503DOA0KaTWwvOVdYCFLm3zWuSOmrX/GsEc7ovasOWwjPn878qVjbUKWwx Q4QkF4OhUV9zPtf9tDSAZ3x7QSwoKbCoRCZ/xbyTUPyQ1VvNy/mYrBcYlzHodsaqUDjHuW+I SQQYEQIACQUCRND5ggIbDAAKCRBy3lIGd+N/BCO8AJ9j1dWVQWxw/YdTbEyrRKOY8YZNwwCf afMAg8QvmOWnHx3wl8WslCaXaE8= Message-ID: <5d790a56-1498-094e-6bb4-48345a231e55@FreeBSD.org> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 4E2BB852EF X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.99 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.991,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:51 -0000 X-Original-Date: Tue, 16 Apr 2019 16:28:45 -0700 X-List-Received-Date: Tue, 03 Sep 2019 14:07:51 -0000 On 4/16/19 3:49 PM, Conrad Meyer wrote: > On Tue, Apr 16, 2019 at 2:32 PM John Baldwin wrote: >> There are definitely places arc4random is used where sleeping is not allowed. > > Sure. > >> ipsec generating nonces for AES-CBC is one example I can think of off the >> top of my head. > > IVs for AES-CBC are also a great example of a case we should be seeded for. Yes, but we need some kind of non-blocking API, not an unconditionally-blocking API that deadlocks. >> I think it might be useful to add an explicit WITNESS_WARN >> in arc4random to catch these cases so they can be found and reasoned about. > > Well, we kind of want that, but we also want the warning to disappear > if the consumer has correctly reasoned about it. E.g., if the thread > has verified seeded status with is_random_seeded(), it is no longer > possible for a arc4random consumption to block. Right? I think that > may be difficult to integrate with the WITNESS_WARN, so even if all > consumers are correctly implemented, we will not eliminate the witness > warnings. Do you have any ideas? The only dumb proposal I have is > burning a flag in td_flags for "this thread checked > is_random_seeded(), and it returned true." Eh, I thought that we periodically pulled in new entropy to generate a new chacha20 key for the PRNG and that could be blocking as well when I was last reading this code, or is that not correct? Or maybe arc4random passes in a flag to disable reseeding so it isn't blocking once the PRNG has been seeded at least once? Still, what I would suggest is to have the existing arc4random() use WITNESS_WARN. We could provide an alternative API that is non-blocking and returns EWOULDBLOCK. Code that trips over the warning would have to be changed to use the non-blocking API and then deal with EWOULDBLOCK. One way of dealing with that would be to check the is_random_seeded() flag earlier in the function, subsystem, whatever and then the code could assert that the non-blocking API never failed. >> Note that I actually often run into unseeded systems when doing development >> using qemu for non-x86 architectures. For example, when booting mips from >> qemu, there is no loader, the kernel just starts, and since the endian is >> opposite, I frequently regenerate the filesystem using makefs. > > Right. Perhaps we could incorporate boot/entropy generation into > makefs? Or pass host entropy into some kernel accessible region (env > var, whatever) via qemu? The latter is sort of a general problem for > VMs. You want to be able to snapshot and clone a VM without producing > reproducible RNG state, but Fortuna doesn't handle that explicitly > (aside from future entropy differences and forward secrecy causing > quick divergence). There are things like virtio-rng for modern x86 VM environments, but those don't exist on things like the MIPS MALTA machine. I also don't actually care at all (as in absolutely zero) about the entropy of keys generated for a test qemu instance I fire up on my desktop that doesn't permit inbound access from the outside world. Having some kind of tunable / kernel option for those use cases (that isn't the default) doesn't seem unreasonable. -- John Baldwin