[Python-Dev] SEC: Spectre variant 2: GCC: -mindirect-branch=thunk -mindirect-branch-register

141 views
Skip to first unread message

Wes Turner

unread,
Sep 16, 2018, 10:09:27 AM9/16/18
to Python-Dev, Python-Ideas
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>
Date: Wednesday, September 12, 2018
Subject: SEC: Spectre variant 2: GCC: -mindirect-branch=thunk -mindirect-branch-register
To: distutils-sig <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)?


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, 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> wrote:
"What is a retpoline and how does it work?"


Wes Turner

unread,
Sep 16, 2018, 10:18:35 AM9/16/18
to Python-Dev, Python-Ideas
There's probably already been an ANN announce about this?

If not, someone with appropriate security posture and syntax could address:

Whether python.org binaries are already rebuilt

Whether OS package binaries are already rebuilt

Whether anaconda binaries are already rebuilt

Whether C extension binaries on pypi are already rebuilt

Wes Turner

unread,
Sep 16, 2018, 8:31:23 PM9/16/18
to Nathaniel Smith, Python-Dev, Python-Ideas, distutils-sig
Are all current Python builds and C extensions vulnerable to Spectre variants {1, 2, *}?

There are now multiple threads:

"SEC: Spectre variant 2: GCC: -mindirect-branch=thunk -mindirect-branch-register"


Original thread (that I forwarded to security@):
"[Python-ideas] Executable space protection: NX bit,"
> ~ Do trampolines / nested functions in C extensions switch off the NX bit?

On Sunday, September 16, 2018, Nathaniel Smith <n...@pobox.com> wrote:
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.

Are there different CFLAGS and/or gcc compatibility flags in conda builds of Python and C extensions?

Where are those set in conda builds?

What's the best way to set CFLAGS in Python builds and C extensions?

export CFLAGS="-mindirect-branch=thunk -mindirect-branch-register"
./configure
make

?

Why are we supposed to use an old version of GCC that doesn't have the retpoline patches that only mitigate Spectre variant 2?
 

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.

"PEP 571 -- The manylinux2010 Platform Tag"

"Tracking issue for manylinux2010 rollout"

Are all current Python builds and C extensions vulnerable to Spectre variants {1, 2, *}?

Antoine Pitrou

unread,
Sep 17, 2018, 5:28:13 AM9/17/18
to pytho...@python.org

Hi,

Please don't cross-post so heavily. python-dev is sufficient for this.

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.

Note there are plenty of data-driven conditional jumps in Python. It
will not be easy to determine which ones are vulnerable to exploiting
through speculative execution of a mispredicted branch. The bytecode
evaluation loop sounds like a potential attack target, but it's also
performance-sensitive.

Regards

Antoine.
_______________________________________________
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

Steve Dower

unread,
Sep 17, 2018, 12:46:09 PM9/17/18
to pytho...@python.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: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

> <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

> <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

Wes Turner

unread,
Sep 17, 2018, 3:00:43 PM9/17/18
to Steve Dower, pytho...@python.org


On Monday, September 17, 2018, Steve Dower <steve...@python.org> wrote:
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.
 
What did you fuzz with?
Does that assume that e.g. Fortify has identified all bugs in CPython C?
There have been a number of variants that have been disclosed; which did who test for?
 

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?
 
* 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.

* 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.

* 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?

I thought I read that RH has a kernel flag for userspace?


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?
 

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.

Extensions are composed of arbitrary C, which certainly can both directly exploit and indirectly enable remote exploitation of Spectre and Meltdown vulnerabilities.

Most users of python are installing arbitrary packages (without hashes or signatures).
 

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

Wes Turner

unread,
Sep 17, 2018, 3:44:43 PM9/17/18
to Steve Dower, Python-Dev
On Mon, Sep 17, 2018 at 2:58 PM Wes Turner <wes.t...@gmail.com> wrote:

I thought I read that RH has a kernel flag for userspace?

"Controlling the Performance Impact of Microcode and Security Patches for CVE-2017-5754 CVE-2017-5715 and CVE-2017-5753 using Red Hat Enterprise Linux Tunables"

> Indirect Branch Restricted Speculation (ibrs)
> [...] When ibrs_enabled is set to 1 (spectre_v2=ibrs) the kernel runs with indirect branch restricted speculation, which protects the kernel space from attacks (even from hyperthreading/simultaneous multi-threading attacks). When IBRS is set to 2 (spectre_v2=ibrs_always), both userland and kernel runs with indirect branch restricted speculation. This protects userspace from hyperthreading/simultaneous multi-threading attacks as well, and is also the default on certain old AMD processors (family 10h, 12h and 16h). This feature addresses CVE-2017-5715, variant #2.
> [...]
> echo 2 > /sys/kernel/debug/x86/ibrs_enabled
 
