zlacker

[parent] [thread] 80 comments
1. crater+(OP)[view] [source] 2021-07-20 21:26:20
> I'm glad that I'm working in a time where I can build all of my parsers and attack surface in Rust and just think way, way less about this.

I'm beginning to worry that every time Rust is mentioned as a solution for every memory-unsafe operation we're moving towards an irrational exuberance about how much value that safety really has over time. Maybe let's not jump too enthusiastically onto that bandwagon.

replies(9): >>Ar-Cur+v2 >>ddalci+R3 >>colone+v4 >>static+H4 >>bitwiz+o5 >>TaupeR+Ia >>tialar+xd >>jvande+Hh >>UncleM+kq1
2. Ar-Cur+v2[view] [source] 2021-07-20 21:41:04
>>crater+(OP)
… it is a solution for every memory-unsafe operation, though?
replies(1): >>choege+a7
3. ddalci+R3[view] [source] 2021-07-20 21:48:47
>>crater+(OP)
What’s with the backlash against Rust? It literally is “just another language”. It’s not the best tool for every job, but it happens to be exceptionally good at this kind of problem. Don’t you think it’s a good thing to use the right tool for the job?
replies(3): >>crater+C4 >>ameliu+28 >>zo1+yf1
4. colone+v4[view] [source] 2021-07-20 21:52:50
>>crater+(OP)
The article we are commenting on is about targeted no-interaction exploitation of tens of thousands of high profile devices. I think this is one of the areas where there is a very clear safety value (not just theoretical).
◧◩
5. crater+C4[view] [source] [discussion] 2021-07-20 21:54:03
>>ddalci+R3
> What’s with the backlash against Rust?

What's with the hyping of Rust as the Holy Grail as the solution to everything not including P=NP and The Halting Problem?

replies(1): >>pdimit+x6
6. static+H4[view] [source] 2021-07-20 21:54:25
>>crater+(OP)
I'm a security professional so it's based on being an experienced expert, not some sort of hype or misplaced enthusiasm.
7. bitwiz+o5[view] [source] 2021-07-20 22:00:28
>>crater+(OP)
Whole classes of bugs -- the most common class of security-related bugs in C-family languages -- just go away in safe Rust with few to no drawbacks. What's irrational about the exuberance here? Rust is a massive improvement over the status quo we can't afford not to take advantage of.
◧◩◪
8. pdimit+x6[view] [source] [discussion] 2021-07-20 22:10:07
>>crater+C4
No serious and good programmer is hyping Rust as the "Holy Grail". You are seeing things due to an obvious negative bias. Link me 100x HN comments proving your point if you like but they still mean nothing. I've worked with Rust devs for a few years and all were extremely grounded and practical people who arrived at working with it after a thorough analysis of the merits of a number of technologies. No evangelizing to be found.

Most security bugs/holes have been related to buffer [over|under]flows. Statistically speaking, it makes sense to use a language that eliminates those bugs by the mere virtue of the program compiling. Do you disagree with that?

replies(2): >>tptace+27 >>maqp+p8
◧◩◪◨
9. tptace+27[view] [source] [discussion] 2021-07-20 22:13:47
>>pdimit+x6
Nobody seriously thinks it's "Rust" that's the silver bullet either; they just believe memory-safe languages are. There are a bunch of them to choose from. We hear about Rust because it works in a bunch of high-profile cases that other languages have problems with, but there's no reason the entire iMessage stack couldn't have been written in Swift.
replies(4): >>pdimit+n7 >>static+r7 >>tialar+Of >>option+io
◧◩
10. choege+a7[view] [source] [discussion] 2021-07-20 22:14:14
>>Ar-Cur+v2
No. Rust cannot magically avoid memory-unsafe operations when you have to deal with, well, memory. If I throw a byte stream at you and tell you it is formatted like so and so, you have to work with memory and you will create memory bugs.

It can however make it extremely difficult to exploit and it can make such use cases very esoteric (and easier to implement correctly).

replies(2): >>Ar-Cur+Fd >>UncleM+Cj
◧◩◪◨⬒
11. pdimit+n7[view] [source] [discussion] 2021-07-20 22:16:39
>>tptace+27
Agreed. I was simply mostly addressing this person's obvious beef with Rust.
◧◩◪◨⬒
12. static+r7[view] [source] [discussion] 2021-07-20 22:17:13
>>tptace+27
Totally. I said Rust because I write Rust. Like, that's (part of) my job. Rust is no more memory safe (to my knowledge) than Swift, Java, C#, etc.

I also said "way, way less" not "not at all". I still think about memory safety in our Rust programs, I just don't allocate time to address it (today) specifically.

replies(2): >>noizej+Vh >>paavoh+ZR
◧◩
13. ameliu+28[view] [source] [discussion] 2021-07-20 22:21:50
>>ddalci+R3
It is good to keep in mind that the Rust language still has lots of trade-offs. Security is only one aspect addressed by Rust (another is speed), and hence it is not the most "secure" language.

For example, in garbage collected languages the programmer does not need to think about memory management all the time, and therefore they can think more about security issues. Rust's typesystem, on the other hand, can really get in the way and make code more opaque and more difficult to understand. And this can be problematic even if Rust solves every security bug in the class of (for instance) buffer overflows.

If you want secure, better use a suitable GC'ed language. If you want fast and reasonably secure, then you could use Rust.

