6 ms·
Would Rust Secure Curl?
- duckerude 6y agoThis is counting the number of bugs, but what about the severity? https://curl.se/docs/CVE-2018-1000007.html https://curl.se/docs/CVE-2018-1000007.html is a logic bug that may cause sensitive headers to be sent to the wrong host on redirects. It's slightly obscure, but I can imagine what an exploit looks like. https://curl.se/docs/CVE-2018-1000120.html https://curl.se/docs/CVE-2018-1000120.html is a memory bug that lets you write a single null byte out of bounds. That's a security issue, but exploiting it seems less straightforward. (Though maybe it is more dangerous than the other one on net? I don't know enough about these issues to say.) It could be that Rust would prevent half the vulnerabilities yet prevent much less than half the danger caused by vulnerabilities.
- lostcolony 6y agoSo you're saying Rust would make it more secure, but is not a magical panacea that prevents all security holes? I mean...okay. Still seems like a good reason to write it in Rust?
- duckerude 6y agoI'm only saying that Daniel's claim that "C is not the primary reason for our past vulnerabilities" might be basically right, even though the article says it's wrong. I'm a big fan of Rust, if it matters.
- tux3 6y agoDo note that the "single out of bound NULL byte" vulnerability has famously caught people off-guard in the past due to it being unexpectedly exploitable =) https://googleprojectzero.blogspot.com/2014/08/the-poisoned-nul-byte-2014-edition.html https://googleprojectzero.blogspot.com/2014/08/the-poisoned-... Those kind of exploits are thankfully getting harder with the many layers of mitigations we have today, but trying to predict which memory bug will or will not be exploitable is a very unintuitive and inadvisable exercise.
- foodstances 6y agoYou know what would definitively prove whether it would? Just do it! I'm so tired of these "rewrite in rust" articles that have no code behind them. Spend the time and write a replacement for curl, ship it, and people will start using it instead of curl. In some years time, you can write a paper showing how many vulns your replacement had vs. rust. curl continues to be written in C because it has someone actually doing the work to write and update it. A theoretical rust replacement does not exist because no one is doing the hard work of writing and maintaining it. It's like LibreSSL vs OpenSSL. Did LibreSSL end up being more secure? At least we can find out instead of just guessing about whether removing crappy code from OpenSSL would be a good idea.
- steveklabnik 6y agoDid you see the link in the article? Curl does now have some Rust in it. People have been doing that work.
- amelius 6y agoThe problem with security in Rust is that the language emphasizes the reduction of memory bugs. The resulting code then creates an increased cognitive load which can make other bugs more likely. Therefore, use Rust if you really have to. Otherwise, tools like automated garbage collection are a much better way to reduce the likelihood of bugs.
- creata 6y ago> the language emphasizes the reduction of memory bugs That's not really true: Rust's borrowing and ownership apply to most kinds of in-program resource ownership and aliasing, not just memory. > The resulting code then creates an increased cognitive load which can make other bugs more likely. I'm not saying you're wrong, but I'd like to see any evidence for this. Personally, I'd expect the opposite to be true: knowing whether any given object is non-exclusively borrowed, exclusively borrowed, or owned at any point in the program sounds like very useful documentation for people reading the code.
- jstimpfle 6y agoFrom skimming some Rust code now and then, it seems to me that Rust programs look completely different at least. While C programs focus on creating simple data structures and getting the task done with as few memory operations as possible, in Rust I've dominantly seen use of types, memory/resource safety patterns and external libraries. My theory is that this removes direct understanding what happens and instead shifts the focus on how to get the task done while not violating the type system rules. In both cases, what the programmer minimizes in the first place might be the lines of code or maybe "code complexity". (Assuming programmers tend to do what most directly leads to completion of the programming task). I'm not in a position to claim that this theory is actually true, and I won't take a stance which is "better", but personally the former is much more appealing to me, for purely aesthetic reasons.
- cryptoquick 6y agoRust provides a good balance between performance, correctness, and ergonomics. It's called the "Goldilocks language", because it's not too slow, it's not too unsafe, and it's not too difficult. Also, much of the tooling I used to add to projects in other languages is either built-in and commonly used (test, fmt), or easily added to cargo (edit, bench, web, mobile).
- fortran77 6y ago> Rust proponents may seem overly zealous and I think this has led to a minor backlash of people thinking “Rust can’t be that great surely; these people must be confused zealots, like Trump supporters or Christians”. But it’s difficult to argue with numbers like these. Huh!?
- Blahah 6y agoWhat part are you huh?ing at?
- Yajirobe 6y agoChristians - confused zealots?
- gameswithgo 6y agoWell either y'all are or everyone else is....or just all of us.
- dwaltrip 6y agoEither way, this is definitely not the point of the post. It seems worthwhile to make an effort to avoid rehashing highly controversial, unrelated topics -- even if the article accidentally baits us into it.
- mrec 6y agoC'mon. I'm as atheist as they come, but anyone who equates Christians with zealots has never encountered the Church of England.
- Brian_K_White 6y agoSure. Fits. Are you looking for support or something? The language was unnecessary and unprofessional, but those are that only ways it was wrong. If I were writing something in a personal context where such opinions were not out of place rather than a technical article, I would absolutely apply that characterization. You don't have to. But Don't be so baffled that anyone else does.
- jjmartins 6y agoDoes Hacker News approve articles where the author insults Christians? Calling them "confused zealots"?
- curtis3389 6y ago> On-Topic: Anything that good hackers would find interesting. That includes more than hacking and startups. If you had to reduce it to a sentence, the answer might be: anything that gratifies one's intellectual curiosity.
- rat9988 6y agoI cannot see how you can give such an answer in good faith.
- deleted 6y ago[deleted]
- depressedpanda 6y agoI think it was unnecessary and off-topic, and the quality of the article suffered for it. However, the rest of the content was interesting.
- rat9988 6y agoSame here. The content is interesting, but he just made the whole things worse by insulting people.
- rvz 6y agoI couldn’t care less of it. Everyone ignores their political mini-rants or whatnot. It’s completely irrelevant to the discussion; especially this one.
- charonn0 6y agoDoes it really matter?
- Blikkentrekker 6y ago
- tux3 6y ago>These are how I classified the bugs. If I’ve got something drastically wrong let me know. I'm really happy to see the data behind the claim! I've been slowly desensitized to opinions masquerading as unsourced supporting graphs of dubious provenance. It's so simple, but kudos to the author for the transparency. When Daniel wrote "C is not the primary reason for our past vulnerabilities", he may or may not have been right. But he sadly did not back that up with easily verifiable, refutable, data. Data is like a ray of sunlight. Instead of arguing high-level opinions, let's argue the data
- GeekyBear 6y agoHere's some data I found interesting: >Speaking at the BlueHat security conference in Israel last week, Microsoft security engineer Matt Miller said that over the last 12 years, around 70 percent of all Microsoft patches were fixes for memory safety bugs. https://www.zdnet.com/article/microsoft-70-percent-of-all-security-bugs-are-memory-safety-issues/ https://www.zdnet.com/article/microsoft-70-percent-of-all-se... Of course, Rust isn't the only language that tries to address memory safety, but it is one of the few that does so while retaining the performance of C.
- pjmlp 6y agoMicrosoft's current security advisory is to use C#/F# (including their newly introduced low level capabilities up to .NET 5), Rust and then C++ alongside Core Guidelines. However the same Microsoft has backtracked in their rejection of C, adding support for C11 and C17, replaced the C++ userspace drivers framework with a C one, and despite all security sales pitch for Azure IoT, they ship Sphere OS and RTOS with a C only SDK.
- quelsolaar 6y agoNo, Data does not get to decide what cUrl is implemented in, Who ever implements it gets to decide. If you want to prove that RustUrl would be better then cUrl, you will have to implement it and prove that its actually better, by taking users away from cUrl. Decisions are made by those who make things not by those who have opinions, even if they are backed up by data. Daniel doesn't have to defend his choices, because you can write your own if you don't like his.
- throwaway_2hf1 6y agoLeaving aside the strangely bigoted comment about religion, his argument about Rust securing all memory bugs is vapid. As anyone acquainted with high-performance networking code in Rust has seen (remember the Actix fallout?), it's very hard to do a great many things without unsafe Rust. I'd much prefer a deeper discussion about a) how many of these bugs are actually important in practice and b) how a few of them would be solved by idiomatic, safe Rust. This article doesn't do either and doesn't answer the question in its own title.
- muskox2 6y agoHow many memory bugs of the same calibre has Actix had, even with the large amount of unsafe code in its codebase?
- lvass 6y agocurl is in widespread use while Actix remains fairly obscure, so this isn't a particularly good comparison. Is there even a Rust project that publicly discloses it's bugs in the same manner as curl?
- steveklabnik 6y agoWhat manner is that, and how is it special?
- lights0123 6y agoA lot of the Actix-web drama was the author refusing to replace unsafe code with safe code that performs equally as well. After the creator quit, the community took over and removed a lot of the unsafe code present.
- pjscott 6y agoI checked a few, and they mostly look like cases of non-performance-critical code that just happens to have some fiddly, slightly-wrong memory-handling logic -- which Rust would, indeed, make much harder to mess up with little or no runtime penalty.
- deleted 6y ago[deleted]
- IgorPartola 6y agoI really should learn Rust. I am just nostalgic for C because C makes me feel like I am doing something closer to what the CPU works with. I know there are several layers underneath all that, but with C you can do all manner of dangerous things that by any means you shouldn’t be allowed to do. I have used it for a few projects over the years but lately the only place I really get into it is programming Arduinos or similar. I am sure sooner or later we will get a good toolkit for a language that both does proper memory management AND can allow you to do all the things you can do with C on a microcontroller, but so far I haven’t seen that. Also, I have it on my TODO to go back and redo the Capture the Flag challenges from like 10 years ago that dealt with things like stack overflows. I had a ton of fun working on those and it would be fun to revisit them. Anyone got a modern version of something like that?
- TylerE 6y agoZig is what you want. It can cross-compile down to tiny tiny binaries with no dependencies that run on microcontrollers quite comfortably.
- IgorPartola 6y agoThanks! I spent a couple of hours looking at it and it looks like a really cool language. Unfortunately no build targets for the ESP8266/ESP32 which is my current t microcontroller of choice but the next time I try to put together a project that targets a different architecture I’ll try Zig out!
- tux3 6y agoHave you done the https://microcorruption.com/ https://microcorruption.com/ CTF from 2014? It starts pretty simple, but I remember it being super fun.
- IgorPartola 6y agoI have an account there according to my password manager! But like Gandalf I have no memory of this place. Very cool, I know what I’ll be doing tomorrow, thank you!
- jcranmer 6y agoOne of the things the author neglects is the ease of use of newtypes in Rust. This can actually alleviate a lot of parsing issues, by making it impossible to use stuff without parsing. An example of where I've recently done something like this is my sparse linear algebra code. I have distinct types for column and row vectors for a matrix, so that if I want to right-multiply A with a vector, the input has to be a column vector and the output has to be a row vector. Similarly, if I want to left-multiply A with a vector, the input has to be a row vector and the output has to be a column vector.
- p-squared 6y agoMaybe Rust makes newtypes _easy_, but certainly C supports similar idioms by way of wrapping data in a unique struct.
- steveklabnik 6y agoThe only significant difference is that you have to give the inner value a name in C, but you don't in Rust. It's a pretty marginal advantage.
- mappu 6y agoI'm happy with the article overall. >there are also a decent number of other bugs that come from cURL doing ad-hoc inline character-by-character parsing of just about everything, whereas in Rust you would probably use a library to fully parse things. cURL is the library to fully parse these things,
- dbrgn 6y agoThe author was probably referring to parser generators or combinator libraries like non or pest.
- mappu 6y agoThis was my initial charitable interpretation too, but the linked URL is actually to a specific url parsing crate. That's definitely in cURL's wheelhouse.
- klysm 6y agocURL isn't an abstract parsing library in the notion that is intended here. Rust has some libraries that give you pretty high level abstractions for generalized parsing that are also incredibly performant - something that's not really a thing in C.
- paledot 6y agoThat jumped out at me too. cURL is one of the most ubiquitous libraries out there. It's worth keeping its dependencies to an absolute minimum, even if it means having to rewrite a function here and there.
- GnarfGnarf 6y agoHow do I do GUI in Rust? User interface dialogs. Can I do linked lists in Rust? Can I define classes such that: cInches in1, in2, in3; // basically a float cCm cm; // basically a float in1 = in2 + in3; // OK in1 == 2.f * in2; // OK in1 = in2 / in3; // compilation error cm = in1; // compilation error void foo(cInches in); foo(cm); // compilation error
- steveklabnik 6y ago1. Use a binding to a library or write your own. Gtk bindings are probably the most mature option, but there are some exciting in-progress ones. 2. Yes. One is even provided in the standard library, if that suits your needs. However, most people don’t use linked lists because other data structures are near-universally better. 3. Rust doesn’t have classes, but you can do something similar. The name is the “newtype pattern.”
- cryptoquick 6y agoYeah, you can do newtypes (or just defining new types), in addition to Structs, Enums, and Traits. For those who don't know, Traits are like a sort of "class interface" that can be automatically applied to things that have implementations for those traits, and conversion between, once that code is pulled in scope via `use`. Rust doesn't have classes or inheritance, instead, it has more powerful tools, ones that aren't as limited.
- cryptoquick 6y agoWhy is this being downvoted? Am I wrong about something? If so, please tell me, I'm still learning. Ah. Maybe it's because I explained stuff that's basically newtypes using language that might make it seem they're different? Ugh. HN comments always make me so neurotic. But the content is usually more interesting than dev.to. I just wish they'd get rid of the downvote feature.
- loves_mangoes 6y ago
- onox 6y agoC libraries/applications like these, which have many memory and logic bugs, should be written in SPARK. It can fully prove that your code is correct. The latest version of the SPARK tools can also handle ownership of pointers [1] (scroll down a little to the ownership_transfer.adb example) So RIIS it is! ;) [1] https://learn.adacore.com/courses/intro-to-spark/chapters/01_Overview.html#no-aliasing-of-names https://learn.adacore.com/courses/intro-to-spark/chapters/01...
- quelsolaar 6y agoThis is a tool issue and not a language issue. I think that if you do some thing in code that results in unintended behavior, then that's a bug that should be communicated to the developer during development. A buffer over-run isn't a bug, its the symptom of a a bug in the arithmetic that computes how to access the buffer. The way to fix that is to communicate and address the bug during development, not to try to mitigate the symptom at run time. I am a C programmer, and to me buffer over-runs are a rare class of bugs, and a class of bugs that are (at least on the heap, and often on the stack) trivial to find and fix with the tools i have.
- xxpor 6y agoHow are they trivial? The issue with buffer overruns is that they're usually silent. If you have an array of pointers, and you overrun that array, you could end up assigning garbage to another pointer variable. Then when you deref that, if you're lucky it'll be outside the mapped memory addresses for that process and you crash. If you're unlucky, you read or write to a random location. Basically the point is, it's very easy to end up in a situation where you know you have a bug but you're 2+ levels of indirection from the actual logic error. Those sorts of issues are always the biggest time sink.
- quelsolaar 6y agoI have a debug mode in my code base, where I wrap malloc, free, and realloc with debug versions that over allocate all allocations that are made, and put magic numbers before and after the memory blocks. These are periodically checked to make sure nothing has been overwritten that shouldn't be. You can find this code on my website, www.gamepipeline.org as part of the "forge" library. The system tells me very precisely what has gone wrong with buffer over-runs, and it also make memory leaks and double frees trivial to find. Visual studios debug mode does something similar with buffer overruns on the stack, but I tend not to put very many buffers on the stack so that much more rare as an issue. If you want to go even more hardcore, windows has "gflags" that you can turn on to find overruns using memory protection. LLVM also have the "Checked C" compiler that also finds these issues. My own system is so good that, I haven't used gflags in a few years and I also haven't tested Checked C so I cant vouch for it, but there are loads of possibilities in this space that i hope to explore further in the future.
- krisoft 6y agoI know I’m not reacting to the substance here but thats a terribly designed diagram. If the goal is to compare these values then why don’t they all start at the same level? This stacked exploded bar chart is unconventional and hard to parse at a glance. Dare I say even missleading how the author’s prefered option (the “yes” collumn) is towering above all the other numbers even though it is roughly head to head with the “no” collumn. (47 vs 42).
- jacobolus 6y agoIt is a trade-off. Compared to a standard bar chart, this version makes it easier to judge partial cumulative sums of several adjacent bars.
- alisausaaaa 6y agoWanna have hot-lovin' conversations? You’re on the right way! - https://adultlove.life https://adultlove.life