> echo 2 > /proc/sys/kernel/ibrs_enabled will turn on IBRS in both userspace and kernel

...
On Mon, Sep 17, 2018 at 5:26 AM Antoine Pitrou <soli...@pitrou.net> wrote:
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.

"Speculative Execution Exploit Performance Impacts - Describing the performance impacts to security patches for CVE-2017-5754 CVE-2017-5753 and CVE-2017-5715"

- Revised worst-case peformance impact: 4-8%

Steve Dower

unread,
Sep 17, 2018, 4:15:24 PM9/17/18
to Wes Turner, pytho...@python.org
On 17Sep2018 1158, Wes Turner wrote:
> On Monday, September 17, 2018, Steve Dower <steve...@python.org
> <mailto:steve...@python.org>> wrote:
>
> 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.
>
> What did you fuzz with?
> Does that assume that e.g. Fortify has identified all bugs in CPython C?
> There have been a number of variants that have been disclosed; which did
> who test for?

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

Nathaniel Smith

unread,
Sep 17, 2018, 4:16:15 PM9/17/18
to Wes Turner, Python Dev
Hi Wes,

It's great you're passionate about python security, but this is the wrong way to go about it. Spectre is inherently super subtle and confusing, so if there's something that people need to do, then we need a clear, comprehensive write-up of what the threat is and how to address it. Perhaps you could find some collaborators with expertise in these things and work with them off-list to put something like that together – that could be quite helpful.

What isn't helpful is what you've been doing instead: sending incoherent jumbles of vaguely-related text, to multiple highly-subscribed mailing lists, multiple times a day, for a week now. This is worse than useless. Please stop.

-n

_______________________________________________
Python-Dev mailing list
Pytho...@python.org
https://mail.python.org/mailman/listinfo/python-dev

Wes Turner

unread,
Sep 17, 2018, 6:10:36 PM9/17/18
to Steve Dower, pytho...@python.org
To summarize:

- CPython may be vulnerable to speculative execution vulnerabilities, but none are known.
- In general, CPython is currently too slow for speculative execution exploitation to be practical.
  - Sandboxed, JIT'ed JS is not too slow for speculative execution exploitation to be practical
    - (Not otherwise discussed here: PyPy's sandboxed JIT may not be too slow for speculative execution exploitation to be practical.)

- C extensions may be vulnerable to speculative execution vulnerabilities; but that's the authors' and users' problem (and so it's appropriate to mention this to extension owners following distutils-sig/PyPA)
  - C extensions can set indirect branch CFLAGS only with GCC 7.3 and GCC 8+; which are only usable with conda and the forthcoming manylinux2010 spec

- Linux kernels with [IBRS, STIBP, IBPB] can enable userspace protection
- The revised worst-case performance impacts for variant 2 mitigations are 4-8%

- MSVC has a /Qspectre flag for variant 1

- Because there is no exploit provided (or currently thought possible with just CPython), this security-related dialogue is regarded as a nuisance.
- There is no published or official statement or investigation from the Python community regarding Spectre (or Meltdown) vulnerabilities.

Here's a good write-up:
Safety_instructions_for_Meltdown_and_Spectre

Have a good day!

Franklin? Lee

unread,
Sep 18, 2018, 12:51:21 AM9/18/18
to wes.t...@gmail.com, Python Dev
I believe this is the article Wes wanted to link to:
https://www.thomas-krenn.com/en/wiki/Safety_instructions_for_Meltdown_and_Spectre

