From: "Ahmed S. Darwish" <darwish.07@gmail.com>
To: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
a.darwish@linutronix.de, LKML <linux-kernel@vger.kernel.org>,
Theodore Ts'o <tytso@mit.edu>,
Nicholas Mc Guire <hofrat@opentech.at>,
the arch/x86 maintainers <x86@kernel.org>,
Andy Lutomirski <luto@kernel.org>
Subject: Re: x86/random: Speculation to the rescue
Date: Tue, 1 Oct 2019 19:18:05 +0200 [thread overview]
Message-ID: <20191001171805.GA2982@darwi-home-pc> (raw)
In-Reply-To: <201910010932.C6DF862@keescook>
On Tue, Oct 01, 2019 at 09:37:39AM -0700, Kees Cook wrote:
> On Tue, Oct 01, 2019 at 06:15:02PM +0200, Ahmed S. Darwish wrote:
> > On Sat, Sep 28, 2019 at 04:53:52PM -0700, Linus Torvalds wrote:
> > > Ahmed - would you be willing to test this on your problem case (with
> > > the ext4 optimization re-enabled, of course)?
> > >
> >
> > So I pulled the patch and the revert of the ext4 revert as they're all
> > now merged in master. It of course made the problem go away...
> >
> > To test the quality of the new jitter code, I added a small patch on
> > top to disable all other sources of randomness except the new jitter
> > entropy code, [1] and made quick tests on the quality of getrandom(0).
> >
> > Using the "ent" tool, [2] also used to test randomness in the Stephen
> > Müller LRNG paper, on a 500000-byte file, produced the following
> > results:
> >
> > $ ent rand-file
> >
> > Entropy = 7.999625 bits per byte.
> >
> > Optimum compression would reduce the size of this 500000 byte file
> > by 0 percent.
> >
> > Chi square distribution for 500000 samples is 259.43, and randomly
> > would exceed this value 41.11 percent of the times.
> >
> > Arithmetic mean value of data bytes is 127.4085 (127.5 = random).
> >
> > Monte Carlo value for Pi is 3.148476594 (error 0.22 percent).
> >
> > Serial correlation coefficient is 0.001740 (totally uncorrelated = 0.0).
> >
> > As can be seen above, everything looks random, and almost all of the
> > statistical randomness tests matched the same kernel without the
> > "jitter + schedule()" patch added (after getting it un-stuck).
>
> Can you post the patch for [1]?
>
Yup, it was the quick&dirty patch below:
(discussion continues after the patch)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c2f7de9dc543..26d0d2bb3337 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1177,6 +1177,8 @@ struct timer_rand_state {
*/
void add_device_randomness(const void *buf, unsigned int size)
{
+ return;
+
unsigned long time = random_get_entropy() ^ jiffies;
unsigned long flags;
@@ -1205,6 +1207,8 @@ static struct timer_rand_state input_timer_state = INIT_TIMER_RAND_STATE;
*/
static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
{
+ return;
+
struct entropy_store *r;
struct {
long jiffies;
@@ -1255,6 +1259,8 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
void add_input_randomness(unsigned int type, unsigned int code,
unsigned int value)
{
+ return;
+
static unsigned char last_value;
/* ignore autorepeat and the like */
@@ -1308,6 +1314,8 @@ static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
void add_interrupt_randomness(int irq, int irq_flags)
{
+ return;
+
struct entropy_store *r;
struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
struct pt_regs *regs = get_irq_regs();
@@ -1375,6 +1383,8 @@ EXPORT_SYMBOL_GPL(add_interrupt_randomness);
#ifdef CONFIG_BLOCK
void add_disk_randomness(struct gendisk *disk)
{
+ return;
+
if (!disk || !disk->random)
return;
/* first major is 1, so we get >= 0x200 here */
@@ -2489,6 +2499,8 @@ randomize_page(unsigned long start, unsigned long range)
void add_hwgenerator_randomness(const char *buffer, size_t count,
size_t entropy)
{
+ return;
+
struct entropy_store *poolp = &input_pool;
if (unlikely(crng_init == 0)) {
@@ -2515,9 +2527,11 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
*/
void add_bootloader_randomness(const void *buf, unsigned int size)
{
+ return;
+
if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
add_hwgenerator_randomness(buf, size, size * 8);
else
> Another test we should do is the
> multi-boot test. Testing the stream (with ent, or with my dieharder run)
> is mainly testing the RNG algo. I'd like to see if the first 8 bytes
> out of the kernel RNG change between multiple boots of the same system.
> e.g. read the first 8 bytes, for each of 100000 boots, and feed THAT
> byte "stream" into ent...
>
Oh, indeed, that's an excellent point... I'll prototype this and come
back.
thanks,
--
Ahmed Darwish
next prev parent reply other threads:[~2019-10-01 17:18 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-28 22:24 x86/random: Speculation to the rescue Thomas Gleixner
2019-09-28 23:53 ` Linus Torvalds
2019-09-29 7:40 ` Thomas Gleixner
2019-09-29 8:05 ` Alexander E. Patrakov
2019-09-30 1:16 ` Linus Torvalds
2019-09-30 2:59 ` Linus Torvalds
2019-09-30 6:10 ` Borislav Petkov
2019-09-30 16:06 ` Linus Torvalds
2019-10-01 13:51 ` Borislav Petkov
2019-10-01 17:14 ` Linus Torvalds
2019-10-01 17:50 ` [PATCH] char/random: Add a newline at the end of the file Borislav Petkov
2019-09-30 18:05 ` x86/random: Speculation to the rescue Kees Cook
2019-09-30 3:37 ` Theodore Y. Ts'o
2019-09-30 13:16 ` Theodore Y. Ts'o
2019-09-30 16:15 ` Linus Torvalds
2019-09-30 16:32 ` Peter Zijlstra
2019-09-30 17:03 ` Linus Torvalds
2019-10-01 10:28 ` David Laight
2019-10-15 21:50 ` Thomas Gleixner
2019-10-01 16:15 ` Ahmed S. Darwish
2019-10-01 16:37 ` Kees Cook
2019-10-01 17:18 ` Ahmed S. Darwish [this message]
2019-10-01 17:25 ` Linus Torvalds
2019-10-06 12:07 ` Pavel Machek
2019-10-02 12:01 ` Theodore Y. Ts'o
2019-10-06 11:41 ` Pavel Machek
2019-10-06 17:26 ` Linus Torvalds
2019-10-06 17:35 ` Pavel Machek
2019-10-06 18:06 ` Linus Torvalds
2019-10-06 18:21 ` Pavel Machek
2019-10-06 18:26 ` Linus Torvalds
2019-10-07 11:47 ` Theodore Y. Ts'o
2019-10-07 22:18 ` Pavel Machek
2019-10-08 11:33 ` David Laight
2019-10-09 8:02 ` Pavel Machek
2019-10-09 9:37 ` David Laight
-- strict thread matches above, loose matches on Subject: below --
2019-10-01 2:14 hgntkwis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191001171805.GA2982@darwi-home-pc \
--to=darwish.07@gmail.com \
--cc=a.darwish@linutronix.de \
--cc=hofrat@opentech.at \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox