-
Notifications
You must be signed in to change notification settings - Fork 738
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
WIP: Check Control Flow Guard on Windows #21154
base: master
Are you sure you want to change the base?
Conversation
If Control Flow Guard (CFG) is enabled in Windows, set TR_NoResumableTrapHandler in the JIT. This change relies on API GetProcessMitigationPolicy. Its minimum supported client version is Windows 8 and its minimum supported server version is Windows Server 2012. Fixes: eclipse-openj9#19892 Signed-off-by: Annabelle Huo <[email protected]>
703ed2d
to
e547739
Compare
@0xdaryl @keithc-ca May I ask you to review this change? Thank you! @JamesKingdon fyi |
The JIT change is ok with me. |
// If Control Flow Guard (CFG) is enabled in Windows, set TR_NoResumableTrapHandler | ||
if (J9_ARE_ALL_BITS_SET(javaVM->sigFlags, J9_SIG_WINDOWS_MITIGATION_POLICY_CFG_ENABLED)) |
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.
Please finish each sentence with a period.
This should use _ANY_
instead of _ALL_
(it's testing a single bit):
// If Control Flow Guard (CFG) is enabled in Windows, set TR_NoResumableTrapHandler.
if (J9_ARE_ANY_BITS_SET(javaVM->sigFlags, J9_SIG_WINDOWS_MITIGATION_POLICY_CFG_ENABLED))
While you're here, please correct the typo on line 3289 (jitt -> jit).
#if defined(WIN32) | ||
#if defined(_WIN32_WINNT_WINBLUE) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WINBLUE) |
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.
Suggest merging these:
#if defined(WIN32) && defined(_WIN32_WINNT_WINBLUE) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WINBLUE)
then updating the #endif
comment
#endif /* defined(WIN32) && defined(_WIN32_WINNT_WINBLUE) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WINBLUE) */
HMODULE h_kernel32 = GetModuleHandle(TEXT("kernel32.dll")); | ||
|
||
if (h_kernel32 && IsWindows8OrGreater()) { | ||
void *getProcessMitigationPolicyFunc = (void*)GetProcAddress(h_kernel32, "GetProcessMitigationPolicy"); |
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.
Suggest introducing a typdef, so fewer casts are needed:
typedef (BOOL (WINAPI * PMP_func)(HANDLE, PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
PMP_func getProcessMitigationPolicyFunc = (PMP_func)GetProcAddress(h_kernel32, "GetProcessMitigationPolicy");
Please make null checks explicit and split the condition according to our coding standard:
if (((PMP_func)NULL != getProcessMitigationPolicyFunc)
&& getProcessMitigationPolicyFunc(
GetCurrentProcess(),
ProcessControlFlowGuardPolicy,
&cfgPolicy,
sizeof(cfgPolicy))
&& cfgPolicy.EnableControlFlowGuard
) {
Change status to |
If Control Flow Guard (CFG) is enabled in Windows, set
TR_NoResumableTrapHandler
in the JIT.This change relies on API
GetProcessMitigationPolicy
. Its minimum supported client version is Windows 8 and its minimum supported server version is Windows Server 2012.Fixes: #19892