mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
e575339564
Employ the same hardening that glibc and the Linux kernel use for generating stack guards: zero the first byte of the guard such that if C-style string functions read out of bounds on the stack, we do not overwrite or potentially leak the stack guard.
32 lines
909 B
C++
32 lines
909 B
C++
/*
|
|
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Format.h>
|
|
#include <AK/Types.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/internals.h>
|
|
#include <unistd.h>
|
|
|
|
#if defined __SSP__ || defined __SSP_ALL__
|
|
# error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
|
|
#endif
|
|
|
|
extern "C" {
|
|
|
|
extern uintptr_t __stack_chk_guard;
|
|
// Initialized in `initialize_libc` (we leave a placeholder value here before initialization).
|
|
__attribute__((used)) uintptr_t __stack_chk_guard = (uintptr_t)0xc6c7c8c9;
|
|
|
|
__attribute__((noreturn)) void __stack_chk_fail()
|
|
{
|
|
dbgln("Error: USERSPACE({}) Stack protector failure, stack smashing detected!", getpid());
|
|
if (__stdio_is_initialized)
|
|
warnln("Error: Stack protector failure, stack smashing detected!");
|
|
abort();
|
|
}
|
|
|
|
} // extern "C"
|