Clang 15 Lands support to randomize structure layout, Linux prepare to use it

In the corresponding behavior already provided by the GCC compiler, LLVM/Clang unhooked the “RandStruct” feature to optionally allow randomizing the layout of the structure for C code.

Clang RandStruct support is implemented similarly to GCC and designed as a compile-time hardening to make it harder for attackers to retrieve data from program structures. Support can be enabled via the “-frandomize-layout-seed=” or “-frandomize-layout-seed-file=” options to provide the deterministic random seed allowing for reproducible builds.

The patch was merged last week in what will be LLVM/Clang 15 this fall.

Meanwhile, Google’s Kees Cook prepared for-next/randstruct with Linux kernel RandStruct integration to be extended to also work with the Clang compiler. So far, Linux kernel RandStruct support obviously just worked with the GCC compiler to randomize sensitive Linux kernel structures in the name of greater security. Look for this Clang support in for-next/randstruct to land with Linux kernel 5.19 this summer.

Using Linux kernel RandStruct hardening may incur some performance hit, but there is also a build-time setting to try to limit structure layout randomization to cache groups of members of the size of a row to reduce this performance cost, but with reduced randomization.