diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2016-06-20 22:05:33 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2016-06-20 22:05:33 +0000 |
commit | ecfcc07a485cef97fed411d9a926a3c1a6ef11b6 (patch) | |
tree | f3e6a64fc265c98d1e16ab6a9c35fc1b7055c3d7 | |
parent | 843b6513988b772e8a600fa896c2fe1d3715b830 (diff) | |
download | bcm5719-llvm-ecfcc07a485cef97fed411d9a926a3c1a6ef11b6.tar.gz bcm5719-llvm-ecfcc07a485cef97fed411d9a926a3c1a6ef11b6.zip |
[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.
llvm-svn: 273205
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc | 9 | ||||
-rw-r--r-- | compiler-rt/test/msan/Linux/sendmsg.cc | 23 |
2 files changed, 11 insertions, 21 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index ae78da2e74b..b7664c4e513 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -5639,16 +5639,15 @@ INTERCEPTOR(SSIZE_T, send, int fd, void *buf, SIZE_T len, int flags) { } 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; diff --git a/compiler-rt/test/msan/Linux/sendmsg.cc b/compiler-rt/test/msan/Linux/sendmsg.cc index 2f5600729f0..6a8ef83c118 100644 --- a/compiler-rt/test/msan/Linux/sendmsg.cc +++ b/compiler-rt/test/msan/Linux/sendmsg.cc @@ -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"); |