-
Notifications
You must be signed in to change notification settings - Fork 12
[PROF-15201] fix(profiler): close two TOCTOU races between SIGPROF handler and JFR lifecycle #614
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1381,8 +1381,6 @@ Error Profiler::start(Arguments &args, bool reset) { | |
| _libs->updateBuildIds(); | ||
| } | ||
|
|
||
| enableEngines(); | ||
|
|
||
| // Refresher must be running before the trap fires: dlopen_hook's | ||
| // signal-context branch only marks dirty and relies on the refresher | ||
| // to call refresh() within REFRESH_INTERVAL_NS (500 ms). | ||
|
|
@@ -1396,7 +1394,6 @@ Error Profiler::start(Arguments &args, bool reset) { | |
| _num_context_attributes = args._context_attributes.size(); | ||
| error = _jfr.start(args, reset); | ||
| if (error) { | ||
| disableEngines(); | ||
| switchLibraryTrap(false); | ||
| _libs->stopRefresher(); | ||
| return error; | ||
|
|
@@ -1471,6 +1468,15 @@ Error Profiler::start(Arguments &args, bool reset) { | |
| // TODO: find a better way to resolve the thread name. | ||
| onThreadStart(nullptr, nullptr, nullptr); | ||
|
|
||
| // enableEngines() (_enabled=true) is intentionally deferred until here, | ||
| // after _jfr.start() and all engine starts. Previously it was called | ||
| // before _jfr.start(), creating a TOCTOU race: a SIGPROF delivered | ||
| // between enableEngines() and _jfr.start() completing would enter | ||
| // recordSample() on partially-initialized JFR structures. | ||
| // Paired with drainInflight() in CTimer::stop() which closes the | ||
| // symmetric race on the stop side. | ||
| enableEngines(); | ||
|
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.
When wall profiling is requested, Useful? React with 👍 / 👎. |
||
|
|
||
| _state.store(RUNNING, std::memory_order_release); | ||
| _start_time = time(NULL); | ||
| __atomic_add_fetch(&_epoch, 1, __ATOMIC_RELAXED); | ||
|
|
||
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.
With
jvmtistackson Linux, this increment is not balanced when the handler takes thecurrent->inInitWindow()early return a few lines below. A single sample delivered during that thread-init window permanently leaves_inflightpositive, causing every laterCTimer::stop()to wait until the 200 ms timeout and then proceed without knowing whether any real handler is still in flight, which defeats the drain this patch adds.Useful? React with 👍 / 👎.