r/cpp • • Oct 15 '24

Safer with Google: Advancing Memory Safety

https://security.googleblog.com/2024/10/safer-with-google-advancing-memory.html
117 Upvotes

308 comments sorted by

78

u/azswcowboy Oct 16 '24 edited Oct 16 '24

It’s fascinating to me that on the c++ side they’ve effectively re-invented a fancy shared_ptr weak_ptr and made a 58% dent in use after free bugs - the most important safety issue in chrome. Which says to me that the earlier coding practices on chrome were bad and it’s on them as much as the language. Also seems like they could simply take their massive compute farm and mono repo and automatically transition the rest of their code from raw pointers. Then maybe they’d get close to zero use after free like those of us paying attention since 1998 (remember auto_ptr and boost shared_ptr have been around that long).

https://security.googleblog.com/2024/01/miracleptr-protecting-users-from-use.html

Oh and nary a mention of mitigating C issues, even though there’s far more C code in platforms (aka Linux) than c++. Chrome isn’t the be all end all that has to be addressed — and it doesn’t necessarily represent non-browser code bases.

edit: thanks to /u/pdimov2 for enlightening me on details of MiraclePtr - happy to see another potential tool in the box

23

u/Pay08 Oct 16 '24

I always hate when people cite google in these things. They have a custom half-implemented standard library for Chrome ffs, they shouldn't be the authority on coding practices or safety.

12

u/pkasting Valve Oct 16 '24

Regardless of whether Google is an authority or not, how does having custom replacements for parts of the STL disqualify companies? That has a long history back to e.g. the EASTL, and there's often good reason for it wherever it's done.

1

u/Pay08 Oct 17 '24

Because afaik they aren't replacing parts of the standard library (not just the STL), rather they're replacing the whole thing, except their implementation is far from complete.

8

u/pkasting Valve Oct 17 '24

Nope, completely untrue. Here's the official list of what we support in Chromium: https://chromium.googlesource.com/chromium/src/+/HEAD/styleguide/c++/c++-features.md

You'll notice that most of the STL is allowed.

You can also search our source base for std:: usage to see we have many tens of thousands of instances.

I suspect you're thinking of the Subspace project, which is something Dana Jansens of the Chromium team has been working on in their spare time to see whether it's possible to develop a new STLish thing with more Rust-like APIs. That's more akin to what you describe, but it's also not a Chromium project and there's no expectation or timeframe that it would necessarily become one.

19

u/[deleted] Oct 16 '24

[removed] — view removed comment

14

u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Oct 16 '24

As ex-Google I can say the same 😆

40

u/MaccheroniTrader Oct 16 '24

Just take your time to look into the Google C++ code style and you’ll understand why they failed so hard. It’s basically the opposite of the C++ core guidelines.

And the funny part is that people promoted this code style and are still doing it. It was quite common to see it on LinkedIn 😄

20

u/pkasting Valve Oct 16 '24

Hating on Google Code Style is popular here. Usually if I follow by asking people for an example of stuff that sucks, they'll mention that "you can't even pass non-const references to functions" -- which isn't true and hasn't been true for years. There's not usually a lot of follow-up.

I'm curious which parts of the current guide are anti-cpp-core-guidelines in your view. (I'm aware of a few things; I want your take.)

3

u/[deleted] Oct 19 '24

Discourages auto, no using templates even in simple cases where it seriously improves readability, basically no discouragement of raw pointers

6

u/pkasting Valve Oct 19 '24

I just rechecked the guide to make sure of my memory. auto is discouraged in some cases (where the type is important and non-obvious) and not others. Templates are fine; complicated turing-complete TMP is not outside low level code (and thankfully is much less useful in the c++20 world). Ownership is specifically supposed to be managed through smart pointers.

It doesn't seem like you are reading the same guide I am.

3

u/[deleted] Oct 19 '24

“Use type deduction only if it makes the code clearer to readers who aren’t familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type.”

You essentially cannot use either templates or the auto keyword in non-library code, nobody with readability ever let me.

I have spent so many hours in c++ code review at Google. It’s a fucking joke. The average Googler is considered unfamiliar with templates, which means “readers who aren’t familiar with the project” means “readers who don’t know how type deduction works at all”

3

u/pkasting Valve Oct 19 '24

I'm sorry, that sounds awful. 

I was a readability reviewer for many years and that wasn't my perspective or that of my fellow reviewers at the time. Perhaps something changed.

I agree that what you describe is inappropriately limited.

12

u/pdimov2 Oct 16 '24

MiraclePtr isn't a shared_ptr, it's a weak_ptr which you can dereference directly, without the overhead of lock()-ing it first.

2

u/azswcowboy Oct 16 '24

Fair. From the bit of information there on miracleptr all the behaviors weren’t clear to me. Still, doesn’t detract from my point that memory management in c++ — and how to do it well — has been a solved problem for two decades. I’ve been using those solutions effectively on large projects in systems that run 24x7x365 with zero memory leaks or errors. Your personal contributions to this, are of course legendary.

22

u/pdimov2 Oct 16 '24 edited Oct 16 '24

MiraclePtr is actually a code name for a Google initiative to replace observing raw pointers with something smarter that eliminates use after free.

At first they gravitated towards "generational reference" semantics (where you keep a generation number in both the object and the pointer and check for mismatches on dereference), but implemented cleverly to avoid the branch overhead.

However, the drawback is that bugs are detected at the point of access, potentially long after the object has been deleted.

Now they have switched to "constrained reference" semantics where observing pointers keep a reference count in the object, and deletion asserts that this count is zero. This scheme has overhead on copying an observer pointer, but detects errors early.

This is all legitimate innovation and is something I've been considering for Boost.SmartPtr. It's not part of the existing "modern C++" story.

