<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Andrew Lilley Brinker — Memory Safety</title>
  <subtitle>Posts about Memory Safety</subtitle>
  <id>https://www.alilleybrinker.com/topics/memory-safety/atom.xml</id>
  <link rel="self" type="application/atom+xml" href="https://www.alilleybrinker.com/topics/memory-safety/atom.xml"/>
  <link rel="alternate" type="text/html" href="https://www.alilleybrinker.com/topics/memory-safety/"/>
  <updated>2026-01-28T12:00:00.000Z</updated>
  <author><name>Andrew Lilley Brinker</name><uri>https://www.alilleybrinker.com/</uri></author>
  <entry>
    <title>Memory Safety for Skeptics</title>
    <id>https://cacm.acm.org/practice/memory-safety-for-skeptics/</id>
    <link rel="alternate" type="text/html" href="https://cacm.acm.org/practice/memory-safety-for-skeptics/"/>
    <published>2026-01-28T12:00:00.000Z</published>
    <updated>2026-01-28T12:00:00.000Z</updated>
    <summary>Making the case for pursuing memory safety amid time and budget constraints, with or without Rust.</summary>
  </entry>
  <entry>
    <title>The Problem is New Code</title>
    <id>https://www.alilleybrinker.com/blog/the-problem-is-new-code/</id>
    <link rel="alternate" type="text/html" href="https://www.alilleybrinker.com/blog/the-problem-is-new-code/"/>
    <published>2024-09-26T12:00:00.000Z</published>
    <updated>2024-09-26T12:00:00.000Z</updated>
    <summary>Identifying that assuring memory safety in new code is the highest leverage point for assuring existing codebases.</summary>
    <content type="html" xml:base="https://www.alilleybrinker.com/blog/the-problem-is-new-code/">&lt;p&gt;Folks at Google explain how to think about the move to memory safe languages:
“the problem is new code.”&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;The Google Security Blog has an article, out yesterday, titled
&lt;a href=&quot;https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html&quot;&gt;“Eliminating Memory Safety Vulnerabilities at the Source”&lt;/a&gt;, which explains
something in very clear detail which I think is essential for understanding
software security:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The problem is new code&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When I published &lt;a href=&quot;https://www.alilleybrinker.com/blog/cpp-must-become-safer/&quot;&gt;“C++ Must Become Safer”&lt;/a&gt; back in July, I tried to explain
this fact through a small case study of the &lt;code&gt;curl&lt;/code&gt; codebase, referencing some
analysis done by Daniel Stenberg, creator of &lt;code&gt;curl&lt;/code&gt;. To wit:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For any software project, we should expect that over time, if the code
doesn’t change substantially and the project receives some rate of bugfixes,
the number of vulnerabilities latent in the codebase will decrease.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This was &lt;em&gt;correct&lt;/em&gt; but much less &lt;em&gt;clear&lt;/em&gt; than the phrase chosen by Andrew
Vander Stoep and Alex Rebert in the Google post.&lt;/p&gt;
&lt;p&gt;Defects in code, and thus vulnerabilities, are overwhelmingly introduced when
code is written. We expect that memory safe languages reduce the number and
severity of defects in code at the time of writing by enforcing more static
checks which eliminate classes of defects. So for &lt;em&gt;new&lt;/em&gt; code, they ought to
be the default. Yet for existing code, it’s entirely possible that the benefits
of a rewrite are minimal if enough time has passed.&lt;/p&gt;
&lt;p&gt;The Google post also provides a formula for the density of vulnerabilities
in code given some “average vulnerability lifetime.” For some projects, where
assurance techniques, including bugfixes, are minimal, we might nonetheless
expect this lifetime to be quite long. We should very much care about reducing
this lifetime through techniques which reduce defects in code and which
discover vulnerabilities. Not all projects will have an average lifetime as
short as ones we’d expect Google to be able to achieve.&lt;/p&gt;
&lt;p&gt;I really hope that this phrase, “the problem is new code” enters the lexicon
of common phrases in software, diffusing out into the community and becoming
commonly-held folk knowledge. I will certainly be using it myself.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>C++ Must Become Safer</title>
    <id>https://www.alilleybrinker.com/blog/cpp-must-become-safer/</id>
    <link rel="alternate" type="text/html" href="https://www.alilleybrinker.com/blog/cpp-must-become-safer/"/>
    <published>2024-07-16T12:00:00.000Z</published>
    <updated>2024-07-16T12:00:00.000Z</updated>
    <summary>Not everything will be rewritten in Rust, so C++ must become safer, and we should all care about C++ becoming safer.</summary>
    <content type="html" xml:base="https://www.alilleybrinker.com/blog/cpp-must-become-safer/">&lt;p&gt;Not everything will be rewritten in Rust, so C++ &lt;em&gt;must&lt;/em&gt; become safer, and we
