summaryrefslogtreecommitdiffstats
path: root/sys/dev/random
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-02-18 08:21:51 +0000
committerdelphij <delphij@FreeBSD.org>2015-02-18 08:21:51 +0000
commit1089c4379d704b36ef6f3cc39671c0cc20cfb881 (patch)
tree7306027764728c4bda0a2dc02c4f254f839721a6 /sys/dev/random
parent8f7883a87967eff00b5db7212f0627ea5e686370 (diff)
downloadFreeBSD-src-1089c4379d704b36ef6f3cc39671c0cc20cfb881.zip
FreeBSD-src-1089c4379d704b36ef6f3cc39671c0cc20cfb881.tar.gz
- fortuna.c: catch up with r278927 and fix a buffer overflow by using the
temporary buffer when remaining space is not enough to hold a whole block. - yarrow.c: add a comment that we intend to change the code and remove memcpy's in the future. (*) Requested by: markm (*) Reviewed by: markm Approved by: so (self)
Diffstat (limited to 'sys/dev/random')
-rw-r--r--sys/dev/random/fortuna.c7
-rw-r--r--sys/dev/random/yarrow.c1
2 files changed, 7 insertions, 1 deletions
diff --git a/sys/dev/random/fortuna.c b/sys/dev/random/fortuna.c
index 6f6febb..2bb31f4 100644
--- a/sys/dev/random/fortuna.c
+++ b/sys/dev/random/fortuna.c
@@ -298,8 +298,13 @@ random_fortuna_genrandom(uint8_t *buf, u_int bytecount)
KASSERT((bytecount <= (1 << 20)), ("invalid single read request to fortuna of %d bytes", bytecount));
/* F&S - r = first-n-bytes(GenerateBlocks(ceil(n/16))) */
- blockcount = (bytecount + BLOCKSIZE - 1)/BLOCKSIZE;
+ blockcount = bytecount / BLOCKSIZE;
random_fortuna_genblocks(buf, blockcount);
+ /* TODO: FIX! remove memcpy()! */
+ if (bytecount % BLOCKSIZE > 0) {
+ random_fortuna_genblocks(temp, 1);
+ memcpy(buf + (blockcount * BLOCKSIZE), temp, bytecount % BLOCKSIZE);
+ }
/* F&S - K = GenerateBlocks(2) */
random_fortuna_genblocks(temp, KEYSIZE/BLOCKSIZE);
diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c
index 8c1de99..88e09af 100644
--- a/sys/dev/random/yarrow.c
+++ b/sys/dev/random/yarrow.c
@@ -450,6 +450,7 @@ random_yarrow_read(uint8_t *buf, u_int bytecount)
}
uint128_increment(&yarrow_state.counter.whole);
if ((i + 1) * BLOCKSIZE > bytecount) {
+ /* TODO: FIX! remove memcpy()! */
randomdev_encrypt(&yarrow_state.key,
yarrow_state.counter.byte, tbuf, BLOCKSIZE);
memcpy(buf, tbuf, bytecount - i * BLOCKSIZE);
OpenPOWER on IntegriCloud