Skip to content

Commit

Permalink
workaround msvc uninitialized stack bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Dec 26, 2024
1 parent 1400a30 commit eb4430e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
35 changes: 18 additions & 17 deletions SystemInformer/ksisup.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,20 @@ NTSTATUS PhRestartSelf(
)
{
#ifndef DEBUG
#define DEFAULT_MITIGATION_POLICY_FLAGS \
(PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_ALWAYS_ON)
#define DEFAULT_MITIGATION_POLICY_FLAGS2 \
(PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_ALWAYS_ON | \
PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_ALWAYS_ON)
// PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_ALWAYS_ON
// PROCESS_CREATION_MITIGATION_POLICY2_XTENDED_CONTROL_FLOW_GUARD_ALWAYS_ON
static ULONG64 mitigationFlags[] =
{
(PROCESS_CREATION_MITIGATION_POLICY_HEAP_TERMINATE_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY_HIGH_ENTROPY_ASLR_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY_IMAGE_LOAD_PREFER_SYSTEM32_ALWAYS_ON),
(PROCESS_CREATION_MITIGATION_POLICY2_LOADER_INTEGRITY_CONTINUITY_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY2_STRICT_CONTROL_FLOW_GUARD_ALWAYS_ON |
// PROCESS_CREATION_MITIGATION_POLICY2_BLOCK_NON_CET_BINARIES_ALWAYS_ON |
// PROCESS_CREATION_MITIGATION_POLICY2_XTENDED_CONTROL_FLOW_GUARD_ALWAYS_ON |
PROCESS_CREATION_MITIGATION_POLICY2_MODULE_TAMPERING_PROTECTION_ALWAYS_ON)
};
#endif
NTSTATUS status;
PPROC_THREAD_ATTRIBUTE_LIST attributeList = NULL;
Expand Down Expand Up @@ -483,17 +484,17 @@ NTSTATUS PhRestartSelf(
status = PhUpdateProcThreadAttribute(
attributeList,
PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY,
&(ULONG64[2]){ DEFAULT_MITIGATION_POLICY_FLAGS, DEFAULT_MITIGATION_POLICY_FLAGS2 },
sizeof(ULONG64[2])
mitigationFlags,
sizeof(ULONG64) * 2
);
}
else
{
status = PhUpdateProcThreadAttribute(
attributeList,
PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY,
&(ULONG64[1]) { DEFAULT_MITIGATION_POLICY_FLAGS },
sizeof(ULONG64[1])
mitigationFlags,
sizeof(ULONG64) * 1
);
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions phlib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -8808,8 +8808,7 @@ NTSTATUS PhInitializeProcThreadAttributeList(
PPROC_THREAD_ATTRIBUTE_LIST attributeList;
SIZE_T attributeListLength;

if (!InitializeProcThreadAttributeList(NULL, AttributeCount, 0, &attributeListLength))
return STATUS_NO_MEMORY;
InitializeProcThreadAttributeList(NULL, AttributeCount, 0, &attributeListLength);

attributeList = PhAllocateZero(attributeListLength);
attributeList->AttributeCount = AttributeCount;
Expand All @@ -8820,7 +8819,8 @@ NTSTATUS PhInitializeProcThreadAttributeList(
PPROC_THREAD_ATTRIBUTE_LIST attributeList;
SIZE_T attributeListLength;

attributeListLength = FIELD_OFFSET(PROC_THREAD_ATTRIBUTE_LIST, Attributes[AttributeCount]);
attributeListLength = FIELD_OFFSET(PROC_THREAD_ATTRIBUTE_LIST, Attributes);
attributeListLength += sizeof(PROC_THREAD_ATTRIBUTE) * AttributeCount;
attributeList = PhAllocateZero(attributeListLength);
attributeList->AttributeCount = AttributeCount;
*AttributeList = attributeList;
Expand Down

0 comments on commit eb4430e

Please sign in to comment.