News for hackers. Stuff that matters.
Re:ARM Pointer Authentication by raverbashing on Sunday June 04, 2017 @07:08AM (#14480788)
How about we start the retirement of C as it is a liability more than an asset at this day and age

How about we only use languages that (as you propose) work with memory slices not naked pointers and where the concept of a null pointer does not exist

How about we only operate on memory slices after checking boundaries

Re:ARM Pointer Authentication by microcolonel on Sunday June 04, 2017 @08:20AM (#14481112)
What? Are you going to force them? People write C because it is convenient, productive, and popular enough to attract contributors and find tools. C has the best dynamic analysis and debugging tools of really any language.

You can think yourself superiour and turn up your nose, but the fact remains that many people have perfectly good reasons to write and maintain C. Your haughty commentary has no impact on that.

You may think that bounds checking is the answer to all situations, but if you're writing a realtime system, there's often no point in running the program if it can fail from an out of bounds read or write anyway. In a flight control system, or an ECU, there is often nothing productive about crashing. You need to verify your pointer logic, instead of hoping your program will crash.

Re:ARM Pointer Authentication by raverbashing on Sunday June 04, 2017 @09:05AM (#14481354)
> You need to verify your pointer logic, instead of hoping your program will crash.

I love how most of the comments are, in essence "you're too dumb to use C". Just check the pointers right? Too bad people who think they are too smart do get bitten by those issues

I guess that's why people won't use other technologies beyond C in embedded systems (they do use)

Re:ARM Pointer Authentication by microcolonel on Sunday June 04, 2017 @09:52AM (#14481585)
You evidently didn't read and understand what you're responding to, try again.
Re:ARM Pointer Authentication by camgunz on Sunday June 04, 2017 @11:05AM (#14481918)
> How about we start the retirement of C as it is a liability more than an asset at this day and age

There's really only one replacement for C right now and it's Rust. If you don't like or can't use Rust (for whatever reason) you're gonna stick with C, and when you consider how much work has gone into making Rust a viable C alternative, it's clear we're a long way away from having a healthy ecosystem of C replacements.

Re:ARM Pointer Authentication by _ph_ on Sunday June 04, 2017 @11:41AM (#14482071)
C (and C++, who inherited most problems with memory insecurity from C) are still used for a very wide variety of programs. There are plenty of alternatives to C other than Rust. Which of them is appropriate depends on the task at hand. In no particular order, all the following languages can replace C with greater memory safety:

Rust, Go, Oberon, Common Lisp, Scheme, D, Java

Re:ARM Pointer Authentication by camgunz on Monday June 05, 2017 @06:10PM (#14492691)
Rust/D:

- Lack of library and platform support

- Lack of tooling

- Lack of standardization

Go:

- Lack of tooling

- Lack of standardization

- GC

- Slower

- Higher memory usage

Oberon (Ada, RTS, etc.):

- Lack of library and platform support

- Lack of tooling

- Lack of standardization

- Obscure

Common Lisp/Scheme:

- Lack of library and platform support

- Lack of tooling

- Lack of standardization

- GC

- Slower

- Higher memory usage

- Obscure

- Can't access arbitrary memory locations (?)

Java:

- GC

- Slower

- Higher memory usage

- Can't access arbitrary memory locations

I'm not really a C apologist, but I am pretty irritated with the near-constant calls for C deprecation. It's a lot easier to say, "C sucks!" than it is to do something about it, and I think we should at least internalize how difficult replacing C will be before we go around castigating people for continuing to use it.

Re:ARM Pointer Authentication by littlestymaar on Tuesday June 06, 2017 @05:12AM (#14495817)
To be fair, C also has drawbacks

C:

- error prone

- Lack of modern typing (generics vs void pointer)

- Lack of dependency management

- no high level constructs

- unintuitive semantics (undefined behaviors)

Re:ARM Pointer Authentication by camgunz on Tuesday June 06, 2017 @04:01PM (#14500771)
Oh absolutely! But those are merely drawbacks, not limitations. In contrast, there are many machines that simply can't host a JVM, or many platforms Rust just doesn't run on.

And that's just the "this is impossible" level. Sure you can build a database in Python, but it'll be slow and a memory hog, so if your requirements are "database, fast, low memory profile", then you can't use Python. Importantly, if you think those ever will be your requirements, you can't use Python.

I say this a lot but, engineering is about tradeoffs. There are still plenty of valid reasons to use C/C++. I'm tired of the knee-jerk "BOOOOO C" on HN these days, and while I certainly think we need to dispel the myth that you can write a meaningfully large, memory-safe program in C, I don't think we need to go as far as "you should never use C ever again". In fact, I think we need to be honest about the current state of the art in order to fully replace C -- which I wholeheartedly support.

Re:ARM Pointer Authentication by littlestymaar on Tuesday June 06, 2017 @07:34PM (#14502466)
> In contrast, there are many machines that simply can't host a JVM

Well, if you're thinking in term of available resources, not really : most (if not every) chip on payment cards or SIM cards run Java[1] despite being incredibly limited in term of resources.

There are other (niche) example of Java running directly on bare metal, see Jazelle[2] for instance.

> or many platforms Rust just doesn't run on

Right now, absolutely but there is no technical limitation whatsoever that prevents Rust from running on these platforms. It might come, in the next decade or so if Rust gets enough traction, only time can tell.

I totally agree with the rest of your comment though.

[1]: https://en.wikipedia.org/wiki/Java_Card

[2]: https://en.wikipedia.org/wiki/Jazelle

Re:ARM Pointer Authentication by camgunz on Wednesday June 07, 2017 @10:22AM (#14506647)
Yeah and that Java stuff is super cool; didn't Sun float a CPU with support for Java bytecode a long time ago? But they don't run a "full" JVM; I more or less mean "can run Apache Commons".

And yeah most of the platforms Rust doesn't support are either legacy or very niche. It's an interesting topic though; platform developers and manufacturers seem to have no problem shipping tweaked C compilers (usually some awful old GCC fork), but I've yet to see them use LLVM. I think Rust is hamstrung a little by having only the one compiler, but it's an entirely unfair expectation of such a young and ambitious project. Plus, it's hard to outdo LLVM.

We'll see how it goes. Maybe we'll see a lot less platform proliferation as mindshare moves away from C, but it's also possible that LLVM will just grow its platform support.

I also wonder if we'll see industry become a little more relaxed in its requirements. Like requiring multiple implementations, language standardization, or security/development standardization and verification. Most of this stuff grew out of C's instability, but with a more stable language maybe it doesn't matter? Or there are parallels in the web world too, like multiple browser vendors have to be on board with a feature for it to eventually become a standard, whereas with Rust it's pretty much whatever the Rust community decides and LLVM supports. Do we still care about standards and multiple implementations? Are the roadblocks worth it? I feel like on one hand I think they are, but also that if we accept them then we're kind of implicitly accepting C forever.

Re:ARM Pointer Authentication by minipci1321 on Sunday June 04, 2017 @08:44AM (#14481243)
> and where the concept of a null pointer does not exist

How that would benefit stability? I'd argue that having an equivalent of NaN for integer types would benefit array index computations more.

Re:ARM Pointer Authentication by raverbashing on Sunday June 04, 2017 @09:06AM (#14481360)
Re:ARM Pointer Authentication by microcolonel on Sunday June 04, 2017 @11:59AM (#14482145)
This is bloviatory though. NULL/0 is an incredibly useful value, it is the simplest to test for in hardware, which is why it is the basis of booleans in every major systems language. Because null is used for boolean evaluation, null is the perfect value for a pointer which doesn't point to anything.

Any time where you have an important distinction between the address of a valid object, and a non-address (next address at the end of a linked list, leaf node of a tree, failed initialization of a pointer). Zero is also used to terminate strings, for similar convenience/efficiency reasons.

C compilers and static analyzers together tend to catch possible null dereference bugs with near certainty these days, so people don't tend to ship them these days, if they make any effort at all. I have not encountered a null pointer dereference which wasn't typo-related in... I don't remember the last time it happened.

If you really want to be certain downstream users of your API won't struggle with it, put the null check in your sample code with a fat comment which says "This is NULL 0.001% of the time, and it really hurts when you don't handle that".

ALGOL, of course, is the sort of language which doesn't have pointer arithmetic. I would agree that a language without pointer arithmetic should not have NULL pointers, if only because it doesn't make any sense for there to be an abstract reference to an object which can not be used with functions designed for it.

In a language with integer pointers, like C, you check for null at allocation time. I've also seen people consider functions which could return NULL pointers to return something like an option type, where null is considered None, and everything else considered Some.

Re:ARM Pointer Authentication by littlestymaar on Tuesday June 06, 2017 @05:19AM (#14495847)
Null is a useful value, but you don't need it everywhere, that's why many modern languages have opt-in null-able types instead of that as a default behavior.

I would argue than in at least 80% of the cases you don't want your values to be null, and that's in those situations mistakes are made (because you don't expect the value to be null !)

Re:ARM Pointer Authentication by raverbashing on Sunday June 04, 2017 @12:35PM (#14482278)
You seem to ignore all the failures and security breaches caused by null pointers and null terminators missing
Re:ARM Pointer Authentication by microcolonel on Sunday June 04, 2017 @12:59PM (#14482374)
No, I just think that in some cases it's worth it.

Some people should really be using bounds checks and option types more often, and I often use bounded functions for handling strings in fixed-size buffers. Some people write bugs into their programs for a lack of understanding or care given to these aspects of the language; but many people also make wonderful and unique things out of them.

I just don't think that the baby should be thrown out because somebody overfilled the bathwater. There is a time and a place for zero tests, null pointers, and pointer/index arithmetic.

Re:ARM Pointer Authentication by raverbashing on Sunday June 04, 2017 @01:14PM (#14482435)
> There is a time and a place for zero tests, null pointers, and pointer/index arithmetic.

Yes. In MMUless microprocessors with kbytes of memory or less