should all care about C++ becoming safer.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;It has become increasingly apparent that not only do many programmers see
the benefits of memory safety, but policymakers do as well. The concept of
“memory safety” has gone from a technical term used in discussions by the
builders and users of programming languages to a term known to
&lt;a href=&quot;https://advocacy.consumerreports.org/research/report-future-of-memory-safety/&quot;&gt;Consumer Reports&lt;/a&gt; and the
&lt;a href=&quot;https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/&quot;&gt;White House&lt;/a&gt;. The key contention is that software
weaknesses and vulnerabilities have important societal impacts&lt;span class=&quot;em-dash&quot;&gt;—&lt;/span&gt;software
systems play critical roles in nearly every part of our lives and society&lt;span class=&quot;em-dash&quot;&gt;—&lt;/span&gt;and so making software more &lt;em&gt;secure&lt;/em&gt; matters, and improving memory
safety has been identified as a high-leverage means to do so.&lt;/p&gt;
&lt;p&gt;Policymakers believe it’s high leverage because of quality reporting
from a number of software companies, including &lt;a href=&quot;https://msrc.microsoft.com/blog/2019/07/a-proactive-approach-to-more-secure-code/&quot;&gt;Microsoft&lt;/a&gt;,
&lt;a href=&quot;https://langui.sh/2019/07/23/apple-memory-safety/&quot;&gt;Apple&lt;/a&gt;, and &lt;a href=&quot;https://android-developers.googleblog.com/2020/02/detecting-memory-corruption-bugs-with-hwasan.html&quot;&gt;Google&lt;/a&gt;, showing that a large portion of the
vulnerabilities they track for their own software are derived from
memory &lt;em&gt;unsafety&lt;/em&gt;. This reporting was then aggregated by
&lt;a href=&quot;https://alexgaynor.net/2020/may/27/science-on-memory-unsafety-and-security/&quot;&gt;Alex Gaynor&lt;/a&gt;, &lt;a href=&quot;https://oxide.computer/podcasts/oxide-and-friends/1208089&quot;&gt;Yael Grauer&lt;/a&gt;, and
others to make a compelling case that you could achieve meaningful reduction
in software vulnerabilities, and importantly in the &lt;em&gt;severity&lt;/em&gt; of
vulnerabilities, by improving memory safety.&lt;/p&gt;
&lt;p&gt;It’s important to pause here and note that many existing popular languages are
already, at least partially, memory safe. In fact, the US government’s
&lt;a href=&quot;https://media.defense.gov/2023/Dec/06/2003352724/-1/-1/0/THE-CASE-FOR-MEMORY-SAFE-ROADMAPS-TLP-CLEAR.PDF&quot;&gt;“Case for Memory Safe Roadmaps,”&lt;/a&gt; published in December of 2023,
lists C♯, Go, Java, Python, and Swift as memory safe languages, all &lt;em&gt;garbage
collected&lt;/em&gt; languages which cover an enormous number of devices today. C♯ is
an extremely popular language for Windows machines with the .NET runtime, Go
is used for many web servers and pieces of “cloud native” software run by
popular cloud hosts, Java is the language of Android and a great deal of
widely-deployed software used by large enterprises, Python is the most
popular language today for many data science applications, and Swift is the
recommended language for all iOS applications today (though Objective-C
remains supported and widely used as well). All of these languages are
already delivering meaningful memory safety, though many still present at
least some memory safety–related issues like permitting dereferencing of
&lt;code&gt;null&lt;/code&gt; pointers.&lt;/p&gt;
&lt;p&gt;The one other language on the list from the “Case for Memory Safe Roadmaps” is
Rust, and Rust is unique in that list for being the only memory safe language
&lt;em&gt;without&lt;/em&gt; garbage collection. I believe &lt;em&gt;this&lt;/em&gt; fact is part of why so much
movement is happening around memory safety &lt;em&gt;now&lt;/em&gt;. Rust has enabled memory
safety in contexts where garbage collection is not generally accepted, and
therefore languages which require it do not generally see adoption. In those
spaces, the overwhelming majority of existing code is written in C or C++.&lt;/p&gt;
&lt;p&gt;It is &lt;em&gt;this&lt;/em&gt; code to which Rust presents an intruiguing possibility: could we
rewrite that code from C or C++ into Rust, and thereby gain the benefits of
memory safety where they were not previously feasible? It has become a common
joke both inside and outside of the Rust community that, for any project,
people should &lt;a href=&quot;https://enet4.github.io/rust-tropes/rewrite-in-rust/&quot;&gt;Rewrite It In Rust&lt;/a&gt;, and that the
&lt;a href=&quot;https://enet4.github.io/rust-tropes/rust-evangelism-strike-force/&quot;&gt;Rust Evangelism Strike Force&lt;/a&gt; stands ready to make this recommendation
to any project it observes, especially when memory safety–related
vulnerabilities arise.&lt;/p&gt;
&lt;h2 id=&quot;not-everything-will-be-rewritten-in-rust&quot;&gt;Not Everything Will be Rewritten in Rust&lt;/h2&gt;
&lt;p&gt;Despite the jokes, not everything will be rewritten in Rust, and in fact, many
things that are in C and C++ today &lt;em&gt;should not&lt;/em&gt; be rewritten in Rust. This is
also the position of many major tech corporations and foundations,
including…&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Google
&lt;figure&gt;
&lt;blockquote class=&quot;hang-double&quot;&gt;
“We expect that rewriting large, existing unsafe codebases will often be
impractical. and recommend that old, unsafe codebases be updated gradually
via interoperability or by enforcement of safer coding patterns rather than
entirely rewritten.”
&lt;/blockquote&gt;
&lt;figcaption&gt;
&lt;a href=&quot;https://www.regulations.gov/comment/ONCD-2023-0002-0074&quot;&gt;Google’s
response&lt;/a&gt;
response to the 2023 Request for Input (RFI) on Open Source Software Security
from the United States Office of the National Cyber Director (ONCD)
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
The Open Source Security Foundation (OpenSSF)
&lt;figure&gt;
&lt;blockquote class=&quot;hang-double&quot;&gt;
“[R]efactoring large existing code bases into a new language is typically
non-trivial. It can introduce new bugs and vulnerabilities, and in some cases
it is difficult to redeploy new object code (e.g., in OT/ICS devices). We
encourage new development to occur in memory-safe languages where practical.
Organizations should take a risk-based approach for existing code, focusing
their refactoring efforts where it will be the most beneficial; it would be
too costly and risky to try to rewrite all software currently in memory-unsafe
languages. Focusing on rewriting the riskiest components of the most important
software is a practical approach for existing software.”
&lt;/blockquote&gt;
&lt;figcaption&gt;
The &lt;a href=&quot;https://www.regulations.gov/comment/ONCD-2023-0002-0046&quot;&gt;OpenSSF&lt;/a&gt; response to the ONCD RFI.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
Trail of Bits
&lt;figure&gt;
&lt;blockquote class=&quot;hang-double&quot;&gt;
“Unfortunately, the majority of OSS that is still used, maintained, and extended
for critical web and operating system infrastructure predates widespread
adoption of memory safe programming languages. Over 65% of websites are served
by an open source server written in an unsafe programming language like C or
C++. The cost (both monetary and logistically) of migrating all or any
significant portion of OSS to memory safe programming languages is substantial.
A cost-benefit analysis is therefore necessary.&lt;br&gt;&lt;br&gt;
When performing this analysis, it is important to observe that pre-existing
testing should be considered a security property and as important as any core
feature: rewriting a piece of software in Rust can actually introduce security
problems if, for example, the previous implementation’s tests are not included
in the rewrite. Thus, these rewrites need to be performed carefully and
holistically, with consideration for existing tests and undocumented
invariants.”
&lt;/blockquote&gt;
&lt;figcaption&gt;
The &lt;a href=&quot;https://www.regulations.gov/comment/ONCD-2023-0002-0076&quot;&gt;Trail of Bits&lt;/a&gt; response to the ONCD RFI.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
GitHub
&lt;figure&gt;
&lt;blockquote class=&quot;hang-double&quot;&gt;
“Supporting rewrites of the most critical open-source software
components in memory safe languages can produce valuable experience for
developers and funders. If rewritten components are adopted at scale, they
will reduce the vulnerability of the software ecosystem. However, rewrites
are also acknowledged by developers to be very expensive, bear the risk of
introducing new non-memory safety errors, and are, ultimately, a long-term
project. Therefore, additional strategies should also be prioritized, both
to foster the adoption of memory safe programming languages for new code and
to increase the efficiency and impact of increasing the safety of existing
components, including through rewrites.”
&lt;/blockquote&gt;
&lt;figcaption&gt;
&lt;a href=&quot;https://www.regulations.gov/comment/ONCD-2023-0002-0084&quot;&gt;GitHub’s&lt;/a&gt; response to the ONCD RFI.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To understand, we’ll need to do a cost-benefit analysis of rewrites like this.&lt;/p&gt;
&lt;p&gt;The benefits of rewriting software from a memory unsafe language like C or C++
into a memory safe language like Rust seem clear: you introduce memory safety,
and eliminate vulnerabilities related to it! Since we have the reporting from
Apple, Google, Microsoft, and others showing that many of their vulnerabilities
are related to memory safety, and in fact the &lt;em&gt;percentages&lt;/em&gt; of vulnerabilities
they’ve observed which are memory safety–related seem stable across
organizations, we should expect that moving to memory safety should in general
result in similar reductions in vulnerabilities!&lt;/p&gt;
&lt;p&gt;However, let’s step back: the reported proportions of vulnerabilities assigned
to memory safety issues are for &lt;em&gt;actively developed&lt;/em&gt; projects, which means
these are projects which are being maintained and for which new lines of code
are being written.&lt;/p&gt;
&lt;p&gt;Software defects, including weaknesses and vulnerabilities, can be thought of
in relation to the lines of code produced at a given time. Per 1,000 lines of
code, you have an expected “defect rate.” Some of those defects may be
weaknesses, which are not exploitable, while others may be vulnerabilities,
which are exploitable. Either way, they are “born” with the introduction of
new code. While changes over time may convert weaknesses to vulnerabilities,
by making something exploitable which previously wasn’t exploitable, and new
interactions between systems may make assumptions in existing code no longer
valid and thus introduce vulnerabilities, in both cases over time we can assume
that defect rates decrease because we expect the rate of fixing defects in
a fixed segment of code to outpace the introduction of new vulnerabilities
from changing system interactions.&lt;/p&gt;
&lt;p&gt;To put it more plainly: &lt;strong&gt;if you don’t rewrite the code substantially, and you
periodically fix bugs, over time the number of vulnerabilities in the code
falls.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you’re familiar with the idea of “systems thinking” and more specifically
of modeling “stocks and flows,” that’s basically what we’re doing here. In
this context, the “stocks” are &lt;em&gt;amount of code&lt;/em&gt; and &lt;em&gt;number of detects&lt;/em&gt;,
and the “flows” are &lt;em&gt;introduction of new code&lt;/em&gt;, and &lt;em&gt;discovery of defects&lt;/em&gt;.
I am not going to do a more detailed stocks and flows breakdown here, but this
kind of thinking is a good approach for modeling the considerations here.&lt;/p&gt;
&lt;p&gt;Any project can use assurance techniques like code review, testing, code
analysis, defensive programming, and more to reduce the defect rate or increase
the rate that defects are identified and fixed.&lt;/p&gt;
&lt;p&gt;Daniel Stenberg, the creator of &lt;code&gt;curl&lt;/code&gt;, the popular “command line tool and
library for transferring data with URLs” (to quote the project), covers this
idea quite nicely in his 2022 blog post
&lt;a href=&quot;https://daniel.haxx.se/blog/2022/08/22/increased-cve-activity-in-curl/&quot;&gt;“Increased CVE Activity in curl?”&lt;/a&gt;. In the “Finding vs. Introducing”
section, he notes that over time, the &lt;code&gt;curl&lt;/code&gt; project has reduced the rate
at which new vulnerabilities are introduced. 75% of the CVEs reported against
the project at the time the article was written were from before March 2014,
when the project was much smaller in terms of code size. While the introduction
of new code has stayed relatively linear over time, the rate of vulnerabilities
per 1,000 lines of code has decreased through the use of assurance techniques
like rigorous testing.&lt;/p&gt;
&lt;p&gt;For any software project, we should expect that over time, if the code doesn’t
change substantially and the project receives some rate of bugfixes, the number
of vulnerabilities latent in the codebase will decrease.&lt;/p&gt;
&lt;p&gt;For inactively developed projects, which we should not expect to be introducing
new vulnerabilities at substantial rates, a rewrite may actually be counter-
productive. While a rewrite to a new language could eliminate memory safety
vulnerabilities, it also is likely to introduce many new vulnerabilities of
&lt;em&gt;other types&lt;/em&gt;. If the expected rate of latent memory safety vulnerabilities
in the code is low, this tradeoff may not be worthwhile.&lt;/p&gt;
&lt;p&gt;In this analysis I’ve so far ignored the economic considerations, but those are
also important. Code rewrites are &lt;em&gt;expensive&lt;/em&gt;, because (as any employer can
tell you), &lt;em&gt;staff time&lt;/em&gt; is expensive, especially for programmers who tend to
fetch high pay relative to many other professions. For legacy software which is
currently in maintenance mode with minimal staff support, and thus cheap to run,
the cost/value proposition of a rewrite may not make sense, and may in fact
change the calculus around the legacy systems entirely. Often a system becomes a
legacy system because it is not valuable enough to maintain, but too costly to
decomission and replace. If a cheap-to-maintain legacy system is faced with the
proposition of an expensive rewrite, it may instead be eliminated. The
externalities of this kind of change are difficult to consider in advance and
in general.&lt;/p&gt;
&lt;h2 id=&quot;c-must-become-safer&quot;&gt;C++ Must Become Safer&lt;/h2&gt;
&lt;p&gt;However, this does not mean we ought to throw in the towel for codebases
already written in C or C++ which may not be worth rewriting in Rust. Those
codebases &lt;em&gt;matter&lt;/em&gt;, or else they would not be preserved in operation, and
that means these are codebases whose function in some way impacts people’s
lives, and that vulnerabilities in them may result in real harm. Throwing
up our collective hands for these languages when there exists the possibility
of reducing harm is unacceptable.&lt;/p&gt;
&lt;aside class=&quot;info-callout&quot; aria-labelledby=&quot;why-just-cpp&quot;&gt;
  &lt;p id=&quot;why-just-cpp&quot; class=&quot;info-callout-title&quot;&gt;Why Just C++?&lt;/p&gt;
  &lt;p&gt;For the remainder of this post, I’ll be focusing only on C++. I believe we should want both C and C++ to become safer languages, but I think there is more appetite to pursue this in the C++ community and standards group than there is for C, and that C++ already has a number of language affordances which prime it to be able to introduce safety-providing abstractions which would likely be more difficult in C. My general recommendation in favor of advancing safety applies to both, but I am going to focus on C++ here.&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;So, what should we do? To quote &lt;a href=&quot;https://bsky.app/profile/steveklabnik.com/post/3kwwqxuik2c2h&quot;&gt;Steve Klabnik on this issue&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[I]t seems (to me) like there are now four camps in the “how do we