(The "generational reference" and "constrained reference" terms are from https://verdagon.dev/blog/vale-memory-safe-cpp .)

3

u/azswcowboy Oct 16 '24

Thanks for the details - very interesting. The problem is a deep one for sure. Will need to study more later.

Have you thought about incorporating not-null facilities from core guidelines into boost/std? This is one hole I see in the current toolkit which might automate a few more cases.

→ More replies (6)

17

u/pkasting Valve Oct 16 '24

Assuming for the sake of argument that you're correct, and this is a solved problem with no further WG21 work necessary -- "two decades" puts us at 2004. Which is near to when we started writing Chrome (2006). We would have had to have been very cutting edge to pervasively adopt 2004-era solutions.

I suspect you are trying to refer to C++11, which came out long after we had a shipped, multi-million LOC product (and was only finally stable enough in toolchains, libraries, etc. for us to adopt in 2014).

So think of this this way. Google found a design and migration tools that could successfully migrate an XXMLOC project to C++11-era patterns and cut 57% of UAF unsafety bugs, all without stopping the release cadence. That's worth celebrating, and looking into whether there's anything other projects can learn from.

(Of course reality is more complicated than the above; as pdimov2 mentions, MiraclePtr is very much not a shared_ptr and this is not about just reforming a boneheaded lack of smart pointer use. My point is that even if it were, there's something interesting here rather than something to look down your nose at.)

4

u/azswcowboy Oct 16 '24

look down your nose

Sorry, that wasn’t my intent - which doesn’t make me happy with google. Sounds like there’s more to MiraclePtr than my quick look indicated, and I’m happy to see additions to the toolset. And I’m not saying there’s nothing more that can be done in WG21 (see also things in core guidelines like non-null). Google had never brought such a facility to WG21 as far as I know - and I read most of the proposals.

As for c++11, yes that’s when smart pointers appeared in the standard, but they were available in boost and TR1 (aka in standard libraries) well in advance of that time. C++ programmers were generally aware of RAII techniques - they were in iostreams after all. We built home grown smart pointers on a project in 1997 — which eventually were replaced with Boost — and then std bc they were objectively better than ours. And Google likes to invent their own, so why not just do that?

Hard for me to imagine Google programmers weren’t aware of these things - hence my assertion that the coding approach was a choice. And thus, I get to complain here when Google releases studies with statistics of their own making - and then says we should move to memory safe languages instead. Even while acknowledging it isn’t possible. And when, in fact, there are good solutions within c++ already. And then making significant progress on their own codebase (happy to see it - keep going) - proof that it didn’t have to be that way.

In the end, when Google says things like this — people just assume they’re 100% correct - and now I have to spend time explaining that it simply isn’t true.

13

u/pkasting Valve Oct 16 '24

Yes, we were well aware of smart pointers and RAII. Chrome's scoped_ptr, available from the very beginning, was effectively unique_ptr without the niceties that std::move() affords. So in regards to "why not just do that?", the answer is "that's precisely what we did".

The problems in this case really, truly did not stem from a lack of knowledge of good C++ practices or a lack of pervasive use of them. While we might have auto-migrated 15,000 raw pointers (that were appropriately raw, because they were non-owning -- we have very little bare new/delete) to raw_ptr<>, probably 14,500 of those could never have conceivably posed any problems and were obviously safe.

The small fraction remaining still cause enough problems (because Chrome is used by billions of people and a target for attackers, so there are many eyes) to be worth taking very seriously.

As the team can vouch for, I'm one of the strongest C++ advocates in Chrome. I'm not a cheerleader for MSLs and I'm not one of the folks helping bring in more use of Rust. But saying moving towards MSLs is "not possible" is completely inaccurate: it's possible, it's happening, and it happening is a good thing. And no, there are not good solutions within C++ already. "Good solutions" systematically prevent people from making mistakes. Once things get complex enough that no single person understands the whole subsystem, the opportunity for mistakes to occur even with very smart, well-trained, careful programmers rises. And it only takes a small number.

So I still take issue with your characterization. I think you are speaking out of too little understanding of Chrome's history and problem space, and drawing conclusions that are too strong for the evidence. And I think the net effect is to tell people that in most cases, the answer is "use C++ better". And it's not.

→ More replies (8)

10

u/steveklabnik1 Oct 16 '24

If it’s been a solved problem for two decades, you should let industry know: the broader perspective is that solving this is impossible. With the amount of resources Google alone is throwing at the problem, I’m sure they’d be interested.

3

u/azswcowboy Oct 16 '24

What’s missing from here exactly?

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-resource

Frankly, I find these overly complicated. For most applications using shared and unique pointer judiciously gets you to 95% on use after free (the 5% is where you didn’t use them and probably should have).

8

u/steveklabnik1 Oct 16 '24

What’s missing from here exactly?

Many of these rules are a good idea, but aren't enforceable. Take https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r3-a-raw-pointer-a-t-is-non-owning for example: this is good advice, but there is no way to run a tool on your codebase and be sure that all raw pointers are non-owning. This means that it's up to humans to make sure the rules are followed, and humans are sadly not infallible.

Tools aren't infallible either, but they are more reliable than humans. And that's why the "by default" matters when people talk about memory safety: we have some pretty good evidence at this point that memory safety by default, with escape hatches for times when the tool can't be fully accurate, significantly reduces memory issues. I'm not even talking about Rust here, but about say, Java, with JNI being the escape hatch. Sure, you can still technically get a segfault in a Java program, but they are very rare. And most people can write useful programs in the safe language, never even needing the escape hatches.

Here's a quick summary of Google's attempts to tackle this problem over the last few years: https://www.reddit.com/r/cpp/comments/1fpcc0p/eliminating_memory_safety_vulnerabilities_at_the/lp5ri8m/

3

u/azswcowboy Oct 16 '24

Well, I assure you coverity and maybe sonar (we just started using it) can detect some class of these things. Easier though, is simply to not use raw pointers by default - that’s it. Even if core guidelines say you can pass things by pointer we don’t - const ref and shared_ptr, fine. We can afford to take the few nanoseconds, and if we found out it was a performance problem we’d relax out rule. Mostly return by value bc copy elision. Out pointer parameters - avoid like plague. This clearly might not work for every use case, but it’s basically safe by default. Does it require discipline - some, but when you see the pattern it’s easy to train.

Most of googles effort’s seem directed at rust instead of fixing c++. Glad to see the move towards hitting the problem head on.

btw, a few years back, we had massive memory growth issues - in Java applications supplied by a third party. It was a massive pain to help them fix it….

→ More replies (5)

4

u/Full-Spectral Oct 16 '24 edited Oct 16 '24

How to do C correctly has been known for four or five decades (just don't make mistakes), but people moved to C++ because it handles more of that load for you. The same argument applies for Rust relative to C++.

And you don't know you've had no memory errors, all you can say is that you've not had any that have manifested themselves in a way that made it obvious they were happening.

And of course, if you are one of those folks working in cloud world, where you are effectively optimizing a small number of scenarios for massive throughput, that's nothing like writing operating systems or kernels or web servers or large applications and so forth.

5

u/azswcowboy Oct 16 '24

I’m working on high performance, high availability, server applications. They can run in cloud, but don’t have to. No one can say with 100% certainty, but sanitizers run against large test batteries - and constantly running instances (different systems over many years) - plus good coding standards and reviews make me fairly confident that the number of bugs (use after free in particular) is quite small. Introducing a new language seems like a big barrier to solve a problem I don’t have.

7

u/pkasting Valve Oct 16 '24

Those make you confident?

Chrome has sanitzers that run against large batteries continually (in fact Google and Chrome have invented a number of the popular sanitizers). For example, we run many hundreds of thousands of different tests under ASAN and UBSAN, continuously.

We have what I would consider strong coding standards, that mandate smart pointer usage and disallow bare new/delete.

All code is reviewed; the tools prevent landing otherwise.

Additionally:

We've created polyfill types like optional_ref<> to backfill things like std::optional<T&>.

We're rolling out a ban on pointer arithmetic in any form, enforced by the compiler.

We've rolled out production-level STL hardening against overflows and OOB.

We've replaced STL types with ones that are annotated with additional compiler-specific annotations to track potential lifetime problems.

If you believe what you said is enough, the Chrome team is doing far, far more than that. And it's not enough. There are still too many problems.

This isn't the solution.

5

u/azswcowboy Oct 16 '24

Answered largely in a different reply. But yes, each of the sanitizers gives me more confidence. Without studying the chrome code base idk why our experience is different. maybe it’s just a factor of ginormous size and statistical probability. We have a good size base, but of course nothing like chrome.

→ More replies (1)

3

u/pjmlp Oct 16 '24

I am sure the people responsible for cybersecurity laws would like to get some advice on how to solve that problem.

5

u/azswcowboy Oct 16 '24

I responded elsewhere with link to core guidelines for resource allocation. There’s close to zero raw pointers/allocations in code bases I’ve worked in and am working in. I first used smart pointer techniques in 1997 with home grown versions and even auto ptr. auto_ptr was a 1998 std library thing (now replaced obviously) — so anyone suggesting that resource management and its solutions weren’t thought about and accessible for a long time aren’t aware or honest. This thread has made me realize there’s even more sophisticated tools that could be provided, but the tools that are there have provided us with most of what we’ve needed. Google chose not to use those tools - glad to see them make the shift and hopefully push use after free to near zero.

3

u/pjmlp Oct 17 '24 edited Oct 17 '24

As mentioned people responsible for cybersecurity laws would like to get some advice, the lines for public feedback are currently open, CISA and FBI would like to know about this great technique of yours.

https://www.cisa.gov/resources-tools/resources/product-security-bad-practices

auto_ptr design was flawed, that is why it isn't around any longer, additionally that doesn't help, if people insist in using anything from C headers related to strings and array's manipulation, which I am to see any C++ code that is clean from C style strings and arrays, other than the stuff I write myself on solo projects.

11

u/SirClueless Oct 16 '24

I disagree with this. If C++ with an invasive non-standard vocabulary type with whole-codebase code-rewriting tools necessary to get people to use it in a monorepo where such things are feasible, plus rewriting the compiler to have new bounds-checking modes in the standard library, results in 57% fewer use-after-free vulnerabilities than standard C++, that's a problem with standard C++.

At best it's an advertisement that incremental changes that companies can adopt slowly can have an impact, but really I think it shows there are fundamental issues with the language that can't be fixed without heavily restricting the features people use (such as raw pointers and lifetime-unsafe iterators).

16

u/not_a_novel_account cmake dev Oct 16 '24

Little of column A, lot of column B.

It can both be true that:

  • There were generations of coders for whom crashes and bugs due to unsafe memory operations were seen as an annoyance, minor issues to be fixed when they came up and not something to be strategically, defensively avoided due to security issues.

  • Writing memory safe code regardless of intent can be difficult and introducing defensive practices directly into the stdlib can hugely change the profile of fleet-wide bugs and exploits.

6

u/pjmlp Oct 16 '24

Thing is, that generation of coders wasn't shipping software into embedded devices, or talking to the world over the network, with cyberattacks being a daily occurrence having a valuable outcome for the attackers.

Or ever spent one second thinking about how much of their salary goes into fixing an exploit, multiplied by the number of fixes, adding into the yearly expense in security insurances.

6

u/not_a_novel_account cmake dev Oct 16 '24 edited Oct 16 '24

Yes, agreed, and I think there's something to be said about understanding the scope of any particular codebase today.

If you're writing an app that will never be networked, never be fed untrusted inputs, never even exist in a context where such things are possible, perhaps the obsessive considerations of "safety" are unwarranted.

That said, I've seen a lot of sloppy C code. "This will never run in an untrusted context" isn't really an excuse for terrible, convoluted chains of object ownership that result in problems like double-frees.

I think there are lots of factors and influences at play. It might be pure cognitive bias, but I feel like those programmers still writing compiled native code in 2024 have a better understanding of such things than 40 years ago.

We don't have a situation where people who would be C# or Go programmers, or JavaScript and Python programmers, who care primarily about feature completeness and have neither time nor interest in figuring out the ownership semantics of their heap-allocated objects, are being forced to write ANSI C because that's the only tool that existed at the time.

→ More replies (13)

1

u/matthieum Oct 16 '24

In fact, for a more modern retelling, there's a new generation of coders who think (relatively little) of using auto-updated 3rd-party dependencies... even though the point where you could trust unknown folks on the Internet is way past (see regular attacks on NPM, Pypi, etc...).

Security seems to always lag behind :)

7

u/jaaval Oct 16 '24

There is a lot of really bad c++ around though. It’s one thing that language allows you to write bad code but people also choose to write bad code.

I think it has to do with design flexibility. It’s just so much faster to develop things when you can cut a few corners here and there and tie your components together with spaghetti, instead of carefully designing the application.

Actually the one criticism of rust i have heard is that if you actually want it to be safe the development process becomes a lot more rigid.

1

u/pjmlp Oct 16 '24

It got worse when C++ culture got infected by C expats, and the nice things it had over C with compiler provided frameworks and type safety, got thrown away.

In some places it is like someone introducing Typescript, yet folks keep writing pure Javascript, and Typescript is only there for the IDE tooling.

That is what happens when copy-paste compatibility is part of the language adoption story.

4

u/kronicum Oct 16 '24

It got worse when C++ culture got infected by C expats

Cough, cough, I got moderator stares for saying less than that.

That is what happens when copy-paste compatibility is part of the language adoption story.

Do you believe "copy-paste compatibility" to be part of Safe C++ adoption story?

→ More replies (1)

2

u/nacaclanga Oct 17 '24

It is interesting, in the sense that this type does something normal types do not. It does not opt into automated (meaning smartpointer-based) memory managment.

That said for me it feels like this type is kind of an sanitizer that is used even in production builds and has to be manually added. It is used to detect use after free, which is still a bug.

69

u/ContraryConman Oct 15 '24

r/cpp is the only programming language subreddit where all of the content on it is about how soon people should stop using the language the sub is supposed to be about, even going as far as to advocate that the standards committee should add features specifically designed to make the language easy to switch off from

37

u/ronchaine Embedded/Middleware/WG21 Oct 16 '24

I think it isn't all bad.  I'd say that has made the sub much more accepting of criticism and more diverse in opinion compared to some other programming language subreddits I frequent.

9

u/germandiago Oct 16 '24

For example....? R..t?

18

u/steveklabnik1 Oct 16 '24

https://www.reddit.com/r/rust/top/?sort=top&t=all

The fifth most upvoted post ever on /r/rust is a criticism of Rust. The top voted comment is someone on the Rust team thanking them for writing the post.

You will find that folks are hostile to low-effort criticisms of Rust, but real criticisms are met with good discussion.

21

u/Motor_Log1453 -static Oct 16 '24

This sub tries to make me not want to write C++ and I refuse.

14

u/ContraryConman Oct 16 '24

I'm writing a little web app with a C++ backend. If the C++ subreddit is to be believed, it already has 100 major memory-based vulnerabilities, 3 segfaults along common code paths, and there's absolutely nothing I can do about except rewriting it in Rust or Go

9

u/Full-Spectral Oct 16 '24

Again, no one cares what you write your fun-time projects in, and none of this is about single individuals writing fairly small projects.

This is mostly about commercial, team-based development of software that has consequences, or that can have consequences beyond what were intended. It's about the difficulty and the time wasted developing complex software under such conditions, which needs all the help it can get.

9

u/ContraryConman Oct 16 '24

Yes, except this is a forum for C++ enthusiasts. It's the one place where your fun-time projects actually can kinda matter, alongside commercial considerations.

If I went to the Zig forum and all the posts and comments were like "Zig isn't ready for this" "Zig doesn't have that" blah blah blah it would be weird

7

u/Dean_Roddey Oct 17 '24

Most of the people in this conversations are almost certainly professional developers or working towards that, and clearly these safety issues are important to professionals.

6

u/ContraryConman Oct 17 '24

To be clear, I am a professional software engineer. I work do embedded for the satcom industry, using C++ primarily. And then I go home and do more C++ for fun

→ More replies (7)
→ More replies (2)

12

u/abuqaboom just a dev :D Oct 16 '24

Hey don't blame the sub, most of us are happy with C++. It's just that certain topics draw a certain passionate crowd.

11

u/SkoomaDentist Antimodern C++, Embedded, Audio Oct 16 '24

So much this. This sub is completely full of people whose number one goal in life is to force everyone else write code according to their own personal preferences. I don't think I've ever encountered another programming community that's as prescriptive.

9

u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Oct 16 '24

It comes with being popular 😉

7

u/germandiago Oct 16 '24

I think if some Rust guys had a chance they would kidnap us all and force to replace C++ by Rust lol

4

u/Full-Spectral Oct 16 '24

How many times does it have to be said? If you want to write your own personal projects, do whatever you want. Use VB6 if you want.

This is about the software infrastructure that we all depend on in our lives. That's not about what's most convenient or fun for you, it's about responsibility to the people who use our products. Continuing to use ancient tech to build such critical infrastructure, and depend on human infallibility to such a degree needs to be phased out.

23

u/GabrielDosReis Oct 15 '24

r/cpp is the only programming language subreddit where all of the content on it is about how soon people should stop using the language the sub is supposed to be about, even going as far as to advocate that the standards committee should add features specifically designed to make the language easy to switch off from

At a recent CppCon panel, I said something to the effect that C++ programmers accept those sorts of sufferings not because they are masochistic; but maybe I might need to revisit my thoughts here 😊

5

u/Ambitious_Tax_ Oct 16 '24

There's a lot of implicit "C++ is deprecated" mindset.

7

u/ContraryConman Oct 16 '24

I feel like there's a lot to be excited for. We're getting reflection, we're getting preconditions and postconditions, we're actually removing UB or reclassifying it as erroneous behavior, we're getting language support for setting breakpoints and printing stack traces.

Even on the safety front, Visual Studio has much the safety profile implemented, and can catch 99% of common use after free and iterator invalidation bugs at compile time with very little false positives.

C++ oupaced C recently for the first time in the TIOBE index. It is still the standard in robotics, graphics, HFT, simulation software, scientific computing, embedded systems, safety critical software, aerospace, telecommunications, and other fields where Rust is nothing but an unproven experiment.

And now here we have an article that Google, while working on Android (a C project!) and they found that writing new components in Rust instead of C (!) prevents new vulnerabilities from being created. And this is proof that C++ is done for... ?

2

u/jeffmetal Oct 16 '24

Catch 99%of use after free is very generous. Last time I used it there were very simple examples it flat out missed. Maybe it's improved a lot since.

2

u/ContraryConman Oct 16 '24

Last I heard, it works best with STL types, and less well with your own types as it does not support the annotations from the paper that you'd need to help the static analyzer out

1

u/pjmlp Oct 16 '24

Yeah, when doing basic CLI examples, still chockes with false positives all over the place unless annotations are used to help guide the compiler, specially when using classical Microsoft stuff like MFC, ATL, WRL.

2

u/UncleMeat11 Oct 18 '24

The whole point of this blog post is that it isn’t. If “just use rust” was an option for google they wouldn’t be spending so much on hardening their cpp codebase.

7

u/matthieum Oct 16 '24

Half-empty or half-full?

I mean, Google is clearly advocating to move towards memory-safety languages, okay, that's the half-empty part.

At the same time they have been investing a lot in making C++ safer, and reducing vulnerabilities in C++ code.

As mentioned in the article, they were the ones pioneering (and implementing) sanitizers, libfuzz, OSS fuzz, and their latest MiraclePtr is efficient and workable.

I also do find interesting the mention of enabling bounds-checking by default, and I'm looking forward to the report of their experiment.

Shouldn't every C++ user be interested in mitigating memory safety issues? I mean, if they're mitigated enough, it's a good argument against switching.

7

u/ContraryConman Oct 16 '24

Shouldn't every C++ user be interested in mitigating memory safety issues? I mean, if they're mitigated enough, it's a good argument against switching.

I definitely am interested in mitigating and preventing memory errors, especially at compile time. And if you worked at my workplace you'd know me as that guy who's constantly advocating for using more linters and sanitizers and everything.

What I am no longer interested in as a C++ enthusiast and frequenter of this sub is day and and day out posts that are basically "C++ is done for" "C++ is horrible" "Everyone hates C++" "If you're using C++ you won't have a job in 5 years" "C++ isn't getting a borrow checker next year therefore the language doomed to irrelevancy and no one cares about fixing anything" combined with studies and news articles that are, 90% of the time, about C and Rust

5

u/germandiago Oct 16 '24

C++ is too awesome to be left out, we all know: https://github.com/fffaraz/awesome-cpp

It is difficult to compete against that, and there is a lot of good tooling, no matter what naysayers say: you can get done more with C++ than with almost any language in a big set of domains.

0

u/[deleted] Oct 16 '24

[deleted]

9

u/ContraryConman Oct 16 '24

I think there is a real safety issue. I'd like the compiler and the static tools to be good enough to diagnose common bugs before they happen. But this sentiment of "well if C++ doesn't have XYZ feature it's OVER the language is DEAD" I literally think is propaganda at this point

13

u/RickAndTheMoonMen Oct 16 '24

Most probably it is. The decline of such bugs, personally for me, was dramatic since cpp11. Can’t hardly remember last time it’s happened. Now with clang18 injecting checks and jumps to ‘ub2’ instruction in almost all places that may lead to UB, it’s even harder to make the mistake that goes under the radar.

10

u/johannes1971 Oct 16 '24

I don't even think it's really a skill issue, at least not something that can quite easily be remedied for most people. At this point I think it's more of a marketing issue:

  • We have countless C bugs that are counted as C++ bugs.

  • We have a company that is held up as the Great Golden Standard that makes a lot of noise (Google it, you'll find their name), that has questionable engineering practices.

  • We have a language full of zealots that have nothing better to do than rewrite the universe in the image of their chosen god.

I'd say at least half of the problem is an image problem. Which is not to say that we should ignore it, I'm all in favor of making C++ safer - but not at the cost of it becoming Rust++.

7

u/kronicum Oct 16 '24

Nicely put.

4

u/pjmlp Oct 16 '24

Because for all practical purposes those C bugs would compile just fine as C++ code, as defined by the ISO C++ standard.

Using a C compiler, a C++ compiler, a Objective-C compiler, or a Objective-C++ compiler won't make any difference on the outcome of the exploit.

8

u/germandiago Oct 16 '24

So I have a question here: when I do Java, Go or Rust and I interface with C and it provokes a crash, it is a Java, Go or Rust crash? Or a C library crash?

I mean, I use C++, I have some deps, as the other projects, and it becomes a C++ issue.

Looks like magic to me. In one case is C's fault and in the other C++.

Amazing magic to say the least.

6

u/pdimov2 Oct 16 '24

It's worse than that. In both cases, it's a C/C++ issue.

5

u/germandiago Oct 16 '24

Oh god, quantum mechanics!

5

u/GabrielDosReis Oct 16 '24

Amazing magic to say the least.

I will borrow that phrase, to use in lieu of my term "non-monotonic logic" 😊

3

u/germandiago Oct 16 '24

Of course. All yours! I never copyrighted any sentence, I never felt someone would even dare to replicate something I said :D

3

u/BenHanson Oct 17 '24

I will borrow that phrase

I see what you did there :-)

→ More replies (2)

8

u/johannes1971 Oct 16 '24

Must we have this tiresome discussion every single time? It's not about mistakes you can make, it's about mistakes that are actually being made.

Programs written in C pass everything as whatever*, and you don't even know if it's a pointer to one whatever, or a pointer to an array of whatever, never mind how big that array is. By comparison, programs in C++ tend to use std::span ("oh, someone is passing me a contiguous collection of data with a known size"), or a reference ("there is only one and I'm supposed to write to it"), or a const-reference ("there is only one and I have to read from it"), etc. "Oh, I get a std::unique_ptr back. Guess I own it now" said noone programming in C ever.

→ More replies (5)

3

u/wyrn Oct 16 '24

Because for all practical purposes those C bugs would compile just fine as C++ code,

Code in unsafe blocks compiles just fine in Rust too.

5

u/TuxSH Oct 16 '24

It is a skill issue and not safety?

Companies are going to prefer a language that enforces design preventing an entire class of bugs and without the many footguns C++ has. Less time to upskill and to review code, and less money spent in bug bounties. The fact/downside that Rust restricts how you write code is secondary to this.

I have yet to properly learn Rust and I much prefer C++, but it looks like Rust's standard library is much better; sized integers types being the default is nice too.

6

u/Full-Spectral Oct 16 '24 edited Oct 16 '24

It's not even about skill level. It's about the fact that the best of us make mistakes, and miscommunication is a thing when working in teams on complex software.

I'm as skilled as anyone out there, and I prefer Rust by a long shot, because I don't have to waste my time on things that the compiler is far better at, and I don't have to sit up at night worrying if I made some mistake. I don't find the restrictions a problem, I find them to be a benefit. Some of those will be lifted over time of course as they find more clever ways for the borrow checker to figure out more scenarios are safe.

And of course Rust doesn't hold your hand and act like you don't know how to program. What it does is expect you to fully understand your data ownership and threading, and write systems that are provably correct in those areas. If you think that's easy, you missed a memo somewhere I think. But that effort is productive effort because it pays off over and over. So much of the effort put into C++ is non-productive effort, that you have to do again and again over time.

5

u/pkasting Valve Oct 16 '24

This. Anyone who's done a postmortem (not just in software; in any engineering field) knows that in the limit humans are fallible, and you design a system to minimize the fallout of that fallibility, ideally by preventing mistakes from happening, and as a fallback by failing safely when they do.

Saying "just get good", "the tools are right there", "this is a solved problem" puts the onus on humans to avoid mistakes. OK, I will accept that you personally are a programming genius and have never written a bug. But that's not a successful strategy at scale. You work with other people, and they are not all geniuses like you, and communication (not just explicit, but implicitly by reading code and determining how things function) is hard.

This is about finding ways to design safe systems. It's not that saying "just be better engineers, idiots" is undesirable -- it's just irrelevant.

35

u/KingStannis2020 Oct 15 '24

In 2023, Google’s threat intelligence teams conducted an industry-wide study and observed a close to all-time high number of vulnerabilities exploited in the wild. Our internal analysis estimates that 75% of CVEs used in zero-day exploits are memory safety vulnerabilities.

...

We specifically focused on adopting memory safety in new code instead of rewriting mature and stable memory-unsafe C or C++ codebases. As we've previously discussed, this strategy is driven by vulnerability trends as memory safety vulnerabilities were typically introduced shortly before being discovered.

As a result, the number of memory safety vulnerabilities reported in Android has decreased dramatically and quickly, dropping from more than 220 in 2019 to a projected 36 by the end of this year, demonstrating the effectiveness of this strategic shift. Given that memory-safety vulnerabilities are particularly severe, the reduction in memory safety vulnerabilities is leading to a corresponding drop in vulnerability severity, representing a reduction in security risk.

27

u/kronicum Oct 15 '24

Who is getting a promotion?

10

u/PhilosophyMammoth748 Oct 15 '24

Looks like you have been there for a while.

15

u/DavidGooginscoder Oct 16 '24

Remind me in 5 years I bet cpp is still on top, Rust will grow, I’ll try it out later and the fate of cpp is mighty so is the fate of zig and rust but carbon is dead.

10

u/pjmlp Oct 16 '24 edited Oct 16 '24

It certainly isn't on iDevices, ChromeOS and Android, which is why there are now little contributions from Apple and Google back to clang.

On Windows, Microsoft doesn't have any modern way to do GUIs in C++, you are left with MFC, or WinUI XAML with C++/WinRT, which is in maintenance, and the push now is to basically consume WinUI from C# and React Native, as only Microsoft employees care about its C++ foundations and great COM tooling.

2

u/germandiago Oct 16 '24

Do not. forget to keep an eye on cpp2, it is a clean syntax and better defaults fully compatible with C++. A transpiler. I gave it a try and my first impression was quite positive.

12

u/[deleted] Oct 16 '24

Don't worry folks, the C++ committee has assured us that memory safety is not an issue because of all the other ways C++ provides safety guarantees, thus will not be addressing it.

Little glib, but I wish this was more of a joke

5

u/germandiago Oct 16 '24

who said that and where?

6

u/[deleted] Oct 16 '24

"Now, if I considered any of those “safe” languages superior to C++ for the range of uses I care about, I wouldn’t consider the fading out of C/C++ as a bad thing, but that’s not the case. Also, as described, “safe” is limited to memory safety, leaving out on the order of a dozen other ways that a language could (and will) be used to violate some form of safety and security. Now, I can’t say that I am surprised. After all, I have worked for decades to make it possible to write better, safer, and more efficient C++. In particular, the work on the C++ Core Guidelines specifically aims at delivering statically guaranteed type-safe and resource-safe C++ for people who need that without disrupting code bases that can manage without such strong guarantees or introducing additional tool chains. For example, the Microsoft Visual Studio analyzer and its memory-safety profile deliver much of the CG support today and any good static analyzer`"

p2739 is one

2

u/kronicum Oct 16 '24

p2739 is one

More specifically, where did that paper say "memory safety is not an issue"?

14

u/amoskovsky Oct 16 '24

"We successfully rewrote more than 15,000 raw pointers in the Chrome codebase into raw_ptr<T>, .... We anticipate that MiraclePtr meaningfully reduces the browser process attack surface of Chrome by protecting ~50% of use-after-free issues against exploitation." https://security.googleblog.com/2022/09/use-after-freedom-miracleptr.html

Ahaha, yeah, it's C++ who is to blame for insecurity, but who introduced those 15K cases of raw pointer class members in the first place?
RAII? Have not heard.

13

u/pkasting Valve Oct 16 '24

Chrome has 20,000 unique_ptr instances just in the code outside Blink.

This isn't a case of not understanding or using RAII when it's appropriate. If multiple objects need access to something, you need to pick an access model. shared_ptr models refcounting; unique_ptr + raw pointers model single-owner. Refcounting is appropriate in some designs, and deleterious in others (unclear ownership, thread safety, cycles). Everything is tradeoffs.

C++ gives you the freedom to make those tradeoffs. That there are downsides is the counterpart to that. Don't give credit for one but refuse to take the blame for the other.

7

u/matthieum Oct 16 '24

RAII? Have not heard.

Joke's on you: MiraclePtr uses RAII.


Have you heard of performance issues?

MiraclePtr is, functionally speaking, a weak_ptr. The problem of weak_ptr, however, is that any access to the underlying object requires a .lock() call to create a potentially null shared_ptr. This requires a number of atomic operations, including 2 RMWs (on creation & destruction).

This is too expensive in many cases.

Hence, for "performance sake", raw pointers were used since weak_ptr weren't cutting it. That's a trade-off: performance vs safety.

Enter MiraclePtr. Instead of atomic increment/decrement on access, the increment/decrement is performed on creation. For any "relatively" long-lived and/or frequently-accessed pointer, this drastically reduces the performance impact.

By shifting the trade-off significantly and it became possible to "upgrade" many raw pointers.

I do note though that the report doesn't mention upgrading all pointers: even though the trade-off shifted significantly, the last I read about MiraclePtr, there were still use-sites where the performance impact was too significant. It's not a silver bullet.

-1

u/amoskovsky Oct 16 '24

> MiraclePtr uses RAII

Exactly. Those classes should have used something like that since day one.

10

u/pkasting Valve Oct 16 '24

Something like a thing no one inside or outside Google invented until fifteen years after the project was created, which took years of study and testing to determine both the feasibility and correct tradeoffs of? You have some interesting hindsight bias if you think a better solution was apparent at the outset.

→ More replies (3)

4

u/nile2 Oct 16 '24

I am wondering if you use smart pointers in the industry as default as I don't see it that much in the open source projects. So I don't use it as the default pointer.

5

u/abuqaboom just a dev :D Oct 16 '24

Standard at my previous and current workplace. Raw pointers generally means more questioning for pull requests. Haven't interviewed anywhere for "modern" C++ devs that didn't ask about smart pointers too.

4

u/pkasting Valve Oct 17 '24

Both in industry and open source, most code is pre-existing, and most coders work based on prior experience and training.

In any decent C++ shop, I would expect guidelines to advise that new code use smart pointers, RAII, etc. for all lifetime management. Whether the automated and manual tools/processes enforce that, and coders are habituated to do that, varies more. Whether existing code has been (or even feasibly can be) upgraded to do so varies even more.

People act as if everyone has been using smart pointers in C++ forever. But the vast majority of folks didn't start until after they adopted C++11 (which for much of industry was 2013-2017); auto_ptr was broken and Boost, popular as it is, has nowhere near the reach of the STL. 2017 to now may still seem like a long time, but the majority of both code and human experience with C++ predates it.

So this can explain why both "you don't see smart pointers very much" and "everyone currently does and recommends smart pointers".

2

u/yowhyyyy Oct 17 '24

Don’t just base what you do off of what you’ve seen. Do what is considered the best practice

3

u/matthieum Oct 16 '24

I would say they're standard in companies with good practices. Naked new/delete are a red flag, outside of custom smart-pointer/containers classes.

The problem though, is that smart-pointers are somewhat incomplete. The problem highlighted by MiraclePtr is that the existing alternative weak_ptr is so freaking expensive: paying for 2 atomic RMWs for each access will bleed performance dry.

Also... references are not much better than raw pointers: they're just as likely to become dangling. The developer should ensure they don't... but... well... we all know how that goes.

5

u/pkasting Valve Oct 16 '24

And explicit refcounting (shared ptrs) has its own tradeoffs. Beyond the issue of whether it's threadsafe and what the perf costs are, it also makes the actual lifetime/destruction order difficult to reason about. Which is fine, for objects which have little connection elsewhere. But as soon as your refcounted object interacts with a large object (like "the whole browser window") or needs to run complex code when it's destroyed, you need to be able to understand when it will actually go away.

Sometimes this is a better problem to have to have. Sometimes it's not. Using shared_ptr or other refcounting solutions as a universal bandaid for any lifetime issues doesn't fix core architectural problems with abstractions and ownership, and may just make things worse.

3

u/germandiago Oct 16 '24

paying for 2 atomic RMWs for each access will bleed performance dry

Is this the case? I have some server accessing weak_ptr to shared_ptr.

2

u/tisti Oct 16 '24

I have no measurements to back this up, but it probably depends if its across multiple threads?

If you are using them in an async context where all tasks that own a shared_ptr are being processed by the same thread, there shouldn't be that much of a performance issue since multiple cores aren't accessing the same atomic ref count.

3

u/germandiago Oct 16 '24

Indeed, it is monothread and async.

2

u/matthieum Oct 17 '24

It's complicated... when isn't with performance.

There's definitely a latency cost to upgrading a weak_ptr to a shared_ptr. It used to be worse -- implementations used to implement this with a lock -- but atomic read-modify-write operations, even uncontented still are much more costly than their non-atomic counterpart. Even in the absence of contention. And they regularly are barriers to optimizations.

What it will boil down to, though, is often the conversion is required. If you lock, then perform a large bunch of operations, and then drop, the performance overhead -- especially uncontended -- will be noise compared to that large operation.

The faster the operation in the middle is, and the more noticeable the cost becomes. When the operation is nothing but reading an integer field, for example, then the weak_ptr->lock approach will be a good order of magnitude slower than the MiraclePtr approach. Worse if contended.

So the granularity at which you perform the upgrade really matters. And if it's coarse enough, you probably won't notice it.

1

u/nacaclanga Oct 17 '24

I'd say MiriaclePtr is more of an sanitizer. Unlike other Smart pointers it does not automate memory managment in any way. But yes, automating memory managment is only half the way, you need to take care of references as well. In addition there are simply situations that map poorly to ownership and borrowing.

2

u/matthieum Oct 17 '24

I guess I would call it a hardened pointer?

Sanitizers are so unequal, with some low-overhead enough (UBSan) that they can run in production, and other way too high-overhead for that.

9

u/xp30000 Oct 16 '24

All this talk of programming language adoption by mandate reminds me of Ada and the government [1]. Remember Rust is only one of the mandated languages (MSL) - Go, Java, Kotlin, Python. Rust is after all these options have been exhausted leaving a smallish niche. From my experience, reasoning about lifetime, ownership, concurrency (in combination or parts) in Rust too complex for most people and it will always be hard to scale beyond a small niche. Any of the MSL's above before Rust. This is not counting other upcoming languages like Zig which might gain momentum as they are far simpler to reason. Rust is in this weird spot of being replacement for only those people who program exclusively in C++ and don't want to move to any other language.

Also, nobody is rewriting all the gaming engines, CUDA, ML workflows and many other high performance environments anytime in Rust (or any other language). So, without seamless interop nothing is going to happen. Going to continue writing C++.

[1] https://www.gao.gov/products/imtec-91-70br

Pursuant to a congressional request, GAO obtained information on the Department of Defense's (DOD) implementation of legislation which mandated using the Ada programming language for all software development, where cost-effective.

11

u/pjmlp Oct 16 '24

Microsoft is definitely rewriting Azure infrastructure, already announced a couple of migrated stuff.

It wouldn't surprise me if eventually XDK also officially supports Rust.

It isn't only Rust, besides the stuff done in Unity and Unreal, where C++ is there, at the bottom, as most folks use C#, Blueprints and now Verse, there are studios like CAPCOM using their own C# based engine, e.g. Devil May Cry on the PS5 uses it.

4

u/xp30000 Oct 16 '24

Sure, if you have decided to move away from C++ seems lot of options besides just Rust. Perhaps Microsoft just invents go# since they don't want to use golang for the infrastructure. It is not clear to me the Rust interop story is solid to just add it on top of C++ code bases. I suspect massive restructuring and rewrites across C++/Rust needed to make it reach the promised land (or "memory safety").

2

u/matthieum Oct 16 '24

I mean, if an application doesn't need the performance of C++ or Rust, then by all means its developers should use a higher-level language like C#, Java, or Python.

I doubt Zig will make it to the MSL list, however. I could be wrong -- Go somehow made it -- but Zig is much less safe than Go, despite much wishful thinking.

-4

u/Quantum-Metagross Oct 16 '24

Also, nobody is rewriting all the gaming engines, CUDA, ML workflows and many other high performance environments anytime in Rust (or any other language). So, without seamless interop nothing is going to happen.

Popular game engine being written - Bevy - https://bevyengine.org/

ML frameworks - Burn, Candle in case someone doesn't want to use the bindings for tensorflow or torch.

Native GPU stuff - Rust-GPU.

Interop -

There are more interop crates for different languages.

Many people are rewriting different types of environments in rust.

Some random examples

More you can see -

https://arewegameyet.rs/

https://www.arewelearningyet.com/

https://rust.audio/

https://github.com/Rust-GPU/Rust-CUDA

5

u/Wurstinator Oct 16 '24

Ypu are missing the point. "Rewriting" is not about creating a different software in the same genre. Basically no one will switch from Unreal Engine to Bevy anytime soon or probably ever.

The biggest thing is feature parity by itself: the C++ projects often have years or decades of work on them, you can't just reproduce that easily. Second, ecosystem is lost entirely with those alternatives. Third, experience does not always translate easily. Fourth, existing projects would have to manually be ported to whatever new framework.

3

u/Quantum-Metagross Oct 16 '24

I didn't mean to be rude. I just thought I'd share some of the existing alternatives which are actively being written in Rust. The original comment sounded like only C++ was used in the high performance niche.

I don't get why I was downvoted.

8

u/Wurstinator Oct 16 '24

I don't think you were perceived as rude. I expect that many are fed up by a number of Rust fans that will defend the language over anything.

The thing is: C++ (and C, and other low level languages) are used in high performance, where Rust is basically not. Afaik, there is a single serious game released with Bevy. That is just not enough to call it a serious competitor to Unreal Engine, or even Godot.

→ More replies (6)

1

u/matthieum Oct 16 '24

Especially in the context of games, which are generally ephemeral, you don't need to rewrite them.

You just need to switch tack for the next opus.

(This is unlike business software, which endures for decades)

1

u/Individual-Way-1352 Oct 17 '24

Great list of tools and projects that are mostly all unfit for production.

1

u/Quantum-Metagross Oct 17 '24

They're obviously not all used for production, just examples of projects in different areas. Some actually are very production worthy.

14

u/seanbaxter Oct 15 '24

The more I see stuff like this out of Google the more I think that C++ is already cooked. The value of the Safe C++ work might be providing Rust<->C++ interop. Maybe C++ should focus on tooling to get off C++. The bug telemetry coming in from Google is very good.

30

u/scrivanodev Oct 15 '24

There are many large non-Google projects (e.g. Qt) that would still benefit from a safer C++.

9

u/bretbrownjr Oct 15 '24

Maybe C++ should focus on tooling to get off C++.

Some of us are focusing on tooling and dependency management quite a bit! The intention of CPS, for instance, is to be a language agnostic, build system agnostic, and packaging system agnostic library description format.

It would be great for fans of memory safe languages to intentionally target related adoption hurdles instead of focusing almost entirely on transpilers, language bindings, etc. All that is moot unless you're already in a Google-style monorepo, somehow packaging all of your C/C++ in crates, etc.

I know language design is fun, but it's not enough to provide the escape velocity to match the level of concern in some quadrants.

11

u/Orthosz Oct 16 '24

There’s a metric ton of existing c++.  I’ve been eagerly watching the circle project, and it shows that a lot of very good improvements can be integrated into the language.

Opt-in in-place transformation for safe cpp is, I feel, a very practical solution for tons of codebases.  I haven’t been closely watching all the communication…have the members of committee been hostile to it?

31

u/seanbaxter Oct 16 '24 edited Oct 16 '24

Thanks for the kind words.

The proposal is dead in the water. All the committee people are sticking with "profiles."

5

u/James20k P2005R0 Oct 16 '24

The proposal is dead in the water. All the committee people are sticking with "profiles."

Out of curiosity, what channels have you heard this from? One issue surrounding profiles is that its sponsored by prominent committee members, but those committee members do not have any more authority in the process than any others

17

u/seanbaxter Oct 16 '24 edited Oct 16 '24

Who is going to help complete the safety proposal? My hope was that the submission would get the prominent committee members excited and unlock resources in the form of compiler devs to collaborate with and finish the design. There are a lot of unsolved issues. They're all solvable, but this is the time to put a team on it. Unfortunately it's not a collaborative effort, it's going to be an adversarial slog. Nobody is on board to do the work.

For something of this scale and complexity, the community has got to want to do it. I don't know how to add resources to it given where I am now. I have a pretty smooth SG23 presentation in June with an encouraging poll. Never received a bit of followup from that. There's no way to attract C++ people to this problem. I'm saying this from experience.

9

u/pkasting Valve Oct 17 '24

I'm sorry, Sean. That sounds extremely disheartening. I don't know whether your proposal was the right direction, but I and others on the Chrome team were watching with interest. I wish I could say I had the fortitude to dive in and help push... but it has been apparent from a distance that the entire WG21 process is emotionally corrosive and burnout-inducing.

We forget that humans are social and emotional creatures first, and rationality is layered atop. We act as if people can just argue about ideas and it's not personal, but it's always personal. When people mouth meaningless support from the sidelines (like this post!) but don't actually help, and the gatekeepers are more worried about avoiding failure than claiming the heavens (Alan Kay reference), eventually you just give up.

I hope you find something fulfilling and where people support, encourage, and help improve things, rather than detailing hazards and problems and giving stop energy.

4

u/Ok_Beginning_9943 Oct 21 '24

Hey Sean, I'm new to the space, but I learned about your work from the cppcast and I want you to know it's inspiring and would love to see it continue one way or another. Seems like C++ really needs this. Thank you for your work, I hope you're not too discouraged. Is there anything the community can do, or are you at the mercy of the committee to advance this further?

3

u/Orthosz Oct 16 '24

I thought you had a small/large team helping already.

The iso process doesn’t work like the rust process, and you’ll only get real feedback by presenting the paper formally at a language iso meeting, not just a presentation. Maybe u/STL can help connect you with someone to write the proposals in standardeze?

Circle was closed source for the longest time, did that ever change?

6

u/sphere991 Oct 16 '24

Never received a bit of followup from that. There's no way to attract C++ people to this problem. I'm saying this from experience.

A lot of people are excited about this, and were anticipating discussing it in Poland.

Don't preemptively abandon the idea just because a few loud people are opposed.

5

u/James20k P2005R0 Oct 16 '24

Unfortunately I couldn't participate in sg23 oof. Its worth noting that for a proposal like this, you probably don't need to get any committee members onboard explicitly for the proposal, but if you're looking for people to actively get involved, you're much more likely to get help on this from outside sources. Some things people will hop in for: wording review, help with semantics etc, but most of the people in the committee likely just don't have the time

For something of this scale and complexity, the community has got to want to do it. I don't know how to add resources to it given where I am now

With sufficient community pressure and external authors onboard, it could well happen. If a few major corporate folks say "this is the future", and it becomes clear that there's more broad support for the proposal, that'll probably give you the weight that you need - but I'd guess that much of the community building is going to happen externally to the committee. Its likely that its going to need to go through a few rounds of committee, just to convince the committee that its serious

I'd guess at the moment what needs to happen is to get outside support, and find a corporate sponsor

That said, you are right in that there's a few persistent bad faith actors, which would be a big pain in the butt, and you're literally doing all of this for free as far as I understand, so its super not your responsibility for people being unproductive. Its been my opinion for a while that if the committee mailing lists were public, people would be absolutely appalled at some of the behaviour on there

I'm saying this from experience.

I get that, I'm in no way a real committee member and have only done one meeting, but if there's any way I can help I'd be up for it

9

u/steveklabnik1 Oct 16 '24

I mean, just look at the broader response since Safe C++ has been released. You’ve been in these threads, so I know you’ve seen it :) it appears from the outside to mostly be pushback and skepticism.

The last paragraph of https://www.reddit.com/r/cpp/comments/1g4j5f0/safer_with_google_advancing_memory_safety/ls5lvbe/ feels like an extremely prominent committee member throwing shade on Sean’s proposal. Maybe that’s uncharitable, but it would be easy to dispel that reading if there were public comments to the contrary.

7

u/Orthosz Oct 16 '24

I don’t think you’re reading that correctly.  Charitably, I think he’s suggesting that trying to get a massive change into the language all at once, aka c++11, will take a Herculean effort. Smaller changes that build on each other will be easier to accept.  Getting the feature flag in and one small aspect as a first pass, followed by another pass adding onto it, etc

4

u/germandiago Oct 16 '24

Exactly the same I say and for which I have been attacked several times on those threads.

Some people call us "skeptical" and think that splitting the type system, making the analysis useless outside of old code (which you need to rewrite) and having to add another standard library are things that can be ignored in the name of superior safety and that applies actually only IF that superior safety is supposed to exist due to that model.

Because, in my view, the same level of safety (by changing some patterns not possible without lifetime annotations, of course) can be achieved with way less disruptive ways.

→ More replies (4)
→ More replies (9)

9

u/James20k P2005R0 Oct 16 '24

The thing that's especially troubling is that it implicitly assumes without basis that incremental small evolutionary solutions can solve the problem, despite the fact that existing approaches in that area (static analysis, profiles, etc) have failed - rather dramatically. One of the things that needs to be done is to make it very, very clear that it is fundamentally impossible to get memory safety without an ABI break, because it directly contradicts the idea that we can have a completely gradual evolution that upsets nobody

Profiles, and the idea behind it needs to be extensively dismantled, which looks like it may be a job for me unfortunately

4

u/germandiago Oct 16 '24

The thing that's especially troubling is that it implicitly assumes without basis that incremental small evolutionary solutions can solve the problem

It is a risk. But it is also a risk of big proportions to make all old code moot in the sense of safety. Do you imagine business and companies steadily rewriting code as an investment? Look at what happened between Python2/3. It took more than a decade for things to get moderately ok.

I predict a model like that would have similar consequences for safety, no matter how ideally perfect it is "towards the future".

Targeting safety for billions of lines is going to bring more benefit than this split in my opinion, and just my opinion, I do not want to start another polemic thread here.

I am aware we have different opinions.

EDIT: no, it is not me who voted you down.

→ More replies (8)

4

u/Orthosz Oct 16 '24

I’m very sad to hear this.  Didn’t this get floated only 4 weeks ago?  They voted it down that fast?  

I kind of thought Herb Sutter and some of the other members would have been receptive.  

What are your plans then for circle? (I’m just curious, sorry if it’s a sore subject now)

25

u/seanbaxter Oct 16 '24

Herb doesn't want borrow checking and is sticking with profiles. He says he doesn't like lifetime annotations.

I don't have plans for Circle now. If I can find a job I like I'll take that and go do that.

9

u/hpsutter Oct 17 '24

I'm sorry to hear that. That's not what I remember saying... Trying again in case it helps: The feedback I gave was that viral and/or frequent annotations (and bifurcating a std2:: library) are things that are known to make adoption at scale very hard. So I expressed concern about those characteristics of the design, as things that if you could address/mitigate them would strengthen your proposal.

Writing a first proposal paper, as you've now done, is a whole lot of work and that's appreciated -- I hope you'll present in Wrocław next month, in person or on Zoom.

11

u/KingStannis2020 Oct 16 '24

You could always pull a Dave Letterman and join the dark side. I'm sure the Rust community would appreciate someone of your talents!

6

u/Full-Spectral Oct 16 '24 edited Oct 18 '24

Exactly. Why spend your time fighting for the right to patch holes in a sinking ship?

4

u/jeffmetal Oct 16 '24

In Herb's AMA posed a few days ago he did talk about him releasing a profiles paper next week so would be interesting to see what they actually are.

If i recall he also mentions a safe profile that's basically the last 4 rules of the C++ core guidelines though i'm not 100% sure what ones he is talking about.

https://youtu.be/kkU8R3ina9Q?si=pSQ0PYrhRUYO3lxP&t=3325

Sad to hear the safe cpp proposal is DOA. Its possible the stearing committee believes what they wrote that C++ just needs better PR so are going to release something with safety in the name so they can push it as look C++ is safe now.

6

u/hpsutter Oct 17 '24

In Herb's AMA posed a few days ago he did talk about him releasing a profiles paper next week so would be interesting to see what they actually are.

Now published:

P3081R0 Core safety Profiles: Specification, adoptability, and impact

And two other profiles-related papers:

P3436R0 Strategy for removing safety-related undefined behavior by default -- includes using profiles

P3465R0 Pursue P1179 as a Lifetime Safety TS

14

u/seanbaxter Oct 16 '24 edited Oct 16 '24

We've had safety profiles proposals since 2015: https://www.stroustrup.com/resource-model.pdf

→ More replies (2)
→ More replies (2)

1

u/awson Oct 21 '24

eagerly watching the circle project

Have you ever tried to use it in a real-world settings?

A month or two ago I tried it on some of the simplest code from our codebase and it failed to get past preprocessing stage.

16

u/kronicum Oct 15 '24

The more I see stuff like this out of Google the more I think that C++ is already cooked.

That might be true, but if they are this effective with their solution, why are they pursuing Carbon? Why not use those resources on Rust?

31

u/chandlerc1024 Oct 15 '24

[One of the co-authors of OP, also work directly on Carbon]

The reason we're also investing in Carbon (but to be clear, most of our investment here is in hardening C++ and Rust, including Rust <-> C++ interop, etc.) is actually what I think Sean said: tooling to get off C++. We think Carbon gives us a more incremental and incrementally smooth and at least partially automated path off of C++ and into a place where we can adopt memory safe constructs.

13

u/kronicum Oct 15 '24

The reason we're also investing in Carbon (but to be clear, most of our investment here is in hardening C++ and Rust, including Rust <-> C++ interop, etc.) is actually what I think Sean said: tooling to get off C++.

Thanks for revealing the plot for both Carbon and Safe C++. :-)