replies(3): >>tptace+ha >>static+Xa >>tialar+SB
◧◩◪◨
14. maqp+p8[view] [source] [discussion] 2021-07-20 22:25:20
>>pdimit+x6
I like what tptacek wrote in the sibling comment. IIUC Rust keeps getting mentioned as "the" memory-safe language because it's generally equally fast compared to C programs. And it's mainly C and C++ that are memory-unsafe. So Rust is good language to combat the argument of speed (that's often interchangeable with profits in business world, especially if security issues have a flat rate of cyber insurance).
◧◩◪
15. tptace+ha[view] [source] [discussion] 2021-07-20 22:42:51
>>ameliu+28
I don't think this is a good take. Go, Java, Rust, Python, Swift; they all basically eliminate the bug class we're talking about. The rest is ergonomics, which are subjective.

"Don't use Rust because it is GC'd" is a take that I think basically nobody working on memory safety (either as a platform concern or as a general software engineering concern) would agree with.

16. TaupeR+Ia[view] [source] 2021-07-20 22:46:12
>>crater+(OP)
There's literally zero evidence that a program written in Rust is actually practically safer than one written in C at the same scale. And there won't be any evidence of this for some time because no Rust program is as widely deployed as an equivalent highly used C program.
replies(2): >>rrdhar+Eb >>static+8c
◧◩◪
17. static+Xa[view] [source] [discussion] 2021-07-20 22:47:16
>>ameliu+28
> Rust's typesystem, on the other hand, can really get in the way and make code more opaque and more difficult to understand.

I don't disagree with the premise of your post, which is that time spent on X takes away from time spent on security. I'll just say that I have not had the experience, as a professional rust engineer for a few years now, that Rust slows me down at all compared to GC'd languages. Not even a little.

In fact, I regret not choosing Rust for more of our product, because the productivity benefits are massive. Our rust code is radically more stable, better instrumented, better tested, easier to work with, etc.

◧◩
18. rrdhar+Eb[view] [source] [discussion] 2021-07-20 22:53:50
>>TaupeR+Ia
I’d wager Dropbox’s Magic Pocket is up there with equivalent C/C++ based I/O / SAN stacks:

https://dropbox.tech/infrastructure/extending-magic-pocket-i...

◧◩
19. static+8c[view] [source] [discussion] 2021-07-20 22:57:56
>>TaupeR+Ia
That's not true, actually. There is more than "literally zero" evidence. I don't feel like finding it for you, but at minimum Mozilla has published a case study showing that moving to Rust considerably reduced the memory safety issues they discovered. That's just one example, I believe there are others.

There are likely many other examples of, say, Java not having memory safety issues. Java makes very similar guarantees to Rust, so we can extrapolate, using common sense, that the findings roughly translate.

Common sense is a really powerful tool for these sorts of conversations. "Proof" and "evidence" are complex things, and yet the world goes on with assumptions that turn out to hold quite well.

replies(1): >>TaupeR+kr1
20. tialar+xd[view] [source] 2021-07-20 23:11:14
>>crater+(OP)
Not just memory safety. Rust also prevents data races in concurrent programs. And there are a few more things too.

But these tricks have the same root: What if we used all this research academics have been writing about for decades, improvements to the State of the Art, ideas which exist in toy languages nobody uses -- but we actually industrialise them so we can use the resulting language for Firefox and Linux not just get a paper into a prestigious journal or conference?

If ten years from now everybody is writing their low-level code in a memory safe new C++ epoch, or in Zig, that wouldn't astonish me at all. Rust is nice, I like Rust, lots of people like Rust, but there are other people who noticed this was a good idea and are doing it. The idea is much better than Rust is. If you can't do Rust but you can do this idea, you should.

If ten years from now people are writing unsafe C and C++ like it's still somehow OK, that would be crazy.

Imagine it's 1995, you have just seen an Internet streaming radio station demonstrated, using RealAudio.

Is RealAudio the future? In 25 years will everybody be using RealAudio? No, it turns out they will not. But, is this all just stupid hype for nothing? Er no. In 25 years everybody will understand what an "Internet streaming radio station" would be, they just aren't using RealAudio, the actual technology they use might be MPEG audio layer III aka MP3 (which exists in 1995 but is little known) or it might be something else, they do not care.

replies(6): >>deckar+Jh >>pa7ch+hn >>perryi+En >>pcwalt+Lu >>raxxor+VM1 >>SolarN+RQ2
◧◩◪
21. Ar-Cur+Fd[view] [source] [discussion] 2021-07-20 23:13:25
>>choege+a7
That's not memory-unsafety. Memory-safety means avoiding bugs like buffer overflow, ROP, etc.
◧◩◪◨⬒
22. tialar+Of[view] [source] [discussion] 2021-07-20 23:37:32
>>tptace+27
Fair. Two further thoughts:

1. Rust also has other safety features that may be relevant to your interests. It is Data Race Free. If your existing safe-but-slow language offers concurrency (and it might not) it almost certainly just tells you that all bets are off if you have a Data Race, which means complicated concurrent programs exhibit mysterious hard-to-debug issues -- and that puts you off choosing concurrency unless it's a need-to-have for a project. But with Data Race Freedom this doesn't happen. Your concurrent Rust programs just have normal bugs that don't hurt your brain when you think about them, so you feel free to pick "concurrency" as a feature any time it helps.

2. The big surface area of iMessage is partly driven by Parsing Untrusted File Formats. You could decide to rewrite everything in Rust, or, more plausibly, Swift. But this is the exact problem WUFFS is intended to solve.

WUFFS is narrowly targeted at explaining safely how to parse Untrusted File Formats. It makes Rust look positively care free. You say this byte from the format is an 8-bit unsigned integer? OK. And you want to add it to this other byte that's an 8-bit unsigned integer? You need to sit down and patiently explain to WUFFS whether you understand the result should be a 16-bit unsigned integer, or whether you mean for this to wrap around modulo 256, or if you actually are promising that the sum is never greater than 255.

WUFFS isn't in the same "market" as Rust, its "Hello, world." program doesn't even print Hello, World. Because it can't. Why would parsing an Untrusted File Format ever do that? It shouldn't, so WUFFS can't. That's the philosophy iMessage or similar apps need for this problem. NSO up against WUFFS instead of whatever an intern cooked up in C last week to parse the latest "must have" format would be a very different story.

23. jvande+Hh[view] [source] 2021-07-20 23:52:13
>>crater+(OP)
Language absolutism.
◧◩
24. deckar+Jh[view] [source] [discussion] 2021-07-20 23:52:29
>>tialar+xd
> If ten years from now people are writing unsafe C and C++ like it's still somehow OK, that would be crazy.

It's 26 years after Java was released. Java has largely been the main competitor to C++. I don't see C++ going away nor do I see C going away. And it's almost always a mistake to lump C and C++ developers together. There is rarely an intersection between the two.

I think you do not understand how short 10 years is. There are tons of people still running computers on Sandy Bridge.

replies(1): >>tialar+aq
◧◩◪◨⬒⬓
25. noizej+Vh[view] [source] [discussion] 2021-07-20 23:54:37
>>static+r7
If you would have mentioned those other languages in your original post, it might have amplified your valuable and important point even better, rather than triggering some readers effectively accusing you of shilling.

I don’t mean this in a very critical spirit, though.

Communication is really hard - especially in a large setting where not everyone reads you in the same context, and not everyone means well.

On balance, you post was valuable to me!

replies(1): >>static+ui
◧◩◪◨⬒⬓⬔
26. static+ui[view] [source] [discussion] 2021-07-21 00:00:23
>>noizej+Vh
I mentioned Rust because I write Rust professionally. If I wrote Java professionally, as I used to, I would have said "java". So you're probably correct that I could preempt stupid people's posts, but I don't care about the dregs of HN reading into my very clear, simple statement, just because they're upset about rust or whatever. It's just not worth it to me.

I'm glad the post was of value to you. The talk is really good and I think more people should read it.

replies(1): >>noizej+Yj
◧◩◪
27. UncleM+Cj[view] [source] [discussion] 2021-07-21 00:12:39
>>choege+a7
That's totally untrue, unless you are using a really weird definition of "memory safety". A rust program that doesn't make use of the unsafe keyword will not have memory safety bugs. We've had programming languages for decades that are able to happily process arbitrary bytestreams with incredibly buggy code without ever actually writing to a memory region not reachable through pointers allocated by the ordinary program execution.

A Java program can't write over the return address on the stack.

replies(2): >>bogomi+uE >>scoutt+NX
◧◩◪◨⬒⬓⬔⧯
28. noizej+Yj[view] [source] [discussion] 2021-07-21 00:15:45
>>static+ui
I hear you, and it’s your prerogative to choose how much to invest in reducing the attack surface for your communication.

On the other hand, you could choose to think about communications in an analogous way to your code, both being subject to attack by bad actors trying to subvert your good intentions.

So, the argument could be made, that removing attack surface from communication is analogous to hardening your code.

I also come from a coding background (albeit a long time ago) and with the help of some well meaning bosses over time eventually came to realize, that my messages could gain more influence, by reducing unnecessary attack surface. - Doesn’t mean I always get it right, even now - but I am aware and generally try hard to do just that.

replies(2): >>static+sv >>pdimit+g21
◧◩
29. pa7ch+hn[view] [source] [discussion] 2021-07-21 00:48:41
>>tialar+xd
I remain unconvinced that race proof programs are nearly as big a deal as memory safety. Many classes of applications can tolerate panics and its not a safety or security issue. I don't worry about a parser or server in go like I would in C.

(I realize that racing threads can cause logic based security issues. I've never seen a traditional memory exploit from on racing goroutines though.)

replies(2): >>nyanpa+4q >>tialar+Wr
◧◩
30. perryi+En[view] [source] [discussion] 2021-07-21 00:52:37
>>tialar+xd
> also prevents data races in concurrent programs.

I have another neat trick to avoid races. Just write single threaded programs. Whenever you think you need another thread, you either don't need it, or you need another program.

replies(1): >>kaba0+n01
◧◩◪◨⬒
31. option+io[view] [source] [discussion] 2021-07-21 00:58:30
>>tptace+27
It also doesn't help that Rust has this addictive nature and once you tasted your first major Rust program and tamed the borrow checker, you will want to keep using it everywhere. And that's the reason why people keep looking around to rewrite something in Rust. It's in the same category as any other banned drug :)
replies(1): >>tptace+wA
◧◩◪
32. nyanpa+4q[view] [source] [discussion] 2021-07-21 01:17:32
>>pa7ch+hn
I've seen Qt Creator segfault due to the CMake plugin doing some strange QStringList operations on an inconsistent "implicitly shared" collection, that I guess broke due to multithreading (though I'm not sure exactly what happened). In RSS Guard, performing two different "background sync" operations causes two different threads to touch the same list collections, producing a segfault. (These are due to multiple threads touching the same collection/pointers; racing on primitive values is probably less directly going to lead to memory unsafety.)

Apparently in Golang, you can achieve memory unsafety through data races: https://blog.stalkr.net/2015/04/golang-data-races-to-break-m... (though I'm not sure if a workaround has been added to prevent memory unsafety).

◧◩◪
33. tialar+aq[view] [source] [discussion] 2021-07-21 01:18:48
>>deckar+Jh
> I think you do not understand how short 10 years is. There are tons of people still running computers on Sandy Bridge.

Ten years is about the time since C++ 11. I may be wrong, but I do not regret my estimate.

◧◩◪
34. tialar+Wr[view] [source] [discussion] 2021-07-21 01:36:32
>>pa7ch+hn
A Race in Go is Undefined Behaviour. All bets are off, whatever happens, no matter how strange, is OK.

If you have a race which definitely only touches some simple value like an int and nothing more complicated then Go may be able to promise your problem isn't more widespread - that value is ruined, you can't trust that it makes any sense (now, in the future, or previously), but everything else remains on the up-and-up. However, the moment something complicated is touched by a race, you lose, your program has no defined meaning whatsoever.

replies(1): >>gpdere+ma1
◧◩
35. pcwalt+Lu[view] [source] [discussion] 2021-07-21 02:01:20
>>tialar+xd
Well, Zig isn't memory safe (as implemented today; they could add a GC), so it's not a good example of a Rust alternative in this domain. But I agree with your overall point, and would add that you could replace Zig with any one of the dozens of popular memory safe language, even old standbys like Java. The point is not to migrate to one language in particular, but rather to migrate to languages in which memory errors are compiler bugs instead of application bugs.
replies(3): >>tialar+ax >>dralle+rB >>pron+Wh1
◧◩◪◨⬒⬓⬔⧯▣
36. static+sv[view] [source] [discussion] 2021-07-21 02:07:23
>>noizej+Yj
Yep, I definitely get what you're saying and strategic communication is totally worthwhile (I'm a CEO, the value is absolutely not lost on me). It's just not something I prioritize on HN, that's just the personal call I make.
replies(1): >>noizej+sH
◧◩◪
37. tialar+ax[view] [source] [discussion] 2021-07-21 02:20:57
>>pcwalt+Lu
I could have sworn I'd read that Zig's ambition was to be memory safe. Given ten years I don't find that impossible. Indeed I gave C++ the same benefit of the doubt on that timeline. But, when I just searched I couldn't find whatever I'd seen before on that topic.
replies(1): >>dralle+JB
◧◩◪◨⬒⬓
38. tptace+wA[view] [source] [discussion] 2021-07-21 02:56:24
>>option+io
That has not been my experience.
◧◩◪
39. dralle+rB[view] [source] [discussion] 2021-07-21 03:05:12
>>pcwalt+Lu
Zig isn't memory safe but it's still leaps and bounds above C.

