Skip to content
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

Implement stack overflow protection for linux based on actual stack depth #130396

Open
markshannon opened this issue Feb 21, 2025 · 2 comments
Open
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-linux type-feature A feature request or enhancement

Comments

@markshannon
Copy link
Member

markshannon commented Feb 21, 2025

Linux doesn't offer an API for determining the current stack bounds, at least not that I am aware of.

This means we will need to probe the stack using a SIGSEGV handler and longjmp/setjump.
It is somewhat ugly but should work.

Actually, it looks like pthread_get_stackaddr_np might work, and avoid all the complexity of the signal handler. In theory, it should work for MacOS as well.

Linked PRs

@tomasr8 tomasr8 added interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-linux labels Feb 21, 2025
@picnixz picnixz added the type-feature A feature request or enhancement label Feb 21, 2025
markshannon added a commit that referenced this issue Feb 25, 2025
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
@encukou
Copy link
Member

encukou commented Feb 25, 2025

This broke two buildbots (both can be seen in the pre-merge run):

Do you have any leads on these issues?

markshannon added a commit that referenced this issue Feb 26, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 26, 2025
vstinner pushed a commit that referenced this issue Feb 26, 2025
…) (#130572)

GH-130396: Treat clang -Og as optimized for gdb tests (GH-130550)
(cherry picked from commit 129db32)

Co-authored-by: Mark Shannon <[email protected]>
vstinner added a commit that referenced this issue Feb 26, 2025
…) (#130573)

GH-130396: Treat clang -Og as optimized for gdb tests (GH-130550)

(cherry picked from commit 129db32)

Co-authored-by: Mark Shannon <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 26, 2025
…ythonGH-130550) (pythonGH-130573)

pythonGH-130396: Treat clang -Og as optimized for gdb tests (pythonGH-130550)

(cherry picked from commit 129db32)
(cherry picked from commit c4aeb4c)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Mark Shannon <[email protected]>
@colesbury
Copy link
Contributor

colesbury commented Feb 27, 2025

I'm seeing SIGBUS in a compilation modes that use a lot of stack:

export CC=clang-19
./configure -C --with-pydebug --with-thread-sanitizer --disable-gil
make -j

export TSAN_OPTIONS="suppressions=$(pwd)/Tools/tsan/suppressions_free_threading.txt handle_segv=0"
./python -m test test_dictviews -m test_deeply_nested_repr

EDIT: The suppressions seems to be important for reproducing the crash.

colesbury added a commit to colesbury/cpython that referenced this issue Mar 7, 2025
Thread sanitizer will often crash if a test uses more than half the
stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-linux type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants