Skip to content

Commit c0d3fc2

Browse files
sam-githubtargos
authored andcommitted
src: sync access for report and openssl options
Audited usage of per-process OpenSSL and Report options, adding two required mutexes. Also documented existence and typical use of the per-process cli option mutex. PR-URL: #32618 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent b3ac840 commit c0d3fc2

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/node_crypto.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ static X509_STORE* NewRootCertStore() {
973973
if (*system_cert_path != '\0') {
974974
X509_STORE_load_locations(store, system_cert_path, nullptr);
975975
}
976+
977+
Mutex::ScopedLock cli_lock(node::per_process::cli_options_mutex);
976978
if (per_process::cli_options->ssl_openssl_cert_store) {
977979
X509_STORE_set_default_paths(store);
978980
} else {

src/node_errors.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,13 @@ void OnFatalError(const char* location, const char* message) {
406406

407407
Isolate* isolate = Isolate::GetCurrent();
408408
Environment* env = Environment::GetCurrent(isolate);
409-
if (per_process::cli_options->report_on_fatalerror) {
409+
bool report_on_fatalerror;
410+
{
411+
Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
412+
report_on_fatalerror = per_process::cli_options->report_on_fatalerror;
413+
}
414+
415+
if (report_on_fatalerror) {
410416
report::TriggerNodeReport(
411417
isolate, env, message, "FatalError", "", Local<String>());
412418
}

src/node_options.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ class PerIsolateOptions : public Options {
194194

195195
class PerProcessOptions : public Options {
196196
public:
197+
// Options shouldn't be here unless they affect the entire process scope, and
198+
// that should avoided when possible.
199+
//
200+
// When an option is used during process initialization, it does not need
201+
// protection, but any use after that will likely require synchronization
202+
// using the node::per_process::cli_options_mutex, typically:
203+
//
204+
// Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
197205
std::shared_ptr<PerIsolateOptions> per_isolate { new PerIsolateOptions() };
198206

199207
std::string title;
@@ -215,7 +223,8 @@ class PerProcessOptions : public Options {
215223
std::string icu_data_dir;
216224
#endif
217225

218-
// TODO(addaleax): Some of these could probably be per-Environment.
226+
// Per-process because they affect singleton OpenSSL shared library state,
227+
// or are used once during process intialization.
219228
#if HAVE_OPENSSL
220229
std::string openssl_config;
221230
std::string tls_cipher_list = DEFAULT_CIPHER_LIST_CORE;
@@ -231,14 +240,18 @@ class PerProcessOptions : public Options {
231240
bool force_fips_crypto = false;
232241
#endif
233242
#endif
234-
std::string use_largepages = "off";
235-
bool trace_sigint = false;
236-
std::vector<std::string> cmdline;
243+
244+
// Per-process because reports can be triggered outside a known V8 context.
237245
bool report_on_fatalerror = false;
238246
bool report_compact = false;
239247
std::string report_directory;
240248
std::string report_filename;
241249

250+
// TODO(addaleax): Some of these could probably be per-Environment.
251+
std::string use_largepages = "off";
252+
bool trace_sigint = false;
253+
std::vector<std::string> cmdline;
254+
242255
inline PerIsolateOptions* get_per_isolate_options();
243256
void CheckOptions(std::vector<std::string>* errors) override;
244257
};

0 commit comments

Comments
 (0)