[compiler-rt] r273728 - [msan] Fix syscall handlers for pipe, pipe2, socketpair.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 14:15:54 PDT 2016


Author: eugenis
Date: Fri Jun 24 16:15:53 2016
New Revision: 273728

URL: http://llvm.org/viewvc/llvm-project?rev=273728&view=rev
Log:
[msan] Fix syscall handlers for pipe, pipe2, socketpair.

These syscalls write two file descriptors into the output buffer, not one.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
    compiler-rt/trunk/test/msan/Linux/syscalls.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc?rev=273728&r1=273727&r2=273728&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc Fri Jun 24 16:15:53 2016
@@ -1237,17 +1237,15 @@ POST_SYSCALL(fcntl64)(long res, long fd,
 PRE_SYSCALL(pipe)(void *fildes) {}
 
 POST_SYSCALL(pipe)(long res, void *fildes) {
-  if (res >= 0) {
-    if (fildes) POST_WRITE(fildes, sizeof(int));
-  }
+  if (res >= 0)
+    if (fildes) POST_WRITE(fildes, sizeof(int) * 2);
 }
 
 PRE_SYSCALL(pipe2)(void *fildes, long flags) {}
 
 POST_SYSCALL(pipe2)(long res, void *fildes, long flags) {
-  if (res >= 0) {
-    if (fildes) POST_WRITE(fildes, sizeof(int));
-  }
+  if (res >= 0)
+    if (fildes) POST_WRITE(fildes, sizeof(int) * 2);
 }
 
 PRE_SYSCALL(dup)(long fildes) {}
@@ -1880,13 +1878,11 @@ PRE_SYSCALL(socket)(long arg0, long arg1
 
 POST_SYSCALL(socket)(long res, long arg0, long arg1, long arg2) {}
 
-PRE_SYSCALL(socketpair)(long arg0, long arg1, long arg2, void *arg3) {}
+PRE_SYSCALL(socketpair)(long arg0, long arg1, long arg2, int *sv) {}
 
-POST_SYSCALL(socketpair)(long res, long arg0, long arg1, long arg2,
-                         void *arg3) {
-  if (res >= 0) {
-    if (arg3) POST_WRITE(arg3, sizeof(int));
-  }
+POST_SYSCALL(socketpair)(long res, long arg0, long arg1, long arg2, int *sv) {
+  if (res >= 0)
+    if (sv) POST_WRITE(sv, sizeof(int) * 2);
 }
 
 PRE_SYSCALL(socketcall)(long call, void *args) {}

Modified: compiler-rt/trunk/test/msan/Linux/syscalls.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/syscalls.cc?rev=273728&r1=273727&r2=273728&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/syscalls.cc (original)
+++ compiler-rt/trunk/test/msan/Linux/syscalls.cc Fri Jun 24 16:15:53 2016
@@ -19,7 +19,7 @@
    sanity of their behaviour. */
 
 int main(int argc, char *argv[]) {
-  char buf[1000];
+  char buf[1000] __attribute__((aligned(8)));
   const int kTen = 10;
   const int kFortyTwo = 42;
   memset(buf, 0, sizeof(buf));
@@ -111,5 +111,17 @@ int main(int argc, char *argv[]) {
   assert(__msan_test_shadow(&p, sizeof(p)) == -1);
   assert(__msan_test_shadow(buf, sizeof(buf)) >= 32);
 
+  __msan_poison(buf, sizeof(buf));
+  __sanitizer_syscall_post_pipe(0, (int *)buf);
+  assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
+  __msan_poison(buf, sizeof(buf));
+  __sanitizer_syscall_post_pipe2(0, (int *)buf, 0);
+  assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
+  __msan_poison(buf, sizeof(buf));
+  __sanitizer_syscall_post_socketpair(0, 0, 0, 0, (int *)buf);
+  assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
   return 0;
 }




More information about the llvm-commits mailing list