News for hackers. Stuff that matters.
Re:Chromium project finds that 70% of security defects are m... by reubenmorais on Sunday May 24, 2020 @01:07AM (#23289273)
> C++ does sort of have a safe subset.

I see this claim all the time, but can you give some examples of large C++ projects that don't constantly struggle with memory safety issues? (And are looking for them, of course.)

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @01:33AM (#23289374)
The problem is enforcing that safe subset.

It only works when everyone plays balls and doesn't do C style coding, ever.

Usually that can work in small teams with security minded individuals but it isn't a given.

And then there is the little fact that on most surveys, the amount of answers referring any kind of static analysis tooling are usually around 50%.

What C++ has definitely going for it, is having the type system tools to write much safer code than plain old C.

However its copy-paste compatibility with C is also what hinders any attempt to force people to actually only use those better features.

The only way to fix this is having systems programming languages being adopted that aren't C at copy-paste level.

Other would be some kind of Safe C, but both WG14 and C community in general have voted against such improvements.

Re:Chromium project finds that 70% of security defects are m... by anlq100 on Sunday May 24, 2020 @06:30AM (#23290579)
It has nothing to do with C style coding. The worst offenders are the latest and greatest features, as described brilliantly in this very thread:

https://news.ycombinator.com/item?id=23290030

I would argue that the closer you stay to C while using the good features of C++, the safer the code is.

And obviously well written and debugged C code is nearly always more robust than C++ code. But for ideological reasons most people here are unable to acknowledge that, perhaps because they cannot do it.

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @06:38AM (#23290612)
Quite on the contrary, the worst offenders are:

- implicit conversions

- decays from enums to integers

- implicit conversiosn from integers to unexisting enums

- no bounds checking

- implicit conversions between pointers and arrays

- no proper way to ensure a given array length is valid as part of a function parameter

- null terminated strings, that occasionally aren't terminated

- abusing null terminated strings with clever algorithms, e.g. strtok()

- the preprocessor

- const that isn't really const

- variable arguments that require getting the macro type arguments

- UB explored to the last possibility of code optimization

- no safe way to deal with output parameters

- typedef don't introduce strong typing

All of that came from C, not C++.

Re:Chromium project finds that 70% of security defects are m... by why_bother100 on Sunday May 24, 2020 @07:05AM (#23290719)
> implicit conversions

Manageable in C. Integer conversions are only a tiny fraction of all the other implicitness in C++.

> decays from enums to integers

Compiler warns. Recent real compilers like gcc even have exhaustiveness checks like OCaml.

> implicit conversions from integers to unexisting enums.

Compiler warns.

- no bounds checking

Reason about that and implement your own scheme. Or prove.

> implicit conversions between pointers and arrays

Have not seen a single bug due to that in more than 1000000 lines of C.

> null terminated strings, that occasionally aren't terminated

Have not seen a bug due to that, this is the canonical example of an overblown hypothetical threat.

> abusing null terminated strings with clever algorithms, e.g. strtok()

Prove the algorithm or don't use it. Hint: As far as proofs are concerned, NUL terminated strings are like Lisp lists terminated with NIL, hence a well-founded data structure that is easily amenable to proofs (unlike C++ constructs).

- the preprocessor

Rarely introduces anything and is still required for C++, especially in sane test suites.

I don't think all that came from C, things like typedef being an alias rather than a separate type seem much older.

You are again just throwing dirt at C, mocking all people who write actually robust buzzword free software.

You are ignoring that C code is much easier for formal proofs that C++ code (the kind that you advocate).

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @07:17AM (#23290763)
You are ignoring 32 years of proven C exploits since Morris worm introduced in 1988, UNIX kernel exploits, including those that Linux collects every year, which lead to Microsoft (Azure Sphere), Google (Android 11), Apple (iPhone X) and Oracle (Solaris SPARC) enforcing hardware memory tagging.

Which happen to be written in C with several layers of code review and static analysis.

So by your reasoning those 32 years have not happened, in spite of being so easy to prevent exploits in C code.

Yeah, right.

Re:Chromium project finds that 70% of security defects are m... by mmmNZ1 on Sunday May 24, 2020 @07:34AM (#23290820)
Oh, poor Microsoft is forced to use bad bad C-Linux on their Interweb service!

All while their own industrial strength C++-OS (according to you) never has any exploits.

The fact that you are singling out Linux shows that you are only interested in throwing dirt.

Re:Chromium project finds that 70% of security defects are m... by sayusasugi on Sunday May 24, 2020 @09:43AM (#23291453)
Are you joking? Both C and C++ are equally littered with unsafe "features".
Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @01:09PM (#23292901)
I can give you as many UNIX security exploit examples as you feel like having, no need to single out Linux.
Re:Chromium project finds that 70% of security defects are m... by amakk on Sunday May 24, 2020 @01:35PM (#23293103)
It is not about UNIX vs. Linux, it is about the fact that you are always protecting Microsoft, like just now.

I wonder why.

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @05:40PM (#23295071)
Someone woke up in the 90's it seems.

Here is a little tip for you, Microsoft has been acknowledging security issues with C and C++ since the XP SP2 days.

Which is why Windows happens to have plenty of mitigations that only recently FOSS UNIX clones are catching up to.

Yet they have come public that hasn't been enough, hence the migration effort away from C, enforcing programming guidelines with C++ and coming up with plans to migrate to safer systems programming languages.

Guess which OS vendor is now having first party support for writing GUIs in Rust?

But I can also rephrase what Oracle, Apple and Google have stated in the same vein regarding OS security.

Or maybe you prefer the statements of an UNIX hero instead?

Re:Chromium project finds that 70% of security defects are m... by josteink on Sunday May 24, 2020 @03:56AM (#23289944)
> It only works when everyone plays balls and doesn't do C style coding, ever.

If that’s the problem, and solving that would solve all of C++s memory-issues, why have no-one made a compiler option to simply make that code illegal? A -EUNSAFE or whatever?

Re:Chromium project finds that 70% of security defects are m... by pjmlp on Sunday May 24, 2020 @04:24AM (#23290072)
Because what got C++ adopted in first place was its copy-paste compatibility with C.

C++ was also born at Bell Labs, and due to that, all major C compiler vendors quickly started shipping C++ on their boxes as well.

If you take away copy-paste compatibility you might be better off doing D, C# or whatever safe variant already exists.

Which is what many of us have done, to move to type safe languages, and only use C and C++ at the boundaries, in small pockets of unsafe code.

In fact if you look at mobile OSes, that is the reality for app developers, C and C++ are no longer the full stack languages they were 20 years ago, rather used for the kernel, drivers, compositor and shading languages, but everything else happens in safer languages.

And the SDKs only allow you to write libraries, not full applications.

Naturally are clever developers that subvert the workflow and transform the libraries into the actual application.

Re:Chromium project finds that 70% of security defects are m... by the_why_of_y on Sunday May 24, 2020 @06:28AM (#23290568)
Because this would refuse to compile 100% of real-world C++ code, so nobody would use it.

One problem is that C++ can directly include C headers of the operating system, while languages that aren't copy-paste compatible with C have to create some kind of wrapper library for them... this is a major reason for the success of C++, but it also makes improvements of this kind far harder to deploy in practice.

Re:Chromium project finds that 70% of security defects are m... by josteink on Sunday May 24, 2020 @06:47AM (#23290662)
> Because this would refuse to compile 100% of real-world C++ code, so nobody would use it.

So if anyone is claiming you could write real-world safe C++ if you wanted to, they are making a false claim then?

Re:Chromium project finds that 70% of security defects are m... by the_why_of_y on Sunday May 24, 2020 @07:27AM (#23290794)
I think you'd have to do the same thing that you'd do in non-C++ languages: write an abstraction layer that encapsulates the low-level OS access (or hardware access, in embedded software) and whose implementation is unsafe, but whose interface is "safe", whatever that means.

Once you have that to build on top of, such a compiler flag could make sense... if it were possible in C++, which I'm not sure about.

See for example this criticism of one such effort: https://robert.ocallahan.org/2016/06/safe-c-subset-is-vapour...

Re:Chromium project finds that 70% of security defects are m... by josteink on Sunday May 24, 2020 @08:05AM (#23290918)
So in about half a decade the C++ camp has made no improvements wrt to tooling and statically verified safe code, it’s been all talk and no show. And in the meantime Rust has improved massively.

It’s obviously still too early to declare a winner, but to me this sounds like a turtle slowly but surely overtaking a rabbit.

Re:Chromium project finds that 70% of security defects are m... by anlp1kk on Sunday May 24, 2020 @08:06AM (#23290922)
Because you would make many proven algorithms from Knuth or CLRS illegal.

This is never acknowledged by the C++ people: Idiomatic C++ is not suitable for formal proofs, if you don't believe me, ask Xavier Leroy.

Re:Chromium project finds that 70% of security defects are m... by jandrewrogers on Sunday May 24, 2020 @02:52AM (#23289693)
I design high-scale database kernels, large code bases, written in modern C++. I can’t remember the last time we had a memory safety issue. It isn’t as though we don’t have plenty of bugs during development, just not those kinds of bugs. Competent idiomatic code simply doesn’t leave much room for those kinds of bugs to occur. If you “constantly struggle with memory safety issues”, you are doing something fundamentally wrong. That’s not something you can blame on the language.

I am always baffled by the people that supposedly write modern C++ professionally and constantly have memory safety issues. Most serious projects won’t hire you if you aren’t capable of writing memory safe code in your sleep, it is a basic skill.

Re:Chromium project finds that 70% of security defects are m... by AaronFriel on Sunday May 24, 2020 @03:01AM (#23289728)
Is it possible that you haven't found memory safety issues because you haven't been looking for them, haven't been fuzz testing, or haven't had adversarial users of your codebases?
Re:Chromium project finds that 70% of security defects are m... by jandrewrogers on Sunday May 24, 2020 @04:00AM (#23289969)
These are database kernels used for mission-critical things with extreme workload profiles. It has to survive longevity testing at saturating workloads with continuous fault injection. If there were memory safety issues, I think someone would have noticed by now.

The reality is that there isn’t much opportunity for memory safety issues to occur anyway, the type system and scheduler do most of the heavy lifting. Similarly, concurrency safety isn’t much of an issue because threads barely interact. Most high-performance server software looks this way these days.

Bugs tend to be of the boring logic variety that can happen in any programming language.

Re:Chromium project finds that 70% of security defects are m... by AaronFriel on Sunday May 24, 2020 @01:26PM (#23293048)
> These are database kernels used for mission-critical things with extreme workload profiles.

> Similarly, concurrency safety isn’t much of an issue because threads barely interact.

I think the domain you're working in isn't as susceptible to memory safety issues, but that doesn't mean they're not present. It also sounds like they domain you're working in is trivially parallelized if threads "barely interact", which limits your exposure to those memory and data race issues.

If you gave an adversary access to the API of your kernel however, how long do you think before they found a use-after-free, double-free, stack or heap overflow, etc? Days, weeks, or hours?

If you haven't run a fuzzer yet, I wouldn't be so confident.

Re:Chromium project finds that 70% of security defects are m... by saagarjha on Sunday May 24, 2020 @03:20AM (#23289794)
I assure you that the people working on web browsers are in general quite competent and even so often have trouble with memory safety.
Re:Chromium project finds that 70% of security defects are m... by londons_explore on Sunday May 24, 2020 @03:32AM (#23289834)
If you are able to structure your code so there is only ever one construction order for all objects your program uses, and destruction is the reverse order, you're pretty safe for most memory safety bugs.

Sadly as codebases get more complex, that vision gets further and further from reality.

Re:Chromium project finds that 70% of security defects are m... by joshuamorton on Sunday May 24, 2020 @03:12AM (#23289765)
Do you fuzz your code or use something like asan/msan (https://github.com/google/sanitizers)? If not, how do you know that your code is really bug free?
Re:Chromium project finds that 70% of security defects are m... by jandrewrogers on Sunday May 24, 2020 @03:40AM (#23289867)
Far more exhaustive testing than that, these are database kernels. Formal verification of the design and code where it makes sense. Extensive use of the C++ type infrastructure to verify several aspects of correctness at compile-time that would be impractical in any other systems language. The Linux kernel is bypassed for almost everything, most of the schedulers, I/O memory management, etc is in user space like most modern high-performance databases, which actually reduces the bug surface and increases verifiability. It doesn’t have to just be functionally correct, the performance has to be consistent under diverse and adversarial workloads.

No one can know if it is bug free, that is impractical. But it also isn’t like this is a weekend hobby project either. Most of the bugs that get out are in unimportant peripheral code and integrations.

Re:Chromium project finds that 70% of security defects are m... by joshuamorton on Sunday May 24, 2020 @03:53AM (#23289928)
Ok then a followup question: do you use pointers in your code and allocate objects on the heap?

I'm quite curious what tools you're using to formally verify your C++ code if you are. My understanding is that in general you can't, which is why msan/asan exist, to get a first approximation of verifying things that can't be formally verified for most C++ code.

(In general, I'm dubious of these claims that "Most serious projects won’t hire you if you aren’t capable of writing memory safe code in your sleep", because I think if you asked the majority of the members of the C++ committee if they could do that, they'd say no).

Re:Chromium project finds that 70% of security defects are m... by jandrewrogers on Sunday May 24, 2020 @01:14PM (#23292948)
Database engines typically operate within a giant block of memory allocated at bootstrap which is used quite differently than a heap. Mutable references to the address space necessarily exist outside the address space, which presents problems for conventional memory safety models. There are also no pointers per se because almost all memory is directly paged -- objects have no fixed memory address over their lifetime. Most shops use a thin wrapper that implements a pointer-like interface (in the style of std::unique_ptr) that hides the paging and scheduling mechanics. The scheduler design, which is where most of the safety and guarantees that resources can't leak happens, is often verified with a model checker. It is perfectly safe to hold an arbitrary number of concurrent mutable references to an object because safe execution will be resolved dynamically at runtime (which is cheaper than it sounds). There are container libraries designed to work seamlessly in this type of memory model. To a developer writing code against this abstraction, it feels similar to a garbage-collected concurrency-safe language. No locking, no resource management. The abstraction isn't general purpose but it works very well for the kinds of data infrastructure applications where people use C++.

In many of these systems it is standard practice to generate arithmetically limited types pervasively. This is almost transparent in C++17. While it is possible to verify much of this at compile-time in theory, it almost never is because it isn't worth the effort (C++20 may start to change this) and testing at runtime has proven to be nearly as good. People underestimate what is possible with the C++ type infrastructure in this regard.

This type of software design was originally done because it allows for exceptional performance but has become popular for safety reasons. It uniquely allows you to make guarantees about runtime behavior under diverse adversarial workloads that would otherwise be difficult to make.

Bugs in practice tend to occur at the interface with third-party code, which requires dropping out of any internal type system, or in the form of performance anomalies due to unexpected hardware behaviors interacting with the scheduler design. Logic bugs in the core bits tend to be found in testing.

Re:Chromium project finds that 70% of security defects are m... by joshuamorton on Sunday May 24, 2020 @01:21PM (#23293000)
Right, so you're working in a very particular style of application. The style of programming you're using doesn't work for most software and dodges the source of some memory safety issues.

Presuming that this style works equally well for all software seems presumptuous and perhaps naive, does it not?

Re:Chromium project finds that 70% of security defects are m... by ssvss on Monday May 25, 2020 @11:49AM (#23302218)
Do you know of any open-source code architected in the way you explain above. Have you looked at Scylladb codebase, do you know if it is architected this way.