-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
src: add proper mutexes for accessing FIPS state #42278
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,13 @@ bool InitCryptoOnce(Isolate* isolate) { | |
return true; | ||
} | ||
|
||
// Protect accesses to FIPS state with a mutex. This should potentially | ||
// be part of a larger mutex for global OpenSSL state. | ||
static Mutex fips_mutex; | ||
|
||
void InitCryptoOnce() { | ||
Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
Mutex::ScopedLock fips_lock(fips_mutex); | ||
#ifndef OPENSSL_IS_BORINGSSL | ||
OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new(); | ||
|
||
|
@@ -196,6 +202,9 @@ void InitCryptoOnce() { | |
} | ||
|
||
void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | ||
Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
Mutex::ScopedLock fips_lock(fips_mutex); | ||
|
||
#if OPENSSL_VERSION_MAJOR >= 3 | ||
args.GetReturnValue().Set(EVP_default_properties_is_fips_enabled(nullptr) ? | ||
1 : 0); | ||
|
@@ -205,8 +214,13 @@ void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |
} | ||
|
||
void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | ||
Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
Mutex::ScopedLock fips_lock(fips_mutex); | ||
|
||
CHECK(!per_process::cli_options->force_fips_crypto); | ||
Environment* env = Environment::GetCurrent(args); | ||
// TODO: This should not be possible to set from worker threads. | ||
// CHECK(env->owns_process_state()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left out because this could be seen as a semver-major change. If we don’t think it’s semver-major, I’m happy to add this as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth doing this for Node.js 18 as a semver-major anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sure. It’s just not quite as important and I didn’t want to make this PR one that wouldn’t be backported. |
||
bool enable = args[0]->BooleanValue(env->isolate()); | ||
|
||
#if OPENSSL_VERSION_MAJOR >= 3 | ||
|
@@ -227,6 +241,9 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |
} | ||
|
||
void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
Mutex::ScopedLock fips_lock(fips_mutex); | ||
|
||
#ifdef OPENSSL_FIPS | ||
#if OPENSSL_VERSION_MAJOR >= 3 | ||
OSSL_PROVIDER* fips_provider = nullptr; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense for semantic reasons, but is my understanding correct that this is technically not required since
per_process::cli_options_mutex
will already guarantee mutually exclusive access wheneverfips_mutex
is used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct as far as the current state of this PR is concerned. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying! 😃