Google proposes default-ready CFI for Clang and LLVM
The plan extends kernel-style hash checks to C++ virtual calls and to builds that do not use link-time optimization.
Google wants control-flow integrity to become a default defense for C and C++ programs built with Clang, not a specialized option reserved for the Linux kernel or for builds that can afford link-time optimization. Chandler Carruth, writing for Google on LLVM's Discourse forum, said the company is treating that as urgent work, with small fixes already landing and larger design changes still to come.
CFI checks that an indirect call lands only on a function of the expected type. Carruth argued it is a stronger bet than many other hardening techniques because "its security model does not depend on secrets that can be leaked and is not a fundamentally probabilistic mitigation." What has held it back, he said, is deployment cost, runtime overhead, and gaps in how precisely it identifies legal targets. Clang already has two schemes: a fuller CFI implementation and kCFI, the hash-based checks added for the kernel.
The proposal keeps the kCFI model and stretches it. Virtual calls and vtables would get their own hash domain, separate from ordinary function pointers. Source annotations, or similar techniques, would shrink the set of functions a call site is allowed to reach. Google also wants faster checks outside the kernel, LLVM optimizations that understand those checks, and fixes for correctness bugs that show up only when the mitigation is turned on widely. Where hardware backward-edge protection such as pointer authentication or Intel CET is unavailable, the same ideas might cover return addresses as well. Carruth said the team looked at relying only on hardware forward-edge CFI and rejected it: software checks can be both precise enough and fast enough to deploy broadly. CET, he noted, does not encode meaningful type bits, and the default pointer-authentication behavior treats every indirect call as equivalent.
Andrew Pinski said the current kCFI hash, built from a C++-style mangled name, fails for many C compatibility functions, and asked for a different scheme. He also noted that a pointer to a member function can invoke a virtual function, so virtual calls are not confined to vtables. Carruth said revising the hash, including an extension of the existing salt, is in scope. On member pointers, he said the prototype follows the thunk approach already used for Arm pointer authentication. That preserves standard C++ calling rules but breaks a GNU extension, and it also rejects taking the address of a virtual function whose argument or return type is still incomplete, a construct Google has asked the C++ committee to disallow. He said Google has already built its monolithic codebase, including open source dependencies, in this mode without trouble.