1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:47:45 +00:00

Build + LibC: Enable -fstack-protector-strong in user space

Modify the user mode runtime to insert stack canaries to find stack corruptions.

The `-fstack-protector-strong` variant was chosen because it catches more
issues than vanilla `-fstack-protector`, but doesn't have substantial
performance impact like `-fstack-protector-all`.

Details:

    -fstack-protector enables stack protection for vulnerable functions that contain:

    * A character array larger than 8 bytes.
    * An 8-bit integer array larger than 8 bytes.
    * A call to alloca() with either a variable size or a constant size bigger than 8 bytes.

    -fstack-protector-strong enables stack protection for vulnerable functions that contain:

    * An array of any size and type.
    * A call to alloca().
    * A local variable that has its address taken.

Example of it catching corrupting in the `stack-smash` test:
```
courage ~ $ ./user/Tests/LibC/stack-smash
[+] Starting the stack smash ...
Error: Stack protector failure, stack smashing detected!
Shell: Job 1 (/usr/Tests/LibC/stack-smash) Aborted
```
This commit is contained in:
Brian Gianforcaro 2021-01-01 15:27:42 -08:00 committed by Andreas Kling
parent bf3772362a
commit 06da50afc7
7 changed files with 124 additions and 13 deletions

View file

@ -70,13 +70,21 @@ add_custom_command(
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o
)
set_source_files_properties (ssp.cpp PROPERTIES COMPILE_FLAGS
"-fno-stack-protector")
add_library(ssp STATIC ssp.cpp)
add_custom_command(
TARGET ssp
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:ssp> ${CMAKE_INSTALL_PREFIX}/usr/lib/ssp.o
)
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES})
serenity_libc_static(LibCStatic c)
target_link_libraries(LibCStatic crt0)
target_link_libraries(LibCStatic crt0 ssp)
add_dependencies(LibCStatic LibM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
serenity_libc(LibC c)
target_link_libraries(LibC crt0)
target_link_libraries(LibC crt0 ssp)
add_dependencies(LibC LibM)