6 ms·
I disagree about Ted being wrong. A key phrase in Ted's article is Hopefully the simulacrum retains the essence of the problem. What Tedbleed, as your article
by wglb 12y ago
I disagree about Ted being wrong.
A key phrase in Ted's article is Hopefully the simulacrum retains the essence of the problem.
What Tedbleed, as your article calls it, demonstrates is a bug similar to Heartbleed: reuse of a buffer in a memory-safe language is susceptible to leakage of secrets.
While I might answer the question are Rust’s memory safety features being oversold by uninformed zealots?, no I don't think so, but I would suggest that thinking that memory safety ends all security issues is a not good plan.
The key is Unless you venture into the (explicitly demarcated) unsafe portion of Rust, you will not see memory exposure vulnerabilities like Heartbleed: the language does not prevent this. Perhaps your post will stimulate Ted to go further with his example and write an erroneous complete TLS stack in Rust, showing how it too can do Heartbleed. Perhaps you agree that this can be done.
Among the scariest mass vulnerabilities relating to total information disclosure, the Padding Oracle Attack, the BEAST attack, the compression flaw CRIME, none have to do with memory safety of languages. Rust there would not have helped one whit.
Memory safety is just one issue in writing secure code.
Edit: typo
- saidajigumi 12y agoTo my knowledge, no one in the Rust or greater memory-safe programming language community would claim: Using <$LANG> prevents leakage of secrets! When put like that, it sounds like a straw-man argument. In my own words, the narrower and stronger claim being made is that the specific and important avenue by which Heartbleed leaked secrets is not possible without unsafe code in Rust. So if you're going to claim that Ted "isn't wrong", but on terms that no one was originally arguing... I don't even know what to say.
- wglb 12y agoSo if you're going to claim that Ted "isn't wrong", but on terms that no one was originally arguing... Perhaps I am taking a more general implication of this than "Rust would not have exactly reproduced the Heartbleed problem". I infer the overall meaning of Ted's argument, and the general discussion that "Memory safe languages do not prevent information leakage". To me that is what the argument is about.
- danudey 12y agoNothing 'prevents' information leakage other than writing perfect code 100% of the time. If the argument is that you can write a program in Rust that tells someone something they shouldn't know… is that… what's even the argument here? Is that even a question? But in that case, comparing against Heartbleed is pointless. Why not ask about SQL injection attacks? Or directory traversal attacks? Or OS privilege escalation attacks? Or listening on a port that isn't correctly firewalled? Rust won't prevent any of those either, because none of them have anything to do with the language being used. Arguing that it's possible to write code that does the wrong thing is so pointless that I can't understand why this article was written other than as some kind of half-assed hatchet job.
- lmm 12y agoI would claim that using Scala (and presumably Haskell) gives you the tools to make it impossible to leak secrets, if you want to. You could use a path-dependent container type to ensure that content was associated with a particular connection and never passed off to a different connection; if you tried to do something like reusing a buffer, it would be a compile failure. There would be costs to this - both in runtime performance (presumably you wanted to reuse buffers for a reason) and in program complexity. And of course it's possible to make an error in your type definitions (though you have to make two errors to be exploitable - one in the types and one in the values - and the types are shorter and much easier to audit than the full program code). But it absolutely is possible, and I think that pretty soon we'll reach the point where it becomes worthwhile for security-critical code.
- steveklabnik 12y agoYeah but even Haskell (and I'm assuming Scala has something similar) has unsafePerformIO...
- codygman 12y agoBut there is a compiler flag -XSafe which could guarantee none of your code uses it, meaning GP's answer could be yes.
- steveklabnik 12y agoWe have that switch in Rust as well.
- olavk 12y agoAs far as I understand, unsafePerformIO is not unsafe in relation to memory safety issues. It is just unsafe in that it circumvents the IO monad, which means order of execution is not guaranteed.
- steveklabnik 12y agoIt's a different kind of unsafe, but my point is that it violates the normal guarantees of the language.
- deleted 12y ago[deleted]
- tedunangst 12y ago> specific and important avenue by which Heartbleed leaked secrets is not possible without unsafe code in Rust. Alright. Please clarify. What is the specific and important avenue by which Heartbleed leaked secrets?
- TheDong 12y agoBy allowing an attacker to read arbitrary memory of the process that linked against the library In rust, if I write code where I store my secrets in two variables which I pass into my ssl constructor, but retain single ownership of (such that the ssl library may not retain references to them after the constructor exits), there is no way for those exact memory addresses to be read and returned via that library, excepting unsafe. If you say "ah, but the constructor could take a copy and leak that", then that's a different class of vulnerability. It could, but then it would be leaking its memory, not mine.
- tedunangst 12y agoAre we now redefining plaintext passwords and cookies as "not secret"? OpenSSL stored them in the same variable as heartbeat payloads.
- TheDong 12y agoless secret than tls keys, yes. However, that completely does not relate to your question. I'm not saying that they both aren't security vulns, they both are. You asked how heartbleed leaked secrets (implicitly how it was different from the rust code), and I told you how it differs. Where the secrets are stored is different. One is user-supplied secrets only, the other is arbitrary secrets within the process, user-supplied or otherwise. Yes this is different. Your response here is simply moving the goalposts.
- tedunangst 12y agoTo move the goalposts back to position, I'll answer my own question. The specific and important avenue by which Heartbleed leaked secrets was reusing secret containing buffers and miscalculating the initialized length.
- MichaelGG 12y agoMy original comment said that even with a custom allocator, Rust would refuse to compile code that could lead to Heartbleed. This was technically not accurate. (I thought HB was just out of bounds+uninitialized behavior.) I think the real key is that in C, this leak can happen with just malloc+forgetting a memset, no explicit buffer reuse required. Whereas in Rust, you'd need to explicitly reuse the buffer.
- tedunangst 12y agoThe not compiling part was really what piqued my interest. :)
- MichaelGG 12y agoTo be fair, the equivalent of malloc(x) plus a read of x+n bytes wouldn't compile, even with a custom allocator.
- camgunz 12y agoI know next to nothing about rust, but can't you do pretty much whatever you want when you implement a custom allocator? Including allocate a giant buffer ahead of time and reuse stuff with no safety whatsoever?
- MichaelGG 12y agoI'm not sure custom allocators exist. But assuming they did, sure you can. But in that case you're explicitly opting into unsafe code to use uninitialized memory. And, even if you did have such an allocator, you still can't read past the end of the allocation. So if you ask for a 16 byte buffer and attempt to read 17, it'll fail.
- weland 12y agoIt's extremely important to remember this in context: Heartbleed occurred on OpenBSD because OpenSSL had its own wrapper over malloc(). Instead of actually free()-ing those areas when calling openssl_free(), OpenSSL would leave them untouched and reuse them. If that had not been the case, and free() had in fact been called, reading past the actual payload boundaries would have yielded no useful results, because the malloc() in OpenBSD's libc would have cleared it (as opposed to openssl_malloc(), which was reusing previously un-free()-d zones). In other words: idiomatic C and a sane malloc() implementation could have actually prevented Hearbleed. It makes sense to assume that un-idiomatic Rust and reusing memory without clearing it would trigger the same bug.
- _yosefk 12y agoBy "sane malloc" do you mean one that gives you "cleared"/zeroed memory? I think it's a rarity and I think programs kinda assume that malloc takes, I dunno, 300-1000 cycles at worst when allocating many megabytes - whereas zeroing such buffers takes much more. Or did I misunderstand your point about "malloc sanity"?
- Sanddancer 12y agoOpenBSD's malloc function is based on mmap, which will give you cleared pages.
- _yosefk 12y agoYou mean it always relinquishes pages to the OS upon free and never reuses a page? So every malloc is a memset(0) inside the kernel?
- weland 12y agoTechnically yes (although, by default, no), but it's more efficient than that would imply. By default, I think only small chunks are overwritten, so OpenSSL's meagre 64 KB of Heartbleed payload would have been filled with useless junk, whereas multi-megabyte mallocs() in e.g. a RDBMS would have been unaffected. There are some other protection mechanism included, too; there's a more in-depth presentation here: http://www.openbsd.org/papers/eurobsdcon2009/otto-malloc.pdf http://www.openbsd.org/papers/eurobsdcon2009/otto-malloc.pdf
- Trufa 12y agoI don't get your point, what are you trying to say? > What Tedbleed, as your article calls it, demonstrates is a bug similar to Heartbleed Similar but very different in the severity. > but I would suggest that thinking that memory safety ends all security issues is a not good plan. Nobody said that. > The key is Unless you venture into the (explicitly demarcated) unsafe portion of Rust, you will not see memory exposure vulnerabilities like Heartbleed: the language does not prevent this. Sure, if you want to break it, you'll probably can, but you'll have all kinds of warnings before and the few lines where you actually do that, can be proofread the most times. There's nothing preventing you from writing common bugs the generate vulnerability either, but that's simply not possible. > Perhaps your post will stimulate Ted to go further with his example and write an erroneous complete TLS stack in Rust, showing how it too can do Heartbleed. Perhaps you agree that this can be done. Well, Rust may have a memory leak at some point in the future, no software is perfect, but that is one language, that will be review constantly, that is mainly memory safe, the other is one language that is not memory safe where thousands of developers are constantly writing code, inserting lots of heartbleed/memory kind of bugs. > Among the scariest mass vulnerabilities relating to total information disclosure, the Padding Oracle Attack, the BEAST attack, the compression flaw CRIME, none have to do with memory safety of languages. Rust there would not have helped one whit. That's not the point of the article, ted tries to say that hearbleed would be possible, author contradicts this as it shows how the vulnerability would be of different severity.
- tedunangst 12y agoThe fixation on private keys puzzles me. While they were extractable in some cases, it was difficult. Stealing passwords and cookies was trivial however. And how does one use a stolen key? You have to intercept the traffic first. I can abuse a stolen password from anywhere in the world by using it to log in. Then I can read all your (email, etc.) and don't even need the private key. To differentiate these as "very different in severity" is I think quite misleading.
- e12e 12y ago> The fixation on private keys puzzles me. Really? The private key in asymmetric cryptography should never/is assumed to never be known to anyone other than the key-holder. Session keys are understood to be shared, and so are by definition not secure (equivalently, I can log my part of the "conversation" with a server, even if over TLS with PFS). So session keys, session cookies, transmitted data -- is always known by more than one party, a secret key should never be known by more than one party. It is true that most TLS server deployments don't enforce this -- they don't do the asymmetric operations in a trusted computing module, smart card etc -- but they should. They shouldn't store the key in ram, but they currently do. If you get the secret key, you can do many more things than merely intercept traffic. You can impersonate and fake traffic (fake evidence). In addition to all this, being able to read arbitrary memory controlled by the same process is also worse than being able to read stuff that is already being transmitted. This isn't strictly a Rust/other language issue (I imagine, but do not know, that one eg could sanely (if foolishly) share buffers across thread pools, and so potentially leak information across clients -- this would probably be a design error wrt. trust boundaries etc ... but no-one is arguing that any language can prevent design errors). As mentioned in other comments, privilege separation (a la openssh etc) is a great way to help leverage the os/kernel in order to enforce assumptions about the security primitives used. But that's a little beside the point.