The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] random: add a way to get some random bits into the entropy pools early on
@ 2008-11-25 21:26 Arjan van de Ven
  2008-11-25 21:41 ` Matt Mackall
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Arjan van de Ven @ 2008-11-25 21:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: mpm, akpm

>From 5b3b09ac82316c2d4000460d586ebe59303c12c2 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Tue, 25 Nov 2008 11:41:37 -0800
Subject: [PATCH] random: add a way to get some random bits into the entropy pools early on

currently the entropy pool gets seeded on the module_init() level, but there
is at least one consumer of random bits (the oops ID that is printed as part
of the oops).
As a result of this, kerneloops.org is seeing a lot of oopses that all share
the same 'random' number; which used to get filed away as "duplicate".

This patch adds a function to the random driver so that various pieces of
the kernel can add random bits (but not entropy!) to the pool, to avoid
this dupicate ID problem.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 arch/x86/kernel/apic.c |    7 +++++++
 drivers/char/random.c  |   29 +++++++++++++++++++++++++++++
 include/linux/random.h |    3 +++
 kernel/panic.c         |    1 +
 4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c
index 04a7f96..11f7c7d 100644
--- a/arch/x86/kernel/apic.c
+++ b/arch/x86/kernel/apic.c
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/dmi.h>
 #include <linux/dmar.h>
+#include <linux/random.h>
 
 #include <asm/atomic.h>
 #include <asm/smp.h>
@@ -691,6 +692,12 @@ static int __init calibrate_APIC_clock(void)
 	} else
 		local_irq_enable();
 
+	/*
+	 * by now we have enough time spent that there is some value in
+	 * pushing the timestamp to the random pools for early kernel use.
+	 */
+	seed_random_pools();
+
 	if (levt->features & CLOCK_EVT_FEAT_DUMMY) {
 		printk(KERN_WARNING
 		       "APIC timer disabled due to verification failure.\n");
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 675076f..236d285 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -929,6 +929,35 @@ static int rand_initialize(void)
 }
 module_init(rand_initialize);
 
+/*
+ * seed_std_data - seed pool with system timing data
+ *
+ * @r: pool to initialize
+ *
+ * This function mixes some system data into the pool to prepare it for use.
+ * This function can be called really early during boot to at least get some
+ * randomness from the system if random numbers are needed early, for example
+ * as part of the early oops printing.
+ *
+ * No entropy is credited for this seeding.
+ */
+static void seed_std_data(struct entropy_store *r)
+{
+	ktime_t now;
+	unsigned long flags;
+
+	now = ktime_get_real();
+	mix_pool_bytes(r, &now, sizeof(now));
+}
+
+int seed_random_pools(void)
+{
+	seed_std_data(&input_pool);
+	seed_std_data(&blocking_pool);
+	seed_std_data(&nonblocking_pool);
+	return 0;
+}
+
 void rand_initialize_irq(int irq)
 {
 	struct timer_rand_state *state;
diff --git a/include/linux/random.h b/include/linux/random.h
index 36f125c..d23d284 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -72,6 +72,9 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
 u32 random32(void);
 void srandom32(u32 seed);
 
+int seed_random_pools(void);
+
+
 #endif /* __KERNEL___ */
 
 #endif /* _LINUX_RANDOM_H */
diff --git a/kernel/panic.c b/kernel/panic.c
index 6513aac..d71b167 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -295,6 +295,7 @@ static u64 oops_id;
 
 static int init_oops_id(void)
 {
+	seed_random_pools();
 	if (!oops_id)
 		get_random_bytes(&oops_id, sizeof(oops_id));
 
-- 
1.5.5.1



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] random: add a way to get some random bits into the entropy pools early on
  2008-11-25 21:26 [PATCH] random: add a way to get some random bits into the entropy pools early on Arjan van de Ven
@ 2008-11-25 21:41 ` Matt Mackall
  2008-11-26  6:06   ` Arjan van de Ven
  2008-11-26  1:09 ` Andrew Morton
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Matt Mackall @ 2008-11-25 21:41 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel, akpm

On Tue, 2008-11-25 at 13:26 -0800, Arjan van de Ven wrote:
> >From 5b3b09ac82316c2d4000460d586ebe59303c12c2 Mon Sep 17 00:00:00 2001
> From: Arjan van de Ven <arjan@linux.intel.com>
> Date: Tue, 25 Nov 2008 11:41:37 -0800
> Subject: [PATCH] random: add a way to get some random bits into the entropy pools early on
> 
> currently the entropy pool gets seeded on the module_init() level, but there
> is at least one consumer of random bits (the oops ID that is printed as part
> of the oops).
> As a result of this, kerneloops.org is seeing a lot of oopses that all share
> the same 'random' number; which used to get filed away as "duplicate".
> 
> This patch adds a function to the random driver so that various pieces of
> the kernel can add random bits (but not entropy!) to the pool, to avoid
> this dupicate ID problem.

This appears to be equivalent to making random initialize earlier,
except with more code?

If we're going down a route like this, I'd like to see the ability to
actually mix in data (ie MAC addresses, DMI data, etc.) rather than just
timing.

-- 
Mathematics is the supreme nostalgia of our time.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] random: add a way to get some random bits into the entropy pools early on
  2008-11-25 21:26 [PATCH] random: add a way to get some random bits into the entropy pools early on Arjan van de Ven
  2008-11-25 21:41 ` Matt Mackall
@ 2008-11-26  1:09 ` Andrew Morton
  2008-11-26  2:51 ` Ingo Molnar
  2008-11-26 14:02 ` Andi Kleen
  3 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2008-11-26  1:09 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel, mpm

