From: Evgeniy Stepanov Date: Tue, 29 Oct 2013 17:59:45 +0000 (+0000) Subject: [sanitizer] Ptrace syscall handler. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=477f8b73a56e607b3a26c45dab9b9d7a758dea8f;p=platform%2Fupstream%2Fllvm.git [sanitizer] Ptrace syscall handler. llvm-svn: 193633 --- diff --git a/compiler-rt/lib/msan/lit_tests/Linux/syscalls.cc b/compiler-rt/lib/msan/lit_tests/Linux/syscalls.cc index 962fba3..797832d 100644 --- a/compiler-rt/lib/msan/lit_tests/Linux/syscalls.cc +++ b/compiler-rt/lib/msan/lit_tests/Linux/syscalls.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -76,6 +77,10 @@ int main(int argc, char *argv[]) { __sanitizer_syscall_post_mq_timedreceive(kFortyTwo, 5, buf, sizeof(buf), &prio, 0); assert(__msan_test_shadow(buf, sizeof(buf)) == kFortyTwo); assert(__msan_test_shadow(&prio, sizeof(prio)) == -1); + + __msan_poison(buf, sizeof(buf)); + __sanitizer_syscall_post_ptrace(0, PTRACE_PEEKUSER, kFortyTwo, 0xABCD, buf); + assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(void *)); return 0; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc index 0f500d6..baa1d5b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc @@ -2218,9 +2218,45 @@ PRE_SYSCALL(ni_syscall)() {} POST_SYSCALL(ni_syscall)(long res) {} -PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) {} +PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) { + if (data) { + if (request == ptrace_setregs) { + PRE_READ((void *)data, struct_user_regs_struct_sz); + } else if (request == ptrace_setfpregs) { + PRE_READ((void *)data, struct_user_fpregs_struct_sz); + } else if (request == ptrace_setfpxregs) { + PRE_READ((void *)data, struct_user_fpxregs_struct_sz); + } else if (request == ptrace_setsiginfo) { + PRE_READ((void *)data, siginfo_t_sz); + } else if (request == ptrace_setregset) { + __sanitizer_iovec *iov = (__sanitizer_iovec *)data; + PRE_READ(iov->iov_base, iov->iov_len); + } + } +} -POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) {} +POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) { + if (res >= 0 && data) { + // Note that this is different from the interceptor in + // sanitizer_common_interceptors.inc. + // PEEK* requests return resulting values through data pointer. + if (request == ptrace_getregs) { + POST_WRITE((void *)data, struct_user_regs_struct_sz); + } else if (request == ptrace_getfpregs) { + POST_WRITE((void *)data, struct_user_fpregs_struct_sz); + } else if (request == ptrace_getfpxregs) { + POST_WRITE((void *)data, struct_user_fpxregs_struct_sz); + } else if (request == ptrace_getsiginfo) { + POST_WRITE((void *)data, siginfo_t_sz); + } else if (request == ptrace_getregset) { + __sanitizer_iovec *iov = (__sanitizer_iovec *)data; + POST_WRITE(iov->iov_base, iov->iov_len); + } else if (request == ptrace_peekdata || request == ptrace_peektext || + request == ptrace_peekuser) { + POST_WRITE((void *)data, sizeof(void *)); + } + } +} PRE_SYSCALL(add_key)(const void *_type, const void *_description, const void *_payload, long plen, long destringid) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc index fb932bc..8276a96 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -218,6 +218,9 @@ namespace __sanitizer { unsigned struct_user_fpxregs_struct_sz = sizeof(struct user_fpxregs_struct); #endif + int ptrace_peektext = PTRACE_PEEKTEXT; + int ptrace_peekdata = PTRACE_PEEKDATA; + int ptrace_peekuser = PTRACE_PEEKUSER; int ptrace_getregs = PTRACE_GETREGS; int ptrace_setregs = PTRACE_SETREGS; int ptrace_getfpregs = PTRACE_GETFPREGS; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index 0b38d15..6f27ba4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -379,6 +379,9 @@ namespace __sanitizer { extern unsigned struct_user_fpregs_struct_sz; extern unsigned struct_user_fpxregs_struct_sz; + extern int ptrace_peektext; + extern int ptrace_peekdata; + extern int ptrace_peekuser; extern int ptrace_getregs; extern int ptrace_setregs; extern int ptrace_getfpregs;