Date: Fri, 6 Aug 2021 05:13:34 GMT From: "David E. O'Brien" <obrien@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 1ae8bd9a7d5a - stable/12 - fortuna: Drop global lock to zero stack variables Message-ID: <202108060513.1765DY5p000926@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by obrien: URL: https://cgit.FreeBSD.org/src/commit/?id=1ae8bd9a7d5ac1247db21d8f302d3d0513e08702 commit 1ae8bd9a7d5ac1247db21d8f302d3d0513e08702 Author: Conrad Meyer <cem@FreeBSD.org> AuthorDate: 2018-10-26 21:00:26 +0000 Commit: David E. O'Brien <obrien@FreeBSD.org> CommitDate: 2021-08-06 05:12:10 +0000 fortuna: Drop global lock to zero stack variables Also drop explicit zeroing of hash context -- hash finish() operation is expected to do this. PR: 230877 Suggested by: delphij@ Reviewed by: delphij, markm Approved by: secteam (delphij) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D16986 (cherry picked from commit 7be4093a844e80a591221e93d03f3daf6a972be3) --- sys/dev/random/fortuna.c | 65 +++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/sys/dev/random/fortuna.c b/sys/dev/random/fortuna.c index 0eaffa1de439..866899846212 100644 --- a/sys/dev/random/fortuna.c +++ b/sys/dev/random/fortuna.c @@ -374,47 +374,50 @@ random_fortuna_pre_read(void) now = getsbinuptime(); #endif - if (fortuna_state.fs_pool[0].fsp_length >= fortuna_state.fs_minpoolsize + if (fortuna_state.fs_pool[0].fsp_length < fortuna_state.fs_minpoolsize #ifdef _KERNEL /* FS&K - Use 'getsbinuptime()' to prevent reseed-spamming. */ - && (now - fortuna_state.fs_lasttime > SBT_1S/10) + || (now - fortuna_state.fs_lasttime <= SBT_1S/10) #endif ) { + RANDOM_RESEED_UNLOCK(); + return; + } + #ifdef _KERNEL - fortuna_state.fs_lasttime = now; + fortuna_state.fs_lasttime = now; #endif - /* FS&K - ReseedCNT = ReseedCNT + 1 */ - fortuna_state.fs_reseedcount++; - /* s = \epsilon at start */ - for (i = 0; i < RANDOM_FORTUNA_NPOOLS; i++) { - /* FS&K - if Divides(ReseedCnt, 2^i) ... */ - if ((fortuna_state.fs_reseedcount % (1 << i)) == 0) { - /*- - * FS&K - temp = (P_i) - * - P_i = \epsilon - * - s = s|H(temp) - */ - randomdev_hash_finish(&fortuna_state.fs_pool[i].fsp_hash, temp); - randomdev_hash_init(&fortuna_state.fs_pool[i].fsp_hash); - fortuna_state.fs_pool[i].fsp_length = 0; - randomdev_hash_init(&context); - randomdev_hash_iterate(&context, temp, RANDOM_KEYSIZE); - randomdev_hash_finish(&context, s + i*RANDOM_KEYSIZE_WORDS); - } else - break; - } + /* FS&K - ReseedCNT = ReseedCNT + 1 */ + fortuna_state.fs_reseedcount++; + /* s = \epsilon at start */ + for (i = 0; i < RANDOM_FORTUNA_NPOOLS; i++) { + /* FS&K - if Divides(ReseedCnt, 2^i) ... */ + if ((fortuna_state.fs_reseedcount % (1 << i)) == 0) { + /*- + * FS&K - temp = (P_i) + * - P_i = \epsilon + * - s = s|H(temp) + */ + randomdev_hash_finish(&fortuna_state.fs_pool[i].fsp_hash, temp); + randomdev_hash_init(&fortuna_state.fs_pool[i].fsp_hash); + fortuna_state.fs_pool[i].fsp_length = 0; + randomdev_hash_init(&context); + randomdev_hash_iterate(&context, temp, RANDOM_KEYSIZE); + randomdev_hash_finish(&context, s + i*RANDOM_KEYSIZE_WORDS); + } else + break; + } #ifdef _KERNEL - SDT_PROBE2(random, fortuna, event_processor, debug, fortuna_state.fs_reseedcount, fortuna_state.fs_pool); + SDT_PROBE2(random, fortuna, event_processor, debug, fortuna_state.fs_reseedcount, fortuna_state.fs_pool); #endif - /* FS&K */ - random_fortuna_reseed_internal(s, i); - /* Clean up and secure */ - explicit_bzero(s, sizeof(s)); - explicit_bzero(temp, sizeof(temp)); - explicit_bzero(&context, sizeof(context)); - } + /* FS&K */ + random_fortuna_reseed_internal(s, i); RANDOM_RESEED_UNLOCK(); + + /* Clean up and secure */ + explicit_bzero(s, sizeof(s)); + explicit_bzero(temp, sizeof(temp)); } /*-
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108060513.1765DY5p000926>