make C++ safer” category. I’m listing these in an order, I’ll explain
that after:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;contracts&lt;/li&gt;
&lt;li&gt;profiles&lt;/li&gt;
&lt;li&gt;successor languages&lt;/li&gt;
&lt;li&gt;borrow checking&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p&gt;This tweet thread is in response to a vote from a recent C++ standards
committee meeting about further exploration of opportunities for memory
safety in C++, and the rest of the thread goes on to explain Steve’s
understanding of the current state of each of the four approaches.&lt;/p&gt;
&lt;p&gt;These are being pursued, to varying degrees, by people in the C++ standards
process, and outside of it. Herb Sutter, Chair of the ISO C++ Standards
Committee, published an article in March of this year titled &lt;a href=&quot;https://herbsutter.com/2024/03/11/safety-in-context/&quot;&gt;“C++ Safety,
in Context,”&lt;/a&gt; (disclosure: I was a pre-release reviewer for that
article, for which I provided feedback on its descriptions of Rust’s
guarantees and the landscape of memory safety today). Herb’s article
outlines his own view of what C++ can and should pursue for memory safety,
and falls in the “contacts” and “profiles” camps of Steve’s list above.&lt;/p&gt;
&lt;p class=&quot;hang-double&quot;&gt;“Profiles” are also the path recommended by Bjarne Stroustrup, creator
of C++, and the rest of the “C++ Directions Group” in
&lt;a href=&quot;https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2759r0.pdf&quot;&gt;their writing on the topic&lt;/a&gt;. In the “profiles” approach, C++
would support the activation of predefined opt-in sets of additional static
analyses which would restrict what C++ programs can &lt;em&gt;do&lt;/em&gt;, but improve their
safety, while enabling interoperation with C++ written and compiled without
the same profiles.&lt;/p&gt;
&lt;p&gt;That said, there &lt;em&gt;are&lt;/em&gt; critics of the “profiles” approach, and it’s not
clear that this approach has yet borne fruit of producing a meaningfully
safe profile of C++ which approaches the memory safety of Rust, or indeed
of less memory-safe languages like Java.&lt;/p&gt;
&lt;p&gt;Indeed, Sean Baxter, who proposed the vote described above on the C++
standards committee pursuing memory, is also working on one of multiple
successor-language projects for C++: &lt;a href=&quot;https://www.circle-lang.org/site/intro/&quot;&gt;Circle&lt;/a&gt;.
This is item 3 in Steve Klabnik’s list, which includes (known to me, at least):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Circle&lt;/li&gt;
&lt;li&gt;Carbon&lt;/li&gt;
&lt;li&gt;cppfront&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://www.circle-lang.org/site/index.html&quot;&gt;Circle&lt;/a&gt;, Sean’s language, is “a
subset of a superset” of C++. This means you can intermix valid existing C++
code with code written in the safe extension of C++ which is &lt;em&gt;like-C++&lt;/em&gt; but
with limits placed to enforce memory safety.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/carbon-language/carbon-lang/blob/trunk/README.md&quot;&gt;Carbon&lt;/a&gt;,
an “experimental successor to C++,” aims for interoperation with C++
with more safety (though explicitly aiming for fewer safety guarantees than
Rust). Code written in Carbon is &lt;em&gt;not&lt;/em&gt; valid C++ code, but code written in
Carbon is intended to be able to easily call C++, and be easily called by C++
code.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/hsutter/cppfront&quot;&gt;cppfront&lt;/a&gt;, being developed by Herb
Sutter, is an experimental syntax for C++ which compiles to “real” C++, and
essentially is intended to make it easier / the default to write safer C++
code with fewer footguns to remember not to fire.&lt;/p&gt;
&lt;p&gt;As I am not a C++ programmer, I can’t comment on which of these is the &lt;em&gt;right&lt;/em&gt;
approach, and I have no idea which of these will persist or how this effort
will shake out over time. My point here is in fact not to make a case for or
against any of these approaches, but rather to say that anyone with an interest
in advancing memory safety and software security more broadly should care about
these efforts and what happens with C++ long-term.&lt;/p&gt;
&lt;h2 id=&quot;we-should-all-care-about-c-becoming-safer&quot;&gt;We Should All Care About C++ Becoming Safer&lt;/h2&gt;
&lt;p&gt;Which leads me to the crux of the whole point here: C++ isn’t going anywhere.
As good as I think memory safety is (and I’ve been using and involved in Rust
projects since 2014, so it’s 10 years of my career that I’ve committed to this
cause), it will not be universally achieved through rewriting existing code in
Rust.&lt;/p&gt;
&lt;p&gt;The economic costs of these rewrites would be substantial, and in fact such
rewrites may be counterproductive in terms of vulnerability rates even if
pursued in some contexts (code which changes minimally over time and has
been assured well through alternative techniques already). We can’t, and
shouldn’t, even want a near-term future where Rust rewrites are pursued
across all or most software.&lt;/p&gt;
&lt;p&gt;Using memory safe languages for new code is, of course, ideal. I do hope
that over time, the proportion of new code written in non-memory-safe languages
decreases. Yet code has a tendency to last a long time, far longer than we
often anticipate. We won’t be getting rid of C++ any time soon.&lt;/p&gt;
&lt;p&gt;So we should care enormously about what happens to the memory safety of
C++ as a language, and what opportunities may arise to pursue lower-cost and
lower-risk paths to improved memory safety besides full rewrites of existing
code into memory safe languages. Diversifying paths to memory safety through
profiles, contracts, and successor languages are all important to enable
&lt;em&gt;viable options&lt;/em&gt; in more contexts.&lt;/p&gt;
&lt;p&gt;We should also not shame people working with and sustaining existing C and
C++ codebases, nor chide them to pursue rewrites in Rust. This does nothing
to help Rust, and in fact makes it look terrible as a community, and ignores
the often very real constraints holding back rewrites from starting.&lt;/p&gt;
&lt;p&gt;Thank you to everyone involved in the C++ community who is working to make
the language safer. You are doing the hard and often thankless work of securing
something that’s no longer new and shiny. I am sure as you do that you are also
dealing with challenging attitudes within the C++ community, from people who
may feel defensive or uncertain about a memory safe future and C++’s place in
it.&lt;/p&gt;
&lt;p&gt;I hope we can all have a little more empathy, a little more nuance, and a
little less of an Evangelism Strike Force in the future.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Renegotiating C</title>
    <id>https://www.alilleybrinker.com/blog/renegotiating-c/</id>
    <link rel="alternate" type="text/html" href="https://www.alilleybrinker.com/blog/renegotiating-c/"/>
    <published>2024-02-19T12:00:00.000Z</published>
    <updated>2024-02-19T12:00:00.000Z</updated>
    <summary>Expressing empathy for C programmers as they grapple with fear and uncertainty amid the rise of Rust.</summary>
    <content type="html" xml:base="https://www.alilleybrinker.com/blog/renegotiating-c/">&lt;p&gt;Amid the move to memory safe languages, the people who build and build on C and
