在 2025-7-3 20:06, Igor Kostenko 写道:
Fix stack protection bootstrapping issue where the canary initialization
function itself triggers false positive stack overflow detection.

Signed-off-by: Igor Kostenko <work.ker...@gmail.com>
---
  mingw-w64-crt/ssp/stack_chk_guard.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-crt/ssp/stack_chk_guard.c 
b/mingw-w64-crt/ssp/stack_chk_guard.c
index 3ff22e020..7e4a6c1a0 100644
--- a/mingw-w64-crt/ssp/stack_chk_guard.c
+++ b/mingw-w64-crt/ssp/stack_chk_guard.c
@@ -10,7 +10,11 @@
void *__stack_chk_guard; -static void __cdecl __attribute__((__constructor__)) init(void)
+// no_stack_protector attribute added bellow,
+// to disable stack protection checks even before the canary is initialized

Would you please explain the exact meaning of 'canary'?


+// check will always fail at the end of this function
+// initial value (0) != initialzed value (rand or dedbeaf const)

Here are two typos.

While I understand the reason, this explanation doesn't seem so 
straightforward. What about:

   // This function requires `no_stack_protector` because it changes the
   // value of `__stack_chk_guard`, causing stack checks to fail before
   // returning from this function.


+static void __cdecl __attribute__((__constructor__, no_stack_protector)) 
init(void)
  {
    unsigned int ui;
    if (__stack_chk_guard != 0)

For consistency reasons I'd prefer this be `__attribute__((__constructor__, __no_stack_protector__))`. This line is too long now, so maybe we can have

   __attribute__((__constructor__, __no_stack_protector__))
   static void __cdecl init(void)


The `no_stack_protector` was added in GCC 11 and Clang 7, but both have a convention of ignoring unknown attributes, so it's probably fine to leave out a check.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to