This is an archive of the discontinued LLVM Phabricator instance.

[DFSan] Change shadow and origin memory layouts to match MSan.
ClosedPublic

Authored by browneee on Jun 24 2021, 10:30 PM.

Details

Summary

Previously on x86_64:

+--------------------+ 0x800000000000 (top of memory)
| application memory |
+--------------------+ 0x700000008000 (kAppAddr)
|                    |
|       unused       |
|                    |
+--------------------+ 0x300000000000 (kUnusedAddr)
|       origin       |
+--------------------+ 0x200000008000 (kOriginAddr)
|       unused       |
+--------------------+ 0x200000000000
|   shadow memory    |
+--------------------+ 0x100000008000 (kShadowAddr)
|       unused       |
+--------------------+ 0x000000010000
| reserved by kernel |
+--------------------+ 0x000000000000

MEM_TO_SHADOW(mem) = mem & ~0x600000000000
SHADOW_TO_ORIGIN(shadow) = kOriginAddr - kShadowAddr + shadow

Now for x86_64:

+--------------------+ 0x800000000000 (top of memory)
|    application 3   |
+--------------------+ 0x700000000000
|      invalid       |
+--------------------+ 0x610000000000
|      origin 1      |
+--------------------+ 0x600000000000
|    application 2   |
+--------------------+ 0x510000000000
|      shadow 1      |
+--------------------+ 0x500000000000
|      invalid       |
+--------------------+ 0x400000000000
|      origin 3      |
+--------------------+ 0x300000000000
|      shadow 3      |
+--------------------+ 0x200000000000
|      origin 2      |
+--------------------+ 0x110000000000
|      invalid       |
+--------------------+ 0x100000000000
|      shadow 2      |
+--------------------+ 0x010000000000
|    application 1   |
+--------------------+ 0x000000000000

MEM_TO_SHADOW(mem) = mem ^ 0x500000000000
SHADOW_TO_ORIGIN(shadow) = shadow + 0x100000000000

Diff Detail

Event Timeline

browneee created this revision.Jun 24 2021, 10:30 PM
browneee requested review of this revision.Jun 24 2021, 10:30 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJun 24 2021, 10:30 PM
Herald added subscribers: llvm-commits, Restricted Project, cfe-commits. · View Herald Transcript
compiler-rt/lib/dfsan/dfsan.cpp
168

Based on the recent issue about using a replaced memmove.
It seems safe to always keep this CHECK and update the comments to reflect this.

169

Please remove the commented code.

176

This branch seems redundant with the one below.

322–327

Please update the comments to be consistent with other MEM_IS_SHADOW checks.

Thank you for making this work!

compiler-rt/lib/dfsan/dfsan.cpp
861

Please add a comment about that these CheckMemoryLayoutSanity, ... and InitShadow are possible to be shared with MSan (like the TODO in dfsan_platform.h), by moving them and those platform mapping definitions/macros compiler-rt/lib/msan/msan.h to sanitizer_common because it is highly likely that MSan and DFSan always have the same layouts...
Since the change does not branch from MSan's code, w/o comments, it is not easy for others to know they are similar.

892

I suggest moving CheckMemoryRangeAvailability and ProtectMemoryRange to sanitizer_common (if this does not break any sanitizer convention).
They are checking some general things and also some corner cases like "protect address 0...".
If shared, it is more likely that others can help DFSan to improve them.

llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
257

Does this suggest LinuxX8664MemoryMapParams? Not sure if there is a workaround to suppress this warning.

461

in mapping application to shadow and origin....

browneee updated this revision to Diff 354558.Jun 25 2021, 11:06 AM
browneee marked 8 inline comments as done.

Addressed comments.

This revision is now accepted and ready to land.Jun 25 2021, 2:45 PM
gbalats accepted this revision.Jun 25 2021, 2:52 PM