News for hackers. Stuff that matters.
Re:Chromium project finds that 70% of security defects are m... by keithwinstein on Sunday May 24, 2020 @01:02AM (#23289244)
You know, I totally buy that 70% of the vulnerabilities in complex C++ code relate to memory safety, especially in something like Chromium, which is incredibly complex and includes a lot of third-party code that wasn't always designed at first to be robust to untrusted input, and also fast-moving with a ton of code added or churning every week. But I'm not sure I buy that memory-safe languages will consequently be as beneficial for safety (especially in other kinds of software) as that fact would suggest.

For one, not all software is like Chromium. If you look at something like OpenSSH, the vast majority of their security holes have nothing to do with memory safety and are just logic bugs (often caused by features that somebody added that aren't core to the basic SSH experience, e.g. code that interfaces with X11 or something) or protocol weaknesses. (http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=openssh)

The other effect is that in practice, memory-safe languages can come with security baggage of their own. If you look at the zillions of security holes in something like Rails or Wordpress or Django, a fair portion of them relate to an attacker's ability to invoke sophisticated-but-unintended behaviors that are more likely to be hiding in these managed languages (and their support libraries) than in something like C++. E.g. CVE-2013-0156 or CVE-2013-0277 or apparently any current Python or Ruby program that, even today, calls yaml.load on untrusted input. That kind of "security hole from unwanted latent functionality" is less likely to exist in C++. (I realize this is a contrarian view not shared by the vast majority of PL/security experts, but the ones I hang out with seem to interpret "memory-safe language" to mean "expert-written Haskell or, if you want to slum it, Rust" and are not thinking "random Ruby/Python/JavaScript/enterprise Java".)

Not to mention the countless high-profile security holes that have nothing to do with memory safety, e.g. Shellshock, "goto fail", Lucky Thirteen, BEAST, CRIME, POODLE, FREAK, Logjam, etc. Or bugs that are very relevant to Chromium but aren't really Chromium's fault and probably don't appear on their own list, e.g. Meltdown/Spectre etc.

Re:Chromium project finds that 70% of security defects are m... by simias on Sunday May 24, 2020 @06:28AM (#23290571)
I don't understand your argument. You're basically saying "it's possible to write safe code in unsafe languages and vice-versa". Obviously that's true, but I'm not really sure what that tells us.

I mean, supposing that Chromium was rewritten in a safer language, have we any reason to believe that these memory issues would be replaced by a similar number of non-memory-safety issues?

>That kind of "security hole from unwanted latent functionality" is less likely to exist in C++.

Why? That seems like a non-sequitur to me. For me the real difference between the projects you list is that Chromium and OpenSSH are not, as you put it "random Ruby/Python/JavaScript/enterprise Java", they are heavily audited and have a lot of resources allocated into preventing the very issues you mention. Comparing OpenSSH to Wordpress and attributing their respective security track record mainly to the languages they use is fairly absurd IMO. If you're clueless enough not to properly sanitize untrusted input can I really believe that you'd manage to write safe C code?

This thread is oddly reminiscent of discussions around gun control. Because something is not 100% effective doesn't mean that it's not valuable. Although I guess we do need these unsafe languages in case we ever need to overthrow a tyrannical government... no wait, I'm getting confused.

Re:Chromium project finds that 70% of security defects are m... by steveklabnik on Sunday May 24, 2020 @08:36AM (#23291077)
> Although I guess we do need these unsafe languages in case we ever need to overthrow a tyrannical government... no wait, I'm getting confused.

I have heard people say "we rely on exploits to be able to exercise software freedom on locked-down platforms" and "if games were written in Rust, a lot of the glitches speedrunners use would go away and we'd lose our hobby" so... you're not always off.

Re:Chromium project finds that 70% of security defects are m... by ptsneves on Sunday May 24, 2020 @10:37AM (#23291806)
Wow. To equate logic errors with being clueless? You do not need to be clueless to not sanitize input. You just need to forget about it, or incorrectly assume the input is safe, or, basically have a bad day. I make bad assumptions and stupid logic mistakes all the time. I guess everybody does because I see logic bugs everywhere.

Also you assert it is absurd to compare WordPress and openssh In the context of this argument why? They are both widely used software with very high stakes on their reliability and security. They show very well the contrast that even though one is memory managed and the other is not, that does not stop both having serious bugs. Actually it shows memory management is a don't care variable. On the other hand if chromium finds their project has much more memory management issues than other issues, then yes: memory management for the functionality of chromium seems to be a relevant facto upon which improvements can be done.

Re:Chromium project finds that 70% of security defects are m... by jdm2212 on Sunday May 24, 2020 @11:23AM (#23292129)
I think the previous poster was referring to SQL injection vulnerabilities from not sanitizing DB query parameters. And that's something you only f* up if you're clueless (like I was back when I used to do that).
Re:Chromium project finds that 70% of security defects are m... by simias on Monday May 25, 2020 @08:50AM (#23300429)
>Wow. To equate logic errors with being clueless?

I meant that input sanitization is generally an easier problem to solve than writing safe C. If you can't do the former reliably, I'm certain you wouldn't be able to do the latter.

Input sanitization should generally be handled very close to the interface, once you went through this step you should expect to only deal with safe data. Memory safety covers the entire application, if some non-critical debugging function 10 level deep in the call stack messes up when it computes the size of a message buffer you can have a remote code execution vulnerability.

>Also you assert it is absurd to compare WordPress and openssh In the context of this argument why? They are both widely used software with very high stakes on their reliability and security.

Wordpress is a complicated ecosystem with multiple plugins that each can introduce security problems. Its attack surface is also incredibly large since it's generally public facing and anybody can interact with a lot of the features by default. That coupled with the fact that it's extremely popular make it a very good target for attackers. It's also a relatively fast moving target since the web changes fairly fast and new features have to be implemented regularly.

OpenSSH does mostly one thing and does it well. Its surface of attack is a lot smaller and it's vastly easier to audit and test. Its development is also overseen by the OpenBSD developers, who are famously uncompromising regarding safety. The feature set is very stable and changes very slowly.

>Actually it shows memory management is a don't care variable.

The absence of evidence is not the evidence of absence. How much development effort went into making sure that these issues didn't exist? How many thousands of hours auditing the code and making sure it did what people wanted? In a safer language this time could've been spent auditing other parts of the codebase or implementing other features.

I'd also like to point out that one of the biggest OpenSSH vulnerabilities ever found (in the Debian version of OpenSSH where the maintainer heavily reduced the generated key entropy by mistake) was indirectly caused by a memory issue since the reason for the patch was a false-positive returned by Valgrind regarding use of uninitialized memory.

Re:Chromium project finds that 70% of security defects are m... by asveikau on Sunday May 24, 2020 @10:45AM (#23291848)
I think it's a fairly good point you're replying to and so don't shoot the messenger.

There are tons of comments, including here on HN on a regular basis, which one could use to conclude that WordPress should be more secure than anything written in C no matter the quality. And yet, it isn't true in that instance. So it's fine to advocate rust or whatever, but let's not make that other, more dangerous conclusion.

Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @01:06AM (#23289265)
Yes, it is important to note that switching to a memory safe language does not magically solve all your bugs. My own personal anecdote: when I found multiple bypasses in the sandboxing mechanism on macOS, it was not because the relevant code was written in C++, but because the dynamic linker is a really complex system; the things I found clearly flew under the engineer’s radar when they were designing it and they didn’t think beforehand about how those components interacted together. Still, being able to reduce the attack surface area to solely be logic errors is much better than having to deal with memory safety thrown in as well. (Similarly, languages with stricter type systems magically get rid of issues like “you gave me a string and I wanted an int”, but the problems of “you forgot to check the password in this one case” still remain.)
Re:Chromium project finds that 70% of security defects are m... by nindalf on Sunday May 24, 2020 @01:54AM (#23289452)
I think reduction in the number of errors is a worthwhile goal. Switching from C++ to a language without memory safety issues while being just as fast would reduce the number of things the developer and code reviewer have to worry about. They could spend more time searching for bugs in the logic, potentially eliminating further issues.

In practice what I’ve found is that people prefer to deal in absolutes. A large reduction in a category of bugs isn’t enough, it needs to be eliminated altogether, they say. If it’s still possible in a contrived example, what’s the point of investing in switching?

Re:Chromium project finds that 70% of security defects are m... by whatshisface on Sunday May 24, 2020 @02:06AM (#23289513)
It's a miracle that people who think like that use computers at all - after all, computers only reduce the time it takes to perform a clerical task or a calculation, they do not eliminate it.
Re:Chromium project finds that 70% of security defects are m... by TeMPOraL on Sunday May 24, 2020 @02:15AM (#23289552)
No, it's a reflection of a very important heuristic used in programming (that's arguably much more fundamental on a philosophical level, but correct words to categorize it escape me): the zero-one-many principle. If there's more than one something, you have to treat it as if there may be an unbounded number of something. You can only get it out of your head if you can put reliable bounds on it; the best if you can prove there's less than two of something.
Re:Chromium project finds that 70% of security defects are m... by rictic on Sunday May 24, 2020 @03:25AM (#23289814)
So if you could make your build 70% faster, philosophically it wouldn't matter, because you would still have a build step?
Re:Chromium project finds that 70% of security defects are m... by jfoutz on Sunday May 24, 2020 @04:44AM (#23290147)
No, you sort of walked past their point.

A thing can happen zero times (never). An example might be 1+1 =0. You could get really unlucky with cosmic rays or something, but really adding two registers, both containing 1, that result isn't going to be zero unless there's some sort of hardware failure.

A thing can happen once. an example might be, you can delete a file once. There are ways to get unlucky, of corse, but once it's unlinked it's gone.

if it happens more than once, you really should probably think about an unbounded number of times. now days, that sorta means 2^64 times. There will be bugs when something overflows int64, but I hope you get the gist.

The parent comment is talking about invariants you can use in an algorithm.

I think you might be worried about python vs C or something along those lines. Really, it should all work with a pencil and paper. Which is obviously going to be slower than pushing around electrons. But if you can find those invariants, 0-1-many, you can make a better algorithm. If you're stuck with a pencil it'll still make that faster.

Re:Chromium project finds that 70% of security defects are m... by barrkel on Sunday May 24, 2020 @10:09AM (#23291619)
It's a category error to apply the intuition to a risk calculation, though.
Re:Chromium project finds that 70% of security defects are m... by TeMPOraL on Sunday May 24, 2020 @11:16AM (#23292071)
It's not a category error if you're doing an initial guess. Not to mention, particularly in information security, most of "risk calculation" is intuition and guesses, maaaybe sometimes plugged into a probabilistic framework with something resembling rigor.
Re:Chromium project finds that 70% of security defects are m... by barrkel on Sunday May 24, 2020 @02:31PM (#23293512)
I'd say binary considerations are incompatible with risk calculations because no person and no procedure is perfect nor perfectly followed, nothing is completely bug free, etc. Some small part of a calculation might appear binary, but other terms usually dominate.

Risk calculations are far broader than infosec and don't deserve the dismissiveness you seem to be casting towards them. Risk calculations are the core of business. Almost every decision a business makes is a risk calculation; every action has an opportunity cost if it isn't intrinsically risky, and actions with certainty are very rare.

(For the avoidance of doubt, I believe that use of memory-unsafe languages should be avoided if reasonably possible, but there are still plenty of reasonable reasons to use C, C++ etc. instead.)

Re:Chromium project finds that 70% of security defects are m... by TeMPOraL on Sunday May 24, 2020 @04:45PM (#23294532)
I'm not trying to dismiss risk calculations. I appreciate them and challenges involved, having worked on tools supporting risk calculations in corporate space.

I feel this thread is getting out of hand. I initially replied to say why, in general, the kind of thinking that makes you unsatisfied with reductions but not eliminations of concerns, is common among programmers - because it's a sound heuristic. Reducing is good, but eliminating is better.

Re:Chromium project finds that 70% of security defects are m... by smitty1e on Sunday May 24, 2020 @04:29AM (#23290088)
I think you're after Mathematical Induction.

https://en.m.wikipedia.org/wiki/Mathematical_induction

Re:Chromium project finds that 70% of security defects are m... by fpoling on Sunday May 24, 2020 @02:47AM (#23289676)
Also memory-safe languages with GC allow for simpler API and design. That in turn gives more time to think on errors in logic.
Re:Chromium project finds that 70% of security defects are m... by Too on Sunday May 24, 2020 @03:15AM (#23289780)
In many ways yes but not always. After writing lots of C++ and then going back to managed world I often find cases where the opposite is true. Questions like "will this be mutated?" or "will the library shallow copy, deep copy, or hold a reference to this object?" are very hard to answer in most GC languages.
Re:Chromium project finds that 70% of security defects are m... by deckard1 on Sunday May 24, 2020 @04:11AM (#23290025)
You're exceedingly lucky if the developers you work with these days are aware of the differences between shallow and deep copy, or how object references work.

This is where I make the case for having knowledge of asm/C/C++. The JavaScript developers that started on JavaScript or, maybe, Ruby have no clue what the hell is going on in the language they are working in. I see this all the time. From senior and lead developers, too.

They have no mental model for how pointers work. Which means they have no concept of what an object is, on a memory-organization level. They aren't always aware of when mutation will occur, and they are entirely too reliant on operations that are inefficient. In Lisp, this would be the developer than uses CONS everywhere. There is no awareness of the allocations behind the mechanisms. There is premature optimization and then there is not driving into the damn pothole in the first place! One of these is F1 racing and the other is basic driving skills.

I believe this may also explain why so many developers are so bad at using git. Git is entirely based on pointers. There is an elegance and simplicity to git that is lost on many people.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @05:51AM (#23290420)
I’m not sure that is the underlying problem, the lack of knowledge about pointers, I think it is more about that the job programmer today is one of the most common jobs today, that alone lowers the general skill level.

In the old days people usually chose to become a programmer for a reason, today it is like any other job.

Re:Chromium project finds that 70% of security defects are m... by JamesBarney on Sunday May 24, 2020 @12:43PM (#23292709)
Most devs learn what the need to do their jobs. And you can be a very effective Ruby developer without needing to know much of this information.

Just like you can be a very effective C or C++ developer without knowing anything about css (which in my opinion is far more difficult to understand than when and how stack vs heap allocations are made)

Re:Chromium project finds that 70% of security defects are m... by Scramblejams on Sunday May 24, 2020 @04:39AM (#23290123)
I've never found programming so relaxing as when working in languages where almost everything is immutable. I think we're living beneath our privileges here.
Re:Chromium project finds that 70% of security defects are m... by fpoling on Sunday May 24, 2020 @03:36AM (#23289854)
I can agree with that when comparing with plain C code. But reference-counting in C++ and Objective-C leads to exactly the same problem as with managed code. What saves C is that reference-counting there leads to a lot of boilerplate and bugs. To avoid that one needs very clear ownership model.
Re:Chromium project finds that 70% of security defects are m... by Gibbon1 on Sunday May 24, 2020 @04:52AM (#23290181)
I saw an essay by someone discussing going back to C and eschewing leet pointer and decentralized memory allocation for a system of centralized memory allocation and passing handles[1] instead of pointers. Which appeared to make most of the memory safety problems go away.

[1] handles could be unboxed to expose a pointer. But unboxing had machinery to detect and trap on bad handles

Re:Chromium project finds that 70% of security defects are m... by fpoling on Sunday May 24, 2020 @05:15AM (#23290281)
That reminds me about early Fortran where everything was statically allocated including local variables and function return address. To simulate data structures one used arrays of various dimensions. Effectively array indexes where handles. This was not memory safe as there were no bounds checks. But add those when the compiler cannot eliminate them, and one gets fast and memory safe language.

Edit: that static allocation was essentially a centralized store. Everything repeats itself.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:53AM (#23290678)
Re:Chromium project finds that 70% of security defects are m... by Gibbon1 on Sunday May 24, 2020 @04:53PM (#23294611)
That's the essay. I think it's interesting because he's mimicking the way I've been writing firmware. I've found most of the issues with memory safety disappear when you use static and centralized resource allocation, avoid monkeying with pointer arithmetic, and avoid making temporary copies of pointers 'for later'.
Re:Chromium project finds that 70% of security defects are m... by Too on Sunday May 24, 2020 @12:33PM (#23292630)
Sure, you can shared_ptr everything and pretend your are writing C#, which as you say circles back into the same problems of spaghetti-ownership. The difference with c++ or rust is that you have options: plain &-reference for non persistent pointers, const &-references for read only non persistent pointers, copy for true copies, move/unique_ptr for transfer of ownership and shared_ptr for shared ownership. All this information is readily accessible to the caller through the function signature.
Re:Chromium project finds that 70% of security defects are m... by wott on Sunday May 24, 2020 @05:25AM (#23290320)
> I can agree with that when comparing with plain C code. But reference-counting in C++ and Objective-C leads to exactly the same problem as with managed code. What saves C is that reference-counting there leads to a lot of boilerplate and bugs.

You've already been greyed out, but I agree 100% with what you said.

That's my main beef with this kind of bi-weekly discussion where people always put C and C++ in the same bag.

I rarely, if ever, make memory management errors in C. The model can't be more simple. If you don't explicitly allocate, you don't have to care about it (in the general case, it is on the stack and will disappear when exiting a function, anyway you also don't have to care about those implementation details, just do as if it disappeared with scope). If you allocate something (on the heap), then you free it later. Malloc(), free(), end of story. Okay, don't keep pointers to areas you will free or realloc, of course. Any function which returns pointers tomemory chunks are always to be treated as malloc'ed, those objects can never be on the stack and never have a fancy automatic management of any sort.

Now almost each piece of code I wrote in Objective-C contained memory errors/leaks. Be cause 1. I didn't grasp the more complicated, less deterministic (so to speak) models and the jargon well 2. you (well, I) never know right away which type of management was used for the object that some function returned, you have to check the doc and pray it is clearly written 2.b you have to keep that information in mind until the moment when you'd like to release the said object in order to release what should be released and not release what is/will be/has been automatically released now/later/sooner/whoknows.

And I don't even talk about the abomination that is Objective-C++, where I drowned in muddy waters.

Re:Chromium project finds that 70% of security defects are m... by kzrdude on Sunday May 24, 2020 @05:37AM (#23290372)
It's so easy to create thread safety related bugs in C# because it's easy to use parallelism and there are no checks for threading issues.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:11AM (#23290498)
Correct, that is true for any language where you deal with raw threads, managed or unmanaged. That tells us that we should avoid using raw threads and instead use some other API to achieve parallelism.
Re:Chromium project finds that 70% of security defects are m... by nicoburns on Sunday May 24, 2020 @09:04AM (#23291209)
It's not true in Rust. In Rust, objects cannot be concurrently accessed from multiple threads unless they are explicitly marked as thread-safe (with the Sync trait), or wrapped in a a Mutex, which ensures that the safety variants are upheld.
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:08AM (#23298415)
Yes for multi-threaded code, although not quite for multi-processes code, which is what one should be writing when the goal is security.

Then you are back into the same synchronization issues as in every other language.

Re:Chromium project finds that 70% of security defects are m... by vardump on Monday May 25, 2020 @05:28AM (#23299466)
Yeah, it solves only the 99.9% case.
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @08:24AM (#23300263)
So Firefox will return to be a single executable after Rust migration is fully done? After all that is not needed it seems.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @10:59AM (#23291946)
Rust does not compile if you don't use the techniques you described?
Re:Chromium project finds that 70% of security defects are m... by ansible on Sunday May 24, 2020 @11:19AM (#23292095)
> Rust does not compile if you don't use the techniques you described?

Yes, exactly.

https://kkimdev.github.io/posts/2019/04/22/Rust-Compile-Time...

Of course, you can bypass this by using 'unsafe' code, where you are explicitly telling the compiler that you have manually verified Rust's safety guarantees.

This is why a significant portion of Rust's community gets agitated with (possibly unnecessary) use of 'unsafe' in popular libraries.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @11:50AM (#23292348)
Then I stand corrected and applaud the creators of Rust for haven taken these measures for writing thread safe code, because it is supereasy to get threading wrong, even for the most experienced developer.
Re:Chromium project finds that 70% of security defects are m... by littlestymaar on Sunday May 24, 2020 @01:17PM (#23292971)
Interestingly enough, this was the raison d'être of the Rust project at the beginning, while zero-cost abstraction and memory-safety without GC (and the borrow-checker) weren't part if the initial goal. When Rust was first released as a research project it had green threads and a GC (interestingly close to Go actually), but it was already designed with data-race freedom in mind.
Re:Chromium project finds that 70% of security defects are m... by thePunisher on Sunday May 24, 2020 @12:56PM (#23292812)
Both Java and C# are designed for memory-safety but not thread-safety; Rust is.

Considering many of the software problems we face have some connection to thread-safety, Rust is the way to go.

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Wednesday May 27, 2020 @03:50AM (#23320509)
I would consider that the way to go is multi-processes instead, and secure every critical module on their own OS sandbox.

Threading seemed a good idea that went wrong.

Re:Chromium project finds that 70% of security defects are m... by ReactiveJelly on Sunday May 24, 2020 @10:52AM (#23291901)
And in the last quadrant, you can use non-raw threads like the Task or Parallel APIs and still have threading issues in C#.

I'm trying to learn Android and some libraries give zero indication of what thread your callbacks will be called on.

Maybe there's a convention somewhere that says "On Android, you can't assume anything about callbacks, so always assume you're on some anonymous worker thread and lock everything or dispatch to a thread you own"

But I have not come across it yet.

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:12AM (#23298445)
Yes that is the convention.

You cannot assume anything about process or thread lifetimes on Android, as the simple act of rotating the screen will restart your application, and it can be killed at any moment and restarted later, due to memory pressure, or because the use has switched applications.

So whatever was the state of your application can be completely different when the callback is supposed to be invoked later on.

Re:Chromium project finds that 70% of security defects are m... by erichocean on Sunday May 24, 2020 @02:54AM (#23289702)
They're simpler only if you could care less about performance. C and C++ are primarily used in situations where you do care about performance.
Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @03:51AM (#23289913)
Memory safety and performance are not a contradiction, they are widely independant. Yes, some strategies like GC induce an overhead. But in the age of multiprocessor machines, this overhead gets very much reduced by parallel collection. And practice has shown, in programs with a lot of dynamic memory allocation, garbage collected languages often perform even better. There are different approaches, like memory safety by the compiler as Rust does it. And with "performance" in mind, you shouldn't forget, that most large C/C++ programs tend to use libraries to provide some amount of safety, but those libraries are of course adding some overhead too. Finally, the less time you spend on questions of memory management, the more time you have to write an actually fast program.
Re:Chromium project finds that 70% of security defects are m... by dirtydroog on Sunday May 24, 2020 @05:08AM (#23290251)
Sorry, this is hand wavy nonsense. One counter example, we switched from Cassandra (JVM) to Scylla (C++). It was a win in terms of both query latency and infrastructure costs as we required fewer machines to handle the same load.

As for having more time to write a fast program... that's funny. If you want a fast program on something JVM based you're pretty much going to be spending the majority of your time writing things in a way where the GC plays as little role as possible.

Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @05:45AM (#23290400)
Sorry, this is hand wavy nonsense. One counter example, we switched from Cassandra (JVM) to Scylla (C++). It was a win in terms of both query latency and infrastructure costs as we required fewer machines to handle the same load.

Sorry, this is not hand wavy nonsense. And what you are providing is called annectodal evidence.

Also, your universe seems to consist only of the JVM as a memory-safe alternative to C++. Yes, there are a lot of bloated, badly performing programs implemented in Java. However this isn't a given. Yes, some design decisions for Java introduce the risk of bloat, but you can avoid them at much less effort (and risk) than memory corruptions and new features like the value classes are reducing the bloat quite a bit. But still, the JVM is extremely high performance, so for speed in surprisingly many cases, it often beats C++. Virtual method calls are just better optimizable at run time, the Java JIT creates excellent code and Java has some of the best garbage collectors, so at really dynamic memory loads, it beats any manual management by a wide marging.

And of course, there is a whole world beyond Java as alternatives. Rust has been explicitly designed to excel at tasks C++ traditionally shines for, while giving your full safety.

Re:Chromium project finds that 70% of security defects are m... by dirtydroog on Sunday May 24, 2020 @09:26AM (#23291342)
There is an open-source project by LMAX (a forex trading company) called Disruptor[1] that squeezes as much as possible out of the JVM. It's awesome. I ported it to C++ years ago when I wanted to learn about low-latency techniques. However, if you look at the code they need to actually break out of the JVM's safety net to get the performance they need[2]. I couldn't help but ask myself why they didn't just use C++, and when asked one of the devs did admit that their own C++ ports had an approx 10% performance increase (although this was ~7 years ago maybe)

Rust is certainly interesting and it's on my radar. I wonder though, when it comes to having it in use in anger if its guarantees turn out to be over sold, just like the JVM's safety claims were. Time will tell.

Edit: I tend to focus on comapring against the JVM because pretty much any framework you use on The Cloud is JVM based. I'm of the opinion that there are cost savings to be had if these were ported to more appropriate languages, hence the Cassandra vs Scylla comparison. The money saved was 'noticeable'.

[1] https://github.com/LMAX-Exchange/disruptor [2] http://mishadoff.com/blog/java-magic-part-4-sun-dot-misc-dot...

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:23AM (#23298513)
Which is why such projects use the JVM, they save money in developer salaries, developer pool, bug fixes due to security exploits, available set of tooling and libraries, while caring to hand optimize a tiny set of libraries for specialized use cases.

Java 15 just accepted the JEP for native memory management, yet another stepping stone for having value types support.

If the cadence continues, Java will eventually have all the features that it should have had in 1996, had Sun properly taken into consideration languages like Modula-3 and Eiffel.

Which you can get today in a language like Swift, C#, Nim or D, productivity of GC, type safe, while having the language features to do C++ like resource management.

Re:Chromium project finds that 70% of security defects are m... by murderfs on Sunday May 24, 2020 @05:56AM (#23290451)
There are notable examples where garbage collection has both better throughput and latency than manual memory collection: persistent data structures come to mind, because in the absence of garbage collection, you have giant awful cascades of reference count manipulation any time a structure would get freed.

You'll never actually see anyone tout the benefits of using GC for this, though, because the performance characteristics of persistent data structures are so horrendous compared to mutable ones, no one actually uses them in C++.

Re:Chromium project finds that 70% of security defects are m... by pkolaczk on Sunday May 24, 2020 @01:54PM (#23293220)
You can use GC to implement the persistent structure in C++/Rust just fine. But then you pay the GC cost for only that structure, not for all the other things.
Re:Chromium project finds that 70% of security defects are m... by andrepd on Sunday May 24, 2020 @07:36AM (#23290829)
Well yes, if you are comparing GC to refcounting then yes, gc wins.
Re:Chromium project finds that 70% of security defects are m... by pkolaczk on Sunday May 24, 2020 @02:00PM (#23293273)
I wouldn't be so sure. There is no easy answer. It typically wins in trivial benchmarks, where the total heap size is small. However once you have a big heap of other long lived stuff, there is a significant indirect cost caused by scanning the heap, memory barriers and evicting good data from caches. This cost is negligible only if your total heap size is much larger than the live memory set. Also modern manual memory allocators are not as slow as they used to be a few decades ago and they actually allocate in low tens of nanoseconds.
Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @09:41AM (#23291440)
If your problem demands many heap allocations, GC wins also vs. manual memory management. Heap allocation in a generational GC is as fast as stack allocation, you don't get fragmented heaps.
Re:Chromium project finds that 70% of security defects are m... by pkolaczk on Sunday May 24, 2020 @02:01PM (#23293284)
It is nowhere near stack allocation, please stop this nonsense. There was a paper claiming that, but the requirement was to set heap size 7x bigger than needed.

Stack is also very hot in cache. Memory that GC is handing allocations from is not.

I recently ported some of Cassandra code from Java to stack-only Rust and I got ~25x performance improvement, most from avoiding heap allocations and GC.

Re:Chromium project finds that 70% of security defects are m... by dirtydroog on Sunday May 24, 2020 @10:26AM (#23291744)
That depends on the allocator used. The default libc one works but isn't great performance-wise. It is possible to intercept calls to malloc/free by using LD_PRELOAD on Linux. That will allow you to use allocators such as jemalloc or tcmalloc instead.

Of course, repeatedly allocating and freeing is poor for performance. Cache/pre-allocate when you can. This goes for managed languages too.

Re:Chromium project finds that 70% of security defects are m... by thePunisher on Sunday May 24, 2020 @01:03PM (#23292858)
It's usually a trade-off since C++ may be more time consuming and therefore most costly to write. It's also a lot harder to get bug-free because of the manual memory management.

Both Java and C# may be somewhat slower, but the maintainability and freedom from memory management issues more than makes up for this.

Any engineer worth his salt will take this into account.

Re:Chromium project finds that 70% of security defects are m... by citrin_ru on Sunday May 24, 2020 @08:31AM (#23291053)
> Yes, some strategies like GC induce an overhead. But in the age of multiprocessor machines, this overhead gets very much reduced by parallel collection.

If you unlucky and given GC is not well optimized for given workload, then memory usage overhead can be huge. Just a few days ago had such problem with Go (HeapIdle grew until OOM).

Go GC is less mature than Java GC, but Java GC is not free too - sometimes you need to spend a lot of time time to tune GC settings or to optimize code to avoid GC problems.

In my case case it would be faster to use malloc/free than to spend time fighting with GC (looking for a workarounds).

On average GC saves development time and allows to avoid memory management bugs, but in some cases overhead is big and developers have to spend more time, not less.

Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @09:38AM (#23291420)
I have not claimed that a GC is always faster. Indeed, having a GC enables some to write a totally bad performing program. However this doesn't contradict that fact, that in many cases a GC does not only not mean a slower program, but sometimes a faster program. Usually, you don't have to "fight" the GC. In situations, where manual management is vastly better, you do use object pools and preallocated arrays even in a language with a GC.
Re:Chromium project finds that 70% of security defects are m... by thePunisher on Sunday May 24, 2020 @12:59PM (#23292835)
There are quite a few areas in software where determinism is a must, such as games, real-time and systems software.
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:32AM (#23298565)
Yes, for those there are real time GCs as well.

https://www.ptc.com/en/products/developer-tools/perc

https://www.aicas.com/cms/en/JamaicaVM

One of the Java vendors acquired by PTC, Aonix, used to sell real time Java implementations for military deployments, including weapons controls and targeting systems.

You don't want a couple of ms pause when playing with such "toys".

Re:Chromium project finds that 70% of security defects are m... by thePunisher on Thursday May 28, 2020 @12:13PM (#23338995)
Sounds more like snake-oil to me.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:15AM (#23290516)
Both C and C++ have zero built in knowledge about parallelism, so in a modern world where most things are parallel and asynchronous I don’t agree at all with that statement.
Re:Chromium project finds that 70% of security defects are m... by adev_ on Sunday May 24, 2020 @09:36AM (#23291404)
> Both C and C++ have zero built in knowledge about parallelism, so in a modern world where most things are parallel and asynchronous I don’t agree at all with that statement.

And ?

C (even Fortran) had threads and was used to create high performance program with high degree of parallelism before any "concurrent" modern language was even born.

You can not agree if you want. But fact are there, 98% of programs running on the biggest "parallel" machines nowadays (supercomputers) are C, C++ or Fortran.

You don't need to be "designed" concurrent to be efficient at it. The same way you do not need to be designed "Cloud-native (bullshit)" to run on a virtual machine.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @10:57AM (#23291929)
I think that it sets a different mentality if it is part of tools you use, you solve problems differently. It is of course possible to write highly concurrent code in traditional sequential languages and your examples proves that, but supercomputers are a special case with budgets for that. I'm talking about the general case, and I think the post I replied to also assumed that.

We have to give programmers, with different backgrounds & training, tools to write high performant code in their everyday job. Many of the tools we use today are not designed for that. We are stuck in a mental model 50 years old that is no longer true.

Here are some interesting stackoverflow answers. You are of course free to dismiss these answers as anecdotal.

https://stackoverflow.com/a/14637833

https://stackoverflow.com/a/2799779

Re:Chromium project finds that 70% of security defects are m... by sigotirandolas on Sunday May 24, 2020 @08:28AM (#23291024)
Both C and C++ have had a concurrent memory model and threads in the standard library for a decade now. And POSIX threads which are pretty much the same thing have been there for a quarter century on *NIX.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @08:52AM (#23291146)
Sure, there are libraries for concurrency, but there are no language constructs like in other languages.
Re:Chromium project finds that 70% of security defects are m... by cogman10 on Sunday May 24, 2020 @11:03AM (#23291981)
What do you mean by language constructs? As in, a `synchronized` keyword? Or are you thinking along the lines of `async` `await`?

If you mean the `synchronized` keyword, then correct, they don't have that. Most languages do not have that concept. C++ does have mutexes and has had them since C++11 (nearly a decade). C++ also has as part of the language spec the concept of threads, again, there since C++11.

If you meant co-routines, then C++ just added them with C++20.

Or do you mean something different like green threads (ala go)?

C++ certainly has concurrency constructs and has been expanding them since C++11.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @11:22AM (#23292124)
Like Gos goroutines or Erlangs processes. And more of message passing. C++ has added many of these things later on in the standard library, bolted on afterwards.
Re:Chromium project finds that 70% of security defects are m... by erichocean on Sunday May 24, 2020 @02:40PM (#23293583)
If you think that using libraries to do things in C++ means they are "bolted on", then you don't understand C++.

The entire design of C++ is to enable efficient libraries for these kinds of things to be built. And it does, and has, and will continue to for decades more.

Re:Chromium project finds that 70% of security defects are m... by SomeoneFromCA on Sunday May 24, 2020 @02:03PM (#23293293)
You forgot about OpenMP.
Re:Chromium project finds that 70% of security defects are m... by SomeoneFromCA on Sunday May 24, 2020 @02:07PM (#23293312)
The real point of using C and (less so, but still) C++ is not to have the ultimate performance, but to have ultimate control over the program execution. Garbage collection and real-time code are not compatible, because GC introduces random, unexpected stalls in the program flow; even simple reference counting can be harmful, if the last reference get eliminated in the wrong time, and creates a cascade of deallocations.
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:34AM (#23298577)
Then using C and C++ is a mistake, because there isn't an ultimate control about how memory allocator interacts with the OS.

So much that in the 90's there were vendors that could make a business out of selling specialized memory allocators.

Re:Chromium project finds that 70% of security defects are m... by SomeoneFromCA on Monday May 25, 2020 @07:39AM (#23300068)
Really? What about an OS kernel code? How does "it's allcator" interacts "with the OS"? And what these allocators were written in?
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @08:13AM (#23300215)
Usually in a mix of Assembly and whatever is used in OS systems implementation language, not necessarily C.

https://inf.ethz.ch/personal/wirth/ProjectOberon/Sources/Ker...

The malloc() exposed in a ISO C standard library implementation isn't necessarily related to whatever means the OS does memory allocation.

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Monday May 25, 2020 @02:15AM (#23298472)
Nowadays, back in the 80's and early 90's no sane developer would used them on 8 and 16 bit home platforms if they cared about performance.

What C and C++ have going for them is 40 years of investment in optimizing compilers, to detriment of other languages, and abuse of UB in optimizers.

Now with shared compiler backends becoming a mainstream thing across most OSes, that advantage is getting thinner.

Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @03:14AM (#23289775)
They do well in those contexts. They’re used in other places too, but generally with poorer justification and results.
Re:Chromium project finds that 70% of security defects are m... by zetafunction on Sunday May 24, 2020 @08:01AM (#23290904)
My personal experience from reading code that uses Chromium's C++ garbage collector is that that's often not true. While there might no longer be use-after-free errors, it's also no longer possible to make assertions like "object X must outlive Y" because object Y could be referenced arbitrarily and kept alive longer than expected. To get around that, objects might have an explicit shutdown step. But shutting down a large graph of objects is often fraught with peril, especially when that work can span multiple processes.
Re:Chromium project finds that 70% of security defects are m... by johnr2 on Sunday May 24, 2020 @05:39AM (#23290377)
> Switching from C++ to a language without memory safety issues while being just as fast

Does that actually exist? (I mean in the general case, not just a few carefully chosen benchmarks).

Re:Chromium project finds that 70% of security defects are m... by devit on Sunday May 24, 2020 @08:47AM (#23291124)
Rust is that language.

Some things, namely array indexing and RefCell borrowing, have unavoidable extra runtime overhead in the default safe usage, but it's unlikely that it is significant (often array bounds checks are either essential and thus needed in C++ as well or optimized out by LLVM in Rust, and RefCell usage is generally rare), and you can use unsafe unchecked operations as well.

Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @06:31AM (#23290588)
Yes, they do exist. The safety of Rust comes from the compiler (which takes its time), not from run-time checks. For certain style of code, the JVM is actually faster than C++. You also have to consider, that a lot of things you do in a C++ program to make it safer add up performance costs.
Re:Chromium project finds that 70% of security defects are m... by andrepd on Sunday May 24, 2020 @07:32AM (#23290814)
>For certain style of code, the JVM is actually faster than C++.

I find this very hard to believe.

Re:Chromium project finds that 70% of security defects are m... by _ph_ on Sunday May 24, 2020 @08:13AM (#23290955)
It depends on the nature of the code. Static code is very fast in C++, but dynamic code is less so. Virtual method dispatch in C++ is comparatively slow. Hotspot can eliminate much of the cost by using runtime type information. Using runtime information generally is a way for Hotspot to perform optimizations, a static compiler cannot do, because they would be a bad tradeoff. Heap allocation in the JVM is as fast as stack allocation, this gives another boost vs. heap allocation in C++. And even GCing the youngest generation is basically cost free, as long as you don't have many surviving objects.

I don't claim that Java is always faster than C++, that would be silly and there are plenty of Java programs in the wild which proves that it isn't. But there are quite some tasks at which Java is indeed faster.

Re:Chromium project finds that 70% of security defects are m... by sigotirandolas on Sunday May 24, 2020 @09:14AM (#23291265)
In the general case, virtual dispatch has an overhead in both C++ and Java (which btw is only <5 machine instructions), but it's true that Java can sometimes eliminate it with runtime information, which C++ can not use.

However, in my experience, using virtual dispatch is a relatively rare ocurrence in C++ (compared to the vast majority of method calls). On the other hand, on Java, most of _everything else_ is indirect and has overhead: All objects are allocated on the heap, primitives (int) are often objects (Integer) where they ought not to be, all objects have 16 bytes of overhead, etc.

But the JVM will convert those heap allocations to stack allocations! And it will realize those Integers are used as int and remove the overhead! And it will realize you're not using the information on the header of every object!

Perhaps in synthetic benchmarks, but in real programs, where there are an almost infinite amount of code paths, dumb 'data transfer' objects are common and things need to be modularized, the JVM is forced to assume the worst case can happen (even if you as an human can prove that it won't happen) and inhibit those optimizations. And now you have indirect accesses everywhere, memory overhead (=cache trashing) everywhere, the runtime can't vectorize that tight due to Integers, etc.

In fact, I can't think of any domain where there is heavy competition and where high performance is a determining factor where Java has won to C/C++. In browsers, it certainly has not.

Re:Chromium project finds that 70% of security defects are m... by cogman10 on Sunday May 24, 2020 @11:21AM (#23292113)
> (which btw is only <5 machine instructions)

The number of instructions is much less important than what they are doing. In the case of virtual dispatch, it's doing a memory lookup. If that memory is in cache it could be relatively inexpensive but not guaranteed. However, if you have to hit main memory then things are much slower.

> But the JVM will convert those heap allocations to stack allocations!

I was surprised recently to learn this is not the case. (at least, not with hotspot) The JVM will try and "scalarize" things (pull the fields out of the object which may push them onto the stack) but it won't actually allocate a full object on the stack (OpenJ9 will, but I don't see people using that very often).

It is also somewhat bad at doing the Integer to int conversion. That is mainly because the Integer::valueOf method will break things (EA has a hard time realizing this is a non-escaped value). Simple code like

    Integer a = 1;
    a++;
can screw up the current analysis and end up in heap allocations.

There is current work to try and make these things better, but it hasn't landed yet (AFAIK).

> In fact, I can't think of any domain where there is heavy competition and where high performance is a determining factor where Java has won to C/C++. In browsers, it certainly has not.

I think the realm where the JVM can potentially beat C++ is, funnily, work that requires a lot of memory. The thing that the JVM memory model has going for it is that heap allocations are relatively cheap compared to heap allocations in C++. If you have a ton of tiny short lived object allocations then the JVM will do a great job at managing them for you.

Re:Chromium project finds that 70% of security defects are m... by account42 on Friday May 29, 2020 @06:00AM (#23348155)
> I think the realm where the JVM can potentially beat C++ is, funnily, work that requires a lot of memory. The thing that the JVM memory model has going for it is that heap allocations are relatively cheap compared to heap allocations in C++. If you have a ton of tiny short lived object allocations then the JVM will do a great job at managing them for you.

Except C++ also has many other options besides malloc() each of these individual objects.

Re:Chromium project finds that 70% of security defects are m... by vardump on Sunday May 24, 2020 @08:44AM (#23291114)
Allocation heavy C++ can be pretty slow. It's also true unoptimizable (pure) virtual methods performing little work have quite a bit overhead that JVM can avoid.

Of course you normally try to avoid writing C++ like that.

Re:Chromium project finds that 70% of security defects are m... by pkolaczk on Sunday May 24, 2020 @02:13PM (#23293374)
Allocation heavy Java is also very slow. But it is much easier to avoid heap allocations (and virtual calls!) in C++/Rust than in Java.
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Wednesday May 27, 2020 @04:02AM (#23320586)
For the time being, I still hope that Valhalla will eventually make it.
Re:Chromium project finds that 70% of security defects are m... by fluffything on Monday May 25, 2020 @03:39AM (#23298920)
The claim is probably that idiomatic code in one case is faster than idiomatic code in the other, not that you can't write C++ code that isn't equally fast.

For example, if you use `std::vector` or `std::unique_ptr` you would be deallocating memory when those go out of scope. The JVM might actually never do that, e.g., if the program terminates before sufficient memory pressure arises.

Writing Rust code that leaks a `std::vector` is trivial, but doing the same in C++ actually requires some skill.

Re:Chromium project finds that 70% of security defects are m... by vardump on Monday May 25, 2020 @05:23AM (#23299448)
Writing C++ code that leaks a std::vector is absolutely trivial, happens all the time and requires no skill.

  auto* v = new std::vector<char>();
Re:Chromium project finds that 70% of security defects are m... by fluffything on Monday May 25, 2020 @06:16AM (#23299693)
I disagree in that it requires no skill: it requires the user to avoid doing the obvious thing:

    vector<int> foo {...};
and heap allocate a vector on the heap with `new` (without using a smart pointer), and then avoiding your linters warnings about this (e.g. clang-tidy).

If this is common in your place of work, I truly pity you.

Also, trading a call to `free` for a second call to malloc, and a second pointer indirection to the vector elements, isn't a very effective way of improving performance to beat the JVM. The whole idea behind leaking memory is doing less operations, not more :D

In Rust, leaking "the right way" is trivial (mem::forget is safe), but in C++, leaking the stack allocated vector probably requires putting it behind an union or aligned_storage or similar.

Re:Chromium project finds that 70% of security defects are m... by nyanpasu64 on Sunday May 24, 2020 @01:58AM (#23289473)
> the problems of “you forgot to check the password in this one case” still remain.

Maybe type systems could, in some cases, prevent this type of problem. You could construct a system where performing a password authentication returns an object of type Authorized, and performing operations requires passing in objects of type Authorized. I don't know how often this is useful in practice though.

Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @02:19AM (#23289571)
If your type system can handle the case where I can divert code flow along an unsandboxed path by replacing functions from the system libraries even before you can achieve code execution (and long before you certainly though I had code execution), I would like to hear it. But expressed in a less brusque way: yes, encoding state in your type system is generally great, and there is a lot of work being done in languages where you can formally “prove” guarantees about your code. The issue is that your proofs only hold true if the system they run on is correct, you chose exactly the right thing to check, you didn’t just leave out part of the program because you couldn’t fit it into the type system…it’s a nontrivial problem.
Re:Chromium project finds that 70% of security defects are m... by Dylan16807 on Sunday May 24, 2020 @03:32AM (#23289838)
Are you replying to the right comment? It just talks about type systems so you don't forget to check something. No mention of proofs either.
Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @03:39AM (#23289861)
Yes, I replied to the one I meant to. The reason we use type systems is that they let us prove things about our code: simple things like “this is a string, not an int”, more complicated things like “this variable cannot be null”, and to the advanced “I have written up a proof in a theorem-proving language that this program will not deviate from the published specifications in these ways”. My point is that the thing that people really want to prove, which is obviously “does this program work and do so correctly”, is fairly impossible to do so in practice due to some of the problems I mentioned. You can only approximate at this along certain domains.
Re:Chromium project finds that 70% of security defects are m... by fauigerzigerk on Sunday May 24, 2020 @07:41AM (#23290843)
I agree. Some lower level library could be rigged to return an Authorized<UserId> when that user is in fact not authorized.

So we would have to make sure that type safety is ultimately backed by a hardware based encryption module, but that's just not where we are today.

Re:Chromium project finds that 70% of security defects are m... by lmm on Sunday May 24, 2020 @02:12AM (#23289541)
I do this all the time in Scala. Define a marker for "required security level", slap it in a free monad or add it to an existing effect stack, then it just naturally gets propagated right the way up, and you can then put the checking where it makes sense (e.g. right at the outermost request handling level).
Re:Chromium project finds that 70% of security defects are m... by damnyou on Sunday May 24, 2020 @01:56AM (#23289460)
A language with a decent type system can easily take care of issues like forgetting to check the password along one code path, or at least significantly reduce the effort involved.
Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @02:20AM (#23289576)
This is possible, but I certainly would not describe it as “easy”.
Re:Chromium project finds that 70% of security defects are m... by smt88 on Sunday May 24, 2020 @02:29AM (#23289604)
It's very easy in many typed languages.

You have a type for UnauthenticatedUser and one for AuthenicatedUser. You have an authenticate() method to convert from one to the other.

Re:Chromium project finds that 70% of security defects are m... by erichocean on Sunday May 24, 2020 @02:55AM (#23289707)
Now do users with various level of RBAC, and show me how the type system solves that "very easily".

I'll wait.

Re:Chromium project finds that 70% of security defects are m... by damnyou on Sunday May 24, 2020 @09:42AM (#23291443)
It doesn't necessarily solve this completely, but it can be used to significantly reduce the amount of code you have to manually audit. For example, you could use tokens to represent permissions, and arrange your code so that only a small portion of your code can create them. Then you can rely on the presence of that token indicating that a check has been performed in the rest of your code.

The type system is a tool to reduce the space of invalid inputs.

Re:Chromium project finds that 70% of security defects are m... by smt88 on Sunday May 24, 2020 @01:30PM (#23293070)
This is also easy. There are different ways to do it.

Here's an example: create a type, such as "RoleAuthorization". Make it a required parameter for access-controlled methods, either through the constructor of the parent object or explicitly in the method.

In order to create a RoleAuthorization, you must first pass the user's Role object in an authorization method.

If a method requires authorization, the compiler will complain if you don't first check the current user's role through the authorization method.

> I'll wait.

If you're sincerely interested in discussing something, antagonizing someone this way (and implying that you are infallible) really doesn't help.

If you just wanted to make what you believe is a statement of fact, just make it.

If you don't want to discuss the issue at all and would instead prefer to be unchallenged on this topic, why write about it in a comments section?

Re:Chromium project finds that 70% of security defects are m... by machiaweliczny on Sunday May 24, 2020 @03:25AM (#23289812)
Wouldn't union just work?

authenticate() : role1 | role2

Re:Chromium project finds that 70% of security defects are m... by viraptor on Sunday May 24, 2020 @04:15AM (#23290040)
That assumes you know all the roles ahead of time. In many systems they will consist of a large number of variant both in how they authenticate and in what they're allowed to do. It may even depend on environment ideas which cannot be represented in types. (like: user X can issue commands Y, Z in times when they're on call, where "on-call" is a custom operator's rule, not something known earlier)
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:32AM (#23290590)
But you do know every permission in advance, thus static. How a user gets a permission can be dynamic.
Re:Chromium project finds that 70% of security defects are m... by ralls_ebfe on Sunday May 24, 2020 @04:07AM (#23290005)
This, or a union of access rights in a case where roles may be defined in a database.
Re:Chromium project finds that 70% of security defects are m... by pvg on Sunday May 24, 2020 @05:40AM (#23290385)
Not to mention the countless high-profile security holes that have nothing to do with memory safety

I'm not sure this is a sensible way to compare - Heartbleed is a memory safety bug and is a bigger bug than the rest of the ones you've listed combined. The various terrifying nameless iOS exploits that have had actual real-world, documented usage are not clever crypto protocol bugs with catchy names, either.

Re:Chromium project finds that 70% of security defects are m... by fpoling on Sunday May 24, 2020 @02:31AM (#23289611)
OpenSSH focuses on security and correctness, not performance. That allows to use simple idiomatic C. Still, as with Chromium, it does use process isolation to mitigate memory-safety bugs.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:03AM (#23290471)
Meltdown & Spectre is actually consequence of C, Intel adapted their CPUs to emulate the architecture that C implements, so you as developer can still believe that you are working close to the metal. However modern CPUs are very complex so the abstraction was leaky, thus bugs.

This is why we have to abandon C, not only is the language unsafe, it has also driven hardware manufacturing to a bad state with a reinforcing feedback loop, the more C we write the more hardware manufacturers want to make you believe that we still are working on PDP-11.

Re:Chromium project finds that 70% of security defects are m... by amqpp on Sunday May 24, 2020 @11:06AM (#23292002)
Not only that, C is solely responsible for the October revolution and WWII. C was Pol Pot's favorite language and is reportedly used by the Taliban.
Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @11:53AM (#23292364)
Big if true :-)

But here is a great article

https://queue.acm.org/detail.cfm?id=3212479

Re:Chromium project finds that 70% of security defects are m... by SomeoneFromCA on Sunday May 24, 2020 @02:21PM (#23293427)
A very odd article. Everything that said applies to any other compiled programming language, not only C. Even if Pascal or Ada had become more popular than C/C++, it would still have lead to the same architectural decisions we see in x86. In fact the biggest offender - SMT is actually the opposite of instruction-level parallelism the authors are blaming the x86 for.
Re:Chromium project finds that 70% of security defects are m... by fluffything on Monday May 25, 2020 @02:47AM (#23298644)
Chromium, Mozilla, and Microsoft have posted studies that attribute ~70% of their security vulnerabilities to memory safety.

I'm not sure which point you are trying to make, but yes, 100%-70% = 30%, i.e., there are many security vulnerabilities in Firefox, Chrome and Windows that are not attributed to memory safety by these projects, and preventing memory unsafety wouldn't remove all of them (at most "only" 70% of them).

Nobody is claiming here that fixing memory unsafety in software fixes hardware bugs, nor anything about OpenSSH or other projects, and your anecdotes do not show how many security vulnerabilities are caused in those projects due to memory unsafety.

Re:Chromium project finds that 70% of security defects are m... by fetbaffe on Sunday May 24, 2020 @06:27AM (#23290567)
If Wordpress had been written in C there would probably be even more security vulnerabilities.
Re:Chromium project finds that 70% of security defects are m... by asjw on Sunday May 24, 2020 @11:27AM (#23292169)
WordPress Is written in PHP which is written in C