Security

Research

CISA looked at C/C++ projects and found a lot of C/C++ code. Wanna redo any of it in Rust?

So, so many lines of memory-unsafe routines in crucial open source, and unsafe dependencies


The US government's Cybersecurity and Infrastructure Security Agency (CISA) has analyzed 172 critical open source projects and found that more than half contain code written in languages like C and C++ that are not naturally memory safe.

What's more, projects written in memory-safe languages may still be exposed to memory vulnerabilities through unsafe dependencies. The agency's finding is detailed in a report titled, "Exploring Memory Safety in Critical Open Source Projects."

Issued this week by CISA, in conjunction with the FBI, the Australian Signals Directorate’s Australian Cyber Security Center, and the Canadian Cyber Security Center, the report backs a drive by Five Eyes nations to get public and private sector organizations to reduce the number of software vulnerabilities arising from memory safety bugs.

"Memory-unsafe languages require developers to properly manage memory use and allocation," the report finds. "Mistakes, which inevitably occur, can result in memory-safety vulnerabilities such as buffer overflows and use after free. Successful exploitation of these types of vulnerabilities can allow adversaries to take control of software, systems, and data."

Memory-safe languages, like C#, Go, Java, Python, Rust, and Swift, handle memory management for the developer, reducing the opportunity to make memory errors.

In December 2023, CISA, with the help of the NSA, FBI, and the cyber security authorities of Australia, Canada, the UK, and New Zealand published a paper entitled "The Case for Memory Safety Roadmaps." CISA's open source project report follows that roadmap and aligns with America's 2023 National Cybersecurity Strategy.

Memory safety errors, such as buffer overflows, use of uninitialized memory, type confusion, and use-after-free flaws, have been a matter of concern in the technical community for years. They're commonly the result of programming errors in C/C++ code and account for the majority of the vulnerabilities in large codebases.

The 2015 stable release of Rust, a language with strong memory-safety guarantees, gave tech firms a non-aligned systems language they could use to avoid the problems with memory-unsafe code. The competitive implications of adopting languages with strong corporate associations, like C# (Microsoft), Go (Google), Swift (Apple), or Java (Oracle) may have helped make Rust more appealing. But it took a few years for Rust to mature and catch on.

Microsoft has been contemplating the virtues of Rust since at least 2019. But the programming language really took off in 2021, with the formation of the Rust Foundation, backed by founding members AWS, Huawei, Google, Microsoft, and Mozilla.

The C++ community, in response to the fuss about memory-safe languages like Rust, is trying to allow developers to write safer code through C++ profiles, which provide safety guarantees at compile time. Not everyone agrees C++ is up to the challenge.

Whatever the case, Google and Microsoft have made a show of moving toward memory-safe languages, initially for new projects and lately for application rewrites. Google, for example, earlier this year said its Rust development teams are twice as productive as its C++ teams.

At the same time, developers working with the Prossimo project have been rewriting critical open source libraries in Rust to reduce the risk of a memory flaws in legacy code. Just this week, Let's Encrypt said it has deployed ntpd-rs, Prossimo's Rust rewrite of the Network Time Protocol (NTP) daemon. But, as the CISA report shows, there's a lot of work left to do.

The CISA report looked at 172 case studies on a list of critical projects compiled by the Open Source Security Foundation. It found:

The projects evaluated include: Chromium, Gecko, KVM, Linux, LLVM, GCC, JDK, Node, and many others.

The Linux kernel, among the largest projects, "predominantly use memory-unsafe languages," the report says. "Some other large projects (Chromium and Gecko web browser frameworks) use memory-unsafe languages for roughly half of their code."

Linux began incorporating Rust code as of December 2022.

And while CISA conceded in its report that even projects in memory-safe languages can be vulnerable to memory safety bugs, primarily through dependencies, it concluded by urging people to consider rewriting their critical non-safe code:

We encourage others to build on this analysis to further expand our collective understanding of memory-unsafety risk in open source software, evaluate approaches — such as targeted rewrites of critical components in memory-safe languages — to reducing this risk, and to continue efforts to drive risk-reducing action by software manufacturers.

Gunnar Braun, technical manager at the Synopsys Software Integrity Group, told The Register that it's important to raise awareness of memory safety as a means to make software more secure.

"Memory safety should be one of the key considerations when deciding on a programming language," said Braun. "The report and its preceding 'Case for Memory Safe Roadmaps' bring this to C-level executives – where it belongs. Software security and safety are no longer a purely technical concern."

Braun said that the report observes that many of these open source programs run in embedded systems with strict resource constraints. If it's not possible to change programming languages, he said, then that makes it all the more important to employ static code analysis and fuzzing tools to mitigate memory-safety risks.

"Some memory-safe languages, such as Rust or Go, are already making their way into embedded systems, so I'm optimistic that C/C++ will be largely replaced one day – but not today, and not tomorrow," he said. "Until we get there, static code analysis and fuzzing tools will be as important as they always were, if not more." ®

Send us news
81 Comments

Microsoft won't let customers opt out of passkey push

Enrollment invitations will continue until security improves

Australia moves to drop some cryptography by 2030 – before quantum carves it up

The likes of SHA-256, RSA, ECDSA and ECDH won't be welcome in just five years

Boffins trick AI model into giving up its secrets

All it took to make an Google Edge TPU give up model hyperparameters was specific hardware, a novel attack technique … and several days

Open source maintainers are drowning in junk bug reports written by AI

Python security developer-in-residence decries use of bots that 'cannot understand code'

AMD secure VM tech undone by DRAM meddling

Boffins devise BadRAM attack to pilfer secrets from SEV-SNP encrypted memory

US reportedly mulls TP-Link router ban over national security risk

It could end up like Huawei -Trump's gonna get ya, get ya, get ya

Ransomware scum blow holes in Cleo software patches, Cl0p (sort of) claims responsibility

But can you really take crims at their word?

Just how deep is Nvidia's CUDA moat really?

Not as impenetrable as you might think, but still more than Intel or AMD would like

BlackBerry offloads Cylance's endpoint security products to Arctic Wolf

Fresh attempt to mix the perfect cocktail of IoT and Infosec

How Androxgh0st rose from Mozi's ashes to become 'most prevalent malware'

Botnet's operators 'driven by similar interests as that of the Chinese state'

Blocking Chinese spies from intercepting calls? There ought to be a law

Sen. Wyden blasts FCC's 'failure' amid Salt Typhoon hacks

Critical security hole in Apache Struts under exploit

You applied the patch that could stop possible RCE attacks last week, right?