News for hackers. Stuff that matters.
Re:What Spectre and Meltdown Mean for WebKit by ams6110 on Monday January 08, 2018 @11:27PM (#16103608)
> All type checks are also vulnerable. For example, if some type contains an integer at offset 8 while another type contains a pointer at offset 8, then an attacker could use Spectre to bypass the type check that is supposed to ensure that you can’t use the integer to craft an arbitrary pointer.

So, even if WebKit were entirely written in Rust, we'd still be fucked. I'm really starting to think it's about time for me to get out of this business.

Re:What Spectre and Meltdown Mean for WebKit by kibwen on Tuesday January 09, 2018 @12:54AM (#16103934)
I'm actually not sure what that passage is trying to imply at all, I've not seen any prior remarks that Spectre has that sort of implication. AIUI, Spectre lets you read arbitrary memory, not write it, so I'm not sure what they mean by "bypass the type check" and "craft arbitrary pointer". Here's another quote later on:

> But Spectre could theoretically involve any branch that enforces security properties, like the branches used for type checks in JavaScriptCore.

I get the impression this is all referring to JIT'd JS, not to the C++ (or Rust etc.) code powering the underlying engine (where all typechecking is done at compile-time anyway). Of course having the JS engine written in Rust would still allow the same, but it's been known for a long time that Rust's typesystem can't do squat to verify the correctness of dynamically-generated code; it's part of the reason why Mozilla only bothered to kick off a rewrite of Gecko and not SpiderMonkey.

Re:What Spectre and Meltdown Mean for WebKit by pizlonator on Tuesday January 09, 2018 @01:21AM (#16104025)
It's common for C++ code to do type checking dynamically. In WebKit we do this by rolling the type checks ourselves. With RTTI, you can do dynamic type checks using the build-in dynamic_cast primitive. Our changes, particularly the ones having to do with pointer poisoning, are meant to protect C++ code that does dynamic type checks in addition to JIT'd JS code that does dynamic type checks.

Rust's `match` statement is a dynamic type check just like C++'s `dynamic_cast`. I bet you it's implemented using branches.

Re:What Spectre and Meltdown Mean for WebKit by kibwen on Tuesday January 09, 2018 @02:05AM (#16104190)
> Rust's `match` statement is a dynamic type check just like C++'s `dynamic_cast`.

I wonder if this is a case of a difference in terminology, because enum variants (the branches in `match` expressions) aren't considered types in Rust, and have no interaction with Rust's typechecker (Rust always has to assume that every instance of an enum can be any variant, even in cases where we as the programmer know that only one variant is possible).

At the same time I'm still unclear on what the OP is trying to imply. To reiterate, AIUI Spectre can only read, not write, privileged memory, so it's impossible for a Spectre attack to trick the engine into believing that (to use Rust terminology) an instance of an enum is a variant that it isn't. Am I incorrect?

Re:What Spectre and Meltdown Mean for WebKit by bzbarsky on Tuesday January 09, 2018 @02:53AM (#16104350)
The idea is to read random things as follows:

1) Write a function that reads the "nth" value out of an array in JS.

2) Call the function a bunch of times with JS arrays.

3) Pass an integer to that function for the "array" value. This would normally end up throwing. But before it does, the CPU might speculate the VM-internal typecheck as "it's going to be an Array, like the previous 1000 times" and end up doing an "nth value" read out of a memory address that you fully control (by changing which integer you pass).

That is, you can use speculative type confusion in the VM to allow precise control over what memory addresses get accessed and how for your timing attacks on the cache.

Re:What Spectre and Meltdown Mean for WebKit by petascale on Tuesday January 09, 2018 @03:50AM (#16104580)
Hypothetical example pseudocode:

    if is_pointer(pt):
        // do pointer-based stuff
    else:
        raise error
If you train the branch predictor to expect a pointer, it will speculatively treat arbitrary values as pointers until it can determine that they are not. So you can pass in any value and get it treated like a pointer for the duration of the window of speculative execution.

Any conditional branch is potentially vulnerable, an attacker just needs some sort of side effect from speculative execution that persists after rollback.

Re:What Spectre and Meltdown Mean for WebKit by kibwen on Tuesday January 09, 2018 @12:31PM (#16107906)
Thanks for the reply, I think I've got it now: the ultimate attack is still to read arbitrary memory, and the part about defeating typechecking and crafting a pointer is intended to expand the range of memory that can be read.
Re:What Spectre and Meltdown Mean for WebKit by techdragon on Tuesday January 09, 2018 @02:06AM (#16104193)
Serious question, is it even possible to have something like ‘match’ or ‘dynamic_cast’ in a programming language without using branches under the hood?

I’m not talking about research/example microprocessors that don’t have equivalent instructions. I mean isn’t branching a fundamental logical construct and we either do it in hardware with branch assembly operations or emulate functional equivalents of them in the software that runs on the microprocessor some other way? Or is there some clever/old logical/mathematical “alternative” to branches?

Re:What Spectre and Meltdown Mean for WebKit by earenndil on Tuesday January 09, 2018 @02:46AM (#16104320)
Consider something like this:

    struct __internal_variable {
        uint64_t type;
        void *data;
    }
    
    uint64_t __last_type = [number of builtin types];
    
    whenever you create a new type: increment __last_type and associate that type with the number;

    uint64_t typeof(__internal_variable var) {
        return var.type;
    }
    
    function[__last_type] typechecks;
    functions[] = void function(uint64_t type) { failure; }
    functions[int] = void function(uint64_t type) { success; }

    functions[typeof(myvar)]()
If typeof(myvar) is int, then the function that returns success will be called, otherwise failure, no branches involved! Yes, it's a kludge, but it kind of works.

---

Of course, you don't actually need this trick. If you put enough effort into it, you can essentially compile anything to c, after which you can just compile it with the movfuscator[1]

1: https://github.com/xoreaxeaxeax/movfuscator

Re:What Spectre and Meltdown Mean for WebKit by gpderetta on Tuesday January 09, 2018 @03:52AM (#16104590)
That's basically a jump table. Still vulnerable to spectre (variant 2) without mitigations, btw.
Re:What Spectre and Meltdown Mean for WebKit by fpoling on Tuesday January 09, 2018 @04:21AM (#16104720)
It is even worse then switch/match statements. The jump tables can be used to train CPU to jump to a wide variety of addresses than switch/match statements so mounting a speculative execution attack is simpler.
Re:What Spectre and Meltdown Mean for WebKit by gpderetta on Tuesday January 09, 2018 @04:26AM (#16104742)
true. Then again switch statements (and I assume match statements in language that have them) are often compiled down to a jump table...
Re:What Spectre and Meltdown Mean for WebKit by cerved on Tuesday January 09, 2018 @02:13AM (#16104218)
The problem isn't the branches it's the speculative execution
Re:What Spectre and Meltdown Mean for WebKit by kzrdude on Tuesday January 09, 2018 @11:35AM (#16107376)
Yes,it's already implemented as a poc - just look at movfuscator
Re:What Spectre and Meltdown Mean for WebKit by cerved on Tuesday January 09, 2018 @02:08AM (#16104200)
AIUI you create a pointer by issuing an array OoB. The check against this is a brach statement followed by the array OoB. However, the CPU starts executing the array OoB while the check is happening and the memory in the pointer gets loaded into cache.

This is an architecture bug so any security check that relies on simple branching is potentiality vulnerable.

Re:What Spectre and Meltdown Mean for WebKit by josephg on Monday January 08, 2018 @11:43PM (#16103670)
Something I keep coming back to in all this is that maybe we should be surprised that it’s even possible to share a CPU between mutually untrusted programs, let alone do it in so many contexts.

How do we stop his entire class of bugs? What is the Rust for CPU design?

Re:What Spectre and Meltdown Mean for WebKit by 6nf on Monday January 08, 2018 @11:48PM (#16103684)
CPUs tend to have multiple cores these days, would it be possible to assign (in software) all kernal space work to one or more dedicated cores to mitigate some of the risks?
Re:What Spectre and Meltdown Mean for WebKit by politician on Tuesday January 09, 2018 @01:17AM (#16104015)
Yes, well, close.

> Since the 2010 Westmere microarchitecture Intel 64 processors also support 12-bit "process-context identifiers" (PCIDs), which allow retaining TLB entries for multiple linear-address spaces, with only those that match the current PCID being used for address translation.[19][20]

https://en.wikipedia.org/wiki/Translation_lookaside_buffer#P...

HN discussion: https://news.ycombinator.com/item?id=16094349

Re:What Spectre and Meltdown Mean for WebKit by vardump on Tuesday January 09, 2018 @01:43AM (#16104109)
That's just Meltdown workaround.

Spectre was more relevant to context.

Re:What Spectre and Meltdown Mean for WebKit by megablast on Tuesday January 09, 2018 @01:11AM (#16103992)
With a shared cache.
Re:What Spectre and Meltdown Mean for WebKit by gpderetta on Tuesday January 09, 2018 @03:54AM (#16104603)
Some of the newer Intel server CPUs allow statically partitioning the shared L3 cache between cores. It might (or not) work as a way to reduce side channel communications between cores.
Re:What Spectre and Meltdown Mean for WebKit by abecedarius on Tuesday January 09, 2018 @01:15AM (#16104007)
I always liked the https://en.wikipedia.org/wiki/J%E2%80%93Machine idea: gobs of processors each with a small private memory (nothing shared), in a fast mesh network. It fits with physics: accessing local memory can be fast, while distant memory physically just can't. But even if it's really all that, it's just so different from the architectures we've put so much work into or on top of.
Re:What Spectre and Meltdown Mean for WebKit by estebank on Tuesday January 09, 2018 @01:39AM (#16104100)
That sounds like a more extreme version of what the Cell[1] was supposed to be. Developers seemed to think that developing for that architecture was really painful, specially compared to other contemporary console platforms. I'd love it if the progress being made in the industry got us to actually being able to exploit the full potential of such architectures.

[1]: https://en.wikipedia.org/wiki/Cell_(microprocessor)

Re:What Spectre and Meltdown Mean for WebKit by abritinthebay on Tuesday January 09, 2018 @01:59AM (#16104169)
It was painful - mostly because we don't have good tools for that sort of thing and most of our programming sort of hides the idea of multiple CPUs and pretends it's all working at once (in terms of us writing the code anyhow).

It's all abstracted in a very linear way.

Changing all that will take a lot of time if we do.

Re:What Spectre and Meltdown Mean for WebKit by gpderetta on Tuesday January 09, 2018 @03:57AM (#16104614)
Actually multiple CPUs are not normally hidden in mainstream programming languages [1]: i.e. threads are visible. The fiction that it is maintained by the programming languages and hardware is that of a single, coherent address space, which Cell very much did not have.

[1] outside of parallel iteration/folding constructs.

Re:What Spectre and Meltdown Mean for WebKit by abecedarius on Tuesday January 09, 2018 @12:26PM (#16107841)
Yeah. Erlang seems to show that there is a path from here to there, but the Erlang-ish world is tiny relative to the whole industry.
Re:What Spectre and Meltdown Mean for WebKit by UncleEntity on Tuesday January 09, 2018 @09:16AM (#16106273)
> I'd love it if the progress being made in the industry got us to actually being able to exploit the full potential of such architectures.

If they had ever released it as a general purpose computer instead of a locked down game console people could've experimented with it enough to unlock its full potential.

If they were smart they'd dust off the old chips, throw them on a RasberryPi type system and laugh all the way to the bank.

Re:What Spectre and Meltdown Mean for WebKit by krylon on Tuesday January 09, 2018 @02:00PM (#16108731)
There were PCI-Express cards with Cells on them, for numbercrunching or something. These even used the "good" Cells with full 64-bit floating point numbers needed for scientific workloads.

I vaguely remember that the price tag I saw was so outrageous I can understand why that didn't go anywhere.

Would have been interesting, though, I agree.

Re:What Spectre and Meltdown Mean for WebKit by pjmlp on Tuesday January 09, 2018 @02:09AM (#16104206)
> What is the Rust for CPU design?

Intel iAPX 432 could have been it, but they did a lousy job implementing it.

https://en.wikipedia.org/wiki/Intel_iAPX_432

Re:What Spectre and Meltdown Mean for WebKit by frik on Tuesday January 09, 2018 @12:48AM (#16103910)
Yes, we need a many-core CPU. Then every program can run on a core. And we can use MPI, CILK, etc to run parallel programs. Each CPU could run its own small operating system, or using a micro kernel OS.

Writing algorithms in parallel manner isn't as complicated as make to believe you, a lot can be rewritten based on cookbooks/patterns.

Intel developed a many-core CPU (72 CPU cores) called Xeon Phi: https://en.wikipedia.org/wiki/Xeon_Phi

Unfortunately they drifted of the target (instead of making it the successor of x86-64).

For Javascript engines, it would help if the offer an optional fallback "Javascript interpreter" instead of JIT. A JIT is basically at the moment insecure, especially when running untrusted code. The same goes for WebAssembly, let the user deactivate execution/support of it. Please allow end user to enable an alternative JS interpreter for high security things like online banking.

Re:What Spectre and Meltdown Mean for WebKit by eecc on Tuesday January 09, 2018 @02:04AM (#16104187)
Well, Meltdown mitigation involves unmapping as much Kernel as possible when switching modes. It’s so much overhead that I wonder if uK messaging and process context switching is cheaper and faster.
Re:What Spectre and Meltdown Mean for WebKit by om2 on Tuesday January 09, 2018 @05:21AM (#16104981)
Interpreters generally do a lot of branches, so they are also vulnerable to Spectre.
Re:What Spectre and Meltdown Mean for WebKit by pizlonator on Monday January 08, 2018 @11:41PM (#16103665)
Right, programming-language-based security mechanisms that rely on emitting runtime checks are broken and you need something like index masking or pointer poisoning to fix them. Rust could use those fixes as well.
Re:What Spectre and Meltdown Mean for WebKit by iainmerrick on Tuesday January 09, 2018 @09:03AM (#16106177)
Why does Rust need those? Those are things you need when running untrusted code in a sandbox. Is there a scenario where Rust is used that way?

There's WASM, but in that case the extra checks need to be applied at the WASM level, not the Rust level.

Re:What Spectre and Meltdown Mean for WebKit by roca on Tuesday January 09, 2018 @01:58AM (#16104167)
Interestingly you could apply these mitigations in Rust itself --- array index masking where Rust has array bounds checks, and pointer obfuscation where you check the variant tags of algebraic types. Some extra work would be required for unsafe Rust code. That would automatically protect almost all Rust code, whereas most C and C++ code would have to be handled manually.
Re:What Spectre and Meltdown Mean for WebKit by lower on Monday January 08, 2018 @11:53PM (#16103715)
Note that the article talks about type checks for the JavaScript code that is being executed by WebKit, not type checks in the implementation of WebKit itself. So there are two different kinds of type checks involved here.
Re:What Spectre and Meltdown Mean for WebKit by pizlonator on Monday January 08, 2018 @11:55PM (#16103725)
We are using pointer poisoning to protect type checks in WebKit itself as well as type checks in the JavaScript code we execute.

We are using index masking in WTF::Vector and WTF::StringImpl, which are used both for JavaScript execution and for lots of other things in WebKit that want a vector or a string.

Re:What Spectre and Meltdown Mean for WebKit by rcthompson on Tuesday January 09, 2018 @12:42AM (#16103893)
Doesn't Rust do all its type checking at compile time, not run-time?

(Not to say that a correctly-written Rust program wouldn't be vulnerable to Spectre for other reasons, of course.)

Re:What Spectre and Meltdown Mean for WebKit by FreeFull on Tuesday January 09, 2018 @12:50AM (#16103923)
If I'm reading this correctly, the issue isn't with the types of the language you wrote the Javascript engine in, but with Javascript's types. All major Javascript engines are written in C++, which also does all its type checking at compile-time.
Re:What Spectre and Meltdown Mean for WebKit by pizlonator on Tuesday January 09, 2018 @01:08AM (#16103981)
Not quite. Our C++ code often does static_cast<> as a downcast based on testing some condition. That's a run-time type check. This isn't solely about those type checks that were implemented using some built-into-the-language type checking mechanism. Also, C++ does have a dynamic type check primitive (dynamic_cast).

We are mitigating these branch-based type checks with pointer poisoning, and I don't think that those changes are biased in favor of C++ or JS, since both are vulnerable.

Re:What Spectre and Meltdown Mean for WebKit by rcthompson on Tuesday January 09, 2018 @01:02AM (#16103965)
Ah yes, that makes sense.
Re:What Spectre and Meltdown Mean for WebKit by pizlonator on Tuesday January 09, 2018 @01:04AM (#16103974)
Rust has algebraic types, so Spectre could be used to train the branch predictor to take one type case of your match statement, and then have that case taken when the enum is actually in a different shape. That's a violation of the type system.
Re:What Spectre and Meltdown Mean for WebKit by vasili111 on Tuesday January 09, 2018 @01:44AM (#16104110)
> I'm really starting to think it's about time for me to get out of this business.

Maybe it is time to move to IT security business?