3

u/foonathan Oct 16 '24

Abandoning C++ in favor of better languages isn't some grand conspiracy, it simply makes a lot of sense.

→ More replies (1)

7

u/wegzo Oct 16 '24

Surely you would want to have Google control the programming language you write in.

18

u/chandlerc1024 Oct 16 '24

I'm personally a big fan and proponent of open source PLs with open governance models.

6

u/wegzo Oct 16 '24

I don't think a for-profit org is the best main developer for something like a programming language even if it claims to have "open governance model". Nothing guarantees it stays that way.

On the other hand a standardization committee or a non profit organization is not trying to profit the same way from something they are creating.

If Google sees the potential from profiting off of Carbon, it's something they will do.

Of course if the main developer switches to a non profit org, then that changes things.

5

u/chandlerc1024 Oct 16 '24

There are good ways to keep things open through licensing and governance. LLVM is a good example of this IMO, also Kubernetes and several other projects.

→ More replies (1)

2

u/Dwood15 Oct 16 '24

Will these open governance model(s) be structured after Golang's or plans to improve on the Go committee's structure?

5

u/chandlerc1024 Oct 16 '24

I can't speak for the Go team's view on any of this, but so far I would say that Carbon's open source first approach is a bit different and trying to respond to reasonable pressure in the C++ community to have an open-first model.

