News for hackers. Stuff that matters.
Re:SSH gets protection against side-channel attacks by Koffiepoeder on Friday June 21, 2019 @08:16AM (#20241790)
RAM encryption for sensitive data is overlooked in so many applications, even "highly secure" applications like veracrypt [0] only recently started adding it.

In my opinion server-applications of all sorts should encrypt their private keys by default; this makes cold-boot attacks and other memory-escape attacks so much harder, since now two totally unrelated memory chunks have to be combined in order to retrieve the private key (in fact one could argue that, the higher the quantity of memory chunks is, the harder it is to correctly decrypt the original private key; although to me this has the security through obscurity smell).

In practice however, this is rarely done. OpenSSL for example has a whole lot of memory-management functions [1], but none of them seem to include RAM encryption (AFAIK it is not present in the source code elsewhere either, but it's a large one, so I am not familiar with all code. Related: in fact some people even argue it's way too large for it's own good [2]).

Even better still, would be to use the CPU Cache for private keys, since this memory is even more difficult to access through any sort of cold boot. An interesting paper with much more information about this subject can be found here [3], to whom it may concern.

[0] https://github.com/veracrypt/VeraCrypt/commit/321715202aed04...

[1] https://www.openssl.org/docs/man1.1.0/man3/OPENSSL_zalloc.ht...

[2] https://queue.acm.org/detail.cfm?id=2602816

[3] https://www.ieee-security.org/TC/SP2015/papers-archived/6949...

Re:SSH gets protection against side-channel attacks by reza_n on Friday June 21, 2019 @08:30AM (#20241895)
Yup, we added this feature to Varnish Cache a few years ago, random key encryption. It generates a random key at startup and encrypts all memory with it. Since this kind of memory is only resident for the lifetime of the process, it works. We stored the random key in the Linux kernel using the crypto API [0] just because its not safe storing any kind of keys in a memory space used for caching (Cloudbleed [1]). We then use the key to generate a per object HMAC, so each piece of data ends up with its own key, which further prevents something like Cloudbleed. Since we used kernel crypto, overhead was about 50%. If you stay completely in user space, its probably much lower.

[0] https://www.kernel.org/doc/html/v4.17/crypto/userspace-if.ht...

[1] https://en.wikipedia.org/wiki/Cloudbleed

Re:SSH gets protection against side-channel attacks by thijsvandien on Friday June 21, 2019 @09:47AM (#20242426)
Could this be implemented at the OS level, i.e. whenever a proces launches, the OS generates a key that it will keep to itself and use to transparently encrypt all memory allocated by that process?
Re:SSH gets protection against side-channel attacks by mjevans on Friday June 21, 2019 @04:42PM (#20246164)
My first thought was to try to use 'containers' (cgroups) combined with the AMD secure memory extensions to achieve this type of isolation using as much off the shelf hardware as possible.

https://en.wikichip.org/wiki/x86/sme

https://www.kernel.org/doc/Documentation/x86/amd-memory-encr...

From the quick description it sounds like this provides a way of encrypting, per memory page, based on a symmetric key that is backed by some level of hardware encryption. It was not clear (in a quick read) how or where to specify the key by which an individual page is encrypted. That would be a critical component of comprehension with respect to identifying if this could be used to encipher individual processes and further isolate memory. It sounds like it might be possible to establish per-process memory isolation, which is probably the best level of security possible without resorting to entirely isolated hardware.

Re:SSH gets protection against side-channel attacks by the8472 on Friday June 21, 2019 @04:43PM (#20246171)
Per-process keys aren't really possible because memory can change process ownership (vmsplice) or be shared across processes (fork, page cache, memfd). It might be possible for pages marked MADV_DONTFORK

Additionally a per-process key does not help against spectre style attacks where you would trick the process into speculating on protected memory.

Re:SSH gets protection against side-channel attacks by simias on Friday June 21, 2019 @10:04AM (#20242573)
You'd probably want a hardware module to do that lest performance plummets. Memory controllers can already deal with ECC efficiently, adding a simple cypher on top of it should definitely be feasible.
Re:SSH gets protection against side-channel attacks by reza_n on Friday June 21, 2019 @10:04AM (#20242579)
Possibly, but memory is accessed using plain CPU instructions, so it would be hard to transparently encrypt all memory for an application at the kernel level. You do have virtual memory, but I dont think that could be leveraged for this. But who knows whats possible there, maybe if you align and address each memory value at the page boundaries and always force a page fault you could have a really poor implementation :)

Transparent disk encryption, not a problem since devices have filesystems which can implement encryption at that layer.

Re:SSH gets protection against side-channel attacks by repolfx on Saturday June 22, 2019 @06:09AM (#20248867)
Modern Intel chips can encrypt memory on the fly without performance loss (SGX does this). However I think it's not exposed for non-enclave use. Perhaps it should be.

Note: inside the enclave there is a performance loss but that's due to MAC checks. If you just want encryption without integrity against tampering you don't need that.

Re:SSH gets protection against side-channel attacks by zzzcpan on Friday June 21, 2019 @10:52AM (#20242984)
But that wouldn't prevent (mitigate) cloudbleed anymore as the problem is about isolating contexts within process boundaries.
Re:SSH gets protection against side-channel attacks by blattimwind on Friday June 21, 2019 @10:00AM (#20242531)
Technically yes, but practically no, because mediating all memory reads through the kernel would be very slow.

SME/MKTME add hardware support for this.

Re:SSH gets protection against side-channel attacks by nickpsecurity on Friday June 21, 2019 @11:56AM (#20243638)
Yes. Most research makes CPU modifications since that makes the most sense. Sometimes they try to use OS-level techniques. Here's a survey showing some of each:

https://thayer.dartmouth.edu/tr/reports/tr13-001.pdf

Re:SSH gets protection against side-channel attacks by peteretep on Friday June 21, 2019 @09:35AM (#20242342)
Just to clarify my understanding, the reason for doing this is so that random sampling / leakage of the contents of the RAM stops being useful, you need to specifically get the key (and then presumably a whole chunk of encrypted RAM to decrypt?)?
Re:SSH gets protection against side-channel attacks by reza_n on Friday June 21, 2019 @09:51AM (#20242457)
Yup. When something goes wrong in these kinds of applications, you sometimes tend to just randomly dump memory, which is a huge data leak. Or even worse, if someone figures out a way to force a data leak, then your are completely compromised. Having each piece of data with its own key and that key is a combination of data outside of the process address space drastically lowers the chances of data leakage and total compromise.
Re:SSH gets protection against side-channel attacks by Koffiepoeder on Friday June 21, 2019 @08:35AM (#20241923)
Could you point me to the relevant source code? Am highly interested to take a look at it during the weekend.
Re:SSH gets protection against side-channel attacks by reza_n on Friday June 21, 2019 @08:37AM (#20241942)
Re:SSH gets protection against side-channel attacks by AnaniasAnanas on Saturday June 22, 2019 @09:07AM (#20249401)
No offense, I am genuinely curious, why would anyone use any closed source software for anything related to security after the Snowden revelations?
Re:SSH gets protection against side-channel attacks by ris on Friday June 21, 2019 @02:32PM (#20245161)
> Closed source

Ah, so we'll just have to trust you that it's doing anything at all, then.

Re:SSH gets protection against side-channel attacks by dang on Friday June 21, 2019 @02:34PM (#20245182)
"Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith."

https://news.ycombinator.com/newsguidelines.html

Re:SSH gets protection against side-channel attacks by vageli on Friday June 21, 2019 @04:58PM (#20246262)
> "Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith."

> https://news.ycombinator.com/newsguidelines.html

Forgive me but can we not be skeptical of claims made about a commercial product?

Re:SSH gets protection against side-channel attacks by dang on Saturday June 22, 2019 @12:09AM (#20247976)
Of course you can, and there are plenty of ways to do so that don't break the site guidelines. Cheap, snarky one-liners are not the way. If someone's posting about their own work, there's no need to be disrespectful.

It's also not helpful to post such a clichéd dismissal of what someone else says or their work. That's in the site guidelines too.

https://news.ycombinator.com/newsguidelines.html

Re:SSH gets protection against side-channel attacks by isatty on Friday June 21, 2019 @09:57PM (#20247565)
Isn’t his reply valid and an exception to the rule given the context?
Re:SSH gets protection against side-channel attacks by reza_n on Saturday June 22, 2019 @10:12AM (#20249642)
We have no problem sharing our codebase with customers, especially if there are concerns like this. Shoot me a msg if you are genuinely interested in anything you have read.
Re:SSH gets protection against side-channel attacks by simias on Friday June 21, 2019 @10:02AM (#20242554)
I've tried implementing a couple of (toy) password managers over the years and dealing with private keys is genuinely complicated. Even something as trivial as making sure that the memory gets zeroed correctly when you discard the key is trickier than it seems. Compilers these days are very good at detecting "dummy" memsets to memory that's never read afterwards and optimize them away. You have to use some dirty tricks to get the compiler to do what you want (copious amounts of volatile helps).

There's also the problem of making sure that your internal API is sound and doesn't copy the key around. In languages like C it's relatively easy to achieve (because copying a buffer in C normally requires some explicit code) but in higher level languages you might easily mistakenly pass the key object by copy instead of reference, leaving some duplicate of the sensitive information in some other location in RAM.

I think there really should be some kind of industry-standard multiplatform library meant to deal with secret keys that would implement all that behind the scenes and offer a simple API. It's simply too easy to make a dumb mistake when implementing these things, and you won't notice anything is wrong until somebody attempts to actually recover the key somehow.

Re:SSH gets protection against side-channel attacks by cesarb on Friday June 21, 2019 @10:15AM (#20242664)
> Compilers these days are very good at detecting "dummy" memsets to memory that's never read afterwards and optimize them away. You have to use some dirty tricks to get the compiler to do what you want (copious amounts of volatile helps).

Or you can use explicit_bzero(), which is designed for that use case.

Re:SSH gets protection against side-channel attacks by loeg on Friday June 21, 2019 @10:45AM (#20242906)
Sure, although this is a non-standard and potentially non-portable extension. memset_s in Annex K is standard, but all of Annex K is optional, and like the rest of Annex K, it has an awful interface.
Re:SSH gets protection against side-channel attacks by rurban on Saturday June 22, 2019 @10:08AM (#20249618)
explicit_bzero or SecureZeroMemory are all insecure against those new sidechannel attacks we are talking about here. Only memset_s is.

You really need a mfence (full memory barrier), not just a compiler barrier, maybe even a clflush.

Re:SSH gets protection against side-channel attacks by nickpsecurity on Friday June 21, 2019 @11:59AM (#20243671)
You might find this paper interesting in regard to memsets optimized away:

https://www.usenix.org/system/files/conference/usenixsecurit...

I agree with you on a standard platform. Id get a company like Galois to build it. They already have and open-sourced the necessary tooling from thrir prior contracts.

Re:SSH gets protection against side-channel attacks by EGreg on Friday June 21, 2019 @02:09PM (#20244958)
Yes, ALL private keys should be encrypted and stored elsewhere. The onion/knot should be unwound from some remote place, so you have to get access to a FEW places in order to get any private keys.

Now, in MY opinion, the whole idea of servers storing OR MANIPULATING unencrypted user-submitted information is what’s wrong with our current Internet culture. This needs to stop. It has massive social and economic effects and creates honeypots for hackers.

The sooner we make end-to-end encryption a basic expectation, the sooner we change our society to have a far more private and safe environment for everyone, and correct massive power imbalances: an organization or user should have power and data and connections and ability to SPAM others because people VOLUNTARILY gave them those things, not because they happened to build proprietary software and run it on infrastructure that is needed to operate the application!!!

Re:SSH gets protection against side-channel attacks by rocqua on Friday June 21, 2019 @11:54AM (#20243618)
> in fact one could argue that, the higher the quantity of memory chunks is, the harder it is to correctly decrypt the original private key; although to me this has the security through obscurity smell

I am not sure this is a bad place for security through obscurity. ASLR is similar. The thing is, here we are not using this is a primary mechanism. (that would be preventing RCE) Instead, this would be a secondary 'defense in depth' measure meant to make it harder to deploy an exploit after you have been compromised.

For such a second layer of defense in depth, obscurity is a decent option. Things go wrong if you start relying on your obscurity to do anything but slow down an attacker.

Re:SSH gets protection against side-channel attacks by viraptor on Friday June 21, 2019 @02:40PM (#20245229)
I feel like the should be a different name for that class of mitigations. Probabilistic security maybe? Security through obscurity for me is "we won't publish our algorithm". But that's not the same as ASLR or memory encryption which targets specific type of attack by adding probably-too-high randomness to the attack path.
Re:SSH gets protection against side-channel attacks by latchkey on Friday June 21, 2019 @09:07AM (#20242166)
AMD has some interesting work in this area.

https://github.com/qemu/qemu/blob/master/docs/amd-memory-enc...

Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @09:45AM (#20242416)
RAM encryption is a feature in my password manager (java):

https://github.com/andy-goryachev/PasswordSafe/blob/master/s...

Curiously, RAM encryption, and its relative - clearing secrets from memory when not in use - cannot be added to the Bouncycastle library because they use java BigInteger (unless reflection is used of course).

Re:SSH gets protection against side-channel attacks by kjeetgill on Friday June 21, 2019 @01:00PM (#20244295)
You can't treat memory, even arrays, as singular memory locations in Java. Stuff moves around because collectors are cimpacting.. If you want to "write in place" in Java you need to either use a non-moving garbage collector, use sun.misc.Unsafe to read write memory directly, or mayyyyyybe take advantage of humongous allocations (arrays big enough that the JVM won't move them).
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @02:19PM (#20245043)
Direct ByteBuffer?
Re:SSH gets protection against side-channel attacks by the8472 on Friday June 21, 2019 @03:40PM (#20245701)
Yes, a direct byte buffer wrapped in class that ensures you can never copy the data somewhere else. That would also require cryptographic routines that can operate on bytebuffers or varhandles, which is quite an obstacle since many crypto libraries consume keys as byte[].
Re:SSH gets protection against side-channel attacks by sjwright on Friday June 21, 2019 @10:27AM (#20242754)
How do you guarantee actual clearing of physical memory in a garbage collected VM?
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @10:51AM (#20242967)
by explicitly clearing it when an operation is finished.

example:

https://github.com/andy-goryachev/PasswordSafe/blob/master/s...

byte[] key = generateKey(); try { // sensitive operation } finally { Crypto.zero(key); }

once the operation finishes, the memory is cleared (and possibly subject to gc)

the problem is that some java classes, for instance BigInteger, are not designed for cryptographic operations - it's underlying arrays are not easily accessible (save for reflection).

Re:SSH gets protection against side-channel attacks by saurik on Friday June 21, 2019 @11:23AM (#20243300)
In that code, after generateKey, during the sensitive operation, the system might need to do a garbage collection, at which point this array might have been copied to a different location in memory before your call to zero. You have to also "pin" (afaik this is the usual terminology for this) that array to a fixed location (which would then have to be a feature of that runtime and garbage collector) after allocating it but before generating the key.
Re:SSH gets protection against side-channel attacks by rurban on Saturday June 22, 2019 @10:14AM (#20249657)
Java also has no mfence or clflush support, so crypto.zero would never be secure. It might overwrite the key in the store buffer only, but not on the heap immediately, so prone to sidechannel attacks.
Re:SSH gets protection against side-channel attacks by java-man on Tuesday June 25, 2019 @11:26AM (#20275165)
This is interesting. Could you explain this please?
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @11:33AM (#20243390)
So what you are saying is that JVM copying surviving object between generational pools might expose secrets in memory?

A very good point, thank you.

What could be done to mitigate this? Direct ByteBuffer per

https://stackoverflow.com/questions/5670862/bytebuffer-alloc...

?

Re:SSH gets protection against side-channel attacks by MarkSweep on Friday June 21, 2019 @06:17PM (#20246728)
In .NET you can pin memory in the GC heap, either using something like the fixed expression in C# or GCHandle. A quick Googleing did not turn up something usable directly by Java, except ByteBuffer.
Re:SSH gets protection against side-channel attacks by pstrateman on Friday June 21, 2019 @11:13AM (#20243213)
That operation is almost certainly optimized out.
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @11:34AM (#20243405)
Would you elaborate please?
Re:SSH gets protection against side-channel attacks by pstrateman on Saturday June 22, 2019 @01:24PM (#20250674)
The compiler will see that your operation does nothing and simply not do it.
Re:SSH gets protection against side-channel attacks by java-man on Sunday June 23, 2019 @12:35AM (#20253325)
What I mean was: do you know this to be the case for JVM 8 later? This is an interesting subject. Was there a study or a paper you can refer me to?
Re:SSH gets protection against side-channel attacks by pstrateman on Sunday June 23, 2019 @04:11PM (#20258368)
JVM 8 isn't an implementation, it's a specification.

Assuming you mean oracles implementation, it's likely that it is.

https://www.sjoerdlangkemper.nl/2016/05/22/should-passwords-... http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buf... https://man.openbsd.org/explicit_bzero.3

Re:SSH gets protection against side-channel attacks by java-man on Sunday June 23, 2019 @04:32PM (#20258482)
Thank you. I was hoping for a more definitive answer, may be a reference to an explicit test involving memory dump analysis.
Re:SSH gets protection against side-channel attacks by marvin-83 on Friday June 21, 2019 @11:55AM (#20243620)
I believe he is referring to compiler optimisation which removes wasteful or extraneous operations. I don't write in Java though, so can't comment more than that.
Re:SSH gets protection against side-channel attacks by Too on Saturday June 22, 2019 @02:27AM (#20248308)
Ideally private keys should never touch the main CPU at all. You should use something like a secure enclave or a a key-dongle like Yubikey.
Re:SSH gets protection against side-channel attacks by rurban on Saturday June 22, 2019 @08:15AM (#20249195)
No. The CPU cache can easily be read out with sidechannel attacks via hyperthreading. It's the similar problem as unencrypted keys at the absolute location, which doesn't get cleared with explicit_bzero, which e.g. libsodium refused to fix. Hopefully crypto maintainers will get to their senses eventually.

https://github.com/jedisct1/libsodium/issues/802

Re:SSH gets protection against side-channel attacks by jedisct1 on Saturday June 22, 2019 @01:25PM (#20250675)
libsodium has the sodium_mshield()/sodium_munshield(). For libhydrogen, storing a large prekey can be a problem, so it may only be implemented on some platforms.
Re:SSH gets protection against side-channel attacks by spacephysics on Friday June 21, 2019 @08:29AM (#20241884)
If I were writing a cryptographic algorithm in C++, how would I ensure the CPU cache was used for private keys? Would it have to be written in a lower level language, or does there exist a library for C/C++?
Re:SSH gets protection against side-channel attacks by Zarathustra_ on Friday June 21, 2019 @08:33AM (#20241909)
Previous thread with lots of relevant information: https://news.ycombinator.com/item?id=8542405

Short answer is yes usually, and if not, you can always do inline asm. Of course, you're really, really, really not supposed to write your own crypto.

Re:SSH gets protection against side-channel attacks by vinay_ys on Friday June 21, 2019 @12:12PM (#20243818)
If everyone follows this advice, who will write the crypto code? If anything we need lot more people who are formally trained to write proper crypto code and find bugs in such code etc.
Re:SSH gets protection against side-channel attacks by Zarathustra_ on Friday June 21, 2019 @01:47PM (#20244759)
Let me qualify that. You're right, we do need a lot more people. But the answer is, don't write your own, write as part of a team. Ideally, a public and peer-reviewed project. The short answer is many people will work on it together, but don't write your own.