9 ms·
Building on Rock, Not Sand
- dsign 9y agoWe run high-load web services in something-other-than-c with managed memory and checked array access. It is native, 8/9 as fast as C, and it works. We will never have the budget to pay for the additional 1/9th that C would afford us, in terms of security concerns. Yet, everyday, I have to field questions about why our low-level, network-facing system code is not written in C... old prejudices die hard.
- brainwipe 9y agoHave you ever been asked to switch down into Assembler mid-function in C to solve timing issues in the hardware? I have... but that was 20 years ago!
- Cthulhu_ 9y agoWhat counters do you offer though? Or maybe reverse the question - why do they think you should use C? That last 1/9th performance? I'm pretty sure that last factor also isn't due to the language and there's still room for performance improvements.
- code5fun 9y ago"something-other-than-c" Which letter?
- JustAMinute 9y agoIf you haven't written a version of it in C, how do you know it's 8/9 as fast. What are you basing that figure on.
- rixed 9y agoHow do you mesure performance against C ? Did you implement a rival unsafe C version to compete with, or is this just a guess ? If so, what makes you believe C would only yield a 10% improvement? I'm asking because my own gut estimate of the cost of automatic memory management is significantly higher.
- Quarrelsome 9y agoisn't this exactly the sort of line of questioning that the OP is complaining about? In my experience of managed software 99.9% of performance problems are due to stupids and 0.1% are due to marshalling and GC costs. An average unmanaged developer seems to assume the opposite.
- blub 9y agoSome managed languages can have pretty good performance, but at significant memory usage cost. Performance is not a single dimension. It's a very legitimate question to ask how it was measured. Obviously they're happy with their performance and we can't comment on that, but the other claims regarding speed vs. C were more general.
- Quarrelsome 9y agoWhat part of: > I'm asking because my own gut estimate of the cost of automatic memory management is significantly higher. Is reasonable and not dripping with bias? My gut estimate says it doesn't matter in many cases. So where does that leave us?
- blub 9y agoI said it's a legitimate question to ask, not that their stated reason for asking is legitimate and I stand by what I said.
- nine_k 9y agoLook at the cost equation. Whatever additional resources they need to spend is a payment for improved safety / security. It's like saying that a reinforced door with a lock is more expensive and heavy than a regular cardboard-and-planks one, and is slower to open. It is! But is has other advantages, not attainable otherwise.
- weberc2 9y agoCan I ask what it is?
- s_kilk 9y agoMy money's on Go.
- rlonstein 9y ago> My money's on Go. Based on submission history, I'd guess Haskell.
- s_kilk 9y agoAh, now that’s intriguing! Thanks
- weberc2 9y agoSeems like it would be hard to get Haskell to run 8/9 as fast as C. Haskell is much harder to reason about performance than Go or C, and it's pretty easy to make a seemingly innocuous change that slows your program dramatically.
- tome 9y ago> Seems like it would be hard to get Haskell to run 8/9 as fast as C. The typical factor mentioned in the Haskell world is 1/2 the performance of C.
- pjc50 9y ago> why our low-level, network-facing system code is not written in C Really I think these days, in fact since the Morris Worm, people should be asking the opposite question: why is network-facing code written in C given that almost any error can lead to an exploitable security compromise? I do not buy the performance argument at all any more. So few systems are really performance-constrained by network processing (usually it's the network itself or the disk), you have to write horizontally scalable code anyway if you want to make use of multiple cores, so almost all cases where it's a bottleneck are more cheaply dealt with by scaling rather than tinkering with the software. There are people doing HFT in Java. The managed languages are quite capable of great performance with a little effort and imagination.
- elevensies 9y agoWatching Heartbleed and Cloudbleed happen really drove it home for me. Given that routine programming errors can cause private data to be transmitted unintentionally, I have to question the sanity of writing networking software handling private data in C.
- jeremysalwen 9y agoIf you really want to build on "rock", check out Bedrock: http://plv.csail.mit.edu/bedrock/ http://plv.csail.mit.edu/bedrock/ . Don't just prove your program is memory safe, prove it satisfies arbitrary properties! (A bit tongue in cheek, but the tools are really cool). Check out http://adam.chlipala.net/cpdt/cpdt.pdf http://adam.chlipala.net/cpdt/cpdt.pdf for a nice introduction.
- bpicolo 9y agoVery formal sorts of languages are super interesting. They might tend towards striking the wrong balance, though. Rust is super interesting to me because it prevents the most common vulnerabilities w/regards to memory safety that show up time and again, but it's accessible enough that it's got a big community and a ton of high quality libraries. I think that's a pretty awesomely potent combination.
- bjz_ 9y agoFor the short term and mid term yes. However I do hope that in the long term the ideas from ATS, Liquid Haskell, Idris, F*, etc. will be iterated on in order to make them more accessible and usable. In the mean time we'll probably start to see Rust graft on more and more correctness tools like dependent types and SMT solvers, and it will begin to get a little ungainly, like dependently typed Haskell is. But there's only so many ideas you can try out in a new language, and Rust has made the right decisions on that front in the interests of getting into production this decade. :)
- harveywi 9y agoI would love to see an experience report of someone who has used Bedrock in a nontrivial application.
- hguhghuff 9y agoNovice question: isn't rust fatter?
- bjz_ 9y agoGreat question. There's and FAQ on that: https://www.rust-lang.org/en-US/faq.html#why-do-rust-programs-have-larger-binary-sizes-than-C-programs https://www.rust-lang.org/en-US/faq.html#why-do-rust-program... - tl;dr is that it is by default but you can slim it down to the same size as a C executable if you need to.
- petiepooo 9y agoAnother rust proponent lecturing the world on how they should rewrite everything in rust. yawn
- hkmurakami 9y agoThe rust evangelism strike force stages yet another sortie!
- bsder 9y agoYou might want to look up the fact that the author is a HEAVY FREAKIN' DUTY C++ PROGRAMMER before making uninformed whingeing. http://robert.ocallahan.org/2017/09/rr-50-released.html http://robert.ocallahan.org/2017/09/rr-50-released.html http://robert.ocallahan.org/2017/07/confession-of-cc-programmer.html http://robert.ocallahan.org/2017/07/confession-of-cc-program...
- petiepooo 9y agoThe first link has no relevance to the discussion, and the second I had indeed read before posting. Need I point out that C++ IS NOT C. Being a good C++ programmer does not make you a good C programmer, and vis versa. I would argue, in fact, that many of the capabilities that a knowledgable, current C++ coder depends on would make them more liable to encounter issues coding in C, std::auto_ptr being chief among them.
- rkangel 9y agoIt was subtle but he put 'Rewrite in Rust' in caps, which I took to mean that it was a self aware use of a meme, while still making a valid point.
- chrismorgan 9y agoRobert is an expert C/C++ programmer, but understands the problems with those languages, which has led to articles like http://robert.ocallahan.org/2017/07/confession-of-cc-programmer.html http://robert.ocallahan.org/2017/07/confession-of-cc-program.... Robert is now a Rust proponent because it works. From today’s article, I think this is the money quote: > My sincere hope is that people will at least stop choosing C for new projects. At this point, doing so is professional negligence.
- kosma 9y agoTalk is cheap; show me the code. There's a lot of talk about rewriting some crucial pieces in Rust but no actual work to follow it.
- briansmith 9y agohttps://github.com/bluejekyll/trust-dns https://github.com/bluejekyll/trust-dns
- jasode 9y agoFyi... that Rust project doesn't actually cover the functionality of dnsmasq. Dnsmasq also includes a DHCP server and the ability to read a blacklist to act as an ad blocker. In contrast, the "trust-dns" project is more of a replacement for the "bind" program instead of "dnsmasq". If your intention was to only show that "non trivial Rust code exists", that's fine. However, some others might get the wrong impression that it's a Rust version of dnsmasq.
- rkangel 9y agohttps://github.com/redox-os/redox https://github.com/redox-os/redox
- bjz_ 9y agoServo, Firefox, Redox-OS, libsvg, Linker-d, GNOME, Maidsafe, pieces of Fuchsia... it's a huge effort, but it's beginning to pick up steam. I'm certainly trying to play my part as well (still private, but will be OSS).
- pmontra 9y agoNothing comes for free. I expect to have to trade something for security. It seems we have to trade speed and size. Ok, it shouldn't matter to us: this should not be developers' call. Instead it should go into a costs benefit matrix with plenty of other technical and not technical stuff. Developers will advise on their part of the matrix, marketers on their own, etc. Managers will make the decision and be held responsible for security breaches (or plauded for the lack of) as much as for every other feature of the product.
- sanxiyn 9y ago> It seems we have to trade speed and size. Why do you think so?
- wongarsu 9y agoIn principle things can come for free. Sometimes something new is strictly better. I am fairly confident that GCC outperforms early C compilers in every relevant metric (in theory GCC is ofc vastly more expensive because of decades of labor invested in it, but I don't pay that investment). Right now Rust is slower than C (though not always slower than C++), produces bigger binaries, and compiles slower. But more safety required a more expressive language, and a more expressive language contains more information for code generation and optimizer. It's certainly conceivable that in a few years the Rust compiler might generate faster code than C compilers.
- roca 9y ago
- blub 9y agoWhat if there is just not enough interest in improving C++'s safety? Or in improving safety at all? That's the scary thought. I also have to point out that these pesky C buffer overflows are trivial to avoid in C++: just use std::vector::at.
- ryansama 9y agoIt would be nice to have more healthy competition in this space. Any suggestions? Would it not be great to have a language as powerful as Rust but with the ease of Go? Anyhow, must be like CAP. You can't have everything in a language.
- chrismorgan 9y agoWhen Mozilla first sponsored Rust, it was with the goal of being the fastest memory-safe language around; at the time, it was thought that that required garbage collection. Only later (2011 or so), with the application of some comparatively recent research, did it progressively become apparent that it was in fact possible to have a practical memory-safe language without garbage collection; Rust progressively lost its garbage collected types (the @ sigil), and steadily settled down to its current model, which requires strong ownership to make it memory-safe and references + lifetimes to make it useful (otherwise you have a straightforward linear type system, which while functional is not very useful for fast code—you need references for that!). The hard part of Rust is strongly tied to ownership and lifetimes. You can’t get rid of them and keep memory safety without introducing garbage collection on at least almost everything. And thus you’re roughly at Go.
- bpicolo 9y agoHappen to have a link to the research that relates to this? I've been trying to up my CS-paper-reading game.
- chrismorgan 9y agoA quick search based on certain keywords I remembered yields https://www.reddit.com/r/rust/comments/2d94tu/is_there_any_academic_background_for_rusts_static/ https://www.reddit.com/r/rust/comments/2d94tu/is_there_any_a... which may help. Regions is the key thing. But right now I’m going to bed.
- bpicolo 9y agoThanks :)
- sanxiyn 9y agoNote that you can write safe C code. seL4 is written in C! (And verified in Isabelle.) If that is too hard core, PolarSSL is a normal looking C code, which still has been proved to lack any buffer overflow. https://trust-in-soft.com/polarssl-verification-kit/ https://trust-in-soft.com/polarssl-verification-kit/ has details. On the other hand, it probably is less effort to rewrite PolarSSL in Rust than doing that proof.
- jabot 9y agoI think the seL4 kernel rather proves that you can write safe haskell, verify it, and then transpile that to C. That's different from directly writing C...
- sanxiyn 9y agoWell, you aren't directly writing C anyway. Unless you are https://xkcd.com/378/ https://xkcd.com/378/ -- using tools is perfectly okay. Anyway, PolarSSL is definitely not transpiled. Its source language is C.
- jabot 9y agohttp://www.cvedetails.com/vulnerability-list/vendor_id-12001/product_id-22470/year-2015/opec-1/Polarssl-Polarssl.html http://www.cvedetails.com/vulnerability-list/vendor_id-12001... ... and your point is? EDIT: more recent bugs: https://tls.mbed.org/security https://tls.mbed.org/security These bugs include double-free and use-after-free - which are not covered by the original analysis, right?
- agumonkey 9y agoin the end the idea is that if you are semantic aware, then everything is safe; it's just operations from exp -> env -> store to env -> store etc etc
- nine_k 9y agoIndeed! You can write safe programs for e.g. the original Turing Machine. But I bet you'll end up writing tools to make creating a safe program of any non-trivial size feasible. A large class of these tools is usually called "programming languages".
- Nokinside 9y agoIf someone thinks that compiler for their favorite programming language provides safety they have no idea what safe code is. C/C++ is used to write safe code for medical and aerospace applications every day. The compiler for the languages like C, C++, Ada, Rust or whatever, is not enough. You can get better static and dynamic code analysis and test coverage analysis tools for C/C++/Ada than you can for Rust.
- rkangel 9y agoThe term 'safe' varies a lot based on context. In this context it is being used to mean 'memory safe' - i.e. that the compiler can eliminate a class of behaviour that are the root of a number of recent security issues. "Safe" in the context of medical and aerospace means something very different, but is much closer to the meaning of "Secure" in this context. No compiler is ever going to prevent you writing insecure code - there can always be a logic problem, bad choice of crypto algorithm etc..
- Nokinside 9y agoMemory safe code is the basic requirement of of safety critical code. Btw. memory safety includes checking for stack and heap exhaustion.
- deleted 9y ago[deleted]
- titzer 9y ago> C/C++ is used to write safe code for medical and aerospace applications every day. Crack is smoked by humans every day. This is an Argumentum ad Populum (https://web.cn.edu/kwheeler/fallacies_list.html https://web.cn.edu/kwheeler/fallacies_list.html). And I dispute the statement anyway; what is "safe" code without a guarantee of memory safety?
- Nokinside 9y ago> what is "safe" code without a guarantee of memory safety? Memory safety is the absolute minimum for safety critical code. It seems to be surprise for most people that you can write memory safe code in C and check for that statically and that includes static stack and heap exhaustion checks.
- xelxebar 9y agoI'm always confused by the "safe language" evangelism. Reducing cognitive load is a Good Thing TM; I get that. But aren't we just trusting the Rust compiler and JVM to not have subtle bugs that introduce memory management errors into our programs? Centralizing the memory management code to some well tested core---like the Rust compiler or some C lib---sounds to be the crux of wiring memory safe code, not the language.
- bjz_ 9y agoTrouble is that in C there is no way to encapsulate the unsafe code. Rust has tools that let you do that - it's not perfect, but depending on the level you are working at you can even build operating systems like Redox with the majority of the code in safe Rust. The language has not been formally specified which is a concern, but this is an active area that is also being worked on in collaboration with universities. This should make it easier to write unsafe code in combination with theorem provers like Lean or Coq for even greater confidence, and ensure that any soundess holes in the type system are found.
- blub 9y agoThe ability to grep for "unsafe" is probably the biggest advantage of Rust. I would love to have that in C++.
- sanxiyn 9y agoYou are right. On the other hand, in practice, implementing it in language (really, compiler) seems more effective than in library, as in reducing number of bugs. Why it is so is an interesting question, but is not very relevant to empirical basis of safe language evangelism.
- chrismorgan 9y agoConcerning Rust specifically—Rust’s memory safety comes from its type system; specifically, its strong ownership model, which leads to its lifetime model. Without these, you simply can’t have a fast, memory-safe language: either you surrender speed, by boxing everything, or you surrender safety. My point is that it’s not possible to just isolate the hazardous chunks into a well-tested core; it needs to be pervasive in the language’s memory model and type system in a way that C and C++ just don’t have.
- anon-123 9y agoC++ is not C. They are two totally different languages. Boundaries and overflows are not an issue in C++ like they are in C. I have no idea why people can't understand this.
- sanxiyn 9y agoBecause it is not true. C++ is not memory safe. Especially, C++ is not very good at handling use-after-free.
- blub 9y agoIt's not memory safe, but with some good practices and library support it's in a different league of safety compared to C. Just the availability of smart pointers, vector array and string puts it waaay ahead of plain C. The bugs in dnsmasq were buffer overflows. In this case, the good practices would be always use std::array and std::vector and index with "at". Tackling UAF is more complex. It involves using smart pointers exclusively with a runtime-check on dereferencing. This will result in some performance loss. P.S: I'm not saying it trivial to secure C++ code, nor that every project out there is using these techniques. It's a worthwile task to try to make existing C++ projects as safe as possible, and that's an effort parallel to Rust which should have very beneficial results.
- Annatar 9y agoContrary to the quote, given a finite "amount of budget", dnsmasq could have been Rewritten In Rust and these problems avoided. Ah, I see the Rust evangelism strike force is back. n-gate.com is right, as usual.
- barrkel 9y agoGetting rid of C is like gun control. There are irrational, emotional attachments.
- _greim_ 9y agoFoot-gun control. Ha!