This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Fix ptrace interceptor for aarch64
ClosedPublic

Authored by zatrazz on Oct 12 2015, 1:29 PM.

Details

Summary

This patch fixes the ptrace interceptor for aarch64. The PTRACE_GETREGSET
ptrace syscall with with invalid memory might zero the iovec::iov_base
field and then masking the subsequent check after the syscall (since it
will be 0 and it will not trigger an invalid access). The fix is to copy
the value on a local variable and use its value on the check.

The patch also adds more coverage on the Linux/ptrace.cc testcase by addding
check for PTRACE_GETREGSET for both general and floating registers (aarch64
definitions added only).

Diff Detail

Event Timeline

zatrazz updated this revision to Diff 37159.Oct 12 2015, 1:29 PM
zatrazz retitled this revision from to [sanitizer] Fix ptrace interceptor for aarch64.
zatrazz updated this object.
zatrazz added reviewers: kcc, pcc, rengolin, eugenis, samsonov.
zatrazz added a subscriber: llvm-commits.
eugenis added inline comments.Oct 13 2015, 11:28 AM
lib/sanitizer_common/sanitizer_common_interceptors.inc
2464

Hm, we don't check that __sanitizer_iovec in data is accessible. Would you mind adding a READ_RANGE for that before copying it out?

test/asan/TestCases/Linux/ptrace.cc
5–6

This is impossible. You can not build compiler-rt to support all 3 of those at one time.
UNSUPPORTED: AddressSanitizer-x86_64-linux :: TestCases/Linux/ptrace.cc
UNSUPPORTED: AddressSanitizer-i386-linux :: TestCases/Linux/ptrace.cc

Not sure what's the best solution here. Maybe #ifdef-out the entire test on unsupported platforms?

17

Does it mean x86_64 run into the same problem soon?

zatrazz added inline comments.Oct 13 2015, 1:31 PM
lib/sanitizer_common/sanitizer_common_interceptors.inc
2464

Right, I will do it.

test/asan/TestCases/Linux/ptrace.cc
5–6

Right, I misunderstood the idea of REQUIRES. If there is no way to conditionally select the requirement (x86_64 or i386 or aarch64) the way I see to enable this test is to remove the 'requires', enable on all the architectures and then XFAIL on the ones that do not have the instrumented ptrace (since the CHECK: will be still being evaluated even if we #ifdef-out the tests). Suggestions?

17

The REQUIRES issue you noted above in fact showed this is not really necessary for the test itself. I will fix it and also another nits I found in this testcase.

eugenis added inline comments.Oct 13 2015, 2:37 PM
test/asan/TestCases/Linux/ptrace.cc
5–6

How about listing targets this test does not run on as UNSUPPORTED: ?

zatrazz updated this revision to Diff 37368.Oct 14 2015, 11:14 AM

I updated the patch with additional checks for the iovec pointer itself and add
more tests for the test/asan/TestCases/Linux/ptrace.cc taking in consideration
all the current supported platforms. I tested on aarch64, arm*, powerpc64**,
x86_64, and i386. I do not have access to a mips64 machine, but I based the
changes on current code from ./test/sanitizer_common/TestCases/Linux/ptrace.cc.

For arm the test now fails due missing ptrace instrumentation for the architecture,
however I have a patch ready to fix it (so we might XFAIL arm-linux-gnueabi{hf}
for now). For powercp64 I had to use PTRACE_GETREGSET because
PTRACE_GETREGS was not supported on LE system I have access (although
the ptrace itself does not fail).

eugenis accepted this revision.Oct 19 2015, 12:07 PM
eugenis edited edge metadata.
This revision is now accepted and ready to land.Oct 19 2015, 12:07 PM
zatrazz closed this revision.Oct 26 2015, 11:57 AM