I have to admire the practicality of the approach they've been taking.

◧◩◪◨
40. dralle+JB[view] [source] [discussion] 2021-07-21 03:08:57
>>tialar+ax
The Zig approach is "memory safe in practice" vs "memory safe in theory". They don't have any aspirations to total memory safety like Rust, but they want to get most of the way there with a lot less overhead.

Basically they have a lot of runtime checks enabled in debug mode, where you do the majority of your testing, that are then disabled in the release binary.

Additionally the approach they've taken to allocators means that you can use special allocators for testing that can perform even more checks, including leak detection.

I think it's a great idea and a really interesting approach but it's definitely not as rigorous as what Rust provides.

replies(3): >>pcwalt+DH >>adwn+RP >>little+Pm1
◧◩◪
41. tialar+SB[view] [source] [discussion] 2021-07-21 03:10:25
>>ameliu+28
A thing to remember about GC is that it solves only one very important resource. Memory.

If your program loses track of which file handles are open, which database transactions are committed, which network sockets are connected, GC does not help you at all for those resources, when you are low on heap the system automatically looks for some garbage to get rid of, but when you are low on network sockets, the best it could try is hope that cleaning up garbage disconnects some of them for you.

Rust's lifetime tracking doesn't care why we are tracking the lifetime of each object. Maybe it just uses heap memory, but maybe it's a database transaction or a network socket. Either way though, at lifetime expiry it gets dropped, and that's where the resource gets cleaned up.

