summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Thomas McBride <mcbride@cvs.openbsd.org>2004-04-26 02:03:39 +0000
committerRyan Thomas McBride <mcbride@cvs.openbsd.org>2004-04-26 02:03:39 +0000
commit457c95d5f38df1157f61dbb83f547270a0f9aeee (patch)
tree8d1675fc717671a6451960ed4056fc95b9a7cee4
parent108eb7188637786190e3fac136593036552c3802 (diff)
Prevent biases in arc4random() from disclosing the byte order of the firewall.
ok deraadt@
-rw-r--r--sys/net/pf.c26
-rw-r--r--sys/net/pf_norm.c5
2 files changed, 18 insertions, 13 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c
index 185c4d7c102..80d95be10d0 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.441 2004/04/26 00:12:27 cedric Exp $ */
+/* $OpenBSD: pf.c,v 1.442 2004/04/26 02:03:38 mcbride Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -1803,25 +1803,29 @@ pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr,
switch (af) {
#ifdef INET
case AF_INET:
- rpool->counter.addr32[0] = arc4random();
+ rpool->counter.addr32[0] = htonl(arc4random());
break;
#endif /* INET */
#ifdef INET6
case AF_INET6:
if (rmask->addr32[3] != 0xffffffff)
- rpool->counter.addr32[3] = arc4random();
+ rpool->counter.addr32[3] =
+ htonl(arc4random());
else
break;
if (rmask->addr32[2] != 0xffffffff)
- rpool->counter.addr32[2] = arc4random();
+ rpool->counter.addr32[2] =
+ htonl(arc4random());
else
break;
if (rmask->addr32[1] != 0xffffffff)
- rpool->counter.addr32[1] = arc4random();
+ rpool->counter.addr32[1] =
+ htonl(arc4random());
else
break;
if (rmask->addr32[0] != 0xffffffff)
- rpool->counter.addr32[0] = arc4random();
+ rpool->counter.addr32[0] =
+ htonl(arc4random());
break;
#endif /* INET6 */
}
@@ -1946,7 +1950,7 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r,
high = tmp;
}
/* low < high */
- cut = arc4random() % (1 + high - low) + low;
+ cut = htonl(arc4random()) % (1 + high - low) + low;
/* low <= cut <= high */
for (tmp = cut; tmp <= high; ++(tmp)) {
key.gwy.port = htons(tmp);
@@ -2665,7 +2669,7 @@ cleanup:
if ((th->th_flags & (TH_SYN|TH_ACK)) == TH_SYN &&
r->keep_state == PF_STATE_MODULATE) {
/* Generate sequence number modulator */
- while ((s->src.seqdiff = arc4random()) == 0)
+ while ((s->src.seqdiff = htonl(arc4random())) == 0)
;
pf_change_a(&th->th_seq, &th->th_sum,
htonl(s->src.seqlo + s->src.seqdiff), 0);
@@ -2740,7 +2744,7 @@ cleanup:
bport, 0, af);
}
}
- s->src.seqhi = arc4random();
+ s->src.seqhi = htonl(arc4random());
/* Find mss option */
mss = pf_get_mss(m, off, th->th_off, af);
mss = pf_calc_mss(saddr, af, mss);
@@ -3710,7 +3714,7 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif,
return (PF_DROP);
(*state)->src.max_win = MAX(ntohs(th->th_win), 1);
if ((*state)->dst.seqhi == 1)
- (*state)->dst.seqhi = arc4random();
+ (*state)->dst.seqhi = htonl(arc4random());
pf_send_tcp((*state)->rule.ptr, pd->af, &src->addr,
&dst->addr, src->port, dst->port,
(*state)->dst.seqhi, 0, TH_SYN, 0,
@@ -3772,7 +3776,7 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif,
/* Deferred generation of sequence number modulator */
if (dst->seqdiff && !src->seqdiff) {
- while ((src->seqdiff = arc4random()) == 0)
+ while ((src->seqdiff = htonl(arc4random())) == 0)
;
ack = ntohl(th->th_ack) - dst->seqdiff;
pf_change_a(&th->th_seq, &th->th_sum, htonl(seq +
diff --git a/sys/net/pf_norm.c b/sys/net/pf_norm.c
index ea1e2214d84..a05d2b6d0df 100644
--- a/sys/net/pf_norm.c
+++ b/sys/net/pf_norm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_norm.c,v 1.81 2004/04/24 19:14:48 frantzen Exp $ */
+/* $OpenBSD: pf_norm.c,v 1.82 2004/04/26 02:03:38 mcbride Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
@@ -1358,7 +1358,8 @@ pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd,
if (opt[1] >= TCPOLEN_TIMESTAMP) {
src->scrub->pfss_flags |=
PFSS_TIMESTAMP;
- src->scrub->pfss_ts_mod = arc4random();
+ src->scrub->pfss_ts_mod =
+ htonl(arc4random());
}
/* FALLTHROUGH */
default: