This is an archive of the discontinued LLVM Phabricator instance.

WIP [randstruct] Add randomize structure layout support
AbandonedPublic

Authored by void on Mar 2 2022, 5:23 PM.

Details

Summary

The Randstruct feature is a compile-time hardening technique that
randomizes the field layout for designated structures of a code base.
Admittedly, this is mostly useful for closed-source releases of code,
since the randomization seed would need to be available for public and
open source applications.

Why implement it? This patch set enhances Clang’s feature parity with
that of GCC which already has the Randstruct feature. It's used by the
Linux kernel in certain structures to help thwart attacks that depend on
structure layouts in memory.

This patch set is a from-scratch reimplementation of the Randstruct
feature that was originally ported to GCC. The patches for the GCC
implementation can be found here:

https://www.openwall.com/lists/kernel-hardening/2017/04/06/14

Link: https://lists.llvm.org/pipermail/cfe-dev/2019-March/061607.html
Co-authored-by: Cole Nixon <nixontcole@gmail.com>
Co-authored-by: Connor Kuehl <cipkuehl@gmail.com>
Co-authored-by: James Foster <jafosterja@gmail.com>
Co-authored-by: Jeff Takahashi <jeffrey.takahashi@gmail.com>
Co-authored-by: Jordan Cantrell <jordan.cantrell@mail.com>
Co-authored-by: Nikk Forbus <nicholas.forbus@gmail.com>
Co-authored-by: Tim Pugh <nwtpugh@gmail.com>
Co-authored-by: Bill Wendling <isanbard@gmail.com>
Signed-off-by: Bill Wendling <isanbard@gmail.com>

Diff Detail

Event Timeline

void created this revision.Mar 2 2022, 5:23 PM
Herald added a project: Restricted Project. · View Herald Transcript
void requested review of this revision.Mar 2 2022, 5:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 5:23 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
void updated this revision to Diff 413260.Mar 5 2022, 4:02 PM

Update with coding style.

void updated this revision to Diff 413343.Mar 6 2022, 10:58 PM

Fix assert from use of null pointer.

void updated this revision to Diff 413383.Mar 7 2022, 1:58 AM

Don't warn on multiple attributes. Instead, use the last one to indicate whether to randomize the layout or not.

void updated this revision to Diff 413662.Mar 7 2022, 5:01 PM

Don't call little-used function in DeclContext to re-link the record decls.

void retitled this revision from WIP [randstruct] Create basis for unit test module to WIP [randstruct] Add randomize structure layout support.Mar 9 2022, 1:07 AM
void edited the summary of this revision. (Show Details)
void added a reviewer: connorkuehl.
void updated this revision to Diff 414030.Mar 9 2022, 1:07 AM

Place the randomization call where it'll actually work. :-)

void added a comment.Mar 9 2022, 1:12 AM

@connorkuehl This is almost ready to unleash upon the whole community. I wanted to give you the first chance to review it. Please let me know what you think! Hopefully I didn't mess your code up too badly.

void updated this revision to Diff 414500.Mar 10 2022, 2:30 PM

Improve bad cast warning message.

This seems like a duplicate of https://reviews.llvm.org/D121556 -- should this review be abandoned?

void abandoned this revision.Mar 17 2022, 2:14 PM

This seems like a duplicate of https://reviews.llvm.org/D121556 -- should this review be abandoned?

Yes. Thanks :-)