News for hackers. Stuff that matters.
Re:Don't run 'strings' on untrusted files by meowface on Saturday October 25, 2014 @03:14PM (#8509051)
The problem is, until now there has not been a very good systems programming language that allowed you to stay lean on memory without introducing any performance overhead. Rust is certainly a contender, thankfully.

So, there is a perfectly good reason C is still prevalent to this day, even if there are many security implications in doing so.

Re:Don't run 'strings' on untrusted files by lazyjones on Saturday October 25, 2014 @03:24PM (#8509087)
> The problem is, until now there has not been a very good systems programming language that allowed you to stay lean on memory without introducing any performance overhead. Rust is certainly a contender, thankfully.

We've only had Pascal and Modula-2 for what, 40-45 years?

>perfectly good reason C is still prevalent to this day

... it's not that and it's not good. It's just that security implications were largely ignored, people were lazy and innovation and making sound decisions (rather than popular ones) has never been strong in the OSS/Linux community (apart from the kernel itself).

Re:Don't run 'strings' on untrusted files by akira2501 on Saturday October 25, 2014 @03:50PM (#8509189)
http://www.lysator.liu.se/c/bwk-on-pascal.html

It's a hobby horse by this point, but it makes it clear that the Pascal of 30 years ago is not the Pascal of today. The same can be said of C.

These languages have evolved to be where they are today, mostly because hardware has evolved to be where it is today. Castigating past decisions as laziness really seems to be ignorant of this process, what it involved, and why it was necessary to make the decisions that we have up until now.

Engineering, on the whole, is the art of compromise.

Re:Don't run 'strings' on untrusted files by zanny on Saturday October 25, 2014 @10:00PM (#8510046)
Reading through some gstreamer code this weekend, I contend that "C of 30 years ago is not the C of today".

It is still all the most horribly insecure and obtuse passing of raw pointer manipulation and bitwise logic ever. The preprocessor is still hell on software. Every variable is named something like gst_hello_world_parser_box because when you write complex software in it you always get huge name conflicts.

It still thinks the best way to manage memory is to not manage it at all. People complained for so long about having to put your deletes in destructors in C++, too bad you have no such thing in C at all - you don't have classes, after all. Guess it has to go in the procedural function logic. Like 30 years ago.

Re:Don't run 'strings' on untrusted files by lazyjones on Saturday October 25, 2014 @08:10PM (#8509849)
> These languages have evolved to be where they are today, mostly because hardware has evolved to be where it is today.*

No. Pascal and Modula-2 were perfectly usable, safe systems programming capable languages 20 years ago. Pascal was widely used in commercial product development (DOS/Windows), Modula-2 was scarce, but taught at universities with high quality development environments available for many platforms and the Oberon OS was based on the language Oberon, which was heavily influenced by/derived from Modula-2.

Everything necessary to produce safe, maintainable, fast software was available back then, but lazy/uneducated/stubborn people used C instead and wrote crappy software we still have to use today. It's a shame really.

Re:Don't run 'strings' on untrusted files by alayne on Saturday October 25, 2014 @11:17PM (#8510148)
I'm sure Pascal was really the silver bullet and its failure had nothing to do with Pascal derivatives being academic, non-portable, not very expressive, and having numerous other issues.

I think your ad hominem comments about people who implemented in C are in poor taste and not based in reality.

