DF-2251 / fix.diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | --- a/sys/vfs/ufs/ffs_alloc.c +++ b/sys/vfs/ufs/ffs_alloc.c @@ -639,7 +639,7 @@ * Set up a new generation number for this inode. */ if (ip->i_gen == 0 || ++ip->i_gen == 0) - ip->i_gen = krandom() / 2 + 1; + ip->i_gen = ((uint32_t)karc4random() >> 1) + 1; return (0); noinodes: ffs_fserr(fs, cred->cr_uid, "out of inodes"); --- a/sys/vfs/ufs/ffs_vfsops.c +++ b/sys/vfs/ufs/ffs_vfsops.c @@ -1172,7 +1172,7 @@ * already have one. This should only happen on old filesystems. */ if (ip->i_gen == 0) { - ip->i_gen = krandom() / 2 + 1; + ip->i_gen = ((uint32_t)karc4random() >> 1) + 1; if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) ip->i_flag |= IN_MODIFIED; } --- a/sys/vfs/ext2fs/ext2_vfsops.c +++ b/sys/vfs/ext2fs/ext2_vfsops.c @@ -1418,7 +1418,7 @@ * already have one. This should only happen on old filesystems. */ if (ip->i_gen == 0) { - ip->i_gen = krandom() / 2 + 1; + ip->i_gen = ((uint32_t)karc4random() >> 1) + 1; if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) ip->i_flag |= IN_MODIFIED; } --- a/sys/netinet6/frag6.c +++ b/sys/netinet6/frag6.c @@ -94,17 +94,10 @@ void frag6_init(void) { - struct timeval tv; - ip6_maxfragpackets = nmbclusters / 4; ip6_maxfrags = nmbclusters / 4; - /* - * in many cases, random() here does NOT return random number - * as initialization during bootstrap time occur in fixed order. - */ - microtime(&tv); - ip6_id = krandom() ^ tv.tv_usec; + ip6_id = karc4random(); ip6q.ip6q_next = ip6q.ip6q_prev = &ip6q; netmsg_init(&frag6_drain_nmsg, NULL, &netisr_adone_rport, --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -750,7 +750,7 @@ } else { struct mbuf **mnext, *m_frgpart; struct ip6_frag *ip6f; - u_int32_t id = htonl(ip6_id++); + u_int32_t id = htonl(karc4random()); u_char nextproto; /* --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -151,7 +151,6 @@ { struct protosw *pr; int i; - struct timeval tv; pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); if (pr == NULL) @@ -176,14 +175,8 @@ addrsel_policy_init(); nd6_init(); frag6_init(); - /* - * in many cases, random() here does NOT return random number - * as initialization during bootstrap time occur in fixed order. - */ - microtime(&tv); - ip6_flow_seq = krandom() ^ tv.tv_usec; - microtime(&tv); - ip6_desync_factor = (krandom() ^ tv.tv_usec) % MAX_TEMP_DESYNC_FACTOR; + ip6_flow_seq = karc4random(); + ip6_desync_factor = karc4random() % MAX_TEMP_DESYNC_FACTOR; } static void --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -133,7 +133,6 @@ MD5_CTX ctxt; u_int8_t seed[16], digest[16], nullbuf[8]; u_int32_t val32; - struct timeval tv; /* If there's no hisotry, start with a random seed. */ bzero(nullbuf, sizeof(nullbuf)); @@ -141,8 +140,7 @@ int i; for (i = 0; i < 2; i++) { - microtime(&tv); - val32 = krandom() ^ tv.tv_usec; + val32 = karc4random(); bcopy(&val32, seed + sizeof(val32) * i, sizeof(val32)); } } else { @@ -185,8 +183,7 @@ log(LOG_INFO, "generate_tmp_ifid: computed MD5 value is zero.\n"); - microtime(&tv); - val32 = krandom() ^ tv.tv_usec; + val32 = karc4random(); val32 = 1 + (val32 % (0xffffffff - 1)); } --- a/sys/vfs/nfs/nfsm_subs.c +++ b/sys/vfs/nfs/nfsm_subs.c @@ -101,8 +101,6 @@ #include <netinet/in.h> -static u_int32_t nfs_xid = 0; - /* * Create the header for an rpc request packet * The hsiz is the size of the rest of the nfs request header. @@ -154,12 +152,9 @@ */ tl = nfsm_build(&info, 8 * NFSX_UNSIGNED); - /* Get a pretty random xid to start with */ - if (!nfs_xid) - nfs_xid = krandom(); - + /* Random XID per request (32 bits of arc4). */ do { - xid = atomic_fetchadd_int(&nfs_xid, 1); + xid = karc4random(); } while (xid == 0); *tl++ = *xidp = txdr_unsigned(xid); --- a/sys/net/sppp/if_spppsubr.c +++ b/sys/net/sppp/if_spppsubr.c @@ -1248,7 +1248,7 @@ ++sp->pp_loopcnt; /* Generate new local sequence number */ - sp->pp_seq[IDX_LCP] = krandom(); + sp->pp_seq[IDX_LCP] = karc4random(); break; } sp->pp_loopcnt = 0; @@ -2524,7 +2524,7 @@ if (magic == ~sp->lcp.magic) { if (debug) log(-1, "magic glitch "); - sp->lcp.magic = krandom(); + sp->lcp.magic = karc4random(); } else { sp->lcp.magic = magic; if (debug) @@ -2706,7 +2706,7 @@ if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) { if (! sp->lcp.magic) - sp->lcp.magic = krandom(); + sp->lcp.magic = karc4random(); opt[i++] = LCP_OPT_MAGIC; opt[i++] = 6; opt[i++] = sp->lcp.magic >> 24; @@ -4256,16 +4256,10 @@ static void sppp_chap_scr(struct sppp *sp) { - u_long *ch, seed; u_char clen; /* Compute random challenge. */ - ch = (u_long *)sp->myauth.challenge; - read_random(&seed, sizeof(seed), 0); - ch[0] = seed ^ krandom(); - ch[1] = seed ^ krandom(); - ch[2] = seed ^ krandom(); - ch[3] = seed ^ krandom(); + karc4random_buf(sp->myauth.challenge, AUTHKEYLEN); clen = AUTHKEYLEN; sp->confid[IDX_CHAP] = ++sp->pp_seq[IDX_CHAP]; --- a/sys/net/ipfw3_nat/ip_fw3_nat.c +++ b/sys/net/ipfw3_nat/ip_fw3_nat.c @@ -436,7 +436,7 @@ pick_alias_port(struct nat_state *s, struct state_tree *tree) { do { - s->alias_port = htons(krandom() % ALIAS_RANGE + ALIAS_BEGIN); + s->alias_port = htons(karc4random() % ALIAS_RANGE + ALIAS_BEGIN); } while (RB_FIND(state_tree, tree, s) != NULL); } |