Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pre-sandbox setup #1825

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/crypto.h>
#include <openssl/rand.h>

#include <assert.h>

#include "fipsmodule/rand/fork_detect.h"
#include "fipsmodule/rand/internal.h"
#include "fipsmodule/cpucap/internal.h"
#include "internal.h"


Expand Down Expand Up @@ -107,10 +107,15 @@ int CRYPTO_has_asm(void) {
void CRYPTO_pre_sandbox_init(void) {
// Read from /proc/cpuinfo if needed.
CRYPTO_library_init();
// Open /dev/urandom if needed.
CRYPTO_init_sysrand();
// Set up MADV_WIPEONFORK state if needed.
CRYPTO_get_fork_generation();

// The randomness generation subsystem has a few kernel touch points that
// can be blocked when sandboxed. For example, /dev/urandom, MADV_WIPEONFORK
// tagged state, and snapsafe allocated state. All this is implemented lazily.
// Invoke the top-level function that will kick off the lazy work pre-sandbox.
uint8_t buf[10];
if (RAND_bytes(buf, 10) != 1) {
abort();
}
}

const char *SSLeay_version(int which) { return OpenSSL_version(which); }
Expand Down
Loading