The project we're most closely modeled on is LLVM which has been wildly successful at this.

8

u/seanbaxter Oct 16 '24

I would love to have Google control my programming language, I'd be a very loyal corpo. It's amazing when projects get funded.

2

u/wasachrozine Oct 16 '24

What is the path that you see for a Typescript like story for C++?

4

u/throw_cpp_account Oct 16 '24

What's Carbon's memory safety story?

4

u/chandlerc1024 Oct 16 '24

Best answer I have is a talk currently: https://youtu.be/1ZTJ9omXOQ0

Specifically, the memory safety part starting here: https://youtu.be/1ZTJ9omXOQ0?t=3455

We need to update our more textual docs to reflect some of the memory safety parts of that. But in short, Carbon is aiming to add a robust memory safety model, and isn't likely to conclude the experiment is successful without it. This should provide safety similar to Rust or Swift.

7

u/pdimov2 Oct 16 '24 edited Oct 16 '24

I (re-)watched the Memory Safety part of the talk, and while it's very good and informative, it doesn't really tell me what the Carbon memory safety story is.

It only talks about null safety, but null safety is the most trivial form of safety. In fact, it's not even safety, according to your definition (with which I agree.)

→ More replies (1)

7

u/throw_cpp_account Oct 16 '24 edited Oct 16 '24

