From owner-freebsd-fs@freebsd.org Wed Sep 5 07:57:41 2018 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D57B4FE6F75; Wed, 5 Sep 2018 07:57:40 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from gromit.grondar.org (grandfather.grondar.org [IPv6:2a01:348:0:15:5d59:5c20:0:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 66C897620B; Wed, 5 Sep 2018 07:57:40 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from graveyard.grondar.org ([88.96.155.33] helo=gronkulator.grondar.org) by gromit.grondar.org with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91 (FreeBSD)) (envelope-from ) id 1fxSh0-00064g-M2; Wed, 05 Sep 2018 08:57:38 +0100 Content-Type: multipart/signed; boundary="Apple-Mail=_BFFD48EF-4EA4-4154-B13C-6C02B2D6201C"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: newfs silently fails if random is not ready (?) From: Mark R V Murray In-Reply-To: Date: Wed, 5 Sep 2018 08:57:37 +0100 Cc: Lev Serebryakov , FreeBSD Current , freebsd-fs , Xin LI Message-Id: <4637985A-28EF-4A6B-B8A6-764A86005E6B@FreeBSD.org> References: <609400979.20180904230820@serebryakov.spb.ru> <1942661439.20180904235514@serebryakov.spb.ru> <774228883.20180905001035@serebryakov.spb.ru> To: cem@freebsd.org X-Mailer: Apple Mail (2.3445.9.1) X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Sep 2018 07:57:41 -0000 --Apple-Mail=_BFFD48EF-4EA4-4154-B13C-6C02B2D6201C Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Nice catch! Thanks :-) M > On 5 Sep 2018, at 04:13, Conrad Meyer wrote: > > Hi Lev, > > I took a first attempt at reproducing this problem on a fast > desktop-class system. First steps, give us a way to revert back to > unseeded status: > > --- a/sys/dev/random/fortuna.c > +++ b/sys/dev/random/fortuna.c > @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); > > #ifdef _KERNEL > #include > +#include > #include > #include > #include > @@ -384,6 +385,17 @@ random_fortuna_pre_read(void) > return; > } > > + /* > + * When set, pretend we do not have enough entropy to reseed yet. > + */ > + KFAIL_POINT_CODE(DEBUG_FP, random_fortuna_pre_read, { > + if (RETURN_VALUE != 0) { > + RANDOM_RESEED_UNLOCK(); > + return; > + } > + }); > + > + > #ifdef _KERNEL > fortuna_state.fs_lasttime = now; > #endif > @@ -442,5 +454,11 @@ bool > random_fortuna_seeded(void) > { > > + /* When set, act as if we are not seeded. */ > + KFAIL_POINT_CODE(DEBUG_FP, random_fortuna_seeded, { > + if (RETURN_VALUE != 0) > + fortuna_state.fs_counter = UINT128_ZERO; > + }); > + > return (!uint128_is_zero(fortuna_state.fs_counter)); > } > > > Second step, enable the failpoints and launch repro program: > > $ sudo sysctl debug.fail_point.random_fortuna_pre_read='return(1)' > debug.fail_point.random_fortuna_pre_read: off -> return(1) > $ sudo sysctl debug.fail_point.random_fortuna_seeded='return(1)' > debug.fail_point.random_fortuna_seeded: off -> return(1) > > $ cat ./blocked_random_poc.c > #include > #include > #include > > int > main(int argc, char **argv) > { > printf("%x\n", arc4random()); > return (0); > } > > > $ ./blocked_random_poc > ... > > > Third step, I looked at what that process was doing: > > Curiously, it is not in getrandom() at all, but instead the ARND > sysctl fallback. I probably need to rebuild world (libc) to test this > (new libc arc4random based on Chacha). > > $ procstat -kk 1196 > PID TID COMM TDNAME KSTACK > 1196 100435 blocked_random_poc - read_random+0x3d > sysctl_kern_arnd+0x3a sysctl_root_handler_locked+0x89 > sysctl_root.isra.8+0x167 userland_sysctl+0x126 sys___sysctl+0x7b > amd64_syscall+0x940 fast_syscall_common+0x101 > > > When I unblocked the failpoints, it completed successfully: > > $ sudo sysctl debug.fail_point.random_fortuna_pre_read='off' > debug.fail_point.random_fortuna_pre_read: return(1) -> off > $ sudo sysctl debug.fail_point.random_fortuna_seeded=off > debug.fail_point.random_fortuna_seeded: return(1) -> off > > ... > 9e5eb30f > > > Best, > Conrad > _______________________________________________ > freebsd-current@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" > -- Mark R V Murray --Apple-Mail=_BFFD48EF-4EA4-4154-B13C-6C02B2D6201C Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 Comment: GPGTools - http://gpgtools.org iQEzBAEBCgAdFiEEyzPHvybPbOpU9MCxQlsJDh9CUqAFAluPjHEACgkQQlsJDh9C UqBdHwgAg+abT1fvBHrfDw1OvTYLA//1b3KRVkdYTUjMrdzm8g68y5ZThM9L14U3 yDeGszrDCIdnVJ9bBxGjxDeqSPY/3m+0SY2qdCT9Ly3r3t4o08WKbLqXjhooaVQE D5Ag72Q2ehWsR+/squ/Z6+3PQWkgWRE/RxTbwjOOJdZoBdJdArV/wSwOTTmcKEwG kZtxcthHbptf1RGeL+3vlVCXR4L5OoJhTym/DIdkE5rQek6cU+16nUwxNZ1NUxwf EZ07pB6pdQCfwwrh23823/zIW9CXeAxzuAf3U4M1v2EiMcgsO1TmzEVWShygNR64 X3YtB2gi3UkuXWa4TXjA77vzz5M+GA== =mSJR -----END PGP SIGNATURE----- --Apple-Mail=_BFFD48EF-4EA4-4154-B13C-6C02B2D6201C--