This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] change write order of frexpl & frexpf so it doesn't corrupt stack ids
ClosedPublic

Authored by aralisza on Jun 25 2021, 1:34 PM.

Details

Summary

This was fixed in the past for frexp, but was not made for frexpl & frexpf https://github.com/google/sanitizers/issues/321
This patch copies the fix over to frexpl because it caused frexp_interceptor.cpp test to fail on iPhone and frexpf for consistency.

rdar://79652161

Diff Detail

Event Timeline

aralisza created this revision.Jun 25 2021, 1:34 PM
aralisza requested review of this revision.Jun 25 2021, 1:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 25 2021, 1:34 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
aralisza updated this revision to Diff 354596.Jun 25 2021, 1:39 PM

remove comment

aralisza edited the summary of this revision. (Show Details)Jun 25 2021, 1:40 PM
kubamracek added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
972–973

should this get the same fix too?

aralisza updated this revision to Diff 354621.Jun 25 2021, 4:07 PM

change order of frexp too

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
972–973

done~ I didn't do it originally because I figured there was a reason the original author didn't go ahead an make all these changes, but it probably makes sense to do it now anyway

aralisza retitled this revision from [compiler-rt] change write order of frexpl so it doesn't corrupt stack ids to [compiler-rt] change write order of frexpl & frexpf so it doesn't corrupt stack ids.Jun 25 2021, 4:09 PM
aralisza edited the summary of this revision. (Show Details)

This seems reasonable to me. However, we are touching paths used by non-Apple platforms here so I'd like someone outside of Apple to approve too.

delcypher accepted this revision.Jul 1 2021, 10:27 AM
This revision is now accepted and ready to land.Jul 1 2021, 10:27 AM

Ping on this, would love to get an additional reviewer.

vitalybuka accepted this revision.Jul 8 2021, 12:23 PM

Can you please add trivial tests in /sanitizer_common?

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

Even if it does not fail could you also add COMMON_INTERCEPTOR_INITIALIZE_RANGE after the call
to make sure msan shadow is not corrupted by the calls internals

delcypher added inline comments.Jul 8 2021, 3:21 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

I would expect COMMON_INTERCEPTOR_WRITE_RANGE(ctx, exp, sizeof(*exp)) before the call to initialize the range. Do we actually suspect that REAL(frexpf)(x, exp) could corrupt MSan's shadow? I'm not sure how that would happen.

vitalybuka added inline comments.Jul 8 2021, 3:34 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

e.g. calculate on stack of non-instrumented function and then memcpy into output which will be intercepted and also copy "uninitialized" shadow

vitalybuka added inline comments.Jul 8 2021, 3:48 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

With the current implementation of these function probably unnecessary.
But without assuming implementation details, COMMON_INTERCEPTOR_INITIALIZE_RANGE is right thing to do.

aralisza updated this revision to Diff 359170.Jul 15 2021, 4:52 PM

add tests for frexpl and frexpf and call COMMON_INTERCEPTOR_INITIALIZE_RANGE

aralisza added inline comments.Jul 15 2021, 4:54 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

Is this what you are looking for? By "after the call" do you mean after the call to REAL(... or COMMON_INTERCEPTOR_WRITE_RANGE?

aralisza updated this revision to Diff 359171.Jul 15 2021, 4:55 PM

make ordering more consistent

vitalybuka accepted this revision.Jul 15 2021, 5:10 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
976

COMMON_INTERCEPTOR_INITIALIZE_RANGE

This revision was landed with ongoing or failed builds.Jul 16 2021, 10:58 AM
This revision was automatically updated to reflect the committed changes.