Skip to content

Commit 75ecab1

Browse files
committed
Merge branch 'prandom'
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 <davem@davemloft.net>
2 parents 1295966 + a6a9c0f commit 75ecab1

File tree

5 files changed

+294
-46
lines changed

5 files changed

+294
-46
lines changed

drivers/char/random.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,11 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
603603

604604
if (!r->initialized && nbits > 0) {
605605
r->entropy_total += nbits;
606-
if (r->entropy_total > 128)
606+
if (r->entropy_total > 128) {
607607
r->initialized = 1;
608+
if (r == &nonblocking_pool)
609+
prandom_reseed_late();
610+
}
608611
}
609612

610613
trace_credit_entropy_bits(r->name, nbits, entropy_count,

include/linux/random.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
2929
u32 prandom_u32(void);
3030
void prandom_bytes(void *buf, int nbytes);
3131
void prandom_seed(u32 seed);
32+
void prandom_reseed_late(void);
3233

33-
u32 prandom_u32_state(struct rnd_state *);
34+
struct rnd_state {
35+
__u32 s1, s2, s3, s4;
36+
};
37+
38+
u32 prandom_u32_state(struct rnd_state *state);
3439
void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
3540

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

53-
state->s1 = __seed(i, 1);
54-
state->s2 = __seed(i, 7);
55-
state->s3 = __seed(i, 15);
58+
state->s1 = __seed(i, 2U);
59+
state->s2 = __seed(i, 8U);
60+
state->s3 = __seed(i, 16U);
61+
state->s4 = __seed(i, 128U);
5662
}
5763

5864
#ifdef CONFIG_ARCH_RANDOM

include/uapi/linux/random.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,4 @@ struct rand_pool_info {
4040
__u32 buf[0];
4141
};
4242

43-
struct rnd_state {
44-
__u32 s1, s2, s3;
45-
};
46-
47-
/* Exported functions */
48-
49-
5043
#endif /* _UAPI_LINUX_RANDOM_H */

lib/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ config AUDIT_GENERIC
189189
depends on AUDIT && !AUDIT_ARCH
190190
default y
191191

192+
config RANDOM32_SELFTEST
193+
bool "PRNG perform self test on init"
194+
default n
195+
help
196+
This option enables the 32 bit PRNG library functions to perform a
197+
self test on initialization.
198+
192199
#
193200
# compression support is select'ed if needed
194201
#

0 commit comments

Comments
 (0)