Skip to content

[libc] add __stack_chk_guard to generic #121121

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 1 commit into from
Dec 31, 2024

Conversation

RossComputerGuy
Copy link
Member

__stack_chk_guard is needed for many things and it's undefined so let's define it. If we need a more complex definition, we can do it per target or expand it. This is meant as a simple definition.

@llvmbot llvmbot added the libc label Dec 26, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 26, 2024

@llvm/pr-subscribers-libc

Author: Tristan Ross (RossComputerGuy)

Changes

__stack_chk_guard is needed for many things and it's undefined so let's define it. If we need a more complex definition, we can do it per target or expand it. This is meant as a simple definition.


Full diff: https://github.com/llvm/llvm-project/pull/121121.diff

1 Files Affected:

  • (modified) libc/src/compiler/generic/__stack_chk_fail.cpp (+2)
diff --git a/libc/src/compiler/generic/__stack_chk_fail.cpp b/libc/src/compiler/generic/__stack_chk_fail.cpp
index c76ec1407ad356..68ab887afe3175 100644
--- a/libc/src/compiler/generic/__stack_chk_fail.cpp
+++ b/libc/src/compiler/generic/__stack_chk_fail.cpp
@@ -12,6 +12,8 @@
 
 extern "C" {
 
+uintptr_t __stack_chk_guard;
+
 void __stack_chk_fail(void) {
   LIBC_NAMESPACE::write_to_stderr("stack smashing detected\n");
   LIBC_NAMESPACE::abort();

@@ -12,6 +12,8 @@

extern "C" {

uintptr_t __stack_chk_guard;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assign an arbitrary random number as its default value? It should be better than zero.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, hopefully the number I gave is arbitrary and random enough heh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is better to use static_cast<uintptr_t>(XXX); otherwise a warning will be triggered on 32bit targets

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I added that now.

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@SchrodingerZhu SchrodingerZhu merged commit 6f3d1d3 into llvm:main Dec 31, 2024
11 checks passed
@RossComputerGuy RossComputerGuy deleted the feat/libc-stack-protect branch December 31, 2024 07:35
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 31, 2024

LLVM Buildbot has detected a new failure on builder fuchsia-x86_64-linux running on fuchsia-debian-64-us-central1-a-1 while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/10339

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)

@nickdesaulniers
Copy link
Member

Hardcoding a value like this is suspicious. At the very least, our startup code should be initializing this potentially using the AT_RANDOM value from the auxiliary vector...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants