News for hackers. Stuff that matters.
Re:Curl is C by ameliaquining on Monday March 27, 2017 @08:44AM (#13967195)
I'm kind of torn on this.

On the one hand, Curl is a great piece of software with a better security record than most, the engineering choices it's made thus far have served it just fine, and its developers quite reasonably view rewriting it as risky and unnecessary.

On the other hand, the state of internet security is really terrible, and the only way it'll ever get fixed is if we somehow get to the point where writing networking code in a non-memory-safe language is considered professional malpractice. Because it should be; reliably not introducing memory corruption bugs without a compiler checking your work is a higher standard than programmers can realistically be held to, and in networking code such bugs often have immediate and dramatic security consequences. We need to somehow create a culture where serious programmers don't try to do this, the same way serious programmers don't write in BASIC or use tarball backups as version control. That so much existing high-profile networking software is written in C makes this a lot harder, because everyone thinks "well all those projects do it so it must be okay".

Re:Curl is C by marcosdumay on Monday March 27, 2017 @10:17AM (#13967863)
At extreme cases, where you want to prove your network stack, you'd have to write it in C (or something equivalently dangerous), because you can't prove big runtimes.

But in mid-way applications, dangerous languages are dangerous, and should be avoided.

I'd think the most "correct" way to handle this is to create small bits of network code with proof of correctness that handles down parsed and tagged (typed) data into code in high level languages. In that case, Curl type of code would still be in C.

Re:Curl is C by pohl on Monday March 27, 2017 @11:10AM (#13968325)
...you'd have to write it in C (or something equivalently dangerous), because you can't prove big runtimes...

In order for this argument to hold, we would have to live in a world where no one has created a safe language with no runtime.

We don't live in such a world, fortunately.

Re:Curl is C by marcosdumay on Monday March 27, 2017 @12:29PM (#13969115)
Wait, is there a high level language (not assembly) with no runtime out there?

I don't think we are talking about the same thing at all.

Re:Curl is C by pjmlp on Monday March 27, 2017 @03:36PM (#13970959)
Modula-2, Oberon, Ada, Turbo Pascal, Free Pascal, Object Pascal, Quick Basic, Oberon-2, Active Oberon, Oberon-07, CLU, System C#, Modula-2+, Modula-3, D, Cyclone, ATS, Mesa, Algol, PL/I, PL/M,...
Re:Curl is C by steveklabnik on Monday March 27, 2017 @12:40PM (#13969252)
They're making an oblique reference to Rust; it has the same level of runtime that C does.

Many people say "no runtime" to mean "small runtime like C or C++ have" rather than literally no runtime. This is due to the confusion around interpreters sometimes being called "runtimes."

Re:Curl is C by marcosdumay on Monday March 27, 2017 @01:07PM (#13969550)
I suspect it was something about compiled vs. interpreted.

The Rust runtime is larger than C's (I imagine it's not much larger than C++, but this is already way too large). AFAIK, nobody ever proved it works as designed. The fact that it's design is not very stable is also a problem.

Now, with some more thought about it, C itself is not a great target for correctness proofs. Too much is left unspecified, and there is little agreement over some of the lower level stuff. A simplified version of Rust might be a better target than C, if somebody ever creates it, but a lot of the safety would have to be left out of it.

Re:Curl is C by Manishearth on Monday March 27, 2017 @01:13PM (#13969617)
IIRC Rust by default brings in a few things (panic handling is the main one, and also jemalloc) that make its runtime larger than C (but not larger than C++), but they can be disabled with compile flags. Many folks do, for embedded stuff.

Rust also lets you write a custom runtime by specifying a start function if you want.

> The fact that it's design is not very stable is also a problem.

Rust is stable.

Re:Curl is C by steveklabnik on Monday March 27, 2017 @01:19PM (#13969690)
> The Rust runtime is larger than C's (I imagine it's not much larger than C++, but this is already way too large).

I believe that it is smaller than C++'s but larger than C's, but I'm not a mega expert here. I used to know where those files were located in-tree, but don't anymore.

I think there's also several distinctions you can draw here; for example, strictly speaking, almost no runtime is required, but if you're using say, the standard library, you still might end up with a bunch of code. The actual requirements are very small though.

> AFAIK, nobody ever proved it works as designed. The fact that it's design is not very stable is also a problem.

Sorry, I don't understand what you mean here. The runtime?

> A simplified version of Rust might be a better target than C, if somebody ever creates it, but a lot of the safety would have to be left out of it.

I _think_ with the above comments, you mean the Rust langauge overall, not the runtime, right? So, Rust _is_ very stable; post 1.0 we have made extremely small breaking changes, corresponding to the way new C++ standards sometimes introduce minor technical backwards incompatibilities. As for correctness proofs, there are multiple academic institutions working on it; and they don't have to "leave the safety out"; that's what they're trying to prove!

Re:Curl is C by Manishearth on Monday March 27, 2017 @02:53PM (#13970571)
https://github.com/rust-lang/rust/blob/1ca100d0428985f916eea... is the "runtime". sys::thread contains all the TLS stuff (C has TLS too, so it's unclear if this is any more of a runtime). catch_unwind is for toplevel panic handling (which can be nop'd with panic=abort).

Finally, we link to jemalloc, which is an additional bit of runtime of its own (which can be turned off with alloc_system)

Re:Curl is C by steveklabnik on Monday March 27, 2017 @02:57PM (#13970610)
Ah right, it's in src\libstd\rt.rs, not src\rt, ha!
Re:Curl is C by Manishearth on Monday March 27, 2017 @04:53PM (#13971684)
It used to be!

There's also compiler-rt which does some of the eh stuff for panics and whatnot.

Re:Curl is C by bluejekyll on Monday March 27, 2017 @10:59AM (#13968240)
With Rust this tradeoff of safe-with-runtime vs. unsafe-without-runtime is no longer your only choice. Now you can choose safe-with-strong-compiler-no-runtime...
Re:Curl is C by pjmlp on Monday March 27, 2017 @11:57AM (#13968783)
This tradeoff wasn't already an issue with languages like Modula and Ada.
Re:Curl is C by staticassertion on Monday March 27, 2017 @02:58PM (#13970618)
As far as I am aware Ada is not memory safe without a runtime and with the presence of non-static memory. So you either have a runtime, no deallocation, or unsafety.
Re:Curl is C by pjmlp on Monday March 27, 2017 @03:14PM (#13970764)
C also needs a runtime, it is called crt0 on UNIX and it is what calls main(), sets up global initialization functions (constructor functions in GCC C), emulates floating point,...

As for Ada, you can selectively disable which parts of the runtime actually land on the generated executable via compiler pragmas.

Deallocation can be done via pools or controlled types.

Re:Curl is C by staticassertion on Monday March 27, 2017 @03:54PM (#13971104)
OK, I should have said garbage collector, not runtime.
Re:Curl is C by bquinlan on Monday March 27, 2017 @04:22PM (#13971380)
Are you claiming that Module-2 is memory safe?

What about:

  MODULE Boom

  VAR Foo : POINTER TO INTEGER;

  BEGIN
    Foo^ = 123;
  END Boom.
Re:Curl is C by pjmlp on Monday March 27, 2017 @05:29PM (#13971943)
If I remember correctly that is a compiler error, because Foo is not initialized, so no boom.

But if you still want to get your point through and have a boom.

  MODULE Boom;
  IMPORT SYSTEM;

  VAR Foo : POINTER TO INTEGER;

  BEGIN
    Foo := SYSTEM.CAST(POINTER TO INTEGER, 43414);
    Foo^ := 123;
  END Boom.
Notice the use of IMPORT SYSTEM and SYSTEM.CAST, explicit, easy to search for, and to forbid via compiler switch (no unsafe code).
Re:Curl is C by bluejekyll on Monday March 27, 2017 @12:57PM (#13969430)
Yeah, I realized after posting that this would be a critique. I should have stipulated that it's a C syntactic language, which seems to be many peoples preference based on the most successful languages out there.

I never did much with Ada or Modula, so I won't claim to know anything more than their syntax, etc.

Re:Curl is C by AstralStorm on Monday March 27, 2017 @12:41PM (#13969253)
Rust still has no support for true formal analysis. It is therefore pointless to use it for high safety. Use a real theorem checker instead.

Now Rust as a target for compiling proofs into a programming language is pretty nice. Safe code can have no aliasing due to borrow checker (which should also be formally verified). Threading issues are vastly simplified, though fairness still has to be verified, as well as a few other properties.

Re:Curl is C by bluejekyll on Monday March 27, 2017 @12:59PM (#13969464)
Could this be used on the LLVM intermediate code?

http://www.cis.upenn.edu/~stevez/vellvm/

Re:Curl is C by AstralStorm on Tuesday March 28, 2017 @03:12AM (#13974679)
Good find. Likely yes.
Re:Curl is C by 0xFFC on Monday March 27, 2017 @09:36PM (#13973293)
Re:Curl is C by baldfat on Monday March 27, 2017 @09:36AM (#13967565)
> the only way it'll ever get fixed is if we somehow get to the point where writing networking code in a non-memory-safe language is considered professional malpractice.

So using Linux, Windows, BSD or MacOS servers are malpractice? I think you might have over stated your case. So are you waiting for a memory safe Herd re-write? A memory safe any OS will be decades away if someone wanted to start tackling it now.

Re:Curl is C by pjmlp on Monday March 27, 2017 @09:51AM (#13967680)
Microsoft does research how to improve security at OS level and sometimes those efforts do end up on Windows.

Latest examples, Windows 10 secure kernel and Device Driver protection.

https://myignite.microsoft.com/sessions/36925

Or the new Windows USB stack, written in the P language.

https://github.com/p-org/P

UNIXes, not so much beyond patching C exploits.

Re:Curl is C by sqeaky on Monday March 27, 2017 @03:30PM (#13970881)
There are lawsuits open about windows 10 destroying user data. Windows of all flavors has given me nothing but pain. Microsoft is not the benchmark of quality software. Most of their real innovations are in the business model space.
Re:Curl is C by pjmlp on Monday March 27, 2017 @03:38PM (#13970984)
At least people know who to sue when Windows destroys data, not sure who to sue when distribution X does it.
Re:Curl is C by sqeaky on Tuesday March 28, 2017 @11:17AM (#13977291)
In what system can you sue when something some came at no cost, no warranty (express or implied) and in a good faith effort to help everyone at the personal expense of the developer?

If that system exists, it sounds disgusting and unethical. Paying for something changes the nature of the transaction.

Re:Curl is C by baldfat on Tuesday March 28, 2017 @01:52PM (#13978849)
When can people sue Apple for HFS+ issues. Those must be multiple of times higher then anything caused by Windows 10?
Re:Curl is C by madphrodite on Monday March 27, 2017 @10:45AM (#13968121)
And the last windows 7 update black screened my pc and left me in limbo till I was able to restore. What exactly is your point? Windows is not a standard to be held higher than..well anything.
Re:Curl is C by dsacco on Monday March 27, 2017 @11:07AM (#13968310)
The parent commenter used Windows 10 as an example and you used Windows...7. His point, which is that Microsoft actively researches and implements OS-level security improvements, hasn't been rebutted by your statement about Windows 7.

Windows 7 was released in 2009. There are substantial proactive improvements that Microsoft cannot feasibly backport to older OS versions even if they're still within the support period, and the corporate culture was simply different when Windows 7 was released.

Re:Curl is C by petee on Monday March 27, 2017 @11:19AM (#13968408)
Counter-point: Windows 10 updates locked up 2 of my machines - Microsoft has a tough time implementing most things properly...
Re:Curl is C by madphrodite on Wednesday March 29, 2017 @11:54AM (#13987477)
Substantial proactive improvements not relevant to the same build|OS which comes full circle to the linux comment which is so hated. That is: anyone with source and knowledge can make it work and those without...blackscreen.
Re:Curl is C by madphrodite on Monday March 27, 2017 @11:10AM (#13968321)
Did you know that I can still run, patch and support linux distributions written in 2009 if I want to? Did you know that?
Re:Curl is C by baldfat on Monday March 27, 2017 @01:10PM (#13969590)
I think the vast majority of people would say Windows has been getting much better in security since the days of XP. People can choose Linux, BSD, MacOS or Windows and have a good choice that is reasonably secure.
Re:Curl is C by kps on Monday March 27, 2017 @10:58AM (#13968226)
Of course they're overstated their case. Needs differ. When I wrote networking code a couple jobs ago it was in assembler, because a new frame will be along in 67ns whether you're ready or not.
Re:Curl is C by freddref on Monday March 27, 2017 @09:50AM (#13967674)
writing, not using.
Re:Curl is C by fiedzia on Monday March 27, 2017 @10:09AM (#13967803)
> So using Linux, Windows, BSD or MacOS servers are malpractice?

If you sell it as "secure", yes absolutely. And there are many applications where you would not be even considered as a contractor for doing so. There is increasing number of situations where you want to provide hard guarantees (written in contract) about quality of the software and service you are providing. "we are using Linux" sometimes is not good enough.

Re:Curl is C by Corrado on Tuesday March 28, 2017 @04:15AM (#13974946)
I get the feeling that very few old school authors would come forward and say "Hey, my project code is not good and needs to be re-written." Most of the time the message is more like "Sure we're using C but we're very careful and have built in a lot of safeguards."

I like your idea of a default mindset of internet tools should be written in a safe language with proper engineering techniques. I'm not sure I would go as far as malpractice but it might be a good stick to use to force makers into better practices.

Re:Curl is C by greenhouse_gas on Monday March 27, 2017 @11:44AM (#13968651)
Small history of security:

First major security breech through buffer -overflow was in the late 80s.

So when Java came out, they played it "safe" - the language, despite having pointers will be absolutely safe. NullPointerExceptions and ArrayOutOfBoundsException will cause the program to crash rather than corrupting the stack.

Perfect.

Except it wasn't. It ended up being so "holy" that it's now banned in browsers.

So, everyone said to move to JS. Another "perfectly safe" language.

But it's too slow.

So JIT it.

Now it's no longer "perfectly safe".

Rinse and repeat.

And rust won't help here, because while the " compiler " can be guaranteed safe, the code it outputs can't (think of a C compiler written in Rust).

Maybe the solution isn't to rely on language (except for the Kernel) but to make of easy to spawn OS processes that simply have no rights to call any syscalls and limited amount of memory (or a white-listed amount of syscalls).

Take it like this:

Firefox (the browser) has full rights. It starts a process (which can only connect to the network to IP RemoteHost).

If process dies (for whatever reason) or takes too long, tell user that "sorry, sites broken".

Now, malicious code causes the attacker to run arbitrary code? Who cares? You can't overwrite the browser's code and can't break out.

The browser just has to ensure that its subprocess gives you good output.

Same with JS, CSS, or image libraries.

Re:Curl is C by doomrobo on Monday March 27, 2017 @12:23PM (#13969052)
You're conflating the issues of running untrusted code with running trusted code on untrusted input. JS is untrusted code that you run on your computer. Your other examples generally do not fall into this camp.

Java being an allegedly safe server-side language has nothing to do with it being a very difficult language to sandbox when running untrusted code. It doesn't matter what language the malware I just downloaded was written in, because it's malware and it's running on my computer. What makes Java different from C in this case is that when I run a Java application on my server, I can be more confident in the fact that I will not have a buffer overflow, even when I expose the service to the entire internet.

Re:Curl is C by greenhouse_gas on Monday March 27, 2017 @12:51PM (#13969363)
>You're conflating the issues of running untrusted code with running trusted code on untrusted input. JS is untrusted code that you run on your computer. Your other examples generally do not fall into this camp.

No. The issue is that in C (or "release (not debug) rust" (someone here left a comment that rust programs in release mode don't check for array overflows)) untrusted input leads to untrusted code (through buffer-overflow).

So you can compromise a computer through a bug in imagemagick.

>Java being an allegedly safe server-side language has nothing to do with it being a very difficult language to sandbox when running untrusted code

Java was (in the 90s) advertised as safe client-side, hence applets.

Re:Curl is C by steveklabnik on Monday March 27, 2017 @01:02PM (#13969495)
No, release Rust does not do this. That is, the integer may overflow, but the buffer will not, unless you specifically go out of your way to use the unsafe unchecked access functions.
Re:Curl is C by arcticbull on Monday March 27, 2017 @12:29PM (#13969111)
That's actually how many apps on macOS have worked for years. Anything that ships in the Mac App Store runs in a sandbox with limited privileges. In fact, every instance of an Open/Save panel on macOS run in a separate process to the main application and relay their visual appearance using XPC and NSRemoteView. It's pretty cool stuff!
Re:Curl is C by ssokolow on Monday March 27, 2017 @09:20PM (#13973200)
That's also the direction Linux is heading with Flatpak and Flatpak portals.

I'm excited because there will finally be a reliable way for me to apply my preferred Open/Save dialogs to KDE and GTK+ apps alike. (It's being implemented at the toolkit level and you can run an app in Flatpak with sandboxing set to permit-all to get the portal hooking.)

Re:Curl is C by vidarh on Monday March 27, 2017 @12:14PM (#13968949)
> Maybe the solution isn't to rely on language (except for the Kernel) but to make of easy to spawn OS processes that simply have no rights to call any syscalls and limited amount of memory (or a white-listed amount of syscalls).

We have that [1] [2]. It's cumbersome to use, but it's based on the bpf JIT used for tcddump etc.

We also have a variety of other mechanisms you can combine with that to tie down a process. But even then it's hard to get this right in a way that's both performant and secure, because you have to protect every user every time, while for an attacker a very low success rate can still be worth it.

[1] https://www.kernel.org/doc/Documentation/prctl/seccomp_filte...

[2] https://wiki.mozilla.org/Security/Sandbox/Seccomp

Re:Curl is C by misterdata on Monday March 27, 2017 @01:38PM (#13969910)
This is ignoring the fact that sensitive data may actually be inside the (vulnerable, locked-down) process. Or checks inside the process may in some way be influenced (remember register_globals in PHP? This happens even when you execute PHP in a locked-down container).

A safe language greatly helps to prevent the sort of bug that compromises within-process security.