Skip to content

Commit

Permalink
Merge branch 'prandom'
Browse files Browse the repository at this point in the history
prandom fixes/improvements

====================
It would be great if you could still consider this series that fixes and
improves prandom for 3.13. We have sent it to netdev as prandom() originally
came from net/core/utils.c and networking is its main user. For a detailled
description, please see individual patches.

For patch 3 in this series, there will be a minor merge conflict with the
random tree that is for 3.13. See below how to resolve it.

====
Hannes says: on merge with the random tree I would suggest to resolve the
conflict in drivers/char/random.c like this:

if (r->entropy_total > 128) {
	r->initialized = 1;
	r->entropy_total = 0;
	if (r == &nonblocking_pool) {
		prandom_reseed_late();
		pr_notice("random: %s pool is initialized\n",
			  r->name);
	}
}

So it won't generate a warning if DEBUG_RANDOM_BOOT gets activated.
====

Patch 1 should probably also go to -stable.

Set tested on 32 and 64 bit machines.

Thanks a lot!

Ref. original discussion: http://patchwork.ozlabs.org/patch/289951/
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Nov 11, 2013
2 parents 1295966 + a6a9c0f commit 75ecab1
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 46 deletions.
5 changes: 4 additions & 1 deletion drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,11 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)

if (!r->initialized && nbits > 0) {
r->entropy_total += nbits;
if (r->entropy_total > 128)
if (r->entropy_total > 128) {
r->initialized = 1;
if (r == &nonblocking_pool)
prandom_reseed_late();
}
}

trace_credit_entropy_bits(r->name, nbits, entropy_count,
Expand Down
14 changes: 10 additions & 4 deletions include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
u32 prandom_u32(void);
void prandom_bytes(void *buf, int nbytes);
void prandom_seed(u32 seed);
void prandom_reseed_late(void);

u32 prandom_u32_state(struct rnd_state *);
struct rnd_state {
__u32 s1, s2, s3, s4;
};

u32 prandom_u32_state(struct rnd_state *state);
void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);

/*
Expand All @@ -50,9 +55,10 @@ static inline void prandom_seed_state(struct rnd_state *state, u64 seed)
{
u32 i = (seed >> 32) ^ (seed << 10) ^ seed;

state->s1 = __seed(i, 1);
state->s2 = __seed(i, 7);
state->s3 = __seed(i, 15);
state->s1 = __seed(i, 2U);
state->s2 = __seed(i, 8U);
state->s3 = __seed(i, 16U);
state->s4 = __seed(i, 128U);
}

#ifdef CONFIG_ARCH_RANDOM
Expand Down
7 changes: 0 additions & 7 deletions include/uapi/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,4 @@ struct rand_pool_info {
__u32 buf[0];
};

struct rnd_state {
__u32 s1, s2, s3;
};

/* Exported functions */


#endif /* _UAPI_LINUX_RANDOM_H */
7 changes: 7 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ config AUDIT_GENERIC
depends on AUDIT && !AUDIT_ARCH
default y

config RANDOM32_SELFTEST
bool "PRNG perform self test on init"
default n
help
This option enables the 32 bit PRNG library functions to perform a
self test on initialization.

#
# compression support is select'ed if needed
#
Expand Down
Loading

0 comments on commit 75ecab1

Please sign in to comment.