Skip to content

Commit

Permalink
LibC: Use 64-bit stack smash value for 64-bit mode
Browse files Browse the repository at this point in the history
Otherwise it'll use the first 32 bits that happen to come after,
leading to very weird bugs. Fixes SerenityOS#8601
  • Loading branch information
dascandy authored and gunnarbeutner committed Jul 16, 2021
1 parent 205c8a1 commit a5a62f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Kernel/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ extern ctor_func_t end_heap_ctors;
extern ctor_func_t start_ctors;
extern ctor_func_t end_ctors;

extern u32 __stack_chk_guard;
u32 __stack_chk_guard;
extern size_t __stack_chk_guard;
size_t __stack_chk_guard;

extern "C" u8* start_of_safemem_text;
extern "C" u8* end_of_safemem_text;
Expand Down Expand Up @@ -147,7 +147,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init()
// Initialize TimeManagement before using randomness!
TimeManagement::initialize(0);

__stack_chk_guard = get_fast_random<u32>();
__stack_chk_guard = get_fast_random<size_t>();

ProcFSComponentRegistry::initialize();
Thread::initialize();
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibC/crt0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifndef _DYNAMIC_LOADER
extern "C" {

extern u32 __stack_chk_guard;
extern size_t __stack_chk_guard;

int main(int, char**, char**);

Expand All @@ -31,7 +31,7 @@ NAKED void _start(int, char**, char**)

int _entry(int argc, char** argv, char** env)
{
u32 original_stack_chk = __stack_chk_guard;
size_t original_stack_chk = __stack_chk_guard;
arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard));

if (__stack_chk_guard == 0)
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibC/ssp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

extern "C" {

extern u32 __stack_chk_guard;
u32 __stack_chk_guard = (u32)0xc6c7c8c9;
extern size_t __stack_chk_guard;
size_t __stack_chk_guard = (size_t)0xc6c7c8c9;

__attribute__((noreturn)) void __stack_chk_fail()
{
Expand Down

0 comments on commit a5a62f9

Please sign in to comment.