mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
LibC: Move stack canary initialization before the global constructors
Once again, QEMU creates threads while running its constructors, which is a recipe for disaster if we switch out the stack guard while that is already running in the background. To solve that, move initialization to our LibC initialization stage, which is before any actual external initialization code runs.
This commit is contained in:
parent
cf0ad3715e
commit
b9f7966e00
2 changed files with 6 additions and 16 deletions
|
@ -259,6 +259,12 @@ static void initialize_libc(DynamicObject& libc)
|
|||
VERIFY(res.has_value());
|
||||
*((char***)res.value().address.as_ptr()) = s_envp;
|
||||
|
||||
// __stack_chk_guard should be initialized before anything significant (read: global constructors) is running.
|
||||
// This is not done in __libc_init, as we definitely have to return from that, and it might affect Loader as well.
|
||||
res = libc.lookup_symbol("__stack_chk_guard"sv);
|
||||
VERIFY(res.has_value());
|
||||
arc4random_buf(res.value().address.as_ptr(), sizeof(size_t));
|
||||
|
||||
res = libc.lookup_symbol("__environ_is_malloced"sv);
|
||||
VERIFY(res.has_value());
|
||||
*((bool*)res.value().address.as_ptr()) = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue