From owner-svn-src-all@FreeBSD.ORG Wed Feb 18 08:21:53 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 85FA9D57; Wed, 18 Feb 2015 08:21:53 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 56ADD1AE; Wed, 18 Feb 2015 08:21:53 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1I8LqvK032002; Wed, 18 Feb 2015 08:21:52 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1I8Lqxj032000; Wed, 18 Feb 2015 08:21:52 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201502180821.t1I8Lqxj032000@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Wed, 18 Feb 2015 08:21:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278950 - head/sys/dev/random X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Feb 2015 08:21:53 -0000 Author: delphij Date: Wed Feb 18 08:21:51 2015 New Revision: 278950 URL: https://svnweb.freebsd.org/changeset/base/278950 Log: - 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) Modified: head/sys/dev/random/fortuna.c head/sys/dev/random/yarrow.c Modified: head/sys/dev/random/fortuna.c ============================================================================== --- head/sys/dev/random/fortuna.c Wed Feb 18 08:10:13 2015 (r278949) +++ head/sys/dev/random/fortuna.c Wed Feb 18 08:21:51 2015 (r278950) @@ -298,8 +298,13 @@ random_fortuna_genrandom(uint8_t *buf, u 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); Modified: head/sys/dev/random/yarrow.c ============================================================================== --- head/sys/dev/random/yarrow.c Wed Feb 18 08:10:13 2015 (r278949) +++ head/sys/dev/random/yarrow.c Wed Feb 18 08:21:51 2015 (r278950) @@ -450,6 +450,7 @@ random_yarrow_read(uint8_t *buf, u_int b } 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);