summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-08-18 17:39:04 +0200
committerGunnar Beutner <gunnar@beutner.name>2021-08-18 18:01:22 +0200
commitbd6dc5ccec752b0667883b3e5c3d16f65e9b6707 (patch)
tree911505ae9f177b1924c5a583124b4d3f96952ce9 /CMakeLists.txt
parent446bd1e0de384274fbbb9cf5848f97b984fa5af7 (diff)
downloadserenity-bd6dc5ccec752b0667883b3e5c3d16f65e9b6707.zip
Meta+LibC: Don't allow text relocations in SerenityOS libraries
The `-z,text` linker flag causes the linker to reject shared libraries and PIE executables that have textrels. Our code mostly did not use these except in one place in LibC, which is changed in this commit. This makes GNU ld match LLD's behavior, which has this option enabled by default. TEXTRELs pose a security risk, as performing these relocations require executable pages to be written to by the dynamic linker. This can significantly weaken W^X hardening mitigations. Note that after this change, TEXTRELs can still be used in ports, as the dynamic loader code is not changed. There are also uses of it in the kernel, removing which are outside the scope of this PR. To allow those, `-z,notext` is added.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt2
1 files changed, 2 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6b18bf0e8..642c2516ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -299,6 +299,8 @@ else()
add_compile_options(-Wdouble-promotion)
endif()
+add_link_options(LINKER:-z,text)
+
if("${SERENITY_ARCH}" STREQUAL "i686")
add_compile_options(-march=i686)
else()