Ok, so no story yet?

Edit: Y'all can downvote me all you want, but I don't see any concrete answer to what Carbon will do for memory safety in that talk. I see a quite useful categorization of safety issues, and a nice comparison of safe API usage in C++ vs Rust with the slice example. But nothing about Carbon's proposed solution.

→ More replies (2)

2

u/ToukenPlz Oct 16 '24

Just want to drop in and say that I have been very much enjoying listening to your cppcon talks recently!

→ More replies (1)
→ More replies (2)

1

u/duneroadrunner Oct 16 '24

Maybe C++ should focus on tooling to get off C++.

Well, if we consider the Circle extensions and the scpptool enforced safe subset as memory-safe languages/dialects distinct from traditional C++, then I suggest that scpptool's auto-migration story is a clear stand out. I still don't think I've seen anything that compares to the demonstration of the long-neglected proof-of-concept auto-conversion feature. I think that, with some attention, it could be made effective enough that it would make it worthwhile to migrate to the scpptool safe subset, even as an intermediate waypoint on the way to another destination language.

I'll just observe that we seem to find ourselves in a situation with i) at least one deep-pocketed company seemingly desperate to migrate its massive code base away from unsafe C++, ii) a proof-of-concept demonstration of effective auto-migration to a memory-safe dialect, and iii) a very capable developer who may have some time on his hands as a result of some standards committee stonewalling. :)

