From f27d6532f55f2165d85e914ebb4ffc22d9fdd0a8 Mon Sep 17 00:00:00 2001 From: tls Date: Mon, 28 Nov 2011 08:05:05 +0000 Subject: [PATCH] Remove arc4random() and arc4randbytes() from the kernel API. Replace arc4random() hacks in rump with stubs that call the host arc4random() to get numbers that are hopefully actually random (arc4random() keyed with stack junk is not). This should fix some of the currently failing anita tests -- we should no longer generate duplicate "random" MAC addresses in the test environment. --- lib/librumpuser/rumpuser.c | 10 ++++-- sys/dist/ipf/netinet/ip_compat.h | 12 +++++--- sys/dist/ipf/netinet/ip_state.c | 6 ++-- sys/dist/pf/net/pf_ioctl.c | 9 +++--- sys/dist/pf/net/pf_norm.c | 7 +++-- sys/lib/libkern/arc4random.c | 31 ++++++++++--------- sys/lib/libkern/libkern.h | 4 +-- sys/nfs/nfs_vnops.c | 9 +++--- sys/opencrypto/cryptosoft.c | 10 +++--- sys/opencrypto/cryptosoft_xform.c | 8 ++--- sys/rump/include/rump/rumpuser.h | 4 ++- sys/rump/librump/rumpkern/cprng_stub.c | 42 +++++++++++++++++++++++++- sys/sys/cprng.h | 20 +++++++++--- sys/sys/param.h | 4 +-- sys/ufs/ffs/ffs_alloc.c | 7 +++-- 15 files changed, 125 insertions(+), 58 deletions(-) diff --git a/lib/librumpuser/rumpuser.c b/lib/librumpuser/rumpuser.c index 03c2e3ac32dc..021b7e405217 100644 --- a/lib/librumpuser/rumpuser.c +++ b/lib/librumpuser/rumpuser.c @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.c,v 1.15 2011/02/06 21:05:53 pooka Exp $ */ +/* $NetBSD: rumpuser.c,v 1.16 2011/11/28 08:05:05 tls Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -27,7 +27,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: rumpuser.c,v 1.15 2011/02/06 21:05:53 pooka Exp $"); +__RCSID("$NetBSD: rumpuser.c,v 1.16 2011/11/28 08:05:05 tls Exp $"); #endif /* !lint */ /* thank the maker for this */ @@ -640,3 +640,9 @@ rumpuser_getnhostcpu(void) return 1; #endif } + +uint32_t +rumpuser_arc4random(void) +{ + return arc4random(); +} diff --git a/sys/dist/ipf/netinet/ip_compat.h b/sys/dist/ipf/netinet/ip_compat.h index a4a07fb2d2d5..280bfbe6444f 100644 --- a/sys/dist/ipf/netinet/ip_compat.h +++ b/sys/dist/ipf/netinet/ip_compat.h @@ -1,4 +1,4 @@ -/* $NetBSD: ip_compat.h,v 1.29 2010/06/01 08:53:20 plunky Exp $ */ +/* $NetBSD: ip_compat.h,v 1.30 2011/11/28 08:05:05 tls Exp $ */ /* * Copyright (C) 1993-2001, 2003 by Darren Reed. @@ -216,7 +216,7 @@ typedef unsigned int u_32_t; # ifdef _KERNEL # define NEED_LOCAL_RAND 1 -# define ipf_random arc4random +# define ipf_random cprng_fast32 # define KRWLOCK_T krwlock_t # define KMUTEX_T kmutex_t @@ -582,7 +582,8 @@ typedef struct { # ifdef _KERNEL # define NEED_LOCAL_RAND 1 -# define ipf_random arc4random +#include +# define ipf_random cprng_fast32 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ (x)++; MUTEX_EXIT(&ipf_rw); } # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ @@ -806,7 +807,9 @@ typedef unsigned int u_32_t; # endif # endif +#ifndef _KERNEL # define ipf_random arc4random +#endif # if (__NetBSD_Version__ >= 499000000) # ifdef _KERNEL @@ -834,7 +837,8 @@ typedef unsigned int u_32_t; # endif # ifdef _KERNEL -# define ipf_random arc4random +# include +# define ipf_random cprng_fast32 # if (__NetBSD_Version__ >= 399001400) # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT) # endif diff --git a/sys/dist/ipf/netinet/ip_state.c b/sys/dist/ipf/netinet/ip_state.c index c11a8b267acc..50dd7e83885f 100644 --- a/sys/dist/ipf/netinet/ip_state.c +++ b/sys/dist/ipf/netinet/ip_state.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip_state.c,v 1.36 2010/04/17 21:00:44 darrenr Exp $ */ +/* $NetBSD: ip_state.c,v 1.37 2011/11/28 08:05:05 tls Exp $ */ /* * Copyright (C) 1995-2003 by Darren Reed. @@ -115,7 +115,7 @@ struct file; #if !defined(lint) #if defined(__NetBSD__) #include -__KERNEL_RCSID(0, "$NetBSD: ip_state.c,v 1.36 2010/04/17 21:00:44 darrenr Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_state.c,v 1.37 2011/11/28 08:05:05 tls Exp $"); #else static const char sccsid[] = "@(#)ip_state.c 1.8 6/5/96 (C) 1993-2000 Darren Reed"; static const char rcsid[] = "@(#)Id: ip_state.c,v 2.186.2.100 2010/01/31 16:22:55 darrenr Exp"; @@ -228,7 +228,7 @@ int fr_stateinit() * XXX - ips_seed[X] should be a random number of sorts. */ #if !defined(NEED_LOCAL_RAND) && defined(_KERNEL) - ips_seed[i] = arc4random(); + ips_seed[i] = cprng_fast32(); #else ips_seed[i] = ((u_long)ips_seed + i) * fr_statesize; ips_seed[i] += tv.tv_sec; diff --git a/sys/dist/pf/net/pf_ioctl.c b/sys/dist/pf/net/pf_ioctl.c index a6db8fdad6d0..a42621400eff 100644 --- a/sys/dist/pf/net/pf_ioctl.c +++ b/sys/dist/pf/net/pf_ioctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: pf_ioctl.c,v 1.45 2011/08/30 19:05:12 jmcneill Exp $ */ +/* $NetBSD: pf_ioctl.c,v 1.46 2011/11/28 08:05:05 tls Exp $ */ /* $OpenBSD: pf_ioctl.c,v 1.182 2007/06/24 11:17:13 mcbride Exp $ */ /* @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pf_ioctl.c,v 1.45 2011/08/30 19:05:12 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pf_ioctl.c,v 1.46 2011/11/28 08:05:05 tls Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -66,6 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: pf_ioctl.c,v 1.45 2011/08/30 19:05:12 jmcneill Exp $ #include #include #include +#include #endif /* __NetBSD__ */ #include @@ -300,7 +301,7 @@ pfattach(int num) pf_status.debug = PF_DEBUG_URGENT; /* XXX do our best to avoid a conflict */ - pf_status.hostid = arc4random(); + pf_status.hostid = cprng_fast32(); /* require process context to purge states, so perform in a thread */ #ifdef __NetBSD__ @@ -3176,7 +3177,7 @@ pfioctl(dev_t dev, u_long cmd, void *addr, int flags, struct lwp *l) u_int32_t *hid = (u_int32_t *)addr; if (*hid == 0) - pf_status.hostid = arc4random(); + pf_status.hostid = cprng_fast32(); else pf_status.hostid = *hid; break; diff --git a/sys/dist/pf/net/pf_norm.c b/sys/dist/pf/net/pf_norm.c index caa8278d234f..dcfc19f6b586 100644 --- a/sys/dist/pf/net/pf_norm.c +++ b/sys/dist/pf/net/pf_norm.c @@ -1,4 +1,4 @@ -/* $NetBSD: pf_norm.c,v 1.25 2011/08/29 09:50:04 jmcneill Exp $ */ +/* $NetBSD: pf_norm.c,v 1.26 2011/11/28 08:05:05 tls Exp $ */ /* $OpenBSD: pf_norm.c,v 1.109 2007/05/28 17:16:39 henning Exp $ */ /* @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pf_norm.c,v 1.25 2011/08/29 09:50:04 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pf_norm.c,v 1.26 2011/11/28 08:05:05 tls Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: pf_norm.c,v 1.25 2011/08/29 09:50:04 jmcneill Exp $" #ifdef __NetBSD__ #include +#include #else #include #endif /* !__NetBSD__ */ @@ -1446,7 +1447,7 @@ pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd, src->scrub->pfss_flags |= PFSS_TIMESTAMP; src->scrub->pfss_ts_mod = - htonl(arc4random()); + htonl(cprng_fast32()); /* note PFSS_PAWS not set yet */ memcpy(&tsval, &opt[2], diff --git a/sys/lib/libkern/arc4random.c b/sys/lib/libkern/arc4random.c index c7550b7ac775..d5acb3dc63fb 100644 --- a/sys/lib/libkern/arc4random.c +++ b/sys/lib/libkern/arc4random.c @@ -1,4 +1,4 @@ -/* $NetBSD: arc4random.c,v 1.26 2011/11/27 00:09:04 tsutsui Exp $ */ +/* $NetBSD: arc4random.c,v 1.27 2011/11/28 08:05:05 tls Exp $ */ /*- * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc. @@ -112,7 +112,8 @@ kmutex_t arc4_mtx; static inline u_int8_t arc4_randbyte(void); static inline void arc4randbytes_unlocked(void *, size_t); - +void _arc4randbytes(void *, size_t); +uint32_t _arc4random(void); static inline void arc4_swap(u_int8_t *a, u_int8_t *b) @@ -283,18 +284,6 @@ arc4_randbyte(void) return arc4_sbox[arc4_t]; } -u_int32_t -arc4random(void) -{ - u_int32_t ret; - u_int8_t *retc; - - retc = (u_int8_t *)&ret; - - arc4randbytes(retc, sizeof(u_int32_t)); - return ret; -} - static inline void arc4randbytes_unlocked(void *p, size_t len) { @@ -306,7 +295,7 @@ arc4randbytes_unlocked(void *p, size_t len) } void -arc4randbytes(void *p, size_t len) +_arc4randbytes(void *p, size_t len) { /* Initialize array if needed. */ if (!arc4_initialized) { @@ -323,3 +312,15 @@ arc4randbytes(void *p, size_t len) arc4_randrekey(NULL); } } + +u_int32_t +_arc4random(void) +{ + u_int32_t ret; + u_int8_t *retc; + + retc = (u_int8_t *)&ret; + + _arc4randbytes(retc, sizeof(u_int32_t)); + return ret; +} diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index 1040c84e0b44..e6fc8b88683f 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.103 2011/10/01 16:06:24 chs Exp $ */ +/* $NetBSD: libkern.h,v 1.104 2011/11/28 08:05:06 tls Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -313,8 +313,6 @@ char *intoa(u_int32_t); void *memchr(const void *, int, size_t); void *memmove(void *, const void *, size_t); int pmatch(const char *, const char *, const char **); -u_int32_t arc4random(void); -void arc4randbytes(void *, size_t); #ifndef SMALL_RANDOM void srandom(unsigned long); char *initstate(unsigned long, char *, size_t); diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 56445aa6f8d7..67df1bab8f47 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vnops.c,v 1.292 2011/09/27 01:05:08 christos Exp $ */ +/* $NetBSD: nfs_vnops.c,v 1.293 2011/11/28 08:05:06 tls Exp $ */ /* * Copyright (c) 1989, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.292 2011/09/27 01:05:08 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.293 2011/11/28 08:05:06 tls Exp $"); #ifdef _KERNEL_OPT #include "opt_nfs.h" @@ -68,6 +68,7 @@ __KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.292 2011/09/27 01:05:08 christos Exp #include #include #include +#include #include #include @@ -1638,8 +1639,8 @@ again: if (excl_mode == NFSV3CREATE_EXCLUSIVE) { *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE); nfsm_build(tl, u_int32_t *, NFSX_V3CREATEVERF); - *tl++ = arc4random(); - *tl = arc4random(); + *tl++ = cprng_fast32(); + *tl = cprng_fast32(); } else { *tl = txdr_unsigned(excl_mode); nfsm_v3attrbuild(vap, false); diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 6b1430dc4695..13a0d6defdd2 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.38 2011/06/07 15:57:51 drochner Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.39 2011/11/28 08:05:06 tls Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.38 2011/06/07 15:57:51 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.39 2011/11/28 08:05:06 tls Exp $"); #include #include @@ -106,7 +106,7 @@ swcr_encdec(struct cryptodesc *crd, const struct swcr_data *sw, void *bufv, for (i = 0; i + sizeof (u_int32_t) <= EALG_MAX_BLOCK_LEN; i += sizeof (u_int32_t)) { - u_int32_t temp = arc4random(); + u_int32_t temp = cprng_fast32(); memcpy(iv + i, &temp, sizeof(u_int32_t)); } @@ -116,7 +116,7 @@ swcr_encdec(struct cryptodesc *crd, const struct swcr_data *sw, void *bufv, * what arc4random() returns ? */ if (EALG_MAX_BLOCK_LEN % sizeof (u_int32_t) != 0) { - u_int32_t temp = arc4random(); + u_int32_t temp = cprng_fast32(); bcopy (&temp, iv + i, EALG_MAX_BLOCK_LEN - i); @@ -628,7 +628,7 @@ swcr_combined(struct cryptop *crp, int outtype) } else if (exf->reinit) exf->reinit(swe->sw_kschedule, 0, iv); else - arc4randbytes(iv, ivlen); + cprng_fast(iv, ivlen); /* Do we need to write the IV */ if (!(crde->crd_flags & CRD_F_IV_PRESENT)) diff --git a/sys/opencrypto/cryptosoft_xform.c b/sys/opencrypto/cryptosoft_xform.c index 70909cb4e8dd..5a1ac5a1bc6a 100644 --- a/sys/opencrypto/cryptosoft_xform.c +++ b/sys/opencrypto/cryptosoft_xform.c @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft_xform.c,v 1.24 2011/06/07 15:57:52 drochner Exp $ */ +/* $NetBSD: cryptosoft_xform.c,v 1.25 2011/11/28 08:05:06 tls Exp $ */ /* $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $ */ @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.24 2011/06/07 15:57:52 drochner Exp $"); +__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.25 2011/11/28 08:05:06 tls Exp $"); #include #include @@ -744,7 +744,7 @@ aes_ctr_setkey(u_int8_t **sched, const u_int8_t *key, int len) } memcpy(ctx->ac_block, key + len - AESCTR_NONCESIZE, AESCTR_NONCESIZE); /* random start value for simple counter */ - arc4randbytes(&ctx->ivgenctx.lastiv, sizeof(ctx->ivgenctx.lastiv)); + cprng_fast(&ctx->ivgenctx.lastiv, sizeof(ctx->ivgenctx.lastiv)); *sched = (void *)ctx; return 0; } @@ -808,7 +808,7 @@ aes_gmac_setkey(u_int8_t **sched, const u_int8_t *key, int len) return ENOMEM; /* random start value for simple counter */ - arc4randbytes(&ctx->ivgenctx.lastiv, sizeof(ctx->ivgenctx.lastiv)); + cprng_fast(&ctx->ivgenctx.lastiv, sizeof(ctx->ivgenctx.lastiv)); *sched = (void *)ctx; return 0; } diff --git a/sys/rump/include/rump/rumpuser.h b/sys/rump/include/rump/rumpuser.h index 324815a16449..b817ee2926c1 100644 --- a/sys/rump/include/rump/rumpuser.h +++ b/sys/rump/include/rump/rumpuser.h @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.h,v 1.70 2011/08/29 20:48:36 joerg Exp $ */ +/* $NetBSD: rumpuser.h,v 1.71 2011/11/28 08:05:06 tls Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -112,6 +112,8 @@ int rumpuser_dprintf(const char *, ...); int rumpuser_getnhostcpu(void); +uint32_t rumpuser_arc4random(void); + /* rumpuser_pth */ void rumpuser_thrinit(kernel_lockfn, kernel_unlockfn, int); __dead void rumpuser_biothread(void *); diff --git a/sys/rump/librump/rumpkern/cprng_stub.c b/sys/rump/librump/rumpkern/cprng_stub.c index 07602ccc64a3..051cbd4359de 100644 --- a/sys/rump/librump/rumpkern/cprng_stub.c +++ b/sys/rump/librump/rumpkern/cprng_stub.c @@ -1,4 +1,4 @@ -/* $NetBSD: cprng_stub.c,v 1.2 2011/11/21 13:42:37 tsutsui Exp $ */ +/* $NetBSD: cprng_stub.c,v 1.3 2011/11/28 08:05:07 tls Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -40,6 +40,8 @@ #include +#include + /* * This is all stubbed out because of rump build dependency issues I * cannot fix. One is more-or-less caused by the longstanding bogosity @@ -89,3 +91,41 @@ void cprng_strong_destroy(cprng_strong_t *c) memset(c, 0, sizeof(*c)); kmem_free(c, sizeof(*c)); } + +size_t +cprng_fast(void *p, size_t len) +{ + uint8_t *resp, *pchar = (uint8_t *)p; + uint32_t res; + size_t i; + + do { + res = rumpuser_arc4random(); + resp = (uint8_t *)&res; + + for (i = 0; i < sizeof(res); i++) { + *pchar++ = resp[i]; + if (pchar == (uint8_t *)p + len) { + return len; + } + } + } while(1); +} + +uint32_t +cprng_fast32(void) +{ + return rumpuser_arc4random(); +} + +uint64_t +cprng_fast64(void) +{ + uint64_t ret; + uint32_t *ret32; + + ret32 = (uint32_t *)&ret; + ret32[0] = rumpuser_arc4random(); + ret32[1] = rumpuser_arc4random(); + return ret; +} diff --git a/sys/sys/cprng.h b/sys/sys/cprng.h index 148803247d84..268deddf31ed 100644 --- a/sys/sys/cprng.h +++ b/sys/sys/cprng.h @@ -1,4 +1,4 @@ -/* $NetBSD: cprng.h,v 1.1 2011/11/19 22:51:31 tls Exp $ */ +/* $NetBSD: cprng.h,v 1.2 2011/11/28 08:05:07 tls Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -42,26 +42,38 @@ */ #define CPRNG_MAX_LEN 524288 +#ifndef _RUMPKERNEL +/* + * We do not want an arc4random() prototype available to anyone. + */ +void _arc4randbytes(void *, size_t); +uint32_t _arc4random(void); + static inline size_t cprng_fast(void *p, size_t len) { - arc4randbytes(p, len); + _arc4randbytes(p, len); return len; } static inline uint32_t cprng_fast32(void) { - return arc4random(); + return _arc4random(); } static inline uint64_t cprng_fast64(void) { uint64_t r; - arc4randbytes(&r, sizeof(r)); + _arc4randbytes(&r, sizeof(r)); return r; } +#else +size_t cprng_fast(void *, size_t); +uint32_t cprng_fast32(void); +uint64_t cprng_fast64(void); +#endif typedef struct _cprng_strong { kmutex_t mtx; diff --git a/sys/sys/param.h b/sys/sys/param.h index 3bd6fce05ad3..93b2bc9ee6d8 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.396 2011/11/23 23:07:36 jmcneill Exp $ */ +/* $NetBSD: param.h,v 1.397 2011/11/28 08:05:07 tls Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -63,7 +63,7 @@ * 2.99.9 (299000900) */ -#define __NetBSD_Version__ 599005700 /* NetBSD 5.99.57 */ +#define __NetBSD_Version__ 599005800 /* NetBSD 5.99.58 */ #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \ (m) * 1000000) + (p) * 100) <= __NetBSD_Version__) diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index b0901cd250a0..411f1a83eaf2 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffs_alloc.c,v 1.129 2011/09/20 14:01:32 chs Exp $ */ +/* $NetBSD: ffs_alloc.c,v 1.130 2011/11/28 08:05:07 tls Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.129 2011/09/20 14:01:32 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.130 2011/11/28 08:05:07 tls Exp $"); #if defined(_KERNEL_OPT) #include "opt_ffs.h" @@ -81,6 +81,7 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.129 2011/09/20 14:01:32 chs Exp $"); #include #include #include +#include #include #include #include @@ -1388,7 +1389,7 @@ gotit: * Don't bother to swap, it's supposed to be * random, after all. */ - dp2->di_gen = (arc4random() & INT32_MAX) / 2 + 1; + dp2->di_gen = (cprng_fast32() & INT32_MAX) / 2 + 1; dp2++; } initediblk += INOPB(fs);