Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1793017ybj; Sun, 22 Sep 2019 12:03:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKGd4NZj8yTp3449vxO19VVZARn5z/5iW33lcDjZF3r27SL6yGqAe8lvRQXXqAbe+I0sOk X-Received: by 2002:a17:906:6dc1:: with SMTP id j1mr27388201ejt.85.1569179036258; Sun, 22 Sep 2019 12:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569179036; cv=none; d=google.com; s=arc-20160816; b=jHIrMcXtS0/or+gWPjN8UlrA3t9Fk22acFqZ8gmiofLSR5oZtIjCcF5Qte/VTpZ7Yp V/H/Sn43gSGDDz0YeUUNL4m+5CGMPoJN4ep1XKpwihpfcWzIfv+cZyCeut7jIi59u6Kp WdUq6POri8OO55dVUXWmdBkObIkNxp/pamUuaaFK7NAaXPnPdM5Ya+baUXM7CukvFJ7g k5jQGyTXbluR6o3tcUGFgtoX3QNXTThGHol6kqk552T7Mxu74Swl0Ti66A+RqazcqCEm V641DrL5zPbXffzR4SZqM3rWDNceiGvxnjfIfGMr7gQgCWDKJQWPgx/rTTJWdzkKCsw1 Cn4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=whxC0zPAFdseLhTigauFTENmMr4jmbj7R4RgsJaM2E0=; b=sQboKiBds4xacZNmoetlKlc/ARqSPVRDpN3DIgd98EMx1d6c+poALiys3B4Ay0nslb GSm8uVyREDVIz9uDE5BsiMNboD5Umd9vk0AODptztAcCYQALRpOLb6hfbi8ympYVhxiq dkom1SfXZ3UBJAfF+gVFg6RzpIWjRw4F+LdzJfnwk6YKlxUB3KbEYRA1gGu6xm6HJh4a DNwU537Ub1Jc/dB+Py55/hB/lwkBPh1UzTWm7UGMW2R214+KSPp5/80hmmP798fr1tOl 3xgAu45lBCtWzh9sgi8YwQE+fZMzGAKA2MIsM5Knspy44KrKm2Lwiy9CT89iTOaGFCdv lAtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ja/HOdXi"; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o22si4020534ejb.285.2019.09.22.12.03.31; Sun, 22 Sep 2019 12:03:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ja/HOdXi"; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387638AbfITUvw (ORCPT + 99 others); Fri, 20 Sep 2019 16:51:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387598AbfITUvw (ORCPT ); Fri, 20 Sep 2019 16:51:52 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3FCB21971 for ; Fri, 20 Sep 2019 20:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569012711; bh=xg2vlVd+lUwNBRO5ewZnZq4NbIRw0nw27U11uZH30fk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ja/HOdXighvrnJiFLrz4+KK+jUExurZERXM/s9E9gYXmBROOvr2pFDqFILFyC2OWE 9WE/Sxa1j7kQq2UZ9XGCw7M8tv8wlhUKChtrC39CVes45zIqidsR1DyWei3GQR5w5I NXNEmgCZY5E7YJX/nIXRHu7kQOw2KxnAWjdOCfvc= Received: by mail-wm1-f52.google.com with SMTP id f16so3472577wmb.2 for ; Fri, 20 Sep 2019 13:51:50 -0700 (PDT) X-Gm-Message-State: APjAAAV0imFR1LGulvGPvQU/Ru6dLDoB+cK4vLklTmH68WSh2/8RePay vjzoMTXBjJJVGYtZzk1aCcAzyrlOP4lRllEJMcgU5A== X-Received: by 2002:a1c:1bcf:: with SMTP id b198mr5091632wmb.0.1569012709337; Fri, 20 Sep 2019 13:51:49 -0700 (PDT) MIME-Version: 1.0 References: <20190912034421.GA2085@darwi-home-pc> <20190912082530.GA27365@mit.edu> <20190914122500.GA1425@darwi-home-pc> <008f17bc-102b-e762-a17c-e2766d48f515@gmail.com> <20190915052242.GG19710@mit.edu> <20190918211503.GA1808@darwi-home-pc> <20190918211713.GA2225@darwi-home-pc> <20190920134609.GA2113@pc> In-Reply-To: From: Andy Lutomirski Date: Fri, 20 Sep 2019 13:51:37 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC v4 1/1] random: WARN on large getrandom() waits and introduce getrandom2() To: Linus Torvalds Cc: Andy Lutomirski , "Ahmed S. Darwish" , Lennart Poettering , "Theodore Y. Ts'o" , "Eric W. Biederman" , "Alexander E. Patrakov" , Michael Kerrisk , Willy Tarreau , Matthew Garrett , lkml , Ext4 Developers List , Linux API , linux-man Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Sep 20, 2019 at 12:51 PM Linus Torvalds wrote: > > > And the only real question is how to map existing users to these > > semantics. I see two sensible choices: > > > > 1. 0 means "secure, blocking". I think this is not what we'd do if we > > could go back in time and chage the ABI from day 1, but I think it's > > actually good enough. As long as this mode won't deadlock, it's not > > *that* bad if programs are using it when they wanted "insecure". > > It's exactly that "as long as it won't deadlock" that is our current problem. > > It *does* deadlock. > > So it can't mean "blocking" in any long-term meaning. > > It can mean "blocks for up to 15 seconds" or something like that. I'd > honestly prefer a smaller number, but I think 15 seconds is an > acceptable "your user space is buggy, but we won't make you think the > machine hung". To be clear, when I say "blocking", I mean "blocks until we're ready, but we make sure we're ready in a moderately timely manner". Rather than answering everything point by point, here's a updated mini-proposal and some thoughts. There are two families of security people that I think we care about. One is the FIPS or CC or PCI crowd, and they might, quite reasonably, demand actual hardware RNGs. We should make the hwrng API stop sucking and they should be happy. (This means expose an hwrng device node per physical device, IMO.) The other is the one who wants getrandom(), etc to be convincingly secure and is willing to do some actual analysis. And I think we can make them quite happy like this: In the kernel, we have two types of requests for random numbers: a request for "secure" bytes and a request for "insecure" bytes. Requests for "secure" bytes can block or return -EAGAIN. Requests for "insecure" bytes succeed without waiting. In addition, we have a jitter entropy mechanism (maybe the one mjg59 referenced, maybe Alexander's -- doesn't really matter) and we *guarantee* that jitter entropy, by itself, is enough to get the "secure" generator working after, say, 5s of effort. By this, I mean that, on an idle system, it finishes in 5s and, on a fully loaded system, it's allowed to take a little while longer but not too much longer. In other words, I want GRND_SECURE_BLOCKING and /dev/random reads to genuinely always work and to genuinely never take much longer than 5s. I don't want a special case where they fail. The exposed user APIs are, subject to bikeshedding that can happen later over the actual values, etc: GRND_SECURE_BLOCKING: returns "secure" output and blocks until it's ready. This never fails, but it also never blocks forever. GRND_SECURE_NONBLOCKING: same but returns -EAGAIN instead of blocking. GRND_INSECURE: returns "insecure" output immediately. I think we do need this -- the "secure" mode may take a little while at early boot, and libraries that initialize themselves with some randomness really do want a way to get some numbers without any delay whatsoever. 0: either the same as GRND_SECURE_BLOCKING plus a warning or the "accelerated" version. The "accelerated" version means wait up to 2s for secure numbers and, if there still aren't any, fall back to "insecure". GRND_RANDOM: either the same as 0 or the same as GRND_SECURE_BLOCKING but with a warning. I don't particularly care either way. I'm okay with a well-defined semantic like I proposed for an accelerated mode. I don't really want to try to define what a secure-but-not-as-secure mode means as a separate complication that the underlying RNG needs to support forever. I don't think the security folks would like that either. How does this sound?