This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Zero- and pattern-initialization of memory.
ClosedPublic

Authored by eugenis on Apr 29 2020, 2:55 PM.

Details

Summary

Implement pattern initialization of memory (excluding the secondary
allocator because it already has predictable memory contents).
Expose both zero and pattern initialization through the C API.

Diff Detail

Event Timeline

eugenis created this revision.Apr 29 2020, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2020, 2:55 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

What should be the behavior of calloc with pattern_fill_contents, should it still be 0 or the pattern?

glider added a subscriber: glider.Apr 30 2020, 8:44 AM

Out of curiosity, is there any reason to have pattern initialization for heap?
As security researchers note (see the discussion of stack initialization on cfe-dev), zero-initialization has a smaller probability of making existing bugs exploitable.
On the other hand, there is no downside in making the heap zero-initialized, as library features do not introduce language dialects.

Re: calloc behavior, it probably should not return patter-initialized memory even if pattern initialization is enabled.
A lot of code depend on calloc returning zeroes.

compiler-rt/lib/scudo/standalone/combined.h
401–402

Please make this 0xAB a constant.

eugenis updated this revision to Diff 261321.Apr 30 2020, 12:43 PM

named constant for 0xAB

eugenis marked an inline comment as done.Apr 30 2020, 12:58 PM

Pattern initialization for heap can be used as a "poor man's MSan".
Also, it absolutely introduces a language dialect, as in certain code will now reliably work that did not work before. I think security considerations trump that in this case, but it's good to have pattern init as an option, at lease.

I agree on calloc, zeroing memory is in the function's contract.

cryptoad accepted this revision.Apr 30 2020, 2:29 PM
cryptoad added inline comments.
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
140

s/PatterOrZeroFill/PatternOrZeroFill/

This revision is now accepted and ready to land.Apr 30 2020, 2:29 PM
eugenis updated this revision to Diff 261359.Apr 30 2020, 2:44 PM

fix a typo in a comment

eugenis marked an inline comment as done.Apr 30 2020, 2:44 PM
This revision was automatically updated to reflect the committed changes.