[libc-commits] [libc] [libc] fix segfault in stack_chk_guard_test on arm (PR #75962)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Dec 19 11:16:57 PST 2023


https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/75962

>From 1e1e9cbd367a76e14059e8b0c1003bb2f409060f Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 19 Dec 2023 11:11:20 -0800
Subject: [PATCH 1/2] [libc] fix segfault in stack_chk_guard_test on arm

Use a size smaller than the smallest supported page size so that we don't
clobber over any guard pages, which may result in a segfault before
__stack_chk_fail can be called.
---
 libc/test/src/compiler/stack_chk_guard_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/compiler/stack_chk_guard_test.cpp b/libc/test/src/compiler/stack_chk_guard_test.cpp
index 1de2d1b7357f70..df15962acd9678 100644
--- a/libc/test/src/compiler/stack_chk_guard_test.cpp
+++ b/libc/test/src/compiler/stack_chk_guard_test.cpp
@@ -20,7 +20,7 @@ TEST(LlvmLibcStackChkFail, Smash) {
   EXPECT_DEATH(
       [] {
         int arr[20];
-        LIBC_NAMESPACE::memset(arr, 0xAA, 9001);
+        LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
       },
       WITH_SIGNAL(SIGABRT));
 }

>From 5af362aec13c49a4678d039dbc19ace74b97ab59 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 19 Dec 2023 11:16:46 -0800
Subject: [PATCH 2/2] fix stack_smashing_test

---
 libc/test/integration/src/unistd/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/test/integration/src/unistd/CMakeLists.txt b/libc/test/integration/src/unistd/CMakeLists.txt
index 10aac212af355e..3f18231209512a 100644
--- a/libc/test/integration/src/unistd/CMakeLists.txt
+++ b/libc/test/integration/src/unistd/CMakeLists.txt
@@ -45,6 +45,7 @@ if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_ARCHITECTURE_IS_X86})
       libc.include.signal
       libc.include.sys_wait
       libc.include.unistd
+      libc.src.compiler.__stack_chk_fail
       libc.src.pthread.pthread_atfork
       libc.src.signal.raise
       libc.src.sys.wait.wait



More information about the libc-commits mailing list