There are objects where that isn't good enough, but the vast majority of cases, and far more than under a GC, are solved by Rust's Drop trait.

replies(2): >>valent+vF >>kaba0+E01
◧◩◪◨
42. bogomi+uE[view] [source] [discussion] 2021-07-21 03:43:11
>>UncleM+Cj
>"A Java program can't write over the return address on the stack."

Could you say why Java is not susceptible to ROP?

replies(1): >>UncleM+3p1
◧◩◪◨
43. valent+vF[view] [source] [discussion] 2021-07-21 03:57:11
>>tialar+SB
It's not like Rust were the only or even the best language in solving the problems you mentioned. It might be the best performance focused / low-level language though.
replies(1): >>vanvie+6u1
◧◩◪◨⬒⬓⬔⧯▣▦
44. noizej+sH[view] [source] [discussion] 2021-07-21 04:19:23
>>static+sv
fair enough! :-)
◧◩◪◨⬒
45. pcwalt+DH[view] [source] [discussion] 2021-07-21 04:21:37
>>dralle+JB
I don't think Zig is going to be memory safe in practice, unless they add a GC or introduce a Rust-like system. All of the mitigations I've seen come from that language--for example, quarantine--are things that we've had for years in hardened memory allocators for C++ like Chromium PartitionAlloc [1] and GrapheneOS hardened_malloc [2]. These have been great mitigations, but have not been effective in achieving memory safety.

