-
Notifications
You must be signed in to change notification settings - Fork 24
Fix/mingw stack chk crash #171
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d5d8f14
Fix mingwX64 crash by removing constructor in stack_chk.c (#170)
dokar3 46c76bb
Add Windows to CI matrix for mingwX64 testing
dokar3 c9d21da
Make JDK setup script cross-platform for Windows CI
dokar3 b1405c7
Use wget/curl for JDK downloads instead of fetch
dokar3 3788d61
Use unzip on Unix, tar on Windows for zip extraction
dokar3 2932f7f
Guard USER_HOME, unify downloads to curl
dokar3 d4c898a
Add integration test module to verify published artifacts
dokar3 e7a270d
Disable signing in Build CI to fix integration test verification
dokar3 7efdd36
Fix Linux CI failure: filter native targets by host OS when publishing
dokar3 3d82fe4
Fix MinGW crash: disable stack protector instead of providing manual …
dokar3 2589210
Revert stack check removal and disable abort on fail: Fix crash on MinGW
dokar3 9e480d8
Pin Zig to 0.12.0 to fix mingwX64Test crash
dokar3 ce5ffbf
Pin Zig in other workflows and use compile-time random stack canary
dokar3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,18 @@ | ||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
| #include <windows.h> | ||
|
|
||
| #if defined(_WIN32) | ||
|
|
||
| // Default stack guard value | ||
| // Stack guard value for stack-protector support on Windows/MinGW. | ||
| // A static value is used instead of runtime randomization because this code | ||
| // is compiled into a static library linked by Kotlin/Native. Using | ||
| // __attribute__((constructor)) to call LoadLibraryA/GetProcAddress for | ||
| // RtlGenRandom caused crashes (exit code 3) since the constructor runs | ||
| // before the Windows runtime is fully initialized in that context. | ||
| uintptr_t __stack_chk_guard = 0x595e9fbd94fda766; | ||
|
|
||
| void __stack_chk_fail(void) { | ||
| abort(); | ||
| } | ||
|
|
||
| typedef BOOLEAN (WINAPI *RtlGenRandomFunc)(PVOID, ULONG); | ||
|
|
||
| // Initialize the stack guard with a random value | ||
| __attribute__((constructor)) | ||
| static void __stack_chk_init(void) { | ||
| HMODULE hAdvApi32 = LoadLibraryA("advapi32.dll"); | ||
| if (hAdvApi32) { | ||
| RtlGenRandomFunc RtlGenRandom = (RtlGenRandomFunc)GetProcAddress(hAdvApi32, "SystemFunction036"); | ||
| if (RtlGenRandom) { | ||
| uintptr_t random_guard; | ||
| if (RtlGenRandom(&random_guard, sizeof(random_guard))) { | ||
| __stack_chk_guard = random_guard; | ||
| } | ||
| } | ||
| FreeLibrary(hAdvApi32); | ||
| } | ||
| } | ||
| #endif | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Static stack canary weakens stack-smashing protection.
The hardcoded guard value is visible in the source and the compiled binary, which means an attacker who can trigger a buffer overflow can also craft a payload that preserves the canary, effectively bypassing the protection. The rationale for avoiding runtime initialization is well-documented and understandable.
A couple of alternatives worth considering if you want some degree of variation without runtime Windows API calls:
__TIME__,__COUNTER__) so each build gets a different canary. It's not cryptographically strong but at least varies per build.If the threat model for this project doesn't prioritize stack canary strength (embedded JS engine context), the current approach is an acceptable pragmatic tradeoff — just want to flag the security implication explicitly.
🤖 Prompt for AI Agents