Applied assortment of Arch Linux ARM patches
This commit is contained in:
@@ -51,7 +51,7 @@ static const unsigned char lzop_magic[] = {
|
||||
#define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4)
|
||||
#define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4)
|
||||
|
||||
STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len)
|
||||
static inline int INIT parse_header(u8 *input, int *skip, int in_len)
|
||||
{
|
||||
int l;
|
||||
u8 *parse = input;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <linux/export.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/timer.h>
|
||||
|
||||
static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
|
||||
|
||||
@@ -141,7 +142,8 @@ void prandom_seed(u32 entropy)
|
||||
*/
|
||||
for_each_possible_cpu (i) {
|
||||
struct rnd_state *state = &per_cpu(net_rand_state, i);
|
||||
state->s1 = __seed(state->s1 ^ entropy, 1);
|
||||
state->s1 = __seed(state->s1 ^ entropy, 2);
|
||||
prandom_u32_state(state);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(prandom_seed);
|
||||
@@ -158,9 +160,9 @@ static int __init prandom_init(void)
|
||||
struct rnd_state *state = &per_cpu(net_rand_state,i);
|
||||
|
||||
#define LCG(x) ((x) * 69069) /* super-duper LCG */
|
||||
state->s1 = __seed(LCG(i + jiffies), 1);
|
||||
state->s2 = __seed(LCG(state->s1), 7);
|
||||
state->s3 = __seed(LCG(state->s2), 15);
|
||||
state->s1 = __seed(LCG(i + jiffies), 2);
|
||||
state->s2 = __seed(LCG(state->s1), 8);
|
||||
state->s3 = __seed(LCG(state->s2), 16);
|
||||
|
||||
/* "warm it up" */
|
||||
prandom_u32_state(state);
|
||||
@@ -174,26 +176,69 @@ static int __init prandom_init(void)
|
||||
}
|
||||
core_initcall(prandom_init);
|
||||
|
||||
static void __prandom_timer(unsigned long dontcare);
|
||||
static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
|
||||
|
||||
static void __prandom_timer(unsigned long dontcare)
|
||||
{
|
||||
u32 entropy;
|
||||
|
||||
get_random_bytes(&entropy, sizeof(entropy));
|
||||
prandom_seed(entropy);
|
||||
/* reseed every ~60 seconds, in [40 .. 80) interval with slack */
|
||||
seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
|
||||
add_timer(&seed_timer);
|
||||
}
|
||||
|
||||
static void prandom_start_seed_timer(void)
|
||||
{
|
||||
set_timer_slack(&seed_timer, HZ);
|
||||
seed_timer.expires = jiffies + 40 * HZ;
|
||||
add_timer(&seed_timer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate better values after random number generator
|
||||
* is fully initialized.
|
||||
*/
|
||||
static int __init prandom_reseed(void)
|
||||
static void __prandom_reseed(bool late)
|
||||
{
|
||||
int i;
|
||||
unsigned long flags;
|
||||
static bool latch = false;
|
||||
static DEFINE_SPINLOCK(lock);
|
||||
|
||||
/* only allow initial seeding (late == false) once */
|
||||
spin_lock_irqsave(&lock, flags);
|
||||
if (latch && !late)
|
||||
goto out;
|
||||
latch = true;
|
||||
|
||||
for_each_possible_cpu(i) {
|
||||
struct rnd_state *state = &per_cpu(net_rand_state,i);
|
||||
u32 seeds[3];
|
||||
|
||||
get_random_bytes(&seeds, sizeof(seeds));
|
||||
state->s1 = __seed(seeds[0], 1);
|
||||
state->s2 = __seed(seeds[1], 7);
|
||||
state->s3 = __seed(seeds[2], 15);
|
||||
state->s1 = __seed(seeds[0], 2);
|
||||
state->s2 = __seed(seeds[1], 8);
|
||||
state->s3 = __seed(seeds[2], 16);
|
||||
|
||||
/* mix it in */
|
||||
prandom_u32_state(state);
|
||||
}
|
||||
out:
|
||||
spin_unlock_irqrestore(&lock, flags);
|
||||
}
|
||||
|
||||
void prandom_reseed_late(void)
|
||||
{
|
||||
__prandom_reseed(true);
|
||||
}
|
||||
|
||||
static int __init prandom_reseed(void)
|
||||
{
|
||||
__prandom_reseed(false);
|
||||
prandom_start_seed_timer();
|
||||
return 0;
|
||||
}
|
||||
late_initcall(prandom_reseed);
|
||||
|
||||
Reference in New Issue
Block a user