C++ ought to be recognized. Any of us could be hit by an upheaval of technology
in which we’ve invested.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I am tying myself in a knot.&lt;/p&gt;
&lt;p&gt;It all started when I read “&lt;a href=&quot;https://nedbatchelder.com/blog/202401/you_probably_dont_need_to_learn_c.html&quot;&gt;You (Probably) Don’t Need to Learn C&lt;/a&gt;,” a good article
which raises good points about the poor arguments people tend to make when defending
the choice of learning C in this day and age. First and foremost: “you should learn
C so you know how a computer really works.” The article itself refers then to David
Chisnall’s “&lt;a href=&quot;https://dl.acm.org/doi/pdf/10.1145/3212477.3212479&quot;&gt;C is Not a Low-Level Language&lt;/a&gt;,” so I’ll do the same because it makes the
case better than I can. C is not the computer. C is (maybe) the only interface to
syscalls exposed by the operating system, depending on the system. C is (definitely)
an important part of computing history and computing today.&lt;/p&gt;
&lt;p&gt;And yet… “&lt;a href=&quot;https://www.humprog.org/~stephen/research/papers/kell17some-preprint.pdf&quot;&gt;Some Were Meant for C&lt;/a&gt;.” When I was an undergraduate I had a classmate
who insisted on doing every assignment, regardless of the class we were taking, in C.
This was in a program which used C++ almost exclusively, except for the “Software
Engineering” class in Java, the web development classes in the obligatory JavaScript,
or the delightful programming languages class which covered Java, Prolog, Scheme, and…
C.&lt;/p&gt;
&lt;p&gt;Anyway, this classmate insisted C was the &lt;strong&gt;best&lt;/strong&gt; language, the most elegant, the one
in which all of his ideas could be put to the machine in exactly the way he intended.
I didn’t understand it at the time, why he would think that, how he &lt;em&gt;could&lt;/em&gt; think that.
I toiled in the sweatshop of C++, found slight solace in Haskell code I could appreciate
but neither write nor understand. Eventually I found Rust, and… well… &lt;a href=&quot;https://github.com/alilleybrinker&quot;&gt;I like Rust&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Several years after I graduated, I was invited back to teach that same old programming
languages class after the prior professor, Dr. Richard Botting, had passed away. It was
essentially an emergency, as the Computer Science department didn’t have enough faculty to
cover the number of sessions of the class they needed. They were hiring more, but it would
take time, and they needed someone fast.&lt;/p&gt;
&lt;p&gt;By this point I was thoroughly Rust-brained. I’d written my fair share of Rust code, become
the sole Rust evangelist at work, presented at &lt;a href=&quot;https://www.youtube.com/watch?v=Wz2oFEDwiOk&quot;&gt;Rust Belt Rust&lt;/a&gt;, and written most of the
&lt;a href=&quot;https://prev.rust-lang.org/en-US/faq.html&quot;&gt;Rust Frequently Asked Questions&lt;/a&gt; answers. I was, through and through, a Rustacean. So
when I was given the opportunity to teach a class, a class that included &lt;em&gt;C&lt;/em&gt; in its curriculum,
my only question was: “can I change the languages?”&lt;/p&gt;
&lt;p&gt;I was told “yes,” and so I swapped out Haskell for Scheme, and Rust for C.&lt;/p&gt;
&lt;p&gt;The full details of this experience became the focus of &lt;a href=&quot;https://www.youtube.com/watch?v=0PhfaFkzdBA&quot;&gt;my talk at RustConf&lt;/a&gt;. The important
bit is this… during the talk I made a joke: “I replaced C with Rust, because it’s 2017.”
Good joke. Everybody laugh. It was an easy jab at a language against which Rust was clearly
positioned as an alternative, said to an audience all too certain to appreciate it. After all,
who doesn’t love being told they’re doing the better thing?&lt;/p&gt;
&lt;p&gt;However, in the intervening years, some context in the broader ecosystem has changed.
First, a number of companies, their materials dutifully collected by &lt;a href=&quot;https://alexgaynor.net/2020/may/27/science-on-memory-unsafety-and-security/&quot;&gt;Alex Gaynor&lt;/a&gt;
and then &lt;a href=&quot;https://advocacy.consumerreports.org/research/report-future-of-memory-safety/&quot;&gt;reported further by Consumer Reports&lt;/a&gt;, started to report about the prevalence of
memory safety vulnerabilities in their software. The numbers break down to roughly 70%
across many large organizations. That’s a big number!&lt;/p&gt;
&lt;p&gt;Consumer Reports bumping the news was also a big deal. It helped take the topic across the
barrier of “things the computer nerds talk about” and over to “things the policy world
talks about.”&lt;/p&gt;
&lt;p&gt;There also started to be bigger, more noticeable cyber security events where software
security in particular was in question (not just security from the interconnection of systems
and their surprising interactions, but literal “the software did an oopsie with memory”
kinds of vulnerabilities leading to exploitation). Heartbleed, a major vulnerability in OpenSSL.
Log4Shell, where people suddenly realized how &lt;em&gt;omnipresent&lt;/em&gt; and hard to identify or update some
of this software is.&lt;/p&gt;
&lt;p&gt;Not &lt;em&gt;all&lt;/em&gt; of this is memory safety related, but I think the memory safety angle seems
appealing to policymakers because it seems both achievable, and relatively clear. If someone
says they have a new building technique for houses that means a substantial portion of houses
that would fall over today wouldn’t fall over in the future, you as a policy maker would
probably find that pretty appealing?&lt;/p&gt;
&lt;p&gt;So why did memory safety suddenly feel &lt;em&gt;possible&lt;/em&gt;? I think the answer, unintentionally,
&lt;em&gt;is&lt;/em&gt; Rust.&lt;/p&gt;
&lt;p&gt;Memory safety isn’t &lt;em&gt;new&lt;/em&gt;. Even in the &lt;a href=&quot;https://www.cisa.gov/case-memory-safe-roadmaps&quot;&gt;latest guidance from CISA&lt;/a&gt; they list a number of
non-Rust memory safe languages, used on all sorts of widespread platforms. But crucially,
lots of the “big,” “important,” real-world stuff is written in C or C++. They’re what
the grown-ups use. They weren’t memory safe, and there wasn’t really a &lt;em&gt;language&lt;/em&gt; which
bundled up all the assurance guarantees you might want into a package which is easy to use.&lt;/p&gt;
&lt;p&gt;Yeah, some people would write secure C, they’d follow the &lt;a href=&quot;https://misra.org.uk/&quot;&gt;MISRA guidelines&lt;/a&gt; or they’d run
a bunch of analyzers or they’d hire some consultants to audit the code and give them the
okay. At the end of the day, none of those things had the ease of what you get with a new
language that plays in the same sandbox and has memory safety right out of the gate. So
C and C++ retained their distinction, and their cool, by existing in a little exurb
outside of the megalopolis of memory safety, secure in the knowledge that no one could
&lt;em&gt;really&lt;/em&gt; do better without them.&lt;/p&gt;
&lt;p&gt;Rust coming along doesn’t just challenge that security, it upends that security. I think
this is part of why Bjarne Stroustrup and the C++ Directions Group have &lt;a href=&quot;https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2759r0.pdf&quot;&gt;written things
about security and safety&lt;/a&gt; that have seemed, at best, difficult to follow, and at worst
filled with anxiety and defensive about the essential nature and continuing compelling
pitch of C++. They haven’t been at risk before! To reference an old film, “Oh! I’m in
pain. I think this is what &lt;em&gt;pain&lt;/em&gt; feels like.”&lt;/p&gt;
&lt;p&gt;This is not to say that either language has been resting on their laurels, or that Rust
is set to sweep them off the stage. Despite the imagined lurking of a Rust Evangelism
Strike Force prepared to assist C and C++ in shuffling off their mortal coils, I do
not think it is the expectation of technical leaders at major tech companies, nor
policy makers or thinktankers, to fully eliminate C and C++. There’s too much of both
languages around today to get rid of, and we know that replacing old code with new code
has a tendency to introduce new vulnerabilities anyway. In the field of a settled
graveyard, we must be careful digging things up.&lt;/p&gt;
&lt;p&gt;Instead, and you can see this borne out in &lt;a href=&quot;https://www.regulations.gov/docket/ONCD-2023-0002/comments&quot;&gt;the responses to the recent ONCD Request
for Input on open source software security&lt;/a&gt;, many if not most of the respondents
recommend a transition of new code efforts from C and C++ into memory safe languages,
with caution, careful prioritization, and accompanied by other assurance techniques
when such a transition is not feasible or prudent, along with careful protection
and further assurance of the C and C++ code we already have.&lt;/p&gt;
&lt;p&gt;Nor, as I think you’ll find, do the policy documents, academic papers, and thinktank
recommendations floating around recommend that everyone transition to &lt;em&gt;Rust&lt;/em&gt; specifically.
Rust might be the language that helped break the dam on memory safety, but it is
not the &lt;em&gt;only&lt;/em&gt; memory safe language. There are many still who recall the mess of
Ada becoming a mandatory programming language in some contexts, and who do not
wish to repeat such an enforced monoculture.&lt;/p&gt;
&lt;p&gt;So, to bring it back around, why am I in a knot? I have, through personal preference
and a happy accident of history, invested substantial personal time and energy
into building my knowledge and establishing a degree of personal branding around
a programming language that is now after many years &lt;em&gt;winning&lt;/em&gt;. Rust is &lt;em&gt;winning&lt;/em&gt;. It’s
&lt;a href=&quot;https://www.c-span.org/video/?c4808083/user-clip-rust-language-chosen&quot;&gt;being mentioned in Congressional hearings&lt;/a&gt; and recommended by federal agencies.
It’s used all over the globe. You can get real jobs in it now. Why am I troubled?&lt;/p&gt;
&lt;p&gt;I think we’re in the middle of a grand renegotiation of &lt;em&gt;what C means&lt;/em&gt; and
&lt;em&gt;what C++ means&lt;/em&gt;, or what they are in the context of programming, now that they’re
no longer hegemonic powers. To borrow from geopolitics a tad, this is the slow
decline of twin empires and the entrance of a new multipolar world. It is new,
and different, and exciting, but also… sad?&lt;/p&gt;
&lt;p&gt;I think I’m in knots because I look at the people who have invested so much in C
or C++, who now wrestle with the challenges of what this new world means for them,
and I think that could well be me, down the line. None of us are guaranteed that we
back the right horse in our selections of technologies to learn or “teams” to
invest in. None of us are guaranteed that we win.&lt;/p&gt;
&lt;p&gt;Which brings me back to the joke, and my discomfort with it now. Back then, I wanted
to win. I wanted to be superior; to be on the best side, with the best language.
I wanted to be better.&lt;/p&gt;
&lt;p&gt;I’d like to &lt;a href=&quot;https://www.youtube.com/watch?v=iSmkqocn0oQ&quot;&gt;share a video&lt;/a&gt;. It’s of Simon Peyton Jones, a major contributor to Haskell,
sitting with other programming language geeks at a conference years ago. In the video
he explains, happily, that Haskell is useless, but is slowly becoming more useful.
In the video, the other participants, themselves major contributors to other languages,
jump in with their own funny anecdotes and comments. When I first watched this in my
early 20s I thought it was kinda silly, kinda funny. What I see now is that all of
these people were &lt;em&gt;friends&lt;/em&gt;. They weren’t competitors; in fact they readily copy
each other and learn from each other. In the video they talk about how Haskell
learned things from C#!&lt;/p&gt;
&lt;p&gt;It’s easy to form cliques, its easy to form monocultures. It’s easy to want to win,
and when you win it’s easy to gloat.&lt;/p&gt;
&lt;p&gt;As the march toward memory safety policy moves closer, I see more and more &lt;em&gt;angst&lt;/em&gt;
in the comments from C and C++ programmers who are fighting tooth and nail to
preserve the best parts of the thing they love, or to defend themselves and their
own prior choices. I see fear and concern that Rust will become the one true way
they will be forced to take.&lt;/p&gt;
&lt;p&gt;Even as we admit that C and C++’s guarantees are no longer sufficient for the
security needs of the day, given the vast important of the software systems
we use and maintain, I don’t think we need to condemn the people who have invested
in it, or further mock the C and C++ languages. There are good people involved in
them who are trying hard to improve things, and any work we do today is built on
the shoulders of people who came before and tried other things which may or may not
have worked. There wouldn’t be Rust without C++, I imagine, to have paved the way
with many of its own design considerations and choices.&lt;/p&gt;
&lt;p&gt;I don’t know how this transition will work out. We’re in the middle of a grand
renegotiation whose outcome is uncertain. I’m excited to see where it goes.&lt;/p&gt;
&lt;p&gt;Yet as I look out across the vista, and see the shore and opportunity that
lies out of sight beyond it, as I board a ship and begin to sail, I can
look below me and remember, “&lt;a href=&quot;https://www.humprog.org/~stephen/research/papers/kell17some-preprint.pdf&quot;&gt;Some Were Meant for C&lt;/a&gt;”.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Technostructuralism</title>
    <id>https://www.alilleybrinker.com/blog/technostructuralism/</id>
    <link rel="alternate" type="text/html" href="https://www.alilleybrinker.com/blog/technostructuralism/"/>
    <published>2019-04-03T12:00:00.000Z</published>
    <updated>2019-04-03T12:00:00.000Z</updated>
    <summary>The systems we build are manifestations of our politics, so what is the philosophy of Rust?</summary>
    <content type="html" xml:base="https://www.alilleybrinker.com/blog/technostructuralism/">&lt;p&gt;The systems we build are manifestations of our politics. So what is the
