FreeBSD Bugzilla – Attachment 189567 Details for
Bug 182610
[patch] arc4random(3): replace RC4 with ChaCha20, follow OpenBSD
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch to make userspace arc4random fork safe
arc4random-fork-safety.patch (text/plain), 1.83 KB, created by
Jan Kokemüller
on 2018-01-09 19:06:56 UTC
(
hide
)
Description:
patch to make userspace arc4random fork safe
Filename:
MIME Type:
Creator:
Jan Kokemüller
Created:
2018-01-09 19:06:56 UTC
Size:
1.83 KB
patch
obsolete
>diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c >index 1c4d6eebe5fe..4294de02f47e 100644 >--- a/lib/libc/gen/arc4random.c >+++ b/lib/libc/gen/arc4random.c >@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); > #include <limits.h> > #include <stdlib.h> > #include <unistd.h> >+#include <sys/mman.h> > #include <sys/param.h> > #include <sys/sysctl.h> > #include <sys/time.h> >@@ -76,7 +77,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; > static int rs_initialized; > static struct arc4_stream rs; > static pid_t arc4_stir_pid; >-static int arc4_count; >+static int* arc4_count; > > extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, > void *newp, size_t newlen); >@@ -89,6 +90,12 @@ arc4_init(void) > { > int n; > >+ if ((arc4_count = mmap(NULL, sizeof(int), PROT_READ|PROT_WRITE, >+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) >+ abort(); >+ if (minherit(arc4_count, sizeof(int), INHERIT_ZERO) == -1) >+ abort(); >+ > for (n = 0; n < 256; n++) > rs.s[n] = n; > rs.i = 0; >@@ -162,7 +169,7 @@ arc4_stir(void) > */ > for (i = 0; i < 3072; i++) > (void)arc4_getbyte(); >- arc4_count = 1600000; >+ *arc4_count = 1600000; > } > > static void >@@ -170,7 +177,8 @@ arc4_stir_if_needed(void) > { > pid_t pid = getpid(); > >- if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) { >+ if (arc4_count == NULL || *arc4_count <= 0 || !rs_initialized || >+ arc4_stir_pid != pid) { > arc4_stir_pid = pid; > arc4_stir(); > } >@@ -224,7 +232,8 @@ arc4random(void) > { > u_int32_t val; > _ARC4_LOCK(); >- arc4_count -= 4; >+ if (arc4_count) >+ *arc4_count -= 4; > arc4_stir_if_needed(); > val = arc4_getword(); > _ARC4_UNLOCK(); >@@ -238,7 +247,7 @@ arc4random_buf(void *_buf, size_t n) > _ARC4_LOCK(); > arc4_stir_if_needed(); > while (n--) { >- if (--arc4_count <= 0) >+ if (--*arc4_count <= 0) > arc4_stir(); > buf[n] = arc4_getbyte(); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 182610
:
147975
|
147976
|
149068
|
149507
|
189567
|
196272
|
196337
|
196342