From owner-freebsd-fs@freebsd.org Wed Sep 5 15:40:20 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 7FD84FF433A; Wed, 5 Sep 2018 15:40:20 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-it0-f50.google.com (mail-it0-f50.google.com [209.85.214.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 15C3B86658; Wed, 5 Sep 2018 15:40:20 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-it0-f50.google.com with SMTP id d10-v6so10490158itj.5; Wed, 05 Sep 2018 08:40:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=kmLFZdjiIxRY/wZ5aRNWlLrgbE5CuZc0Mn8ocFx3My4=; b=hnI5G8VCvyRCTj3EUv/cGkTCJZk23zPVFZ3t0yx7Q/s3AzMZNaD/Tv21AiiYzefXiz radSli4iVY1KblhtwnkbNGP/bCiWwVgKtjbLN/lGAeaIPL5E1yE4e7Q8kY1NmBah/gsr +5LKxtzbHAx4uLb5P8Cfp30h5ZIhcCckxMC947P5IRJjEvaqdEkKCUtEu0YigX8bbrIP Wve7UJq0i4CQjnd47PdZlBX0Eqd2LOF4stAfQ1hTLDdw/i+dH5PiMDLWOvTCUD4/3brU w4AVk/PPVaocgnieN/R96saP6MPIOdVAkUSWLVTKqV2i7TrEyNcJsX5RmIcYLXEM0Snf fgtA== X-Gm-Message-State: APzg51BxfT0uKvYhvhysY+RNexbW0sQ/tZah0XeEzOVOhyl1md+6XdFu 7RL1c4v7KJes6g/vBiQUiPV/VIVL X-Google-Smtp-Source: ANB0VdYyEgl0cj3dy83KGbIad7mVKPg57gBJT93Qk4sobJN8KvlNgCf/Fk0+DDy65TkbxeRf6wAhlg== X-Received: by 2002:a02:cd0:: with SMTP id 77-v6mr26904077jan.67.1536162019146; Wed, 05 Sep 2018 08:40:19 -0700 (PDT) Received: from mail-it0-f42.google.com (mail-it0-f42.google.com. [209.85.214.42]) by smtp.gmail.com with ESMTPSA id g198-v6sm7093744itg.4.2018.09.05.08.40.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 08:40:18 -0700 (PDT) Received: by mail-it0-f42.google.com with SMTP id 139-v6so10042996itf.0; Wed, 05 Sep 2018 08:40:18 -0700 (PDT) X-Received: by 2002:a24:db09:: with SMTP id c9-v6mr834254itg.92.1536162018500; Wed, 05 Sep 2018 08:40:18 -0700 (PDT) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 2002:a02:9542:0:0:0:0:0 with HTTP; Wed, 5 Sep 2018 08:40:17 -0700 (PDT) In-Reply-To: <4637985A-28EF-4A6B-B8A6-764A86005E6B@FreeBSD.org> References: <609400979.20180904230820@serebryakov.spb.ru> <1942661439.20180904235514@serebryakov.spb.ru> <774228883.20180905001035@serebryakov.spb.ru> <4637985A-28EF-4A6B-B8A6-764A86005E6B@FreeBSD.org> From: Conrad Meyer Date: Wed, 5 Sep 2018 08:40:17 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: newfs silently fails if random is not ready (?) To: FreeBSD Current Cc: freebsd-fs Content-Type: text/plain; charset="UTF-8" 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 15:40:20 -0000 Differential up here: https://reviews.freebsd.org/D17049 for any lurkers I didn't manage to tag in the review. Best, Conrad On Wed, Sep 5, 2018 at 12:57 AM, Mark R V Murray wrote: > 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 >