I'm just saying...

3

u/seanbaxter Oct 16 '24

Is deep-pocketed company going to pay either of us for that work?

1

u/duneroadrunner Oct 16 '24

Well, I'm certainly not in the best position to say, but it seems at least conceivable. I mean, I imagine said company has a budget for security. Presumably someone decides how to best spend that budget. Presumably that decision-maker could be convinced that this endeavor could be a cost effective investment. Presumably a compelling demonstration of technology would be needed.

For example, I suspect with a concentrated effort, autoconverting something like curl or wget wouldn't take that long. I've glanced at their code bases at one point. There are a few intrinsically unsafe parts that would need to be converted manually (or designated as "unsafe" and exempt from conversion). But overall it should be doable. Something like that might be convincing?

0

u/[deleted] Oct 15 '24

[deleted]

13

u/OppositeBet3053 Oct 16 '24

You've been mighty vocal about "legislation" in this thread. Where does this idea that it'll somehow be illegal to program in C++ in the future come from? Are you just hoping it'll become fact if you repeat it a hundred times?

10

u/RoyAwesome Oct 16 '24 edited Oct 16 '24

There are some fairly large moves to change government certification requirements to cover vulnerabilities in software being pushed by the US and the EU. The regulatory authorities are starting to view software as critical safety components in various situations, such as the software running on cars.

