Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6907246ybp; Wed, 16 Oct 2019 00:24:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkRp4PTccdPw+ykowPVynkmhTIIzogdk5fOR7IKV2STQNvCbd7jReIzMT+2Ch45L4PmvuV X-Received: by 2002:a17:906:f110:: with SMTP id gv16mr39080533ejb.331.1571210686483; Wed, 16 Oct 2019 00:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571210686; cv=none; d=google.com; s=arc-20160816; b=UkOnd0R5iPvtrIhBVb62pIxQZ+307x15Mb5INisvPXUcjgT0WF6n3D2pmgdlA+oKL0 HoyHKM6pIzBknpsHOQH7AZhfgpW8vDT1dV/zFE5m3iPDKCF4wwNzeIOwZZK7ECXW8t7O vV3DMTkaCBcF9q17VMoUpG6IO5synUK+X8+IQ55KSHOhIzOdyWjVx0LSp4vgifzlpflG P8u1Vzv8LkK4zRvlkUDq2lBdfGJ2RGWWCeNAGG9SG5rasHCZq6Bm9/V08b8Vqm2Ou7k4 fuKdxNNE3VABAgNmfbxu7sMIodOg8JiJe8BYcdndIzd3DnJgyYJPKkfI6sm76C+lxyQi nknQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=E7W3YxsfSy4zm1rOB5CRXVEdJsE5OJNLd/OPdax+Ics=; b=O2DZv6d4gSYsjzA6OlihD2bn8ddJX8aqcUjgkdZD+nC1aZLVDhsY1dWvhV7fmJQw0z Qt1nPs0ePtLhbOWmSakWZnhh5jJ2RTSTVMjNfV44cs9uTnDmqDFdPC0YXM9u07/z1E53 e6ZUKMy1E9s+eOA/H6s+WDLMwG2otCh45/C7ulHv7hFQ+DVfH9iKS2G9wCd/HhqbbPvP F2zoU+Wip5C1QA2IbJ98du/kiJvtmsXmBCrrqLvRGUvRUurQuyzrGFLqYvakKyDA8eNf e9zVG49hFU8pYAqTT/YkNuiSvEAPtgjQxSQSQASrmSMJ1+tr+nfOBuQN0HGH0FotZfoJ +vdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si17817675ede.196.2019.10.16.00.24.23; Wed, 16 Oct 2019 00:24:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731673AbfJOVum (ORCPT + 99 others); Tue, 15 Oct 2019 17:50:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:47128 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732448AbfJOVuk (ORCPT ); Tue, 15 Oct 2019 17:50:40 -0400 Received: from p5b06da22.dip0.t-ipconnect.de ([91.6.218.34] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iKUiB-0000tN-Rr; Tue, 15 Oct 2019 23:50:36 +0200 Date: Tue, 15 Oct 2019 23:50:33 +0200 (CEST) From: Thomas Gleixner To: David Laight cc: 'Linus Torvalds' , "Theodore Y. Ts'o" , "Ahmed S. Darwish" , LKML , Nicholas Mc Guire , the arch/x86 maintainers , Andy Lutomirski , Kees Cook Subject: RE: x86/random: Speculation to the rescue In-Reply-To: <41646d76683844e7baf068bed35891ad@AcuMS.aculab.com> Message-ID: References: <20190930033706.GD4994@mit.edu> <20190930131639.GF4994@mit.edu> <41646d76683844e7baf068bed35891ad@AcuMS.aculab.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David, On Tue, 1 Oct 2019, David Laight wrote: > From: Linus Torvalds > > Sent: 30 September 2019 17:16 > > > > On Mon, Sep 30, 2019 at 6:16 AM Theodore Y. Ts'o wrote: > > > > > > Which is to say, I'm still worried that people with deep access to the > > > implementation details of a CPU might be able to reverse engineer what > > > a jitter entropy scheme produces. This is why I'd be curious to see > > > the results when someone tries to attack a jitter scheme on a fully > > > open, simple architecture such as RISC-V. > > > > Oh, I agree. > > > > One of the reasons I didn't like some of the other jitter entropy > > things was that they seemed to rely _entirely_ on just purely > > low-level CPU unpredictability. I think that exists, but I think it > > makes for problems for really simple cores. > > > > Timing over a bigger thing and an actual interrupt (even if it's > > "just" a timer interrupt, which is arguably much closer to the CPU and > > has a much higher likelihood of having common frequency domains with > > the cycle counter etc) means that I'm pretty damn convinced that a big > > complex CPU will absolutely see issues, even if it has big caches. > > Agreed, you need something that is actually non-deterministic. > While 'speculation' is difficult to predict, it is actually fully deterministic. I surely agree with Linus that simple architectures could have a more or less predictable or at least searchable behaviour. If we talk about complex x86 CPUs, I tend to disagree. Even the Intel architects cannot explain why the following scenario is not deterministic at all: Single CPU No NMIs No MCEs No DMAs in the background, nothing. CPU frequency is identical to TSC frequency volatile int foo; local_irq_disable(); start = rdtscp(); for (i = 0; i < 100000; i++) foo++; end = rdtscp(); local_irq_enable(); Repeat that loop as often as you wish and observe the end - start delta. You'll see min <= delta <= N * min where N is something >= 2. The actual value of N depends on the micro architecture, but is not identical on two systems and not even identical on the same system after boot and 1e6 iterations of the above. Aside of the fact that N is insane big there is absolutely no pattern in the delta value even over a large number of runs. > Until you get some perturbation from an outside source the cpu state > (including caches and DRAM) is likely to be the same on every boot. See above and read Nicholas paper. It's simply not that likely on anything halfways modern. > For a desktop (etc) PC booting from a disk (even SSD) you'll get some variation. > Boot an embedded system from onboard flash and every boot could > well be the same (or one of a small number of results). > > Synchronising a signal between frequency domains might generate > some 'randomness', but maybe not if both come from the same PLL. > > Even if there are variations, they may not be large enough to give > a lot of variations in the state. > The variations between systems could also be a lot larger than the > variations within a system. The variations between systems are going to be larger as any minimal tolerance in the components have an influence. But even between two boots on a 'noiseless' embedded system factors like temperature, PLL lock times, swing in times of voltage regulators and other tiny details create non-deterministic behaviour. In my former life as a hardware engineer I had to analyze such issues deeply as they create serious trouble for some application scenarios, but those systems where based on very trivial and truly deterministic silicon parts. No commodity hardware vendor will ever go the extra mile to address these things as the effort required to get them under control is exponential vs. the effect. Whether that's enough to create true entropy is a different question, but I do not agree with the upfront dismissal of a potentially useful entropy source. I'm in no way saying that this should be used as the sole source of entropy, but I definitely want to explore the inherent non-determinism of modern OoO machines further. The results are way too interesting to ignore them and amazingly fast at least with the algorithm which I used in my initial post which started this whole discussion. I let that thing run on a testbox for the last two weeks while I was on vacation and gathered 32768 random bits via that debugfs hack every 100ms, i.e. a total of 1.2e7 samples amounting to ~4e11 bits. The analysis is still running, but so far it holds up. Thanks, tglx