On Tue, 25 Nov 2008 13:26:00 -0800
Arjan van de Ven <arjan@infradead.org> wrote:

> currently the entropy pool gets seeded on the module_init() level, but there
> is at least one consumer of random bits (the oops ID that is printed as part
> of the oops).

There seems to be some missing text here.

> As a result of this, kerneloops.org is seeing a lot of oopses that all share
> the same 'random' number; which used to get filed away as "duplicate".
> 
> This patch adds a function to the random driver so that various pieces of
> the kernel can add random bits (but not entropy!) to the pool, to avoid
> this dupicate ID problem.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] random: add a way to get some random bits into the entropy pools early on
  2008-11-25 21:26 [PATCH] random: add a way to get some random bits into the entropy pools early on Arjan van de Ven
  2008-11-25 21:41 ` Matt Mackall
  2008-11-26  1:09 ` Andrew Morton
@ 2008-11-26  2:51 ` Ingo Molnar
  2008-11-26 14:02 ` Andi Kleen
  3 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2008-11-26  2:51 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel, mpm, akpm


* Arjan van de Ven <arjan@infradead.org> wrote:

> >From 5b3b09ac82316c2d4000460d586ebe59303c12c2 Mon Sep 17 00:00:00 2001
> From: Arjan van de Ven <arjan@linux.intel.com>
> Date: Tue, 25 Nov 2008 11:41:37 -0800
> Subject: [PATCH] random: add a way to get some random bits into the entropy pools early on
> 
> currently the entropy pool gets seeded on the module_init() level, but there
> is at least one consumer of random bits (the oops ID that is printed as part
> of the oops).
> As a result of this, kerneloops.org is seeing a lot of oopses that all share
> the same 'random' number; which used to get filed away as "duplicate".
> 
> This patch adds a function to the random driver so that various pieces of
> the kernel can add random bits (but not entropy!) to the pool, to avoid
> this dupicate ID problem.
> 
> Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
> ---
>  arch/x86/kernel/apic.c |    7 +++++++
>  drivers/char/random.c  |   29 +++++++++++++++++++++++++++++
>  include/linux/random.h |    3 +++
>  kernel/panic.c         |    1 +
>  4 files changed, 40 insertions(+), 0 deletions(-)

good catch ...

Acked-by: Ingo Molnar <mingo@elte.hu>

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] random: add a way to get some random bits into the entropy pools early on
  2008-11-25 21:41 ` Matt Mackall
@ 2008-11-26  6:06   ` Arjan van de Ven
  0 siblings, 0 replies; 6+ messages in thread
From: Arjan van de Ven @ 2008-11-26  6:06 UTC (permalink / raw)
  To: Matt Mackall; +Cc: linux-kernel, akpm

On Tue, 25 Nov 2008 15:41:22 -0600
Matt Mackall <mpm@selenic.com> wrote:


> > 
> > This patch adds a function to the random driver so that various
> > pieces of the kernel can add random bits (but not entropy!) to the
> > pool, to avoid this dupicate ID problem.
> 
> This appears to be equivalent to making random initialize earlier,
> except with more code?

well sort of kinda, but arbitrarily early (eg I made the oops ID just
call this whenever it's called first)

> 
> If we're going down a route like this, I'd like to see the ability to
> actually mix in data (ie MAC addresses, DMI data, etc.) rather than
> just timing.

I'll make a second patch for that; it does make sense to do this,
but it also makes sense to just have a "just do the time" helper



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] random: add a way to get some random bits into the entropy pools early on
  2008-11-25 21:26 [PATCH] random: add a way to get some random bits into the entropy pools early on Arjan van de Ven
                   ` (2 preceding siblings ...)
  2008-11-26  2:51 ` Ingo Molnar
@ 2008-11-26 14:02 ` Andi Kleen
  3 siblings, 0 replies; 6+ messages in thread
From: Andi Kleen @ 2008-11-26 14:02 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel, mpm, akpm

Arjan van de Ven <arjan@infradead.org> writes:

> From 5b3b09ac82316c2d4000460d586ebe59303c12c2 Mon Sep 17 00:00:00 2001
> From: Arjan van de Ven <arjan@linux.intel.com>
> Date: Tue, 25 Nov 2008 11:41:37 -0800
> Subject: [PATCH] random: add a way to get some random bits into the entropy pools early on
>
> currently the entropy pool gets seeded on the module_init() level, but there
> is at least one consumer of random bits (the oops ID that is printed as part
> of the oops).
> As a result of this, kerneloops.org is seeing a lot of oopses that all share
> the same 'random' number; which used to get filed away as "duplicate".

This should also help networking, which also relies on some non existant
randomness early on currently.

But I think i would prefer to move the complete random initialization
earlier instead of having special case calls for this.

Feeding in DMI and some other system data and perhaps
some other register values would be also a good idea.
The utsname initialization that is currently in there I always found
amusing because there is no way utsname is set that early.

-Andi

-- 
ak@linux.intel.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-11-26 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-25 21:26 [PATCH] random: add a way to get some random bits into the entropy pools early on Arjan van de Ven
2008-11-25 21:41 ` Matt Mackall
2008-11-26  6:06   ` Arjan van de Ven
2008-11-26  1:09 ` Andrew Morton
2008-11-26  2:51 ` Ingo Molnar
2008-11-26 14:02 ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox