mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
Merge branch 'fanf-random-failures' into 'main'
Revert "Move random number re-seeding out of the hot path" See merge request isc-projects/bind9!6172
This commit is contained in:
@@ -170,7 +170,6 @@ libisc_la_SOURCES = \
|
|||||||
quota.c \
|
quota.c \
|
||||||
radix.c \
|
radix.c \
|
||||||
random.c \
|
random.c \
|
||||||
random_p.h \
|
|
||||||
ratelimiter.c \
|
ratelimiter.c \
|
||||||
regex.c \
|
regex.c \
|
||||||
region.c \
|
region.c \
|
||||||
|
@@ -22,7 +22,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "mem_p.h"
|
#include "mem_p.h"
|
||||||
#include "os_p.h"
|
#include "os_p.h"
|
||||||
#include "random_p.h"
|
|
||||||
#include "tls_p.h"
|
#include "tls_p.h"
|
||||||
#include "trampoline_p.h"
|
#include "trampoline_p.h"
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ void
|
|||||||
isc__initialize(void) {
|
isc__initialize(void) {
|
||||||
isc__os_initialize();
|
isc__os_initialize();
|
||||||
isc__mem_initialize();
|
isc__mem_initialize();
|
||||||
isc__random_initialize();
|
|
||||||
isc__tls_initialize();
|
isc__tls_initialize();
|
||||||
isc__trampoline_initialize();
|
isc__trampoline_initialize();
|
||||||
(void)isc_os_ncpus();
|
(void)isc_os_ncpus();
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <isc/once.h>
|
||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/result.h>
|
#include <isc/result.h>
|
||||||
#include <isc/thread.h>
|
#include <isc/thread.h>
|
||||||
@@ -42,7 +43,6 @@
|
|||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include "entropy_private.h"
|
#include "entropy_private.h"
|
||||||
#include "random_p.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
|
* Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
|
||||||
@@ -88,8 +88,11 @@ next(void) {
|
|||||||
|
|
||||||
return (result_starstar);
|
return (result_starstar);
|
||||||
}
|
}
|
||||||
void
|
|
||||||
isc__random_initialize(void) {
|
static thread_local isc_once_t isc_random_once = ISC_ONCE_INIT;
|
||||||
|
|
||||||
|
static void
|
||||||
|
isc_random_initialize(void) {
|
||||||
int useed[4] = { 0, 0, 0, 1 };
|
int useed[4] = { 0, 0, 0, 1 };
|
||||||
#if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
#if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
/*
|
/*
|
||||||
@@ -105,16 +108,22 @@ isc__random_initialize(void) {
|
|||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
isc_random8(void) {
|
isc_random8(void) {
|
||||||
|
RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) ==
|
||||||
|
ISC_R_SUCCESS);
|
||||||
return ((uint8_t)next());
|
return ((uint8_t)next());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t
|
uint16_t
|
||||||
isc_random16(void) {
|
isc_random16(void) {
|
||||||
|
RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) ==
|
||||||
|
ISC_R_SUCCESS);
|
||||||
return ((uint16_t)next());
|
return ((uint16_t)next());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
isc_random32(void) {
|
isc_random32(void) {
|
||||||
|
RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) ==
|
||||||
|
ISC_R_SUCCESS);
|
||||||
return (next());
|
return (next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +135,9 @@ isc_random_buf(void *buf, size_t buflen) {
|
|||||||
REQUIRE(buf != NULL);
|
REQUIRE(buf != NULL);
|
||||||
REQUIRE(buflen > 0);
|
REQUIRE(buflen > 0);
|
||||||
|
|
||||||
|
RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) ==
|
||||||
|
ISC_R_SUCCESS);
|
||||||
|
|
||||||
for (i = 0; i + sizeof(r) <= buflen; i += sizeof(r)) {
|
for (i = 0; i + sizeof(r) <= buflen; i += sizeof(r)) {
|
||||||
r = next();
|
r = next();
|
||||||
memmove((uint8_t *)buf + i, &r, sizeof(r));
|
memmove((uint8_t *)buf + i, &r, sizeof(r));
|
||||||
@@ -137,6 +149,8 @@ isc_random_buf(void *buf, size_t buflen) {
|
|||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
isc_random_uniform(uint32_t limit) {
|
isc_random_uniform(uint32_t limit) {
|
||||||
|
RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) ==
|
||||||
|
ISC_R_SUCCESS);
|
||||||
/*
|
/*
|
||||||
* Daniel Lemire's nearly-divisionless unbiased bounded random numbers.
|
* Daniel Lemire's nearly-divisionless unbiased bounded random numbers.
|
||||||
*
|
*
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*
|
|
||||||
* See the COPYRIGHT file distributed with this work for additional
|
|
||||||
* information regarding copyright ownership.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <isc/lang.h>
|
|
||||||
|
|
||||||
/*! \file isc/random_p.h
|
|
||||||
* \brief For automatically seeding and re-seeding when required.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ISC_LANG_BEGINDECLS
|
|
||||||
|
|
||||||
void
|
|
||||||
isc__random_initialize(void);
|
|
||||||
/*!<
|
|
||||||
* \brief Seed the thread-local random number state with fresh entropy.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ISC_LANG_ENDDECLS
|
|
@@ -87,11 +87,6 @@ _setup(void **state) {
|
|||||||
result = isc_test_begin(NULL, true, 0);
|
result = isc_test_begin(NULL, true, 0);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
|
||||||
* Ensure the RNG has been seeded.
|
|
||||||
*/
|
|
||||||
assert_int_not_equal(isc_random32(), 0);
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,6 @@
|
|||||||
#include <isc/thread.h>
|
#include <isc/thread.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include "random_p.h"
|
|
||||||
#include "trampoline_p.h"
|
#include "trampoline_p.h"
|
||||||
|
|
||||||
#define ISC__TRAMPOLINE_UNUSED 0
|
#define ISC__TRAMPOLINE_UNUSED 0
|
||||||
@@ -186,11 +185,6 @@ isc__trampoline_attach(isc__trampoline_t *trampoline) {
|
|||||||
* malloc() + free() calls altogether, as it would foil the fix.
|
* malloc() + free() calls altogether, as it would foil the fix.
|
||||||
*/
|
*/
|
||||||
trampoline->jemalloc_enforce_init = malloc(8);
|
trampoline->jemalloc_enforce_init = malloc(8);
|
||||||
|
|
||||||
/*
|
|
||||||
* Re-seed the random number generator in each thread.
|
|
||||||
*/
|
|
||||||
isc__random_initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_threadresult_t
|
isc_threadresult_t
|
||||||
|
Reference in New Issue
Block a user