Put another way: Anything you could do in the malloc/free model that Zig uses right now is something you could do in C++, or C for that matter. Maybe there's some super-hardened malloc design yet to be found that achieves memory safety in practice for C++. But we've been looking for decades and haven't found such a thing--except for one family of techniques broadly known as garbage collection (which, IMO, should be on the table for systems programming; Chromium did it as part of the Oilpan project and it works well there).

There is always a temptation to think "mitigations will eliminate bugs this time around"! But, frankly, at this point I feel that pushing mitigations as a viable alternative to memory safety for new code is dangerous (as opposed to pushing mitigations for existing code, which is very valuable work). We've been developing mitigations for 40 years and they have not eliminated the vulnerabilities. There's little reason to think that if we just try harder we will succeed.

[1]: https://chromium.googlesource.com/chromium/src/+/HEAD/base/a...

[2]: https://github.com/GrapheneOS/hardened_malloc

replies(1): >>pron+oi1
◧◩◪◨⬒
46. adwn+RP[view] [source] [discussion] 2021-07-21 05:58:52
>>dralle+JB
> Basically they have a lot of runtime checks enabled in debug mode, where you do the majority of your testing, that are then disabled in the release binary.

But there's the problem: Testing can't and won't cover all inputs that a malicious attacker will try [1]. Now you've tested all inputs you can think of with runtime checks enabled, you release your software without runtime checks, and you can be sure that some hacker will find a way to exploit a memory bug in your code.

[1] Except for very thorough fuzzing. Maybe. If you're lucky. But probably not.

◧◩◪◨⬒⬓
47. paavoh+ZR[view] [source] [discussion] 2021-07-21 06:24:01
>>static+r7
If we include data race safety in the definition of memory safety (which it ultimately is), then Rust is safer than any commonly used garbage collected language with access to multithreading, including Swift, Java and C#.
replies(1): >>tptace+eU
◧◩◪◨⬒⬓⬔
48. tptace+eU[view] [source] [discussion] 2021-07-21 06:50:59
>>paavoh+ZR
This is a RESF trope. We do not include Rust's notion of data race safety in the definition of memory safety as it is used in security. Not all bugs are created equal.
◧◩◪◨
49. scoutt+NX[view] [source] [discussion] 2021-07-21 07:19:06
>>UncleM+Cj
> A rust program that doesn't make use of the unsafe keyword will not have memory safety bugs

https://www.cvedetails.com/vulnerability-list/vendor_id-1902...

What if the bug is in std?

What if I use a bugged Vec::from_iter?

What if I use the bugged zip implementation from std?

You'll probably blame unsafe functions, but those unsafe functions were in std, written by the people who know Rust better than anyone.

Imagine what you and me could do writing unsafe.

Imagine trusting a 3rd party library...

replies(2): >>cute_b+371 >>UncleM+Bp1
◧◩◪
50. kaba0+n01[view] [source] [discussion] 2021-07-21 07:43:07
>>perryi+En
You do realize that data races can happen between multiple programs as well, when shared resources are used? Which is pretty much a requirement for many things.
replies(1): >>perryi+QX1
◧◩◪◨
51. kaba0+E01[view] [source] [discussion] 2021-07-21 07:45:40
>>tialar+SB
High-level languages can provide abstractions though that can manage object life cycles to a degree for you, for example dependency injection frameworks, like Spring.

Not disagreeing, just mentioning.

replies(1): >>juki+No1
◧◩◪◨⬒⬓⬔⧯▣
52. pdimit+g21[view] [source] [discussion] 2021-07-21 07:58:00
>>noizej+Yj
> So, the argument could be made, that removing attack surface from communication is analogous to hardening your code.

That's true, but this is one of the cases where obtaining the last 5-10% of clarify might require 90% of the total effort.

Now whether one actually already has plucked all the low-hanging fruit in their own communication and if it's already good -- that's a separate discussion.

◧◩◪◨⬒
53. cute_b+371[view] [source] [discussion] 2021-07-21 08:43:01
>>scoutt+NX
Then same logic applies for python, java too? What if there is bug in internal implementation?

Rust Lang strives for safety and safety is no 1 priority. Regarding the unsafe in std please read the source code just to know how much careful they are with the implementation. They only use unsafe for performance and even with unsafe rust, it doesn't provide too much freedom tbh.

The 3rd party thing you are referring etc sounds childish. They are not the rust lang fault tbh. If you don't trust them don't use. It is as simple as that.

So I think telling people rust program that doesn't have unsafe will not have memory safety bugs. Exceptions to this statement do occurs but are rare.

◧◩◪◨
54. gpdere+ma1[view] [source] [discussion] 2021-07-21 09:24:15
>>tialar+Wr
Of course, but when talking about security, a race in Go would be very hard to exploit.

It is a different story in languages meant to run untrusted code of course.

