Crash when CET Shadow Stacks are enabled
Description:
When using greenlet with the glibc tuneables set to enable CET shadow stacks, it leads to crashes. This is because the module is linked such that it advertises shadow stack support even though it currently does not support shadow stacks.
I believe the issue is related to Arch's default package flags. Specifically, -fcf-protection
is enabled in the default makepkg.conf
and the python package is also compiled with the flag. When the greenlet package is then built, I believe it uses the flags from the python package, thus greenlet will also be compiled with -fcf-protection
, making it advertise support.
The issue does not arise when the pip package is used in a virtual environment as it is not compiled with -fcf-protection
. A potential solution would be to turn off that flag when building. I'm not too familiar with the python packaging system and thus cannot directly provide a patch to do that.
I've also filed a feature request in the upstream package for them to include support for CET shadow stacks or turn off the flag there, but I'm not sure whose responsibility it would be to fix the packaging as the issue is related to Arch's compilation/linking flags.
Additional info:
- package version(s): Noticed with Arch package 3.2.1-1, and manual build upstream, affects all versions
- link to upstream bug report, if any: https://github.com/python-greenlet/greenlet/issues/454
Steps to reproduce:
Crashing example:
- Enable permissive shadow stacks:
export GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=permissive
- Use greenlet package:
python test.py
test.py:
import greenlet
f = lambda : print("Hello World!")
greenlet.greenlet(f).switch()
print("Hello World again!")
Not crashing with pip package in venv:
python -m venv venv
source venv/bin/activate
pip install greenlet
export GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=permissive
python test.py