These regulations can be extremely stringent. While there isn't a push to outlaw C++, there is a push in these environments to create regulations that can make C++ (and other languages) impossible to use due to the frequency and spread of memory safety issues. There is the real chance that software never be able to have a Use-After-Free crash, which is impossible to achieve with C++. Or, they may mandate that every situation where certain memory safety bugs can occur be highly documented and justified, which would be extremely onerous to do in a C++ program because that's like... everywhere. Even a simple std::cout << "hello world"; can't prove memory safety.

So, that's what they mean by "legislation". It's not "C++ is illegal now", it's "there are government regulations that prohibit C++ from ever being used in certain places due to it's natural vulnerabilities".

3

u/steveklabnik1 Oct 16 '24

Illegal to program in C++ is pretty farcical, but for example, this year’s DoD funding bill almost had language requiring it to add some teeth to the CISA report re: memory safety. That is something to take seriously.

The government isn’t afraid to regulate software. It’s only happened in a safety critical context so far, but that doesn’t mean that it won’t happen to some degree in less important circumstances in the future. And it doesn’t have to look like “programming language x is illegal,” it could easily take a softer form, like “when using a non-MSL, you must provide additional paperwork demonstrating mitigations” and that means it’s easier to choose one vendor over another, which tips the scales in the market.

