]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43390: Set SA_ONSTACK in PyOS_setsig (GH-24730)
authorGregory P. Smith <greg@krypto.org>
Fri, 5 Mar 2021 05:49:30 +0000 (21:49 -0800)
committerGitHub <noreply@github.com>
Fri, 5 Mar 2021 05:49:30 +0000 (21:49 -0800)
This is friendlier to other in-process code that an extension module or
embedding use could pull in such as CGo where tiny stacks are the norm
and sigaltstack() has been used to provide for signal handlers.

Without this, signals received by a process using tiny stacks may lead
to stack overflow crashes.

Misc/NEWS.d/next/Core and Builtins/2021-03-03-17-58-49.bpo-43390.epPpwV.rst [new file with mode: 0644]
Python/pylifecycle.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-03-03-17-58-49.bpo-43390.epPpwV.rst b/Misc/NEWS.d/next/Core and Builtins/2021-03-03-17-58-49.bpo-43390.epPpwV.rst
new file mode 100644 (file)
index 0000000..ae115db
--- /dev/null
@@ -0,0 +1,6 @@
+CPython now sets the ``SA_ONSTACK`` flag in ``PyOS_setsig`` for the VM's
+default signal handlers.  This is friendlier to other in-process code that
+an extension module or embedding use could pull in (such as Golang's cgo)
+where tiny thread stacks are the norm and ``sigaltstack()`` has been used to
+provide for signal handlers.  This is a no-op change for the vast majority
+of processes that don't use sigaltstack.
index ec770841c8de3a6b6fa9c586901235e1334203e4..d03c6c07f710881a9b09fadf2e86e5b86d7f0cab 100644 (file)
@@ -2884,7 +2884,10 @@ PyOS_setsig(int sig, PyOS_sighandler_t handler)
     struct sigaction context, ocontext;
     context.sa_handler = handler;
     sigemptyset(&context.sa_mask);
-    context.sa_flags = 0;
+    /* Using SA_ONSTACK is friendlier to other C/C++/Golang-VM code that
+     * extension module or embedding code may use where tiny thread stacks
+     * are used.  https://bugs.python.org/issue43390 */
+    context.sa_flags = SA_ONSTACK;
     if (sigaction(sig, &context, &ocontext) == -1)
         return SIG_ERR;
     return ocontext.sa_handler;