Skip to content

[libc] __stack_chk_fail post submit test failures #75962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions libc/src/compiler/__stack_chk_fail.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#ifndef LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
#define LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H

namespace LIBC_NAMESPACE {

// The compiler will emit calls implicitly to a non-namespaced version.
// TODO: can we additionally provide a namespaced alias so that tests can
// explicitly call the namespaced variant rather than the non-namespaced
// definition?
extern "C" {
[[noreturn]] void __stack_chk_fail();

} // namespace LIBC_NAMESPACE
} // extern "C"

#endif // LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
6 changes: 3 additions & 3 deletions libc/src/compiler/generic/__stack_chk_fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "src/__support/OSUtil/io.h"
#include "src/stdlib/abort.h"

namespace LIBC_NAMESPACE {
extern "C" {

LLVM_LIBC_FUNCTION(void, __stack_chk_fail, (void)) {
void __stack_chk_fail(void) {
LIBC_NAMESPACE::write_to_stderr("stack smashing detected");
LIBC_NAMESPACE::abort();
}

} // namespace LIBC_NAMESPACE
} // extern "C"
1 change: 1 addition & 0 deletions libc/test/integration/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions libc/test/src/compiler/stack_chk_guard_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
#include "test/UnitTest/Test.h"

TEST(LlvmLibcStackChkFail, Death) {
EXPECT_DEATH([] { LIBC_NAMESPACE::__stack_chk_fail(); },
WITH_SIGNAL(SIGABRT));
EXPECT_DEATH([] { __stack_chk_fail(); }, WITH_SIGNAL(SIGABRT));
}

TEST(LlvmLibcStackChkFail, Smash) {
EXPECT_DEATH(
[] {
int arr[20];
LIBC_NAMESPACE::memset(arr, 0xAA, 9001);
LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
},
WITH_SIGNAL(SIGABRT));
}