[compiler-rt] r273205 - [msan] Don't check dstaddr in sendto() interceptor.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 15:05:33 PDT 2016


Author: eugenis
Date: Mon Jun 20 17:05:33 2016
New Revision: 273205

URL: http://llvm.org/viewvc/llvm-project?rev=273205&view=rev
Log:
[msan] Don't check dstaddr in sendto() interceptor.

Dstaddr may contain uninitialized padding at the end (common
implementations accept larger addrlen and ignore the extra bytes).
Also, depending on the socket state, dstaddr argument may be ignored.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/test/msan/Linux/sendmsg.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=273205&r1=273204&r2=273205&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Jun 20 17:05:33 2016
@@ -5639,16 +5639,15 @@ INTERCEPTOR(SSIZE_T, send, int fd, void
 }
 
 INTERCEPTOR(SSIZE_T, sendto, int fd, void *buf, SIZE_T len, int flags,
-            void *srcaddr, int addrlen) {
+            void *dstaddr, int addrlen) {
   void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, sendto, fd, buf, len, flags, srcaddr, addrlen);
+  COMMON_INTERCEPTOR_ENTER(ctx, sendto, fd, buf, len, flags, dstaddr, addrlen);
   if (fd >= 0) {
     COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
     COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
   }
-  if (common_flags()->intercept_send && srcaddr && addrlen)
-    COMMON_INTERCEPTOR_READ_RANGE(ctx, srcaddr, addrlen);
-  SSIZE_T res = REAL(sendto)(fd, buf, len, flags, srcaddr, addrlen);
+  // Can't check dstaddr as it may have uninitialized padding at the end.
+  SSIZE_T res = REAL(sendto)(fd, buf, len, flags, dstaddr, addrlen);
   if (common_flags()->intercept_send && res > 0)
     COMMON_INTERCEPTOR_READ_RANGE(ctx, buf, Min((SIZE_T)res, len));
   return res;

Modified: compiler-rt/trunk/test/msan/Linux/sendmsg.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/sendmsg.cc?rev=273205&r1=273204&r2=273205&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/sendmsg.cc (original)
+++ compiler-rt/trunk/test/msan/Linux/sendmsg.cc Mon Jun 20 17:05:33 2016
@@ -1,20 +1,16 @@
-// RUN: %clangxx_msan %s -DSEND -DBUF -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SEND
-// RUN: %clangxx_msan %s -DSENDTO -DBUF -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDTO
-// RUN: %clangxx_msan %s -DSENDMSG -DBUF -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
-
-// FIXME: intercept connect() and add a SEND+ADDR test
-// RUN: %clangxx_msan %s -DSENDTO -DADDR -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDTO-ADDR
-// RUN: %clangxx_msan %s -DSENDMSG -DADDR -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG-ADDR
+// RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SEND
+// RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDTO
+// RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
 
 // RUN: %clangxx_msan %s -DSEND -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
 // RUN: %clangxx_msan %s -DSENDTO -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
 // RUN: %clangxx_msan %s -DSENDMSG -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
 
-// RUN: %clangxx_msan %s -DSEND -DBUF -o %t && \
+// RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && \
 // RUN:   MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
-// RUN: %clangxx_msan %s -DSENDTO -DBUF -o %t && \
+// RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && \
 // RUN:   MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
-// RUN: %clangxx_msan %s -DSENDMSG -DBUF -o %t && \
+// RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && \
 // RUN:   MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
 
 // UNSUPPORTED: android
@@ -49,10 +45,7 @@ int main() {
   socklen_t addrlen = sizeof(serveraddr);
   getsockname(sockfd, (struct sockaddr *)&serveraddr, &addrlen);
 
-#if defined(ADDR)
-  assert(addrlen > 3);
-  __msan_poison(((char *)&serveraddr) + 3, 1);
-#elif defined(BUF)
+#if defined(POISON)
   __msan_poison(buf + 7, 1);
 #endif
 
@@ -78,12 +71,10 @@ int main() {
   ret =
       sendto(sockfd, buf, kBufSize, 0, (struct sockaddr *)&serveraddr, addrlen);
   // SENDTO: Uninitialized bytes in __interceptor_sendto at offset 7 inside [{{.*}}, 10)
-  // SENDTO-ADDR: Uninitialized bytes in __interceptor_sendto at offset 3 inside [{{.*}},
   assert(ret > 0);
 #elif defined(SENDMSG)
   ret = sendmsg(sockfd, &msg, 0);
   // SENDMSG: Uninitialized bytes in {{.*}} at offset 2 inside [{{.*}}, 5)
-  // SENDMSG-ADDR: Uninitialized bytes in {{.*}} at offset 3 inside [{{.*}},
   assert(ret > 0);
 #endif
   fprintf(stderr, "== done\n");




More information about the llvm-commits mailing list