News for hackers. Stuff that matters.
Re:Reading privileged memory with a side-channel by hyperion2010 on Thursday January 04, 2018 @01:25AM (#16068453)
An analogy that was useful for explaining part of this to my (non-technical) father. Maybe others will find it helpful as well.

Imagine that you want to know whether someone has checked out a particular library book. The library refuses to give you access to their records and does not keep a slip inside the front cover. You can only see the record of which books you have checked out.

What you do is follow the person of interest into the library whenever they return a book. You then ask the librarian for a copy of the books you want to know whether the person has checked out. If the librarian looks down and says "You are in luck, I have a copy right here!" then you know the person had checked out that book. If the librarian has to go look in the stacks and comes back 5 minutes later with the book, you know that the person didn't check out that book (this time).

The way to make the library secure against this kind of attack is to require that all books be reshelved before they can be lent out again, unless the current borrower is requesting an extension.

There are many other ways to use the behavior of the librarian and the time it takes to retrieve a book to figure out which books a person is reading.

edit: A closer variant. Call the library pretending to be the person and ask for a book to be put on hold. Then watch how long it takes them in the library. If they got that book they will be in and out in a minute (and perhaps a bit confused), if they didn't take that book it will take 5 minutes.

Re:Reading privileged memory with a side-channel by 314 on Thursday January 04, 2018 @07:50AM (#16069938)
Your analogy is more apt for side-channel attacks in general. Here is a more specific version for Meltdown:

A library has two rooms, one for general books and one for restricted books. The restricted books are not allowed out of the library, and no notes or recordings are allowed to be taken out of the restricted room.

An attacker wants to sneak information out of the restricted room. To do this the pick up a pile of non-restricted books and go into the restricted room. Depending on what they read in there they rearrange the pile of non-restricted books into a particular order. A guard comes along and sees them, they are thrown out of the restricted room and their pile of non-restricted books is put on the issue desk ready to be put back into circulation.

Their conspirator looks at the order of the books on the issue desk and decodes a piece of information about the book in the restricted room. They repeat this process about 500000 times a second until they have transcribed the secret book.

Re:Reading privileged memory with a side-channel by pgt on Friday January 05, 2018 @01:12PM (#16080365)
I don't understand this explanation :/ Why is the room considered restricted if you can go inside? Do I know how all books that exist in the library? How does the order of the thrown out books pertain to the secret book?
Re:Reading privileged memory with a side-channel by ohazi on Saturday January 06, 2018 @04:21AM (#16084535)
> Why is the room considered restricted if you can go inside?

That's the bug. The guard only checks to see whether you're supposed to have access after you walk in and start (speculatively) rearranging books. One way to fix this bug would be to have the guard check your access at the door.

Re:Reading privileged memory with a side-channel by lma21 on Thursday January 04, 2018 @04:57PM (#16074447)
What is the analogy behind being able to go into the restricted room?
Re:Reading privileged memory with a side-channel by 314 on Thursday January 04, 2018 @10:04PM (#16076165)
The restricted room is the part of the machine behind the protection. Memory reads are not checked at the tine access. They are checked when the instruction retires.
Re:Reading privileged memory with a side-channel by AlphaSite on Saturday January 06, 2018 @11:44PM (#16089221)
On intel* this isn’t a property intrinsic to superscalar processors, other architectures check it in flight or while it’s in the issue queue, preventing this side channel.
Re:Reading privileged memory with a side-channel by foota on Thursday January 04, 2018 @05:16PM (#16074598)
You can call into the kernel.

edit: s/call into/trigger a syscall/

Re:Reading privileged memory with a side-channel by IshKebab on Saturday January 06, 2018 @11:31AM (#16085917)
You don't even need to do that for meltdown.
Re:Reading privileged memory with a side-channel by prab97 on Thursday January 04, 2018 @04:27AM (#16069016)
I don't understand how this info can be used for getting what was inside the book? If my understanding of your explanation is correct, book name is analogous to memory address. When the victim (legit process) returned the book with name X (called free on the mem block X), the librarian (OS) erased all pages of the book and repurposed it for printing another book before handing it out to the evil dude(snoopy process).
Re:Reading privileged memory with a side-channel by myrmi on Thursday January 04, 2018 @06:14AM (#16069451)
My attempt, assuming that the books only contain one character each:

The librarian has a list of books you're not allowed to take out. You request one of those books (book X), but it takes a while for search to run to see whether you're allowed to or not. While you're waiting, you say "actually, I'm not really interested in taking out book X, but if the content of that book is 'a', I'd like to take out book Y. If the content of that book is 'b', I'd like to take out book Y+1, and so on".

The librarian is still waiting for the search to complete to see if you can take out book X, but doesn't have anything better to do, so looks inside it, sees that the letter is 'b', and goes and gets book Y+1 so she can hand it over to you.

Now, the original check to see if you can take the first book out completes, and the librarian says "I'm sorry, I can't let you have book X, and I can't give you the book I fetched that you are allowed to take out, otherwise you'd know the content of the forbidden book."

Now, you request book 'Y', which you are allowed. The librarian goes away for a few minutes, and returns with book 'Y', and hands it over to you. You request book 'Y+1', and she hands it over immediately. You request book 'Y+2', and she goes away for a few minutes again, and hands it over.

You now know that Y+1 was (probably) the book she fetched when you made the forbidden request, and therefore that the letter inside the forbidden book was 'b'.

Re:Reading privileged memory with a side-channel by DougN7 on Thursday January 04, 2018 @01:13PM (#16072576)
Great explanation - thank you. One thing I don’t understand is how this can be exploited from javascript. Does it have timing primitives so fine it can tell the difference between a memory lookup served from memory va from cache?
Re:Reading privileged memory with a side-channel by craigyk on Thursday January 04, 2018 @01:29PM (#16072729)
Yes it does because javascript execution has had to become very fast. Fast means you can run a very tight loop that updates a counter to create a fairly high-resolution clock.
Re:Reading privileged memory with a side-channel by wvenable on Thursday January 04, 2018 @01:49PM (#16072918)
What I don't understand is how the branch predictor is even exploitable from JavaScript -- it doesn't have pointers. How can it "request" arbitrary memory locations and time the results?
Re:Reading privileged memory with a side-channel by hyperion2010 on Thursday January 04, 2018 @03:38PM (#16073857)
It has byte arrays and indexing on those which is equivalent to having pointers. See page 6 and 7 of the Spectre paper.
Re:Reading privileged memory with a side-channel by usrusr on Friday January 05, 2018 @08:22AM (#16078365)
So the mid-term fix for js jits should be to gimp indexed array access to the point where an out of bounds index value can never enter speculative execution, right? I'm no expert in these low-level things, but I imagine that speculative execution happens only from conditional jumps and that alternative bounds assurances (e.g. using base+idx%len as the eventually address or limiting it to a sandbox-owned region using a few bitmasks) should be possible that reliably stall the pipeline without allowing speculative access (obviously at considerable performance cost, but the jit should be able to whitelist certain safe access patterns and/or trusted code sources to not let this get out of hand). Am I missing something?
Re:Reading privileged memory with a side-channel by alex_stoddard on Thursday January 04, 2018 @01:33PM (#16072770)
I believe they made their own "good enough" clock out of a loop in a webworker.
Re:Reading privileged memory with a side-channel by prab97 on Friday January 05, 2018 @01:57AM (#16077056)
Thanks, this was a great explanation, really simplified it!
Re:Reading privileged memory with a side-channel by paufernandez on Thursday January 04, 2018 @09:22AM (#16070460)
I understood with your explanation, thanks!
Re:Reading privileged memory with a side-channel by tamriel on Thursday January 04, 2018 @05:47AM (#16069314)
The person checking out the book is a program, so they aren't the brightest.

They check out the book called "how to go to facebook.com". Then they check out "how to type a password". Then they check out "Typing '1234' for Dummies".

I bet you'll never figure out how to get into their facebook account.

Re:Reading privileged memory with a side-channel by pgt on Friday January 05, 2018 @01:03PM (#16080265)
Fantastic explanation of cache timing attacks. This morning I was explaining spectre to non-technical people and let me tell you, "leaking L1 CPU cache memory," is a real party starter. So I'm using there librarian example going forward.
Re:Reading privileged memory with a side-channel by pgt on Saturday January 06, 2018 @03:37PM (#16087310)
I used your explanation in a longer note, "Spectre: How do side-channel attacks work?"[^1] to try and explain how side-channel attacks work (partly to myself, and partly to non-hackers).

[^note]: https://www.facebook.com/notes/petrus-theron/spectre-how-do-...

Re:Reading privileged memory with a side-channel by hyperion2010 on Tuesday January 09, 2018 @03:37AM (#16104520)
Thanks for the heads up!
Re:Reading privileged memory with a side-channel by technics256 on Thursday January 04, 2018 @02:03AM (#16068552)
Thank you for this. Would you say this applies to both Spectre and Meltdown, or one and not the other?
Re:Reading privileged memory with a side-channel by fooker on Thursday January 04, 2018 @03:06AM (#16068714)
This is a general explanation of side channel attacks, as I understand.
Re:Reading privileged memory with a side-channel by craigyk on Thursday January 04, 2018 @04:04AM (#16068915)
yeah, I don't think it is a perfect analogy for Meltdown, I'll try one, someone correct me if I'm misunderstanding Meltdown.

Let's say you want to know if your boss is away on vacation next week so you call their admin and say "you need to double-check my contact info if the boss is going to be out next week". They load up the boss' calendar to check and based on his presence next week then load up your info. Only once done, do they take the time to remember the boss didn't want you to know wether they are in or out. So you hear back, "sorry, can't tell you that, but you follow up with "OK, well can you still double check that my phone number is..."

If they respond quickly with a yes, then your file is still on their screen and the boss is in fact out next week. If there is a short pause while they look it up, then the opposite.

Re:Reading privileged memory with a side-channel by ilitirit on Thursday January 04, 2018 @03:30AM (#16068789)
A timing attack is one type of side channel attack. These types of timing attacks can also be used against poor/unsuitable crypto functions, or even some processes involving general computation e.g. If it takes longer to reject input A than input B, you can reason that input A is closer to the answer (similar to someone reading a paragraph until they reach the first error).

Other side-channel attacks can come in the form of analysing network data, power-consumption (CPUs use more power when they are "busier")... even noise (listen for when the fans start spinning up).

Re:Reading privileged memory with a side-channel by AlphaSite on Saturday January 06, 2018 @11:46PM (#16089224)
Is blinding the only real solution to most of these attacks against Crypto?
Re:Reading privileged memory with a side-channel by hyperion2010 on Thursday January 04, 2018 @04:13AM (#16068953)
Yes, this is a general explanation of side channel attacks against some kind of caching. The more specific example tries to be closer to the type of situation that happens in Spectre, but it is not a direct analogy.