On Mon, Sep 17, 2018 at 6:10 PM Wes Turner <wes.t...@gmail.com> wrote:
>
> To summarize:
>
> - CPython may be vulnerable to speculative execution vulnerabilities, but none are known.
> - In general, CPython is currently too slow for speculative execution exploitation to be practical.
> - Sandboxed, JIT'ed JS is not too slow for speculative execution exploitation to be practical
> - (Not otherwise discussed here: PyPy's sandboxed JIT may not be too slow for speculative execution exploitation to be practical.)

I'm no security researcher, and I barely remember much about
Spectre/Meltdown, but I think the idea is that, if Python takes about
2 milliseconds to run your code, then a difference of +- 10
microseconds is indistinguishable from noise. Try to write software
that can learn to distinguish two similar computers using the running
time of certain functions.

Javascript can be crafted to get close enough to some C programs.
ASM.js and WebAssembly might help.

PyPy's need for mitigation is independent of CPython's.

> - Because there is no exploit provided (or currently thought possible with just CPython), this security-related dialogue is regarded as a nuisance.

More than that. Steve says that he looked into it and decided there
wasn't really anything to worry about. He believes that any exploit of
it will also imply an easier exploit is possible. He also says that
this particular fix won't really help.

Nathaniel is annoyed because Spectre is tricky to understand, and he
assumes you don't understand it as well as you think because you
haven't shown him that you have the expertise to understand it.

> Here's a good write-up:
> Safety_instructions_for_Meltdown_and_Spectre

But how does that apply to CPython? What specifically about CPython
makes the interpreter vulnerable to the attack? Under what conditions
would CPython be vulnerable to this attack, but not an easier attack
of at least the same severity?

The article I linked at the top of this email does not give advice for
interpreter writers at all. It only says what end users and chip
manufacturers ought to do. It is not relevant.

INADA Naoki

unread,
Sep 18, 2018, 2:40:36 AM9/18/18
to Wes Turner, Python-Dev
On Tue, Sep 18, 2018 at 7:08 AM Wes Turner <wes.t...@gmail.com> wrote:
>
> To summarize:
>
> - CPython may be vulnerable to speculative execution vulnerabilities, but none are known.
> - In general, CPython is currently too slow for speculative execution exploitation to be practical.
> - Sandboxed, JIT'ed JS is not too slow for speculative execution exploitation to be practical
> - (Not otherwise discussed here: PyPy's sandboxed JIT may not be too slow for speculative execution exploitation to be practical.)
>

As far as I know, execution speed is important for attacker, not victim.
In case of JavaScript, browser may load attacking code and run it while
user watching websites.
Browsers provides sandbox for JS, but attacker code may be able to
bypass the sandbox by Spectre or Meltdown. So browsers disabled
high precision timer until OSes are updated.

This topic is totally unrelated to compiler options: these compiler options
doesn't prohibit running attacking code, it just guard branches from
branch target injection.

Does my understanding collect? Why should we discuss about execution speed?

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.


Regards,
--
INADA Naoki <songof...@gmail.com>

Franklin? Lee

unread,
Sep 18, 2018, 3:25:12 PM9/18/18
to songof...@gmail.com, Python Dev
On Tue, Sep 18, 2018 at 2:40 AM INADA Naoki <songof...@gmail.com> wrote:
>
> On Tue, Sep 18, 2018 at 7:08 AM Wes Turner <wes.t...@gmail.com> wrote:
> >
> > To summarize:
> >
> > - CPython may be vulnerable to speculative execution vulnerabilities, but none are known.
> > - In general, CPython is currently too slow for speculative execution exploitation to be practical.
> > - Sandboxed, JIT'ed JS is not too slow for speculative execution exploitation to be practical
> > - (Not otherwise discussed here: PyPy's sandboxed JIT may not be too slow for speculative execution exploitation to be practical.)
> >
>
> As far as I know, execution speed is important for attacker, not victim.
> In case of JavaScript, browser may load attacking code and run it while
> user watching websites.
> Browsers provides sandbox for JS, but attacker code may be able to
> bypass the sandbox by Spectre or Meltdown. So browsers disabled
> high precision timer until OSes are updated.
>
> This topic is totally unrelated to compiler options: these compiler options
> doesn't prohibit running attacking code, it just guard branches from
> branch target injection.
>
> Does my understanding collect? Why should we discuss about execution speed?

According to this article, the malicious program needs to act in the
amount of time it takes for the CPU to load a value from memory and
invalidate a branch prediction:
https://hackernoon.com/timing-is-everything-understanding-the-meltdown-and-spectre-attacks-5e1946e44f9f

Stefan Ring

unread,
Sep 20, 2018, 1:31:41 PM9/20/18
to pytho...@python.org
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".

Wes Turner

unread,
Sep 20, 2018, 2:10:37 PM9/20/18
to Stefan Ring, pytho...@python.org


On Thursday, September 20, 2018, Stefan Ring <stef...@gmail.com> wrote:
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".

> Spectre has the potential of having a greater impact on cloud providers than Meltdown. Whereas Meltdown allows unauthorized applications to read from privileged memory to obtain sensitive data from processes running on the same cloud server, Spectre can allow malicious programs to induce a hypervisor to transmit the data to a guest system running on top of it.

- Private SSL certs
- Cached keys and passwords in non-zeroed RAM
- [...]



I really shouldn't need to apologise for bringing this up here.

Here's one:

Is this too slow in CPython with:
- Coroutines (asyncio (tulip))
- PyPy JIT *
- Numba JIT *
- C Extensions *
- Cython *

* Not anyone here's problem.

Franklin? Lee

unread,
Sep 21, 2018, 2:27:15 AM9/21/18
to Wes Turner, Python Dev
On Thu, Sep 20, 2018 at 2:10 PM Wes Turner <wes.t...@gmail.com> wrote:
>
> On Thursday, September 20, 2018, Stefan Ring <stef...@gmail.com> wrote:
>>
>> 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".
>
>
> > Spectre has the potential of having a greater impact on cloud providers than Meltdown. Whereas Meltdown allows unauthorized applications to read from privileged memory to obtain sensitive data from processes running on the same cloud server, Spectre can allow malicious programs to induce a hypervisor to transmit the data to a guest system running on top of it.
> - Private SSL certs
> - Cached keys and passwords in non-zeroed RAM
> - [...]
>
> https://en.wikipedia.org/wiki/Spectre_(security_vulnerability)

It's true that the attacks should worry cloud providers. Doesn't that
mean that companies like Amazon, Microsoft (Steve), and Docker should
have done analyses on CPython's vulnerability to these exploits?
Has/should/can anyone officially representing Python contact the
companies and ask them?

When I followed your quote to find the context, I found it uses, as
its source, a Forbes article. The source cited by THAT article is
Daniel Gruss, who was one of the researchers. Should someone from the
PSF contact the researchers? Steve says he spoke to some of them to
judge whether the proposed compiler flags would help, and decided
against it.

Absent of expert input, here's my non-expert take: That quote requires
an OS-level fix. A Python program without the proper permissions can't
do such things unless there is a vulnerability with the OS, and it is
extremely unlikely for anyone to update Python for Spectre but not
update the OS (and they'd be screwed in any case). And even if there
is a vulnerability in the OS, maybe the way to exploit it is by using
arbitrary Python execution (which you need before you can TRY to use
Spectre) on this Python interpreter. You can then write a new binary
file and run THAT, and it will be fast enough. That's not something
you can fix about CPython.

Also, (again with my understanding) the problem of Spectre and
Meltdown are that you can escape sandboxes and the like, such as the
user/kernel divide, or a software sandbox like that provided by a
JavaScript VM. For CPython to be "vulnerable" to these attacks, it
needs to have some kind of sandbox or protection to break out of.
Instead, we sometimes have sandboxes AROUND CPython (like Jupyter) or
WITHIN CPython. I don't see how it makes sense to talk about a sandbox
escape FOR CPython (yet).

Your original post linked to a discussion about Linux using those
build flags. Linux is a kernel, and has such protections that can be
bypassed, so it has something to worry about. Malicious code can be
native code, which (to my understanding) will be fast enough to
exploit the cache miss time. Here's Google's article about the
retpoline and why it helps:
https://support.google.com/faqs/answer/7625886

As of yet, you have quoted passages that have little relevance to
interpreter devs, especially non-JIT interpreters, and you have linked
to entire articles for non-experts with little relevance to
interpreter devs. This doesn't show that you have any better of an
understanding than I have, which is less than the understanding that
some of the Python devs have, and much less than what Steve has. In
short, it LOOKS like you don't know what you're talking about. If you
have a different and deeper understanding of the problem, then you
need to show it, and say why there is a problem for CPython
specifically. Or find someone who can do that for you.

> Here's one:
> https://github.com/Eugnis/spectre-attack/blob/master/Source.c
>
> Is this too slow in CPython with:
> - Coroutines (asyncio (tulip))
> - PyPy JIT *
> - Numba JIT *
> - C Extensions *
> - Cython *
>
> * Not anyone here's problem.

C extensions are obviously fast enough. I think most of the other
starred examples are fast enough, but it's probably more subtle than I
think and requires further analysis by their devs. I also think
there's something important I'm still missing about what's required
and what it can do.

I don't see what coroutines have to do with it. Coroutines are still
Python code, and they're subject to the GIL.

Wes Turner

unread,
Sep 21, 2018, 3:14:14 AM9/21/18
to Franklin? Lee, Python Dev
I feel like you are actively undermining attempts to prevent exploitation of known vulnerabilities because the software in question is currently too slow.

For a 4-8% performance penalty, we could just add the CFLAGS to the build now and not worry about it.

I give up.

Franklin? Lee

unread,
Sep 21, 2018, 3:25:28 AM9/21/18
to Wes Turner, Python Dev
There is much reason to believe it won't help, and you have given little reason to believe that it will help, or that you even properly understand how the flag mitigates Spectre in programs where it does help.

I am not undermining your attempts for the sake of performance. I am trying to help you understand why no one is taking you seriously, and suggesting what you can do so that they will. One way is to explain why an unsandboxed interpreter needs to protect against a sandbox escape.

Mark Lawrence

unread,
Sep 21, 2018, 4:22:31 PM9/21/18
to pytho...@python.org
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

Wes Turner

unread,
Sep 21, 2018, 10:52:00 PM9/21/18
to Mark Lawrence, pytho...@python.org


On Friday, September 21, 2018, Mark Lawrence <bream...@gmail.com> wrote:
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"?

"Andrew Carnegie - Rags to Riches Power to Peace"
... Vredespaleis

"Think and Grow Rich" by Napoleon Hill

Today is International Day of Peace.

But, now, I've gone way OT,
So, we'll just have to hope IBRS is enabled,
On all of the Jupyter cloud hosts.
 

--
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
Reply all
Reply to author
Forward
0 new messages