Re:Don't run 'strings' on untrusted files by 4ad on Sunday October 26, 2014 @05:55AM (#8510674)
I don't understand why we talk about Pascal at all, since Pascal is just as memory-unsafe as C.
Re:Don't run 'strings' on untrusted files by pjmlp on Sunday October 26, 2014 @06:30AM (#8510726)
No, because Pascal offers proper strings, bound checked arrays,open arrays, real enumerations, numeric ranges and reference parameters.
Re:Don't run 'strings' on untrusted files by ajuc on Sunday October 26, 2014 @06:22AM (#8510716)
in one important practical aspect it isn't - strings are length+content in pascal, not null-delimited as in c. It's very important difference.
Re:Don't run 'strings' on untrusted files by 4ad on Sunday October 26, 2014 @07:19AM (#8510787)
You read into buffers, not strings. You can easily have buffers overflows. Pascal arrays are bounds checked, but not when it matters: http://wiki.lazarus.freepascal.org/Secure_programming#Buffer....
Re:Don't run 'strings' on untrusted files by lazyjones on Sunday October 26, 2014 @07:44AM (#8510828)
The problems mentioned there (assigning to array elements with out-of-bounds indices) can be avoided by using range checks (-CR option for fpc). It's strange (and silly) that this is apparently off by default for fpc, but it's not a language feature of Pascal.
Re:Don't run 'strings' on untrusted files by pjmlp on Saturday October 25, 2014 @04:57PM (#8509387)
> April 2, 1981

USCD Pascal was created in 1978, Mesa in the mid-70s and Algol in 1968.

Most of the complaints don't apply to them.

Re:Don't run 'strings' on untrusted files by cbd1984 on Saturday October 25, 2014 @06:21PM (#8509581)
> UCSD Pascal

bwk's point, then as now, was that once you deviated from Standard Pascal, you had to either bet on a specific horse in the non-standard Pascal race, or develop your own Pascal-like language with its own inherent defects, similar to but different from the defects of Standard Pascal and other Pascal-like languages. Your code would likely never interoperate with anyone else's Pascal variant.

