On Wednesday, September 12, 2018, Wes Turner <wes.t...@gmail.com> wrote:On Wednesday, September 12, 2018, Joni Orponen <j.or...@4teamwork.ch> wrote:On Wed, Sep 12, 2018 at 8:48 PM Wes Turner <wes.t...@gmail.com> wrote:Should C extensions that compile all add`-mindirect-branch=thunk -mindirect-branch-register` [1] to mitigate the risk of Spectre variant 2 (which does indeed affect user space applications as well as kernels)?Are those available on GCC <= 4.2.0 as per PEP 513?AFAIU, onlyGCC 7.3 and 8 have the retpoline (indirect-branch=thunk) support enabled by the `-mindirect-branch=thunk -mindirect-branch-register` CFLAGS.
"What is a retpoline and how does it work?"
On Wed, Sep 12, 2018, 12:29 Joni Orponen <j.or...@4teamwork.ch> wrote:On Wed, Sep 12, 2018 at 8:48 PM Wes Turner <wes.t...@gmail.com> wrote:Should C extensions that compile all add`-mindirect-branch=thunk -mindirect-branch-register` [1] to mitigate the risk of Spectre variant 2 (which does indeed affect user space applications as well as kernels)?Are those available on GCC <= 4.2.0 as per PEP 513?
Pretty sure no manylinux1 compiler is ever going to get these mitigations.For manylinux2010 on x86-64, we can easily use a much newer compiler: RH maintains a recent compiler, currently gcc 7.3, or if that doesn't work for some reason then the conda folks have be apparently figured out how to build the equivalent from gcc upstream releases.
Unfortunately, the manylinux2010 infrastructure is not quite ready... I'm pretty sure it needs some volunteers to push it to the finish line, though unfortunately I haven't had enough time to keep track.
It boiled down to:
* Python allows arbitrary code execution by design
* Pure Python code in CPython has very long per-instruction opcode
sequences that cannot easily be abused or timed
* Injected pure Python code cannot be coerced into generating native
code that is able to abuse Spectre/Meltdown but not able to abuse other
attacks more easily
* Code injection itself is outside of this particular threat model
By comparison with JavaScript, most JS JITs can be easily coerced into
generating specific native code that can break sandbox guarantees (e.g.
browser tabs). Python offers none of these guarantees.
Distributors are of course free to enable these flags for their own
builds, but I recommend against it for the official binaries, and would
suggest that it's worth more PR than actual security and nobody else
needs to enable it either.
(Extension authors with significant scriptable C code need to perform
their own analysis. I'm only talking about CPython here.)
Cheers,
Steve
On 16Sep2018 0707, Wes Turner wrote:
> Should Python builds add `-mindirect-branch=thunk
> -mindirect-branch-register` to CFLAGS?
>
> Where would this be to be added in the build scripts with which
> architectures?
>
> /QSpectre is the MSVC build flag for Spectre Variant 1:
>
> > The /Qspectre option is available in Visual Studio 2017 version 15.7
> and later.
>
> https://docs.microsoft.com/en-us/cpp/build/reference/qspectre?view=vs-2017
>
> security@ directed me to the issue tracker / lists,
> so I'm forwarding this to python-dev and python-ideas, as well.
>
> # Forwarded message
> From: *Wes Turner* <wes.t...@gmail.com <mailto:wes.t...@gmail.com>>
> Date: Wednesday, September 12, 2018
> Subject: SEC: Spectre variant 2: GCC: -mindirect-branch=thunk
> -mindirect-branch-register
> To: distutils-sig <distut...@python.org
> <mailto:distut...@python.org>>
>
>
> Should C extensions that compile all add
> `-mindirect-branch=thunk -mindirect-branch-register` [1] to mitigate the
> risk of Spectre variant 2 (which does indeed affect user space
> applications as well as kernels)?
>
> [1]
> https://github.com/speed47/spectre-meltdown-checker/issues/119#issuecomment-361432244
> <https://github.com/speed47/spectre-meltdown-checker/issues/119#issuecomment-361432244>
> [2] https://en.wikipedia.org/wiki/Spectre_(security_vulnerability)
> <https://en.wikipedia.org/wiki/Spectre_%28security_vulnerability%29>
> [3]
> https://en.wikipedia.org/wiki/Speculative_Store_Bypass#Speculative_execution_exploit_variants
> <https://en.wikipedia.org/wiki/Speculative_Store_Bypass#Speculative_execution_exploit_variants>
>
> On Wednesday, September 12, 2018, Wes Turner <wes.t...@gmail.com
> <mailto:wes.t...@gmail.com>> wrote:
>
> On Wednesday, September 12, 2018, Joni Orponen
> <j.or...@4teamwork.ch <mailto:j.or...@4teamwork.ch>> wrote:
>
> On Wed, Sep 12, 2018 at 8:48 PM Wes Turner
> <wes.t...@gmail.com <mailto:wes.t...@gmail.com>> wrote:
>
> Should C extensions that compile all add
> `-mindirect-branch=thunk -mindirect-branch-register` [1]
> to mitigate the risk of Spectre variant 2 (which does
> indeed affect user space applications as well as kernels)?
>
>
> Are those available on GCC <= 4.2.0 as per PEP 513?
>
>
> AFAIU, only
> GCC 7.3 and 8 have the retpoline (indirect-branch=thunk) support
> enabled by the `-mindirect-branch=thunk
> -mindirect-branch-register` CFLAGS.
>
>
> On Wednesday, September 12, 2018, Wes Turner <wes.t...@gmail.com
> <mailto:wes.t...@gmail.com>> wrote:
>
> "What is a retpoline and how does it work?"
> https://stackoverflow.com/questions/48089426/what-is-a-retpoline-and-how-does-it-work
> <https://stackoverflow.com/questions/48089426/what-is-a-retpoline-and-how-does-it-work>
>
>
>
>
> _______________________________________________
> Python-Dev mailing list
> Pytho...@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/steve.dower%40python.org
I investigated this thoroughly some time ago (when the MSVC flags became available) and determined (with the help of some of the original Spectre/Meltdown investigation team) that there is no significant value in enabling these flags for Python.
It boiled down to:
* Python allows arbitrary code execution by design
* Pure Python code in CPython has very long per-instruction opcode sequences that cannot easily be abused or timed
* Injected pure Python code cannot be coerced into generating native code that is able to abuse Spectre/Meltdown but not able to abuse other attacks more easily
* Code injection itself is outside of this particular threat model
By comparison with JavaScript, most JS JITs can be easily coerced into generating specific native code that can break sandbox guarantees (e.g. browser tabs). Python offers none of these guarantees.
Distributors are of course free to enable these flags for their own builds, but I recommend against it for the official binaries, and would suggest that it's worth more PR than actual security and nobody else needs to enable it either.
(Extension authors with significant scriptable C code need to perform their own analysis. I'm only talking about CPython here.)
Cheers,
Steve
On 16Sep2018 0707, Wes Turner wrote:
Should Python builds add `-mindirect-branch=thunk -mindirect-branch-register` to CFLAGS?
Where would this be to be added in the build scripts with which architectures?
/QSpectre is the MSVC build flag for Spectre Variant 1:
> The /Qspectre option is available in Visual Studio 2017 version 15.7 and later.
https://docs.microsoft.com/en-us/cpp/build/reference/qspectre?view=vs-2017
security@ directed me to the issue tracker / lists,
so I'm forwarding this to python-dev and python-ideas, as well.
# Forwarded message
From: *Wes Turner* <wes.t...@gmail.com <mailto:wes.t...@gmail.com>>
Date: Wednesday, September 12, 2018
Subject: SEC: Spectre variant 2: GCC: -mindirect-branch=thunk -mindirect-branch-register
To: distutils-sig <distut...@python.org <mailto:distutils-sig@python.org>>
Unsubscribe: https://mail.python.org/mailman/options/python-dev/wes.turner%40gmail.com
I thought I read that RH has a kernel flag for userspace?
If you want to push this forward, I suggest you measure performance of
Python compiled with and without the Spectre mitigation options, and
report the results here. That will help vendors and packagers decide
whether they want to pursue the route of enabling those options.
Don't change the subject.
> It boiled down to:
> * Python allows arbitrary code execution by design
>
> Yet binaries built with GCC do have NX? Unless nested functions in C
> extensions?
I don't know anything about GCC settings. Binaries for Windows have been
built with this option for over a decade. It's unrelated to
Spectre/Meltdown.
> * Pure Python code in CPython has very long per-instruction opcode
> sequences that cannot easily be abused or timed
>
> A demonstration of this would be helpful.
That's not how proof-of-concepts work. You can't assume that the lack of
a demonstration proves it is possible - at best you have to assume that
it proves it is *not* possible, but really it just proves that nobody
has a demonstration yet.
What I could demonstrate (again) if I thought it would be worthwhile is
that the changes enabled by the flag do not affect the normal
interpreter loop, and do not affect any code that can be called fast
enough to potentially leak information. Feel free to go ahead and build
with/without the flags and compare the disassembly (and if you do this
and find that compilers are detecting new cases since I looked, *that*
would be very helpful to share directly with the security team).
> * Injected pure Python code cannot be coerced into generating native
> code that is able to abuse Spectre/Meltdown but not able to abuse
> other attacks more easily
>
> So, not impossible.
Of course it's not impossible. But why would you
> * Code injection itself is outside of this particular threat model
>
> [Jupyter] Notebook servers are as wide open to arbitrary code execution
> as browser JS JITs; often with VMs and/or containers as a 'sandbox'
> `pip install requirements.txt` installs and executes unsigned code:
> Python, C extensions
>
> What can a container do to contain a speculative execution exploit
> intending to escape said container?
Python's threat model does not treat the Python process as a sandbox. To
say it another way, if you assume the Python process is a sandbox,
you're on your own.
Arbitrary code, Python or otherwise, can totally escape the process, and
then it's up to the OS to protect against escaping the machine. We do
what we can to reduce unnecessary arbitrary code, but unless you've
properly protected your environment then you have a lot more to worry
about besides speculative execution vulnerabilities.
> By comparison with JavaScript, most JS JITs can be easily coerced
> into generating specific native code that can break sandbox
> guarantees (e.g. browser tabs). Python offers none of these guarantees.
>
>
> This is faulty logic. Because Python does not have a JIT sandbox,
> speculative execution is not a factor for Python?
Because Python does not have a (native) JIT at all, speculative
execution relies on identifying vulnerable and reusable code patterns
within the C code and being able to invoke those directly. Because pure
Python code does not allow this (without relying on other bugs), there
is no way to do this within the threat model we use.
Once you allow arbitrary or unvalidated native code, you are outside the
threat model and hence on your own. And if you find a bug that lets pure
Python code move the instruction pointer to arbitrary native code, that
should be reported to the security team.
> Distributors are of course free to enable these flags for their own
> builds, but I recommend against it for the official binaries, and
> would suggest that it's worth more PR than actual security and
> nobody else needs to enable it either.
>
> (Extension authors with significant scriptable C code need to
> perform their own analysis. I'm only talking about CPython here.)
>
>
> Extension installers (and authors) are not likely to perform any such
> analysis.
Then it is their fault if they are compromised. Open source software
relies on users validating the software themselves, as there is no legal
recourse against developers who do not do it.
> Extensions are composed of arbitrary C, which certainly can both
> directly exploit and indirectly enable remote exploitation of Spectre
> and Meltdown vulnerabilities.
If arbitrary C is running, we can't help you anymore.
> Most users of python are installing arbitrary packages (without hashes
> or signatures).
If they are concerned about Spectre/Meltdown, they should stop doing
this. They should also stop if they are concerned about 1000 other
issues that are much more likely than Spectre/Meltdown.
Cheers,
Steve
_______________________________________________
Python-Dev mailing list
Pytho...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/dev-python%2Bgarchive-30976%40googlegroups.com
_______________________________________________
Python-Dev mailing list
Pytho...@python.org
https://mail.python.org/mailman/listinfo/python-dev
On Tue, Sep 18, 2018 at 8:38 AM INADA Naoki <songof...@gmail.com> wrote:
> I think this topic should split to two topics: (1) Guard Python
> process from Spectre/Meltdown
> attack from other process, (2) Prohibit Python code attack other
> processes by using
> Spectre/Meltdown.
(3) Guard Python from performance degradation by overly aggressive
Spectre "mitigation".
On 21/09/18 08:11, Wes Turner wrote:
I feel like you are actively undermining attempts to prevent exploitation of known vulnerabilities because the software in question is currently too slow.
Did you write "How to Win Friends And Influence People"?
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
_______________________________________________
Python-Dev mailing list
Pytho...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/wes.turner%40gmail.com