philosophy of Rust and what does it offer for the state of software?&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;So Steve Klabnik posted a really thoughtful piece on open source and free software
(&lt;a href=&quot;https://words.steveklabnik.com/what-comes-after-open-source&quot;&gt;read it if you haven’t&lt;/a&gt;),
and the responses on places like Hacker News made an error that seems common in these
circles: believing working harder will solve a problem.&lt;/p&gt;
&lt;aside class=&quot;info-callout&quot; aria-labelledby=&quot;twitter-thread-reproduction&quot;&gt;
  &lt;p id=&quot;twitter-thread-reproduction&quot; class=&quot;info-callout-title&quot;&gt;This is a reproduction of a Twitter thread&lt;/p&gt;
  &lt;p&gt;The following is a reproduction of a thread I’d posted on Twitter back in 2019. I am sharing it here because Twitter has increasingly locked content behind a login prompt and I’d like to be able to refer people to this material without them having to have a Twitter/X account. The original thread can be found at &lt;a href=&quot;https://twitter.com/alilleybrinker/status/1113538427855757313&quot;&gt;Twitter&lt;/a&gt;. The version reproduced here is done without the thread-markers, @-references, and hashtags which were used in the original.&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;This comes up with people defending C, who argue “people should write better C.” Of
course, this is nonsense. If a person can write better C consistently, we should
assume they will. If a person can, with extreme focus, write better C, that doesn’t
mean they can sustain it.&lt;/p&gt;
&lt;p&gt;It comes up with free software too. When someone points out the failures of the free
software movement, the response is “more people should believe in free software,
THEN we can deliver our goals.” This is nonsense. You don’t get more adherents by
demanding more adherents.&lt;/p&gt;
&lt;p&gt;In both scenarios, people refuse to re-examine structures. It’s not that C isn’t
meeting our needs, it’s that we’re not good enough to meet them ourselves. It’s not
that free software isn’t achieving its goals, it’s that not enough people believe in
it for it to succeed.&lt;/p&gt;
&lt;p&gt;This is all tied to the underlying politics of the software developers, often
characterized as “technolibertarian,” which believes strongly in the goodness of
technology, and the primacy of the individual in determining outcomes.&lt;/p&gt;
&lt;p&gt;This ideology is diametrically opposed to the structuralist view that Steve appears to
be taking in his piece, or that tech critics are often taking in their critiques of
tech. It plays out in the thousand externalities of tech which go unaddressed.&lt;/p&gt;
&lt;p&gt;What’s frustrating about this ideology is it opposes resolution of structural problems,
against mounting evidence of their existence and the failure of existing solutions to
fix them. It also connects to a point about programming languages as political objects.&lt;/p&gt;
&lt;p&gt;Steve’s a leader in the Rust community, and that’s no accident. Rust is a structural
response to C. Where a technolibertarian says “write better C,” a Rustacean says
“write Rust, which changes the structure so it, and not you, carries the burden of
correctness.”&lt;/p&gt;
&lt;p&gt;This is not a small point. It’s a microcosm of the fact that the technologies we build
are manifestations of our politics. It is not possible to keep politics out of tech,
because our politics shape how we approach problems, and what we build to fix them.&lt;/p&gt;
&lt;p&gt;We have, as I see it, two competing cultures in tech. The dominant culture,
technolibertarianism, and the counter-culture, which I’ll call technostructuralism.
These two cultures are often talking past each other, but they’re building systems
that match their perspectives.&lt;/p&gt;
&lt;p&gt;I know which side I prefer. Hopefully (maybe with a name, mine or someone else’s)
the technostructuralists can come out of the closet and unify their technology with
their politics. At the very least, let’s move the conversation.&lt;/p&gt;</content>
  </entry>
</feed>