C, which had one de facto standard implementation and less genetic drift (because the standards, first K&R and then ANSI and ISO, were never as terrible as Standard Pascal's definition), didn't suffer from this nearly as much.

Mesa didn't, either, but only because it was fairly obscure, and there sure were a lot of Foogols running around for a while, of which Pascal and its semi-clones formed only one family.

Re:Don't run 'strings' on untrusted files by pjmlp on Sunday October 26, 2014 @02:09AM (#8510354)
Nothing of this was relevant in 1981.

The first K&R was published in 1978, ANSI/ISO C in 1989.

In 1981 C only mattered if you had access to a UNIX system, there were hardly any K&R compliant compilers.

Anyone using C outside a UNIX system was also betting on a specific horse.

Which is one of reasons why ANSI C has so much undefined and unspecified behaviours defined, as the committee didn't want to rule out any implementation.

Re:Don't run 'strings' on untrusted files by chime on Saturday October 25, 2014 @03:22PM (#8509080)
I wonder how big of a project would it be to port all of GNU/Linux to Rust.

Here's a start: https://news.ycombinator.com/item?id=7882211 https://github.com/uutils/coreutils/tree/master/src

Re:Don't run 'strings' on untrusted files by pmoriarty on Sunday October 26, 2014 @04:44AM (#8510557)
I'd rather see it ported to Scheme.
Re:Don't run 'strings' on untrusted files by easytiger on Sunday October 26, 2014 @07:49AM (#8510836)
And then see it fall into disrepair and disuse because it becomes unmaintainable.

LISP is 50 years old. If it was going to become useful for high performance software in large scale distributed teams of development, it would have happened already.

Re:Don't run 'strings' on untrusted files by qu1j0t3 on Sunday October 26, 2014 @07:49PM (#8513029)
Wow, what an extraordinarily ignorant and obtuse remark. Way to go HN!
Re:Don't run 'strings' on untrusted files by easytiger on Monday October 27, 2014 @04:43AM (#8514459)
Please kindly explain where it falls down specifically. Very happy to be wrong should I be missing sometihng.
Re:Don't run 'strings' on untrusted files by tarpherder on Monday October 27, 2014 @05:28AM (#8514547)
No no, you are mistaken. His reply is a special one. See, it not only refers to your reply, but it refers to itself as well! It's amazingly efficient, no need to respond to it any further!
Re:Don't run 'strings' on untrusted files by hsivonen on Sunday October 26, 2014 @01:19AM (#8510292)
I hope fundamental pieces of GNU/Linux system can start migrating to Rust without the FSF objecting to rutsc using LLVM.
Re:Don't run 'strings' on untrusted files by rhelmer on Sunday October 26, 2014 @07:47PM (#8513022)
I wonder if there'd be less friction to porting a BSD - FreeBSD already uses clang to build the kernel+userland, for instance.
Re:Don't run 'strings' on untrusted files by pjmlp on Saturday October 25, 2014 @03:47PM (#8509178)
You mean the myth that C was the first systems programming language, ignoring the fact that its designers just decided to ignore what was being done since the early 60's?
Re:Don't run 'strings' on untrusted files by cbd1984 on Saturday October 25, 2014 @06:23PM (#8509587)
OK, how about this: C was the first portable, non-assembly language used for writing OS kernels. Is that true? And I mean portable in practice, not just in theory, and portable beyond one family of computers.
Re:Don't run 'strings' on untrusted files by pjmlp on Sunday October 26, 2014 @02:02AM (#8510345)
No. OS were already being written in BCPL, Algol, Algol W, Algol 68, PL/I, PL/M and many other languages, battling for a place in the podium of systems programming languages.

C was tied to UNIX, just as the others were tied to the OS of their vendor.

C only became portable after UNIX was available in a few American universities outside AT&T, some students decided to create workstations based on UNIX, while others started to develop C compilers, so that they could continue their work on other systems.

Re:Don't run 'strings' on untrusted files by meowface on Sunday October 26, 2014 @02:08AM (#8510351)
Didn't BCPL and Algol heavily influence C though? What features of BCPL or Algol or other, older languages that were ignored could have made C better?
Re:Don't run 'strings' on untrusted files by pjmlp on Sunday October 26, 2014 @02:44AM (#8510405)
BCPL not much. It was barely an high level assembler.

Now Algol, it had:

- Bounds checked arrays

- Reference parameters to functions/procedures

- Real strings (not the first version in 1960 though)

- Explicit conversions

Quote from Tony Hoare's ACM award article[1]:

"A consequence of this principle is that every occurrence of every subscript of every subscripted variable was on every occasion checked at run time against both the upper and the lower declared bounds of the array. Many years later we asked our customers whether they wished us to provide an option to switch off these checks in the interests of efficiency on production runs. Unanimously, they urged us not to--they already knew how frequently subscript errors occur on production runs where failure to detect them could be disastrous. I note with fear and horror that even in 1980 language designers and users have not learned this lesson. In any respectable branch of engineering, failure to observe such elementary precautions would have long been against the law."

[1]http://www.labouseur.com/projects/codeReckon/papers/The-Empe...

Re:Don't run 'strings' on untrusted files by vidarh on Sunday October 26, 2014 @02:03AM (#8510346)
Multics was mostly written in PL/I. PL/I is certainly portable, though I don't think Multics itself was particularly portable.

BCPL was used to write several OS's that were ported, though while BCPL predates C, I'm not sure if any of the OS's written using it predates Unix.

Re:Don't run 'strings' on untrusted files by yohanatan on Saturday October 25, 2014 @03:54PM (#8509205)
I think you are overlooking OCaml & Haskell (which can both be used skillfully to approach performance of C).
Re:Don't run 'strings' on untrusted files by meowface on Saturday October 25, 2014 @04:07PM (#8509243)
Are there examples of either OCaml or Haskell being used for systems programming? I know that algorithmically they can achieve pretty close performance, but I don't think support is that great for low-level operations.
Re:Don't run 'strings' on untrusted files by tome on Saturday October 25, 2014 @04:19PM (#8509265)
"Ivory" is a Haskell embedded domain specific language for writing safe C programs. One (very loose) way of thinking of it is that it compiles a restricted subset of Haskell to low level C.

http://ivorylang.org/

Re:Don't run 'strings' on untrusted files by yohanatan on Saturday October 25, 2014 @04:31PM (#8509298)
There is also 'Atom' which is an embedded DSL in Haskell for writing real-time embedded systems: http://en.wikipedia.org/wiki/Atom_(programming_language)
Re:Don't run 'strings' on untrusted files by tokenrove on Saturday October 25, 2014 @04:26PM (#8509288)
You might consider Mirage OS (http://www.openmirage.org/) to be systems programming.
Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @04:23PM (#8509282)
It's hard to tell what you mean by "low-level operations." A lot of systems programming, particularly the GNU suite, just deals with manipulating files, sockets, and so on, and Haskell can do that just fine.

Example: http://www.haskell.org/haskellwiki/Simple_Unix_tools

Re:Don't run 'strings' on untrusted files by more_original on Saturday October 25, 2014 @07:02PM (#8509678)
Maybe you could have a look at "Unix system programming in OCaml"?

http://ocamlunix.forge.ocamlcore.org/

Re:Don't run 'strings' on untrusted files by kryptiskt on Saturday October 25, 2014 @04:07PM (#8509242)
Haskell is great, but GHC's runtime system is 50000 lines of C.
Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @04:17PM (#8509261)
Which is relatively inconsequential as long as there's a clear boundary between things that can be manipulated by a user and the C code.

It'd be better if it wasn't C at all, sure, but, from a security perspective I'd take a language with a C runtime over a language where code has to be carefully written in a memory-safe manner any day.

Re:Don't run 'strings' on untrusted files by zanny on Saturday October 25, 2014 @10:02PM (#8510049)
GCC is written in C/C++. I don't think any of the compilers are dogfooding their language because its supposed to be reusing infrastructure.

I'd hope an LLVM compiler for a language would eventually be dogfooded, though.

Re:Don't run 'strings' on untrusted files by yohanatan on Monday October 27, 2014 @02:17AM (#8514143)
http://en.wikipedia.org/wiki/Bootstrapping_(compilers)

This is pretty much the first thing that everyone writes in their new programming language.

Re:Don't run 'strings' on untrusted files by marcosdumay on Saturday October 25, 2014 @03:55PM (#8509211)
Whatever. One can always write unsafe code. No matter in what language. A really secure language is almost worthless because there's so much it can't do.

No, the problem comes from the other end. Strings should not be able to compromise a system. It only needs to read a user supplied file, and write to stdout. There's no reason for it to be allowed to exec a piece of code.

Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @04:07PM (#8509245)
You seem to be arguing against yourself. If 'strings' were written in a safe language, compromising the system would be extremely unlikely. Or are you seriously arguing that languages that are safer than C aren't Turing complete?

There are plenty of memory-safe languages in which you can do nearly everything you'd do in C, and much, much safer. There's no reason whatsoever a program like 'strings' couldn't be written in a memory-safe language.

Re:Don't run 'strings' on untrusted files by AnthonyMouse on Saturday October 25, 2014 @06:02PM (#8509539)
> If 'strings' were written in a safe language, compromising the system would be extremely unlikely.

Shellshock was a parsing bug, the memory safety of bash helped nothing.

Bugs are bugs. When you get an out of bounds exception that leaves your program in an inconsistent state somewhere halfway up the call stack in a code path with poor test coverage, "safe" is not the correct word.

Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @06:08PM (#8509547)
The premise of this conversation is flawed: A language isn't "insecure" or "secure." It's placed at a certain point in a safety spectrum ranging from "Do anything with no safety" to "Safely heat the room and achieve nothing."

What I'm saying is not that you can't write software that can be abused in memory-safe languages. I'm saying that you're much less likely to have extremely serious code execution vulnerabilities if you write a program in Go instead of C.

Re:Don't run 'strings' on untrusted files by AnthonyMouse on Saturday October 25, 2014 @06:52PM (#8509657)
> What I'm saying is not that you can't write software that can be abused in memory-safe languages. I'm saying that you're much less likely to have extremely serious code execution vulnerabilities if you write a program in Go instead of C.

What I'm saying is that "much" less likely is overstating the difference. Most bugs in C programs are not buffer overruns, and even the ones that are would still be bugs in Go or Rust, they would just be a different kind of bug which is still plausibly exploitable under real conditions.

This is not a silver bullet kind of situation. "Rewrite everything in Go" is not actually a fix -- it's replacing code with 30 years worth of bug reports and vulnerability testing with completely untested new code, at the cost of significant resources that could better be used to fix the remaining vulnerabilities.

I'm not even saying that all the existing code is perfect. Replacing OpenSSL with entirely new code would probably do more good than harm just because the existing code is so ugly. But that's the exception rather than the rule.

Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @06:57PM (#8509669)
There are a ridiculous number of serious vulnerabilities in C code related to lack of bounds checking and manual memory management. This isn't really opinion so much as fact. I understand what you're saying, but you're also downplaying the seriousness of C bugs relative to <most other languages> bugs.

> Most bugs in C programs are not buffer overruns, and even the ones that are would still be bugs in Go or Rust, they would just be a different kind of bug which is still plausibly exploitable under real conditions.

I don't follow. What's the equivalent of forgetting to check the length of an input string before chugging it into a too-small array in Go?

> "Rewrite everything in Go" is not actually a fix

I never said that, though. I'm not suggesting we rewrite the GNU tools in Go. But if you were to write the GNU tools from scratch today, C would be a bad choice simply because it's so easy to slip up with devastating effects, and there aren't many advantages to using it for simple tools like 'strings'.

Re:Don't run 'strings' on untrusted files by AnthonyMouse on Saturday October 25, 2014 @08:11PM (#8509852)
> There are a ridiculous number of serious vulnerabilities in C code related to lack of bounds checking and manual memory management. This isn't really opinion so much as fact. I understand what you're saying, but you're also downplaying the seriousness of C bugs relative to <most other languages> bugs.

I feel like "<most other languages> bugs" tend to get ignored because it's not popular to blame <language> for bugs unless <language> is C. For example an enormous number of high severity CVEs are SQL injection but I never hear anybody saying we should replace SQL with a binary interface that clearly distinguishes statements from data, even though that would make more difference in practice than replacing C with something else.

> I don't follow. What's the equivalent of forgetting to check the length of an input string before chugging it into a too-small array in Go?

In Go the program terminates, which is at best a denial of service vulnerability. If the program is anything in the nature of Fail2ban then just causing it to die is a serious problem. Meanwhile when it restarts it will have to somehow deal with whatever corrupted state the crash left behind, which depending on the context can provide the attacker with opportunities to do arbitrarily bad things by manipulating the state to be something the programmer never anticipated. Being able to induce a restart is a huge increase in attack surface.

Immediate program termination is the "take cyanide capsule" solution to serious bugs. It may be better than some of the alternatives but it's still very bad.

Re:Don't run 'strings' on untrusted files by comex on Saturday October 25, 2014 @11:05PM (#8510139)
> For example an enormous number of high severity CVEs are SQL injection but I never hear anybody saying we should replace SQL with a binary interface that clearly distinguishes statements from data, even though that would make more difference in practice than replacing C with something else.

Using bind parameters instead of putting data directly in queries + escaping has been standard for a long time now. That is, instead of saying "make sure to escape everything", like "make sure to avoid any bugs in C code", we indeed prefer to switch to a technique which which doesn't act pathologically in the presence of small errors. In SQL's case it doesn't require replacing the whole language. It technically doesn't have to in C, either - you could have bounds checked C - but I guess once you give up the absolute-maximum-performance goal, people prefer to use different languages.

edit: Also, while program termination is not ideal, in many cases, such as this one (strings), it is basically a non-problem, and at worst, denial of service is still loads better than arbitrary code execution.

Re:Don't run 'strings' on untrusted files by MaulingMonkey on Sunday October 26, 2014 @03:27PM (#8512008)
> I feel like "<most other languages> bugs" tend to get ignored because it's not popular to blame <language> for bugs unless <language> is C. For example an enormous number of high severity CVEs are SQL injection but I never hear anybody saying we should replace SQL with a binary interface that clearly distinguishes statements from data, even though that would make more difference in practice than replacing C with something else.

I don't even use SQL, but I've heard a similar mantra plenty enough times to internalize it.

"but one thing is clear: you should never, ever use concatenated SQL strings in your applications. Give me parameterized SQL, or give me death." ( http://blog.codinghorror.com/give-me-parameterized-sql-or-gi... )

This is an API level change, not a protocol level change - but an API change is the correct answer anyways. If you change the protocol and slap an API like the SQL injection prone ones on top of it, you'll have the same vulnerabilities no matter what the protocol.

For bonus points, use static analysis to catch and forbid query strings that can't be trivially proven static.

> For example an enormous number of high severity CVEs are SQL injection but I never hear anybody saying we should replace SQL with a binary interface that clearly distinguishes statements from data, even though that would make more difference in practice than replacing C with something else.

I see 3x more memory corruption CVEs alone, than SQLI CVEs. I'm not convinced that replacing SQL (or SQL APIs) would be higher impact than replacing C and C++. And since I actually use C and C++ in my daily bread and butter, they're significantly more relevant to me.

But SQLI may be significantly more relevant to you. If that's the case, by all means, focus on them more.

Re:Don't run 'strings' on untrusted files by lazyjones on Sunday October 26, 2014 @08:08AM (#8510857)
> If the program is anything in the nature of Fail2ban then just causing it to die is a serious problem

If that causes a serious problem, then the architecture is bad and unsuitable for solving that problem (remember: programs can also die because of OOM conditions, flakey hardware, admin errors. If this leaves a gaping security hole open for an attacker, or lead to DoS, then you need a better approach; fail2ban functionality should be in the process handling logins for example, not a separate entity watching logfiles, which might be broken too).

> Being able to induce a restart is a huge increase in attack surface.

Compared to what? Certainly not C code, where very common issues are easily exploitable for arbitrary code execution.

Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @09:39PM (#8510015)
Program termination/exception is clearly preferable to arbitrary code execution.
Re:Don't run 'strings' on untrusted files by tomjen3 on Sunday October 26, 2014 @05:30AM (#8510629)
Does Go force you to sanitize all user input?

Because I am sure if had ported bash to Go, you would still have the same issue with the broken parser. I am not sure if you would still have had heart bleed, but I know you wouldn't have had heart bleed if the openssl people had used the platform libc, instead of rolling their own, so I wouldn't consider heart bleed an issue with C, but an issue with the programmer.

Re:Don't run 'strings' on untrusted files by meowface on Saturday October 25, 2014 @04:06PM (#8509239)
Multiple factors are to blame. I agree this is dumb behavior here by strings, but if the ELF parsing code were to be written in a language like Rust, it's far less likely it would have a bug of this nature.
Re:Don't run 'strings' on untrusted files by thirsteh on Saturday October 25, 2014 @04:12PM (#8509252)
Rust... or pretty much any other language than C.

C is scary from a security perspective because it is both incredibly easy to write code that has subtle but very serious bugs leading to e.g. arbitrary code execution, and it is easy to exploit those vulnerabilities.

Re:Don't run 'strings' on untrusted files by maccard on Sunday October 26, 2014 @06:34AM (#8510732)
So what you're saying is that the bugs from a piece of software written 20 years ago (roughly) can be solved by writing the program in a language that hasn't had a stable release yet? Sure there are better alternatives now, but what widespread, well known, portable language was available in the mid 90's that this could have been written in?
Re:Don't run 'strings' on untrusted files by twoodfin on Saturday October 25, 2014 @05:34PM (#8509469)
Despite the volume of messages on this thread about securing C or replacing it with a safer language for systems implementation, I think your answer is the only practical one.

If you haven't seen it already, you might want to check out HiStar:

http://www.scs.stanford.edu/histar/

Re:Don't run 'strings' on untrusted files by Confusion on Sunday October 26, 2014 @07:27AM (#8510798)
It's not 'allowed' to exec a piece of code. It parses code and the parser contains a bug that can be exploited to execute code.

Code that is unsafe in this way is impossible to write in most languages.

Re:Don't run 'strings' on untrusted files by zem on Saturday October 25, 2014 @06:27PM (#8509598)
ATS is a definite contender too, especially once the high entry barrier issues are worked on a bit.