Google Online Security Blog
Follow
Retrofitting Spatial Safety to hundreds of millions of lines of C++
Spatial memory safety vulnerabilities, which occur when code accesses memory outside its intended bounds, are a major security risk and have been exploited by attackers to compromise systems and sensitive data. According to Google's Project Zero, these vulnerabilities represent 40% of in-the-wild memory safety exploits over the past decade. To address this, Google is taking a comprehensive approach to memory safety, including using memory-safe languages in new code and retrofitting secure-by-design principles to existing C++ codebases. One key strategy is to implement bounds checking for common data structures, starting with hardening the C++ standard library (libc++). Hardened libc++ introduces security checks to catch vulnerabilities such as out-of-bounds accesses in production. Google has made hardened libc++ default across its server-side production systems, improving spatial memory safety across its services. The performance impact of these changes was surprisingly low, with an average 0.30% impact across services. Enabling hardened libc++ has already prevented exploits, reduced crashes, and improved code correctness, with over 1,000 bugs uncovered and a 30% reduction in segmentation faults. Google is committed to expanding bounds checking to other libraries and migrating its code to Safe Buffers, requiring all accesses to be bounds checked. The company encourages other organizations using C++ to enable their standard library's hardened mode universally by default.