This is an archive of the discontinued LLVM Phabricator instance.

[dfsan] Add origin chain utils
ClosedPublic

Authored by stephan.yichao.zhao on Feb 5 2021, 10:31 AM.

Details

Summary

This is a part of https://reviews.llvm.org/D95835.

The design is based on MSan origin chains.

An 4-byte origin is a hash of an origin chain. An origin chain is a
pair of a stack hash id and a hash to its previous origin chain. 0 means
no previous origin chains exist. We limit the length of a chain to be 16.
With origin_history_size <= 0, the limit is removed.

The number of an origin node reference count is also limited.
See 3.6.1 of this paper.

The change does not have any test cases yet. The following change
will be adding test cases when the APIs are used.

Diff Detail

Event Timeline

stephan.yichao.zhao requested review of this revision.Feb 5 2021, 10:31 AM
stephan.yichao.zhao created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2021, 10:31 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
stephan.yichao.zhao edited the summary of this revision. (Show Details)Feb 5 2021, 10:33 AM

fixed lint warnings

morehouse added inline comments.Feb 8 2021, 12:00 PM
compiler-rt/lib/dfsan/dfsan.cpp
288

Which platforms are these? If non-Linux, we don't care for DFSan.

301

Where is this defined? Please include the file directly.

compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
24

How much of this file is the same as MSan? Can we move the implementation to sanitizer_common and share it with both?

compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h
22
26
compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
24

Will move them into sanitizer_common in a child change.

morehouse added inline comments.Feb 8 2021, 12:14 PM
compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
24

I think I'd prefer to move it first, then review this patch. It would make it easier to see the differences.

stephan.yichao.zhao marked 6 inline comments as done.Feb 8 2021, 10:03 PM
stephan.yichao.zhao added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
288

In terms of this, this happens only on mips.
Removed the restriction, but still keep the comments for reference.

301

It is defined sanitizer_stacktrace.h. We include this file.

compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
24

See D96319.

compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h
22

fixed in the child change D96319.

26

fixed in the child change D96319.

stephan.yichao.zhao marked 5 inline comments as done.

updated

stephan.yichao.zhao planned changes to this revision.Feb 8 2021, 10:04 PM

wait for D96319.

morehouse added inline comments.Feb 11 2021, 8:05 AM
compiler-rt/lib/dfsan/dfsan.cpp
295

We should include dfsan_flags.h for this.

308

Tracking origins through signal handlers could help a lot in debugging obscure bugs.

If it is not possible to track, please add a comment explaining why.

compiler-rt/lib/dfsan/dfsan_origin.h
83

This will fail if origin_history_size is larger than 1 << kDepthBits.

114
126

Nit: Let's move this to the top of the public section above.

stephan.yichao.zhao marked 4 inline comments as done.

updated in terms of comments

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

We include dfsan_flags.h in dfsan.h where we defined flags() before moving it into dfsan_flags.h.

compiler-rt/lib/dfsan/dfsan_origin.h
83

changed this assert to a normal check.

114

Thank you,

126

It refers to the private kDepthBits. The compiler does not allow forward reference for some reason.

morehouse accepted this revision.Feb 11 2021, 10:36 AM
morehouse added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
295

I prefer direct includes so we don't need to touch this file if we later remove the include from dfsan.h.

This revision is now accepted and ready to land.Feb 11 2021, 10:36 AM

added dfsan_flags.h

This revision was landed with ongoing or failed builds.Feb 11 2021, 11:10 AM
This revision was automatically updated to reflect the committed changes.
uabelho added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
305

This function seems to be unused, and currently make clang raise a warning:

12:25:59 /repo/bbiswjenk/fem2s10-eiffel176/workspace/llvm/llvm-master-clang/compiler-rt/lib/dfsan/dfsan.cpp:307:12: error: unused function 'ChainOrigin' [-Werror,-Wunused-function]
12:25:59 static u32 ChainOrigin(u32 id, StackTrace *stack, bool from_init = false) {
12:25:59 ^
12:25:59 1 error generated.

stephan.yichao.zhao marked 2 inline comments as done.Feb 12 2021, 10:14 AM
stephan.yichao.zhao added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
305

Thank you for reporting this. The next change (https://reviews.llvm.org/D96564) will be fixing this. But I submitted a fix to comment this out for now: https://github.com/llvm/llvm-project/commit/a7538fee3a0256a8891e746823f7b0f0ade84e62