News for hackers. Stuff that matters.
Re:Python bytecode is heavily trusted by CPython by haberman on Wednesday October 21, 2015 @05:08AM (#10424360)
The Lua VM used to have a bytecode verifier that attempted to validate that given bytecode was safe. So many holes were discovered in it that it was removed completely.

The design of the Lua language and VM is almost unimaginably simpler than Python. If Lua gave up on this goal, I strongly suspect that no language VM will succeed at having safe bytecode unless the bytecode is specifically designed for security (and such a design would probably involve performance compromises to get this level of security).

Re:Python bytecode is heavily trusted by CPython by maggit on Wednesday October 21, 2015 @05:15AM (#10424370)
Isn't Google's Native Client exactly an example of a safe bytecode? Moreover, it is a safe subset of an already existing really large byte code language (x86 machine code), which inspires me to believe that it should be possible to identify similar subsets that are statically verifiable for other, especially simpler, byte code languages.
Re:Python bytecode is heavily trusted by CPython by sanxiyn on Wednesday October 21, 2015 @07:34AM (#10424767)
Many holes were discovered in Native Client. Difference is that Google was willing to fix them as they were discovered.

For example, https://developer.chrome.com/native-client/community/securit... lists 20 holes. I think the actual number of explicitly discovered holes in CPython and Lua bytecodes are each less than 20, and that was enough for them to give up.

Re:Python bytecode is heavily trusted by CPython by kuschku on Wednesday October 21, 2015 @03:45PM (#10428099)
Google's Sandbox will also show more and more holes every day. Because it's a comparably easy target, especially with x86 being so complicated and even having undocumented Opcodes.

Even just mov or lea are Turing complete.

Re:Python bytecode is heavily trusted by CPython by masklinn on Wednesday October 21, 2015 @05:16AM (#10424374)
Not that there's a point anyway (in Python), `ctypes` is part of the stdlib, you could just call into that and access the VM directly.
Re:Python bytecode is heavily trusted by CPython by Tomte on Wednesday October 21, 2015 @06:06AM (#10424513)
Java's bytecode verifier intrigued me at lot, back at university when we played around with it.

I thought the verifier had been removed last time I checked, but it looks I misremembered that.

Re:Python bytecode is heavily trusted by CPython by kragen on Wednesday October 21, 2015 @06:12AM (#10424541)
It hasn't (although some alternative VMs didn't implement it) but Java applets basically died and now I think people don't really benefit from the bytecode verifier, except arguably in debugging their JVM-targeted compilers. (I say "arguably" because generating valid JVM bytecode sometimes requires bending over backwards a bit, so your compiler would probably be simpler if it didn't have to deal with the verifier.)

Many holes have been found in the verifier over the years. More probably remain, although at this point JIT compiler bugs may be a more significant attack surface.

Re:Python bytecode is heavily trusted by CPython by SEJeff on Wednesday October 21, 2015 @10:27AM (#10425606)
Re:Python bytecode is heavily trusted by CPython by raverbashing on Wednesday October 21, 2015 @08:28AM (#10424941)
Well

"I wouldn't be surprised if hand-generating crazy instruction sequences could do things like crash CPython"

To me is the same as

"I wouldn't be surprised if hand-generating crazy instruction sequences could do things like crash an ELF executable"

Or, what happens if you feed bad code to a JVM?

Re:Python bytecode is heavily trusted by CPython by pjmlp on Wednesday October 21, 2015 @09:09AM (#10425132)
> Or, what happens if you feed bad code to a JVM?

Both the JVM and CLR have a verifier.

Re:Python bytecode is heavily trusted by CPython by hobarrera on Wednesday October 21, 2015 @07:05PM (#10429450)
That doesn't make them uncrashable.
Re:Python bytecode is heavily trusted by CPython by pjmlp on Thursday October 22, 2015 @03:54AM (#10430933)
It makes them resistant to stupid bytecode sequences that aren't supposed to happen.
Re:Python bytecode is heavily trusted by CPython by minopret on Wednesday October 21, 2015 @08:28AM (#10424942)
Let's consider which are the hard parts of verifying that remote code is safe.

Useful verifiers exist. Coq is a state-of-the-art verifier for a large class of propositions. It hasn't been easy to create. Its design is not frozen.

We need to create a specification for safe remote code that is trustworthy. This seems difficult when permitting all the remote code capabilities that we want.

We need to demonstrate constructing specification-compliant code for a nontrivial algorithm with a proof of compliance. This seems costly but feasible.

Re:Python bytecode is heavily trusted by CPython by miohtama on Wednesday October 21, 2015 @05:02AM (#10424345)
Python sandboxes, like RestrictedPython, operate on AST level. But don't try to sandbox the code, create isolated UNIX processes or containers instead.
Re:Python bytecode is heavily trusted by CPython by tkinom on Wednesday October 21, 2015 @07:58AM (#10424847)
Can someone inject bytecode into webpy process via url lookup table or python JSON parser?

If so, this bug report would be a lot more serious. I think no-trivial CMS app server is writting in python.

Re:Python bytecode is heavily trusted by CPython by orf on Wednesday October 21, 2015 @08:24AM (#10424926)
> Can someone inject bytecode into webpy process via url lookup table or python JSON parser?

Obviously not, that would be the biggest security hole ever even without this issue.

> I think no-trivial CMS app server is writting in python.

There are plenty. And are you saying no CMS app should be written in Python because of this issue? Or are you suggesting everyone switch to PHP where it's 100x easier to shoot yourself in the foot (or head)?

Re:Python bytecode is heavily trusted by CPython by shanemhansen on Wednesday October 21, 2015 @10:19AM (#10425550)
A very similar bug happened to rails. They parsed json using a yaml parser that loaded code. http://ronin-ruby.github.io/blog/2013/01/28/new-rails-poc.ht...
Re:Python bytecode is heavily trusted by CPython by sp332 on Wednesday October 21, 2015 @08:33AM (#10424967)
tkinom is just asking about the potential impact if this were a security problem.
Re:Python bytecode is heavily trusted by CPython by orf on Wednesday October 21, 2015 @08:59AM (#10425075)
He's asking about the potential impact of running untrusted bytecode?
Re:Python bytecode is heavily trusted by CPython by sp332 on Wednesday October 21, 2015 @09:50AM (#10425362)
Sure, this (hypothetical) exploit would be a lot more damaging if it were widespread.
Re:Python bytecode is heavily trusted by CPython by orf on Wednesday October 21, 2015 @10:37AM (#10425687)
Not really, because simply by running untrusted Python bytecode in any form you are exposing yourself to much worse than this. You're already past the airtight hatch[1], so it's pointless - "It's like saying that somebody's home windows are insecure because a burglar could get into the house by merely unlocking and opening the windows from the inside."

1. http://blogs.msdn.com/b/oldnewthing/archive/2006/05/08/59235...