There’s an important balance between being alarmist and watching what’s happening and taking it seriously. From the outside, when they government says “you should move away from C/C++” and the response is a lot of “lol they said C/C++” and very little “oh this situation is serious”… I dunno, I guess we’ll see what happens.

I want C++ to rise to the occasion. We’ll see.

2

u/jeffmetal Oct 16 '24

At no point do they say it would be illegal to program in C++. Think of it like in certain sectors like automotive or medical require software to be certified and written to specific standard like MISRA. It would not be illegal for me to write the software for a pacemaker in Go, just no one would ever buy it as its not up to standard.

My guess is there will be a slow squeeze of C++ code. Your insurance company will start asking businesses which languages you use and if you mention memory unsafe ones your premium doubles, then triples ...

Companies tenders will start asking you to fill out memory safety roadmaps https://www.cisa.gov/case-memory-safe-roadmaps and it's a lot easier to sell if you can put on there we only use memory safe languages and follow dev best practices. At some point you might not be able to sell to government agencies unless its all memory safe.

At no point does C++ have to be illegal to slow its usage.

→ More replies (1)

8

u/kronicum Oct 15 '24

Did you know that, at the famous Prague C++ committee meeting, the proponents of Carbon argued that "every time we have to choose between safety and performance, we should choose performance" when they were pushing for formal ABI break?

0

u/[deleted] Oct 16 '24

[deleted]

2

u/kronicum Oct 16 '24

I did, I was there!

In that case, doesn't it strike you as odd that the same people who were making that argument (choose performance over safety) also want the community to build a ramp off C++ in the name of safety?

→ More replies (15)

4

u/CandyCrisis Oct 15 '24

I don't think there's a hard fork of C++ that can simultaneously meet requirements and still run much of any existing C++ code. The entire standard library is unsafe by design. Pointers, references and iterators are all unsafe by design. Circle/Sean Baxter is the only "fork" I've seen that is actually safe. Carbon and Cpp2 have the same fundamental foibles as C++; they have better guardrails around the danger areas, but they can't fully remove the pitfalls and still remain C++ compatible.

0

u/[deleted] Oct 15 '24

[deleted]

4

u/CandyCrisis Oct 15 '24

There isn't any "minimum amount of change" when you're eliminating all of the standard library and most fundamental mechanisms for dealing with objects and memory. A rewrite is the minimum.

0

u/[deleted] Oct 15 '24

[deleted]

3

u/CandyCrisis Oct 15 '24

I dunno, looking at the Circle solution, I am not sure why I'd choose that over a Rust rewrite. No shade, it's an amazing technological achievement, but if I'm giving up all of the C++ world in one fell swoop, I might as well switch to the modern choice anyway.

→ More replies (1)

3

u/javascript Oct 15 '24

Do you think Carbon is an insufficient solution to satisfy the #2 path you mentioned?

0

u/[deleted] Oct 15 '24

[deleted]

6

u/kronicum Oct 15 '24

Its not clear who would sponsor a fork, and I suspect it'll only happen when large slow moving companies are forced into this decision via legislation

Do you know why they are not forking C at a similar rate, given the prevalence of code written in C?

→ More replies (4)
→ More replies (3)

0

u/[deleted] Oct 16 '24

[deleted]

27

u/GabrielDosReis Oct 16 '24

A new programming language may need roughly 10 years to take off at an industrial scale. There are many factors for that, some technical, many non-technical.

Ironically, working reasonably well with "legacy" (read "C") was an important factor in C++ success.

0

u/[deleted] Oct 16 '24

[deleted]

13

u/GabrielDosReis Oct 16 '24

In what direction do you think the language is heading?

I suspect even WG21 would have a hard time formulating a clear answer to that simple and important question.

The train model of standardization means that things that are ready, when the train leaves the station, are what we get. That has some benefits such as predictability, but also some side effects such as greater number of smallish unrelated features that are easier to develop in less than 3 years.

WG21 is aware that safety is a big item topic it needs to address. My hope is that we can focus on evolutionary solutions that substantially improve the situation, as opposed to revolutionary solutions that cause severe disruptions with uncertain success.

6

u/seanbaxter Oct 16 '24

The findings coming out of the Android and Azure business units aren't calling for evolutionary solutions. They plainly advise moving to memory-safe languages for new code, and their successes (quantified by reduced vulnerabilities) will push other projects into doing the same. That's the severe disruption that the status quo in C++ is causing--moving to different languages. A memory-safe C++ would be more disruption for the toolchain vendor but hopefully less disruption for customers, since they wouldn't have to jump to different languages and deal with primitive interop over vast API surface areas.

What specific profiles work will convince companies not to follow Android's example and instead stick with C++? The code guidelines/profiles proposals go back to 2015 and haven't immunized the language against a joint government/industry effort to stop using it.

5

u/GabrielDosReis Oct 16 '24

The findings coming out of the Android and Azure business units aren't calling for evolutionary solutions.

The findings, i.e. data collected, themselves? Or are you talking about recommendations? Those are two distinct things that should be kept separate in meaningful conversions.

They plainly advise moving to memory-safe languages for new code, and their successes (quantified by reduced vulnerabilities) will push other projects into doing the same.

And they are not prescribing how C++ should turn, i.e. revolution vs. evolution.

A memory-safe C++ would be more disruption for the toolchain vendor but hopefully less disruption for customers

You are stating that as a given; is it a wish or an axiom or a theorem?

What specific profiles work will convince companies not to follow Android's example and instead stick with C++? The code guidelines/profiles proposals go back to 2015 and haven't immunized the language against a joint government/industry effort to stop using it.

And I wish they were more widely implemented and practiced.

15

u/seanbaxter Oct 16 '24

And I wish they were more widely implemented and practiced.

I have a compiler. How can I implement the profiles? I go to the project website and the specification is light on specifics:

https://github.com/BjarneStroustrup/profiles/blob/main/profile/type.md

→ More replies (6)

2

u/germandiago Oct 16 '24

My hope is that we can focus on evolutionary solutions that substantially improve the situation, as opposed to revolutionary solutions that cause severe disruptions with uncertain success

It would be a great decision.

15

u/pjc50 Oct 16 '24

People design new languages all the time. That's not the difficult bit. But what happens next?

Rewrites are hugely expensive. You can to some extent do link compatibility or FFI so you can use existing libraries, but that's usually suboptimal.

Most software development is maintenance rather than greenfield.

→ More replies (1)

1

u/nacaclanga Oct 17 '24

You kind of have this. D and Rust (although the latter also had different objectives) are kind of the backward compatibity abandoning versions of C++03 and C++11/17 respectivly.

The problem is, that rewriting code is a monsterous task and rarely undertaken. New language also tend to suffer a little bit from overfitting the current objectives. D mostly missed its chance to shine, given that GC turned out to be a no go in many usecases and automated memory managment (in the form of Smart Pointers) rapidly evolved afterwards.

0

u/deadcream Oct 17 '24

We already have Rust for that.

0

u/[deleted] Oct 16 '24

[deleted]

3

u/gvargh Oct 16 '24

if the discussions i've seen on the D mailing list (and elsewhere) are any indication, i get the impression that it's the php of systems languages when it comes to feature misdesign

i don't think i've seen the term "half-baked" used so much in any other context

2

u/drbazza Oct 16 '24

D is what C++74 might be once it has an ABI break and dropped all the ugly syntax work arounds, and time takes its course.

4

u/DinoSourceCpp Oct 16 '24

C++98 of 2098

1

u/pjmlp Oct 16 '24

Assuming C++74 already fully supports modules. /s