[libc-commits] [libc] [libc] Simple __stack_chk_guard implementation (PR #78804)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Mon Jan 22 20:45:03 PST 2024


https://github.com/SchrodingerZhu requested changes to this pull request.

I hope to put a request changes for further discussions.

Some concerns from my side:
1. Itanium ABI says: 
   > Initialization entries with the same priority from different files (or from other sources such as link command options) will be executed in an unspecified order. 

   Does this mean that we do not know when will the global guard be ready? And this is only for C++, only for one ABI.
   Since we do not have control of how static initialization is really implemented in different ABI, will this potentially mess up something? For example, (although unlikely) the `_Global_XXXX` function of this inserts a stack check, then the ctor alters the value of the global guard which makes `_Global_XXXX` fails in its epilogue.
2. Calling `getauxval` may not be desired since `getauxval` depends on several functions, those who themselves may want to read the global guard when our libc is compiled with stack protectors enabled. Consider the following approach instead:
   ```c++
   #include <config/linux/app.h>
   /* .... */
   if (&app != nullptr) {
     for (auto * p = app.auxv_ptr; *p != AT_NULL; ++p) {
        if (*p == AT_RANDOM) { /* initialize */ }
     }
   }
   ```
3. When pointer width is $\ge 8$, MUSL sacrifices a byte (the second byte) to improve the resistance to string functions by setting it to zero. Should we also consider doing it?


https://github.com/llvm/llvm-project/pull/78804


More information about the libc-commits mailing list