◧◩
55. zo1+yf1[view] [source] [discussion] 2021-07-21 10:22:15
>>ddalci+R3
It's unusually or suspiciously "hyped". Not to the extent as the other sibling exaggerated to, but enough for it to be noticeable and to rub people the wrong way, myself included. It rubs me the wrong way because something feels off about the way it's hyped/pushed/promoted. It's like the new javascript in the programming world. And if we allow it (like we did with JS), it'll overtake way too much mindshare with the unfortunate detriment and neglect of all others.
◧◩◪
56. pron+Wh1[view] [source] [discussion] 2021-07-21 10:46:12
>>pcwalt+Lu
> Well, Zig isn't memory safe (as implemented today; they could add a GC), so it's not a good example of a Rust alternative in this domain.

While the first part of the sentence is mostly true (although the intention is to make safe Zig memory safe, and unsafe Rust isn't safe either), the second isn't. The goal isn't to use a safe language, but to use a language that best reduces certain problems. The claim that the best way to reduce memory safety problems is by completely eliminating all of them regardless of type and regardless of cost is neither established nor sensical;. Zig completely eliminates overflows, and, in exchange for the cost of eliminating use-after-free, makes detecting and correcting it, and other problems, easier.

◧◩◪◨⬒⬓
57. pron+oi1[view] [source] [discussion] 2021-07-21 10:49:12
>>pcwalt+DH
You understand "memory safe in practice" as soundly eliminating all memory safety issues. This is not how I understand it. Zig can exceed Rust's memory safety in practice without soundly eliminating all issues. The reason is that many codebases rely on unsafe code, and finding problems in Zig can be cheaper than finding problems in Rust w/ unsafe. This is even more pronounced when we look at security overall because while many security issues are memory safety issues, many aren't (and most aren't use-after-free bugs); in other words, it's certainly possible that paying to eliminate all use-after-free harms security more than just catching much of it more cheaply. So there is no doubt that Rust programs that don't use unsafe will have fewer use-after-free bugs than Zig programs, but it is very doubtful that they will, on average, be more secure as a result of this tradeoff.
◧◩◪◨⬒
58. little+Pm1[view] [source] [discussion] 2021-07-21 11:27:47
>>dralle+JB
It's not “memory safe in practice”. It's “we provide tools to make our memory unsafe language with as little memory issue as possible”. Is it better than what C or C++ offer out of the box: yes. It's totally reasonable to think that it may be as good as C or C++ with state of the art tooling that most programmers aren't using today because they don't want to invest the effort, so this is a big progress over C.

But this shouldn't be called “memory safety”.

◧◩◪◨⬒
59. juki+No1[view] [source] [discussion] 2021-07-21 11:42:24
>>kaba0+E01
And many languages also provide convenient syntax for acquiring and releasing a resource for a dynamic extent (Java try-with-resources, C# `using`, Python `with`, etc.), which cover the majority of use cases.
replies(1): >>fauige+h12
◧◩◪◨⬒
60. UncleM+3p1[view] [source] [discussion] 2021-07-21 11:44:57
>>bogomi+uE
ROP isn't the vulnerability, but instead the exploitation technique. "Memory safety errors" were around for decades before ROP was widely understood.

A Java program, by construction, cannot write to memory regions not allocated on the stack or pointed to by a field of an object constructed with "new". Runtime checks prevent ordinary sorts of problems and a careful memory model prevents fun with concurrency errors. There are interesting attacks against the Java Security Manager - but this is independent of memory safety.

replies(1): >>bogomi+VL1
◧◩◪◨⬒
61. UncleM+Bp1[view] [source] [discussion] 2021-07-21 11:50:21
>>scoutt+NX
Sure, and the JVM can contain an exploitable buffer overrun.

We are on a thread about "a case against security nihilism".

1. Not all vulnerabilities are memory safety vulnerabilities. The idea that adopting memory safe languages will prevent all vulns is not only a strawman, but empirically incorrect since we've had memory safe languages for many decades.

2. It is the case that a tremendously large number of vulns are caused by memory safety errors and that transitioning away from memory-unsafe languages will be a large win for industry safety. 'unsafe' is a limitation of Rust, but compared to the monstrous gaping maw of eldritch horror that is C and C++, it is small potatoes.

3. You are going to struggle to write real programs without ever using third party code.

62. UncleM+kq1[view] [source] 2021-07-21 11:54:44
>>crater+(OP)
> how much value that safety really has over time

Billions and billions of dollars. Large organizations like Microsoft and Google have published numbers on the proportion of vulns in their software that are caused by memory errors. As you can imagine, a lot of effort is spent within these institutions to try to mitigate this risk (world class fuzzing, static analysis, and pentesting) yet vulns continue to persist.

Rust is not the solution. Memory-safe languages are. It is just that there aren't many such languages that can compete with C++ when it comes to speed (Rust and Swift are the big ones) so Rust gets mentioned a lot to preempt the "but I gotta go fast" concerns.

◧◩◪
63. TaupeR+kr1[view] [source] [discussion] 2021-07-21 12:01:41
>>static+8c
Not sure what your last sentence means - without evidence, there are cases when we guess right, and those when we guess wrong. Are you just choosing to ignore the latter?

The Mozilla case study is not a real world study. It simply looks at the types of bugs that existed and says "I promise these wouldn't have existed if we had used Rust". Would Rust have introduced new bugs? Would there be an additional cost to using Rust? We don't know and probably never will. What we care about is preventing real world damage. Does Rust prevent real world damage? We have no idea.

replies(1): >>static+tB1
◧◩◪◨⬒
64. vanvie+6u1[view] [source] [discussion] 2021-07-21 12:21:48
>>valent+vF
It's not the best language for solving this type of problems? What (kind of) language would you say is even better for that?
replies(2): >>rurban+1P4 >>valent+ah7
◧◩◪◨
65. static+tB1[view] [source] [discussion] 2021-07-21 13:12:45
>>TaupeR+kr1
> Not sure what your last sentence means - without evidence, there are cases when we guess right, and those when we guess wrong. Are you just choosing to ignore the latter?

What I'm saying is that truth is a matter of debate. We believe lots of things based on evidence much less rigorous than a formal proof in many cases - like most modern legal systems, which rely on various types of evidence, and then a jury that must form a consensus.

So saying "there is no evidence" is sort of missing the point. Safe Rust does not have memory safety issues, barring compiler bugs, therefor common sense as well as experience with other languages (Java, C#, etc), would show that that memory safety issues are likely to be far less common. Maybe that isn't the evidence that you're after, but I find that compelling.

To me, the question of "does rust improve upon memory safety relative to C/C++" is obvious to the point that it really doesn't require justification, but that's just me.

I could try to find more evidence, but I'm not sure what would convince you. There's people fuzzing rust code and finding far fewer relevant vulns - but you could find that that's not compelling, or whatever.

◧◩◪◨⬒⬓
66. bogomi+VL1[view] [source] [discussion] 2021-07-21 14:02:03
>>UncleM+3p1
Yes I'm well aware of buffer overflows/stack smashing. I was asking why Java wasn't susceptible to something like ROP.
replies(1): >>UncleM+NO1
◧◩
67. raxxor+VM1[view] [source] [discussion] 2021-07-21 14:06:02
>>tialar+xd
I take that bet about C being pretty prominent in 10 years from now.

A language and a memory access model are no panacea. 10 years is like the day after tomorrow in many industries.

◧◩◪◨⬒⬓⬔
68. UncleM+NO1[view] [source] [discussion] 2021-07-21 14:16:50
>>bogomi+VL1
All memory access in Java goes through fields or array offsets.

There are runtime checks around class structure that ensure that a field load cannot actually read some unexpected portion of memory.

There are runtime checks that ensure that you cannot read through a field on a deallocated object, even when using weakreference and therefore triggering a GC even while the program has access to that field.

There are runtime checks around array reads that ensure that you cannot access memory outside of the allocated bounds of the array.

I have no idea why "susceptible to something like ROP" is especially relevant here. ROP is not the same as "writing over the return address" ROP is a technique you use to get around non-executable data sections and happens after you abuse some memory safety error to write over the return address (or otherwise control a jump). It means "constructing an exploit via repeated jumps to already existing code rather than jumping into code written by the attacker".

But just for the record, Java does have security monitoring of the call stack that can ensure that you cannot return to a function that isn't on the call stack so even if you could change the return target the runtime can still detect this.

◧◩◪◨
69. perryi+QX1[view] [source] [discussion] 2021-07-21 14:55:29
>>kaba0+n01
Yes, and rust can't prevent those.
replies(1): >>adwn+P42
◧◩◪◨⬒⬓
70. fauige+h12[view] [source] [discussion] 2021-07-21 15:10:59
>>juki+No1
Yes, but these features are usually optional. Library users can easily forget to use them and neither library authors nor the compiler can do anything to enforce it.

The brilliant thing about RAAI style resource management is that library authors can define what happens at the end of an object's lifetime and the Rust compiler enforces the use of lifetimes.

replies(1): >>jolux+Mz3
◧◩◪◨⬒
71. adwn+P42[view] [source] [discussion] 2021-07-21 15:26:42
>>perryi+QX1
It can prevent data races in memory shared between processes in the same way it can prevent them in memory shared between threads. Data race prevention isn't built into the Rust language, it is constructed using a combination of the borrow checker and the type system.
replies(1): >>perryi+sf2
◧◩◪◨⬒⬓
72. perryi+sf2[view] [source] [discussion] 2021-07-21 16:18:16
>>adwn+P42
As I understand the borrow checker, it wouldn't detect races that result from the interaction of separate processes, since that would be out of the bounds of the compilation unit. But my knowledge is limited in this, so I maybe wrong.
replies(1): >>static+Ja3
◧◩
73. SolarN+RQ2[view] [source] [discussion] 2021-07-21 19:01:19
>>tialar+xd
> If ten years from now people are writing unsafe C and C++ like it's still somehow OK, that would be crazy.

I mean to be clear, modern C++ can be effectively as safe as rust is. It requires some discipline and code review, but I can construct a tool-chain and libraries that will tell me about memory violations just as well as rust will. Better even in some ways.

I think people don't realize just how much modern C++ has changed.

replies(1): >>static+0a3
◧◩◪
74. static+0a3[view] [source] [discussion] 2021-07-21 20:31:48
>>SolarN+RQ2
It must have changed a shitload in the last 2-3 years if that's the case. What tools are you referring to? I'm pretty familiar with C++ tooling but I haven't paid attention for a little while.
replies(1): >>SolarN+HO5
◧◩◪◨⬒⬓⬔
75. static+Ja3[view] [source] [discussion] 2021-07-21 20:35:32
>>perryi+sf2
Rust has no concept of a process, same as it has no concept of a thread. So you'd build a safe abstraction for sharing memory across processes the same way you do today with threads.
◧◩◪◨⬒⬓⬔
76. jolux+Mz3[view] [source] [discussion] 2021-07-21 23:13:56
>>fauige+h12
I agree that RAII is superior, but it’s not true that compilers and library authors can’t do anything to enforce proper usage of Drop-able types in GC’d languages. C# has compiler extensions that verify IDisposables are used with the using statement, for example. Granted, this becomes a problem once you start writing functions that pass around disposable types.
◧◩◪◨⬒⬓
77. rurban+1P4[view] [source] [discussion] 2021-07-22 12:37:44
>>vanvie+6u1
Actually safe languages fOR example. Pony guarantees all three safeties, memory, type and concurrency, whilst in Rust it's only a plan, just not implementated. Stack overflows, type unsafety, dead locks. POSIX compatible stdlib.

Concurrent Pascal or Singularity also fit the bill, with actual operating systems being written in it.

◧◩◪◨
78. SolarN+HO5[view] [source] [discussion] 2021-07-22 17:43:23
>>static+0a3
The modern standard library, plus some helpers is the big part of it. Compiler warnings as errors are very good at capturing bad situations if you follow the rules (e.g. don't allow people to just make raw pointers, follow a rule of 5). I never said it was as easy to do as in rust.

As for tooling, things like valgrind provide an excellent mechanism for ensuring that the program was memory safe, even in it's "unsafe" areas or when calling into external libraries (something that rust can't provide without similar tools anyway).

My broader point is that safety is more than just a compiler saying "ok you did it", though that certainly helps. I would trust well written safety focused C++ over Rust. On the other hand, I would trust randomly written Rust over C++. Rust is good for raising the lower end of the bar, but not really the top of it unless paired with a culture and ecosystem of safety focus around the language.

replies(1): >>tialar+lP7
◧◩◪◨⬒⬓
79. valent+ah7[view] [source] [discussion] 2021-07-23 05:36:43
>>vanvie+6u1
Any language that offers some kind of effect system that has support for brackets and cancelation, for example Haskell or Scala.

There isn't even specific language support necessary, it's on the library level.

◧◩◪◨⬒
80. tialar+lP7[view] [source] [discussion] 2021-07-23 11:56:12
>>SolarN+HO5
Address sanitizers and valgrind tell you whether your program did something unsafe while you were analysing, but they can't tell you whether the program can do something unsafe.

Since we're in a thread about security this is a crucial difference. I'm sure Amy, Bob, Charlie and Deb were able to use the new version of Puppy Simulator successfully for hours without any sign of unsafety in the sanitizer. Good to go. Unfortunately, the program was unsafe and Evil Emma had no problem finding a way to attack it. Amy, Bob, Charlie and Deb had no reason to try naming a Puppy in Puppy Simulator with 256 NUL characters, so, they didn't, but Emma did and now she's got Administrator rights on your server. Oops.

In contrast safe Rust is actually safe. Not just "It was safe in my tests" but it's just safe.

Even though it might seem like this doesn't buy you anything when of course fundamental stuff must use unsafe somewhere, the safe/unsafe boundary does end up buying you something by clearly delineating responsibility.

For example, sometimes in the Rust community you will see developers saying they had to use unsafe because, alas, the stupid compiler won't optimise the safe version of their code properly. For example it has a stupid bounds check they don't need so they used "unsafe" to avoid that. But surprisingly often, another programmer looks at their "clever" use of unsafe, and actually they did need that bounds check they got rid of, their code is unsafe for some parameters.

For example just like the C++ standard vector, Rust's Vec is a wasteful solution for a dozen integers or whatever, it does a heap allocation, it has all this logic for growing and shrinking - I don't need that for a dozen integers. There are at least two Rust "small vector" replacements. One of them makes liberal use of "unsafe" arguing that it is needed to go a little faster. The other is entirely safe. Guess which one has had numerous safety bugs.... right.

Over in the C++ world, if you do this sort of thing, the developer comes back saying duh, of course my function will cause mayhem if you give it unreasonable parameters, that was your fault - and maybe they update the documentation or maybe they don't bother. But in Rust we've got this nice clean line in the sand, that function is unsafe, if you can't do better label it "unsafe" so that it can't be called from safe code.

This discipline doesn't exist in C++. The spirit is willing but the flesh (well, the language syntax in this case) is too weak. Everything is always potentially unsafe and you are never more than one mistake from disaster.

replies(1): >>SolarN+R29
◧◩◪◨⬒⬓
81. SolarN+R29[view] [source] [discussion] 2021-07-23 18:58:52
>>tialar+lP7
> This discipline doesn't exist in C++.

And this is where the argument breaks down for me. The C++ vector class can be just as safe if people are disciplined. And as you even described, people in rust can write "unsafe" and do whatever they want anyway to introduce bugs.

The language doesn't really seem to matter at the end of the day from what you are telling me (and that's my main argument).

With the right template libraries (including many parts of the modern C++ STL) you can get the same warnings you can from Rust. One just makes you chant "unsafe" to get around it. But a code review should tell off any developer doing something unsafe in either language. C++ with only "safe" templates is just as "actually safe" as rust is (except for with a better recovery solution than panics!).

[go to top]