[llvm-branch-commits] [compiler-rt] 3bd2ad5 - [DFSan] Add several math functions to ABI list.
Author: Matt Morehouse Date: 2020-12-08T10:51:05-08:00 New Revision: 3bd2ad5a0828e956400393e3ea153c417f256aab URL: https://github.com/llvm/llvm-project/commit/3bd2ad5a0828e956400393e3ea153c417f256aab DIFF: https://github.com/llvm/llvm-project/commit/3bd2ad5a0828e956400393e3ea153c417f256aab.diff LOG: [DFSan] Add several math functions to ABI list. These are all straightforward functional entries. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D92791 Added: Modified: compiler-rt/lib/dfsan/done_abilist.txt Removed: diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 21464819e0fe..40dd0f54929b 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -48,20 +48,49 @@ fun:tolower=functional fun:toupper=functional # Functions that return a value that is data-dependent on the input. +fun:__isinf=functional +fun:__isinff=functional +fun:__signbit=functional +fun:__signbitf=functional +fun:__signbitl=functional fun:btowc=functional fun:exp=functional fun:exp2=functional +fun:expf=functional +fun:expl=functional fun:fabs=functional fun:finite=functional +fun:finitef=functional +fun:finitel=functional fun:floor=functional fun:fmod=functional fun:isinf=functional +fun:isinff=functional +fun:isinfl=functional fun:isnan=functional +fun:isnanf=functional +fun:isnanl=functional fun:log=functional +fun:log1p=functional +fun:log1pf=functional +fun:log1pl=functional +fun:log2=functional +fun:log2f=functional +fun:log2l=functional fun:modf=functional +fun:nextafter=functional +fun:nextafterf=functional +fun:nextafterl=functional +fun:nexttoward=functional +fun:nexttowardf=functional +fun:nexttowardl=functional fun:pow=functional +fun:powf=functional +fun:powl=functional fun:round=functional fun:sqrt=functional +fun:sqrtf=functional +fun:sqrtl=functional fun:wctob=functional # Functions that produce an output that does not depend on the input (shadow is ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 483fb33 - [DFSan] Add pthread and other functions to ABI list.
Author: Matt Morehouse Date: 2020-12-08T13:55:35-08:00 New Revision: 483fb333605fc3a392ba140d33e8d9187cf02b70 URL: https://github.com/llvm/llvm-project/commit/483fb333605fc3a392ba140d33e8d9187cf02b70 DIFF: https://github.com/llvm/llvm-project/commit/483fb333605fc3a392ba140d33e8d9187cf02b70.diff LOG: [DFSan] Add pthread and other functions to ABI list. The non-pthread functions are all clear discard functions. Some of the pthread ones could clear shadow, but aren't worth writing custom wrappers for. I can't think of any reasonable scenario where we would pass tainted memory to these pthread functions. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D92877 Added: Modified: compiler-rt/lib/dfsan/done_abilist.txt Removed: diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 40dd0f54929b6..252ec52f1bd25 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -96,6 +96,7 @@ fun:wctob=functional # Functions that produce an output that does not depend on the input (shadow is # zeroed automatically). fun:__assert_fail=discard +fun:__cmsg_nxthdr=discard fun:__ctype_b_loc=discard fun:__cxa_atexit=discard fun:__errno_location=discard @@ -112,8 +113,10 @@ fun:chdir=discard fun:close=discard fun:closedir=discard fun:connect=discard +fun:creat=discard fun:dladdr=discard fun:dlclose=discard +fun:epoll_ctl=discard fun:fclose=discard fun:feof=discard fun:ferror=discard @@ -140,6 +143,7 @@ fun:mkdir=discard fun:mmap=discard fun:munmap=discard fun:open=discard +fun:openat=discard fun:pipe=discard fun:posix_fadvise=discard fun:posix_memalign=discard @@ -251,7 +255,32 @@ fun:qsort=discard ### # pthread ### +fun:__pthread_register_cancel=discard +fun:__pthread_unregister_cancel=discard +fun:pthread_attr_destroy=discard +fun:pthread_attr_getaffinity_np=discard +fun:pthread_attr_getdetachstate=discard +fun:pthread_attr_getguardsize=discard +fun:pthread_attr_getinheritsched=discard +fun:pthread_attr_getschedparam=discard +fun:pthread_attr_getschedpolicy=discard +fun:pthread_attr_getscope=discard +fun:pthread_attr_getstack=discard +fun:pthread_attr_getstackaddr=disacrd +fun:pthread_attr_getstacksize=discard +fun:pthread_attr_init=discard +fun:pthread_attr_setaffinity_np=discard +fun:pthread_attr_setdetachstate=discard +fun:pthread_attr_setguardsize=discard +fun:pthread_attr_setinheritsched=discard +fun:pthread_attr_setschedparam=discard +fun:pthread_attr_setschedpolicy=discard +fun:pthread_attr_setscope=discard +fun:pthread_attr_setstack=discard +fun:pthread_attr_setstackaddr=discard +fun:pthread_attr_setstacksize=discard fun:pthread_equal=discard +fun:pthread_getschedparam=discard fun:pthread_getspecific=discard fun:pthread_key_create=discard fun:pthread_key_delete=discard @@ -263,6 +292,17 @@ fun:pthread_mutex_unlock=discard fun:pthread_mutexattr_destroy=discard fun:pthread_mutexattr_init=discard fun:pthread_mutexattr_settype=discard +fun:pthread_rwlock_destroy=discard +fun:pthread_rwlock_init=discard +fun:pthread_rwlock_rdlock=discard +fun:pthread_rwlock_timedrdlock=discard +fun:pthread_rwlock_timedwrlock=discard +fun:pthread_rwlock_tryrdlock=discard +fun:pthread_rwlock_trywrlock=discard +fun:pthread_rwlock_wrlock=discard +fun:pthread_rwlock_unlock=discard +fun:pthread_setschedparam=discard +fun:pthread_setname_np=discard fun:pthread_once=discard fun:pthread_self=discard fun:pthread_setspecific=discard ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 6f13445 - [DFSan] Add custom wrapper for epoll_wait.
Author: Matt Morehouse Date: 2020-12-09T06:05:29-08:00 New Revision: 6f13445fb601f2ad30cdd0b89492af8681bc6c70 URL: https://github.com/llvm/llvm-project/commit/6f13445fb601f2ad30cdd0b89492af8681bc6c70 DIFF: https://github.com/llvm/llvm-project/commit/6f13445fb601f2ad30cdd0b89492af8681bc6c70.diff LOG: [DFSan] Add custom wrapper for epoll_wait. The wrapper clears shadow for any events written. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D92891 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 80031d96464c..7ba0bf0c2e2f 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -11,12 +11,6 @@ // This file defines the custom functions listed in done_abilist.txt. //===--===// -#include "sanitizer_common/sanitizer_common.h" -#include "sanitizer_common/sanitizer_internal_defs.h" -#include "sanitizer_common/sanitizer_linux.h" - -#include "dfsan/dfsan.h" - #include #include #include @@ -32,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +35,11 @@ #include #include +#include "dfsan/dfsan.h" +#include "sanitizer_common/sanitizer_common.h" +#include "sanitizer_common/sanitizer_internal_defs.h" +#include "sanitizer_common/sanitizer_linux.h" + using namespace __dfsan; #define CALL_WEAK_INTERCEPTOR_HOOK(f, ...) \ @@ -715,6 +715,18 @@ int __dfsw_getpwuid_r(id_t uid, struct passwd *pwd, return ret; } +SANITIZER_INTERFACE_ATTRIBUTE +int __dfsw_epoll_wait(int epfd, struct epoll_event *events, int maxevents, + int timeout, dfsan_label epfd_label, + dfsan_label events_label, dfsan_label maxevents_label, + dfsan_label timeout_label, dfsan_label *ret_label) { + int ret = epoll_wait(epfd, events, maxevents, timeout); + if (ret > 0) +dfsan_set_label(0, events, ret * sizeof(*events)); + *ret_label = 0; + return ret; +} + SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_poll(struct pollfd *fds, nfds_t nfds, int timeout, dfsan_label dfs_label, dfsan_label nfds_label, diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 252ec52f1bd2..bf874d262be9 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -184,6 +184,7 @@ fun:uselocale=discard fun:calloc=custom fun:clock_gettime=custom fun:dlopen=custom +fun:epoll_wait=custom fun:fgets=custom fun:fstat=custom fun:getcwd=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 8f00b1e630f6..087a684f51b9 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -638,6 +639,46 @@ void test_getpwuid_r() { ASSERT_READ_ZERO_LABEL(&pwd, 4); } +void test_epoll_wait() { + // Set up a pipe to monitor with epoll. + int pipe_fds[2]; + int ret = pipe(pipe_fds); + assert(ret != -1); + + // Configure epoll to monitor the pipe. + int epfd = epoll_create1(0); + assert(epfd != -1); + struct epoll_event event; + event.events = EPOLLIN; + event.data.fd = pipe_fds[0]; + ret = epoll_ctl(epfd, EPOLL_CTL_ADD, pipe_fds[0], &event); + assert(ret != -1); + + // Test epoll_wait when no events have occurred. + event = {}; + dfsan_set_label(i_label, &event, sizeof(event)); + ret = epoll_wait(epfd, &event, /*maxevents=*/1, /*timeout=*/0); + assert(ret == 0); + assert(event.events == 0); + assert(event.data.fd == 0); + ASSERT_ZERO_LABEL(ret); + ASSERT_READ_LABEL(&event, sizeof(event), i_label); + + // Test epoll_wait when an event occurs. + write(pipe_fds[1], "x", 1); + ret = epoll_wait(epfd, &event, /*maxevents=*/1, /*timeout=*/0); + assert(ret == 1); + assert(event.events == EPOLLIN); + assert(event.data.fd == pipe_fds[0]); + ASSERT_ZERO_LABEL(ret); + ASSERT_READ_ZERO_LABEL(&event, sizeof(event)); + + // Clean up. + close(epfd); + close(pipe_fds[0]); + close(pipe_fds[1]); +} + void test_poll() { struct pollfd fd; fd.fd = 0; @@ -1027,6 +1068,7 @@ int main(void) { test_dfsan_set_write_callback(); test_dl_iterate_phdr(); test_dlopen(); + test_epoll_wait(); test_fgets(); test_fstat(); test_get_current_dir_name(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] a3eb2fb - [DFSan] Add custom wrapper for recvmsg.
Author: Matt Morehouse Date: 2020-12-09T13:07:51-08:00 New Revision: a3eb2fb247686af0216337687e921118710b56f3 URL: https://github.com/llvm/llvm-project/commit/a3eb2fb247686af0216337687e921118710b56f3 DIFF: https://github.com/llvm/llvm-project/commit/a3eb2fb247686af0216337687e921118710b56f3.diff LOG: [DFSan] Add custom wrapper for recvmsg. The wrapper clears shadow for anything written by recvmsg. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D92949 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 7ba0bf0c2e2f..24a0853bd14b 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -879,6 +880,26 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_nanosleep(const struct timespec *req, return ret; } +SANITIZER_INTERFACE_ATTRIBUTE ssize_t __dfsw_recvmsg( +int sockfd, struct msghdr *msg, int flags, dfsan_label sockfd_label, +dfsan_label msg_label, dfsan_label flags_label, dfsan_label *ret_label) { + ssize_t ret = recvmsg(sockfd, msg, flags); + if (ret >= 0) { +dfsan_set_label(0, msg, sizeof(*msg)); +dfsan_set_label(0, msg->msg_name, msg->msg_namelen); +dfsan_set_label(0, msg->msg_control, msg->msg_controllen); +for (size_t remaining = ret, i = 0; remaining > 0; ++i) { + assert(i < msg->msg_iovlen); + struct iovec *iov = &msg->msg_iov[i]; + size_t written = remaining < iov->iov_len ? remaining : iov->iov_len; + dfsan_set_label(0, iov->iov_base, written); + remaining -= written; +} + } + *ret_label = 0; + return ret; +} + SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_socketpair(int domain, int type, int protocol, int sv[2], dfsan_label domain_label, dfsan_label type_label, diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index bf874d262be9..dc37a08f92ec 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -116,6 +116,8 @@ fun:connect=discard fun:creat=discard fun:dladdr=discard fun:dlclose=discard +fun:epoll_create=discard +fun:epoll_create1=discard fun:epoll_ctl=discard fun:fclose=discard fun:feof=discard @@ -195,6 +197,7 @@ fun:getrusage=custom fun:nanosleep=custom fun:pread=custom fun:read=custom +fun:recvmsg=custom fun:socketpair=custom fun:stat=custom fun:time=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 087a684f51b9..2f1da535c459 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -336,6 +337,41 @@ void test_calloc() { free(crv); } +void test_recvmsg() { + int sockfds[2]; + int ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sockfds); + assert(ret != -1); + + char sbuf[] = "abcdefghijkl"; + struct iovec siovs[2] = {{&sbuf[0], 4}, {&sbuf[4], 4}}; + struct msghdr smsg = {}; + smsg.msg_iov = siovs; + smsg.msg_iovlen = 2; + + ssize_t sent = sendmsg(sockfds[0], &smsg, 0); + assert(sent > 0); + + char rbuf[128]; + struct iovec riovs[2] = {{&rbuf[0], 4}, {&rbuf[4], 4}}; + struct msghdr rmsg = {}; + rmsg.msg_iov = riovs; + rmsg.msg_iovlen = 2; + + dfsan_set_label(i_label, rbuf, sizeof(rbuf)); + dfsan_set_label(i_label, &rmsg, sizeof(rmsg)); + + ssize_t received = recvmsg(sockfds[1], &rmsg, 0); + assert(received == sent); + assert(memcmp(sbuf, rbuf, 8) == 0); + ASSERT_ZERO_LABEL(received); + ASSERT_READ_ZERO_LABEL(&rmsg, sizeof(rmsg)); + ASSERT_READ_ZERO_LABEL(&rbuf[0], 8); + ASSERT_READ_LABEL(&rbuf[8], 1, i_label); + + close(sockfds[0]); + close(sockfds[1]); +} + void test_read() { char buf[16]; dfsan_set_label(i_label, buf, 1); @@ -1089,6 +1125,7 @@ int main(void) { test_pread(); test_pthread_create(); test_read(); + test_recvmsg(); test_sched_getaffinity(); test_select(); test_sigaction(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 4eedc2e - [DFSan] Add custom wrapper for getsockopt.
Author: Matt Morehouse Date: 2020-12-09T14:29:38-08:00 New Revision: 4eedc2e3af3aa01279c5131b527e452c34dde953 URL: https://github.com/llvm/llvm-project/commit/4eedc2e3af3aa01279c5131b527e452c34dde953 DIFF: https://github.com/llvm/llvm-project/commit/4eedc2e3af3aa01279c5131b527e452c34dde953.diff LOG: [DFSan] Add custom wrapper for getsockopt. The wrapper clears shadow for optval and optlen when written. Reviewed By: stephan.yichao.zhao, vitalybuka Differential Revision: https://reviews.llvm.org/D92961 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 24a0853bd14b..0cb075ac632a 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -913,6 +913,20 @@ __dfsw_socketpair(int domain, int type, int protocol, int sv[2], return ret; } +SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getsockopt( +int sockfd, int level, int optname, void *optval, socklen_t *optlen, +dfsan_label sockfd_label, dfsan_label level_label, +dfsan_label optname_label, dfsan_label optval_label, +dfsan_label optlen_label, dfsan_label *ret_label) { + int ret = getsockopt(sockfd, level, optname, optval, optlen); + if (ret != -1 && optval && optlen) { +dfsan_set_label(0, optlen, sizeof(*optlen)); +dfsan_set_label(0, optval, *optlen); + } + *ret_label = 0; + return ret; +} + // Type of the trampoline function passed to the custom version of // dfsan_set_write_callback. typedef void (*write_trampoline_t)( diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index dc37a08f92ec..13513cbb0f23 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -194,6 +194,7 @@ fun:get_current_dir_name=custom fun:gethostname=custom fun:getrlimit=custom fun:getrusage=custom +fun:getsockopt=custom fun:nanosleep=custom fun:pread=custom fun:read=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 2f1da535c459..b57f172d7e4c 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -931,6 +931,27 @@ void test_socketpair() { ASSERT_READ_ZERO_LABEL(fd, sizeof(fd)); } +void test_getsockopt() { + int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + assert(sockfd != -1); + + int optval[2] = {-1, -1}; + socklen_t optlen = sizeof(optval); + dfsan_set_label(i_label, &optval, sizeof(optval)); + dfsan_set_label(i_label, &optlen, sizeof(optlen)); + int ret = getsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen); + assert(ret != -1); + assert(optlen == sizeof(int)); + assert(optval[0] == 0); + assert(optval[1] == -1); + ASSERT_ZERO_LABEL(ret); + ASSERT_ZERO_LABEL(optlen); + ASSERT_ZERO_LABEL(optval[0]); + ASSERT_LABEL(optval[1], i_label); + + close(sockfd); +} + void test_write() { int fd = open("/dev/null", O_WRONLY); @@ -1113,6 +1134,7 @@ int main(void) { test_getpwuid_r(); test_getrlimit(); test_getrusage(); + test_getsockopt(); test_gettimeofday(); test_inet_pton(); test_localtime_r(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 8a874a4 - [DFSan] Add custom wrapper for getsockname.
Author: Matt Morehouse Date: 2020-12-10T08:13:05-08:00 New Revision: 8a874a42298d030715e041dcaae132095dee URL: https://github.com/llvm/llvm-project/commit/8a874a42298d030715e041dcaae132095dee DIFF: https://github.com/llvm/llvm-project/commit/8a874a42298d030715e041dcaae132095dee.diff LOG: [DFSan] Add custom wrapper for getsockname. The wrapper clears shadow for any bytes written to addr or addrlen. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D92964 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 0cb075ac632a..576f7f64e301 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -927,6 +927,21 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getsockopt( return ret; } +SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getsockname( +int sockfd, struct sockaddr *addr, socklen_t *addrlen, +dfsan_label sockfd_label, dfsan_label addr_label, dfsan_label addrlen_label, +dfsan_label *ret_label) { + socklen_t origlen = addrlen ? *addrlen : 0; + int ret = getsockname(sockfd, addr, addrlen); + if (ret != -1 && addr && addrlen) { +socklen_t written_bytes = origlen < *addrlen ? origlen : *addrlen; +dfsan_set_label(0, addrlen, sizeof(*addrlen)); +dfsan_set_label(0, addr, written_bytes); + } + *ret_label = 0; + return ret; +} + // Type of the trampoline function passed to the custom version of // dfsan_set_write_callback. typedef void (*write_trampoline_t)( diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 13513cbb0f23..9a92098f22eb 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -194,6 +194,7 @@ fun:get_current_dir_name=custom fun:gethostname=custom fun:getrlimit=custom fun:getrusage=custom +fun:getsockname=custom fun:getsockopt=custom fun:nanosleep=custom fun:pread=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index b57f172d7e4c..8305941d0054 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -931,6 +931,26 @@ void test_socketpair() { ASSERT_READ_ZERO_LABEL(fd, sizeof(fd)); } +void test_getsockname() { + int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + assert(sockfd != -1); + + struct sockaddr addr = {}; + socklen_t addrlen = sizeof(addr); + dfsan_set_label(i_label, &addr, addrlen); + dfsan_set_label(i_label, &addrlen, sizeof(addrlen)); + + int ret = getsockname(sockfd, &addr, &addrlen); + assert(ret != -1); + ASSERT_ZERO_LABEL(ret); + ASSERT_ZERO_LABEL(addrlen); + assert(addrlen < sizeof(addr)); + ASSERT_READ_ZERO_LABEL(&addr, addrlen); + ASSERT_READ_LABEL(((char *)&addr) + addrlen, 1, i_label); + + close(sockfd); +} + void test_getsockopt() { int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); assert(sockfd != -1); @@ -1134,6 +1154,7 @@ int main(void) { test_getpwuid_r(); test_getrlimit(); test_getrusage(); + test_getsockname(); test_getsockopt(); test_gettimeofday(); test_inet_pton(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] bdaeb82 - [DFSan] Add custom wrapper for sigaltstack.
Author: Matt Morehouse Date: 2020-12-10T10:16:36-08:00 New Revision: bdaeb82a5f84b813f5eb7e63e6e111c4566c61ab URL: https://github.com/llvm/llvm-project/commit/bdaeb82a5f84b813f5eb7e63e6e111c4566c61ab DIFF: https://github.com/llvm/llvm-project/commit/bdaeb82a5f84b813f5eb7e63e6e111c4566c61ab.diff LOG: [DFSan] Add custom wrapper for sigaltstack. The wrapper clears shadow for old_ss. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D93041 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 576f7f64e301..b43f978d8a2c 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -799,6 +799,16 @@ int __dfsw_sigaction(int signum, const struct sigaction *act, return ret; } +SANITIZER_INTERFACE_ATTRIBUTE +int __dfsw_sigaltstack(const stack_t *ss, stack_t *old_ss, dfsan_label ss_label, + dfsan_label old_ss_label, dfsan_label *ret_label) { + int ret = sigaltstack(ss, old_ss); + if (ret != -1 && old_ss) +dfsan_set_label(0, old_ss, sizeof(*old_ss)); + *ret_label = 0; + return ret; +} + SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_gettimeofday(struct timeval *tv, struct timezone *tz, dfsan_label tv_label, dfsan_label tz_label, diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 9a92098f22eb..b8cfa3b9941b 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -200,6 +200,7 @@ fun:nanosleep=custom fun:pread=custom fun:read=custom fun:recvmsg=custom +fun:sigaltstack=custom fun:socketpair=custom fun:stat=custom fun:time=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 8305941d0054..a03f33f769af 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -762,6 +762,15 @@ void test_sigaction() { ASSERT_READ_ZERO_LABEL(&oldact, sizeof(oldact)); } +void test_sigaltstack() { + stack_t old_altstack = {}; + dfsan_set_label(j_label, &old_altstack, sizeof(old_altstack)); + int ret = sigaltstack(NULL, &old_altstack); + assert(ret == 0); + ASSERT_ZERO_LABEL(ret); + ASSERT_READ_ZERO_LABEL(&old_altstack, sizeof(old_altstack)); +} + void test_gettimeofday() { struct timeval tv; struct timezone tz; @@ -1172,6 +1181,7 @@ int main(void) { test_sched_getaffinity(); test_select(); test_sigaction(); + test_sigaltstack(); test_sigemptyset(); test_snprintf(); test_socketpair(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 72fd47b - [DFSan] Add custom wrapper for _dl_get_tls_static_info.
Author: Matt Morehouse Date: 2020-12-10T11:03:28-08:00 New Revision: 72fd47b93d1165f7e4499a5c2b4241dae7ce82ae URL: https://github.com/llvm/llvm-project/commit/72fd47b93d1165f7e4499a5c2b4241dae7ce82ae DIFF: https://github.com/llvm/llvm-project/commit/72fd47b93d1165f7e4499a5c2b4241dae7ce82ae.diff LOG: [DFSan] Add custom wrapper for _dl_get_tls_static_info. Implementation is here: https://code.woboq.org/userspace/glibc/elf/dl-tls.c.html#307 We use weak symbols to avoid linking issues with glibcs older than 2.27. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D93053 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index b43f978d8a2c..3b8c46d642a4 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -461,6 +461,20 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_dl_iterate_phdr( return dl_iterate_phdr(dl_iterate_phdr_cb, &dipi); } +// This function is only available for glibc 2.27 or newer. Mark it weak so +// linking succeeds with older glibcs. +SANITIZER_WEAK_ATTRIBUTE void _dl_get_tls_static_info(size_t *sizep, + size_t *alignp); + +SANITIZER_INTERFACE_ATTRIBUTE void __dfsw__dl_get_tls_static_info( +size_t *sizep, size_t *alignp, dfsan_label sizep_label, +dfsan_label alignp_label) { + assert(_dl_get_tls_static_info); + _dl_get_tls_static_info(sizep, alignp); + dfsan_set_label(0, sizep, sizeof(*sizep)); + dfsan_set_label(0, alignp, sizeof(*alignp)); +} + SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_ctime_r(const time_t *timep, char *buf, dfsan_label timep_label, dfsan_label buf_label, dfsan_label *ret_label) { diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index b8cfa3b9941b..f4d0950e65dc 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -183,6 +183,7 @@ fun:uselocale=discard # Functions that produce output does not depend on the input (need to zero the # shadow manually). +fun:_dl_get_tls_static_info=custom fun:calloc=custom fun:clock_gettime=custom fun:dlopen=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index a03f33f769af..3098616c0e50 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -809,6 +809,22 @@ void test_dl_iterate_phdr() { dl_iterate_phdr(dl_iterate_phdr_test_cb, (void *)3); } +// On glibc < 2.27, this symbol is not available. Mark it weak so we can skip +// testing in this case. +__attribute__((weak)) extern "C" void _dl_get_tls_static_info(size_t *sizep, + size_t *alignp); + +void test__dl_get_tls_static_info() { + if (!_dl_get_tls_static_info) +return; + size_t sizep = 0, alignp = 0; + dfsan_set_label(i_label, &sizep, sizeof(sizep)); + dfsan_set_label(i_label, &alignp, sizeof(alignp)); + _dl_get_tls_static_info(&sizep, &alignp); + ASSERT_ZERO_LABEL(sizep); + ASSERT_ZERO_LABEL(alignp); +} + void test_strrchr() { char str1[] = "str1str1"; dfsan_set_label(i_label, &str1[7], 1); @@ -1147,6 +1163,7 @@ int main(void) { assert(i_j_label != j_label); assert(i_j_label != k_label); + test__dl_get_tls_static_info(); test_bcmp(); test_calloc(); test_clock_gettime(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] fa4bd4b - [DFSan] Add custom wrapper for getpeername.
Author: Matt Morehouse Date: 2020-12-10T12:26:06-08:00 New Revision: fa4bd4b338d1c8c0a95b63b13640b10694b8185c URL: https://github.com/llvm/llvm-project/commit/fa4bd4b338d1c8c0a95b63b13640b10694b8185c DIFF: https://github.com/llvm/llvm-project/commit/fa4bd4b338d1c8c0a95b63b13640b10694b8185c.diff LOG: [DFSan] Add custom wrapper for getpeername. The wrapper clears shadow for addr and addrlen when written to. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D93046 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 3b8c46d642a4..259bec4207dd 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -966,6 +966,21 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getsockname( return ret; } +SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getpeername( +int sockfd, struct sockaddr *addr, socklen_t *addrlen, +dfsan_label sockfd_label, dfsan_label addr_label, dfsan_label addrlen_label, +dfsan_label *ret_label) { + socklen_t origlen = addrlen ? *addrlen : 0; + int ret = getpeername(sockfd, addr, addrlen); + if (ret != -1 && addr && addrlen) { +socklen_t written_bytes = origlen < *addrlen ? origlen : *addrlen; +dfsan_set_label(0, addrlen, sizeof(*addrlen)); +dfsan_set_label(0, addr, written_bytes); + } + *ret_label = 0; + return ret; +} + // Type of the trampoline function passed to the custom version of // dfsan_set_write_callback. typedef void (*write_trampoline_t)( diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index f4d0950e65dc..5d3d31f2e162 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -193,6 +193,7 @@ fun:fstat=custom fun:getcwd=custom fun:get_current_dir_name=custom fun:gethostname=custom +fun:getpeername=custom fun:getrlimit=custom fun:getrusage=custom fun:getsockname=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 3098616c0e50..14cddd8e2a3c 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -956,6 +956,28 @@ void test_socketpair() { ASSERT_READ_ZERO_LABEL(fd, sizeof(fd)); } +void test_getpeername() { + int sockfds[2]; + int ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sockfds); + assert(ret != -1); + + struct sockaddr addr = {}; + socklen_t addrlen = sizeof(addr); + dfsan_set_label(i_label, &addr, addrlen); + dfsan_set_label(i_label, &addrlen, sizeof(addrlen)); + + ret = getpeername(sockfds[0], &addr, &addrlen); + assert(ret != -1); + ASSERT_ZERO_LABEL(ret); + ASSERT_ZERO_LABEL(addrlen); + assert(addrlen < sizeof(addr)); + ASSERT_READ_ZERO_LABEL(&addr, addrlen); + ASSERT_READ_LABEL(((char *)&addr) + addrlen, 1, i_label); + + close(sockfds[0]); + close(sockfds[1]); +} + void test_getsockname() { int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); assert(sockfd != -1); @@ -1177,6 +1199,7 @@ int main(void) { test_get_current_dir_name(); test_getcwd(); test_gethostname(); + test_getpeername(); test_getpwuid_r(); test_getrlimit(); test_getrusage(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 0099316 - [DFSan] Add custom wrapper for pthread_join.
Author: Matt Morehouse Date: 2020-12-10T13:41:24-08:00 New Revision: 009931644a9d2cecdc6e5bf71ed83d59b776eaa3 URL: https://github.com/llvm/llvm-project/commit/009931644a9d2cecdc6e5bf71ed83d59b776eaa3 DIFF: https://github.com/llvm/llvm-project/commit/009931644a9d2cecdc6e5bf71ed83d59b776eaa3.diff LOG: [DFSan] Add custom wrapper for pthread_join. The wrapper clears shadow for retval. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D93047 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 259bec4207dd..0da66c7a440d 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -427,6 +427,18 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_create( return rv; } +SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_join(pthread_t thread, + void **retval, + dfsan_label thread_label, + dfsan_label retval_label, + dfsan_label *ret_label) { + int ret = pthread_join(thread, retval); + if (ret == 0 && retval) +dfsan_set_label(0, retval, sizeof(*retval)); + *ret_label = 0; + return ret; +} + struct dl_iterate_phdr_info { int (*callback_trampoline)(void *callback, struct dl_phdr_info *info, size_t size, void *data, dfsan_label info_label, diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 5d3d31f2e162..513c9ea13de3 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -319,6 +319,10 @@ fun:pthread_setspecific=discard # Functions that take a callback (wrap the callback manually). fun:pthread_create=custom +# Functions that produce output does not depend on the input (need to zero the +# shadow manually). +fun:pthread_join=custom + ### # libffi/libgo ### diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index 14cddd8e2a3c..e21f35426cf0 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -792,8 +792,12 @@ void test_pthread_create() { pthread_t pt; pthread_create(&pt, 0, pthread_create_test_cb, (void *)1); void *cbrv; - pthread_join(pt, &cbrv); + dfsan_set_label(i_label, &cbrv, sizeof(cbrv)); + int ret = pthread_join(pt, &cbrv); + assert(ret == 0); assert(cbrv == (void *)2); + ASSERT_ZERO_LABEL(ret); + ASSERT_ZERO_LABEL(cbrv); } int dl_iterate_phdr_test_cb(struct dl_phdr_info *info, size_t size, ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 5ff3535 - [DFSan] Appease the custom wrapper lint script.
Author: Matt Morehouse Date: 2020-12-10T14:12:26-08:00 New Revision: 5ff35356f1af2bb92785b38c657463924d9ec386 URL: https://github.com/llvm/llvm-project/commit/5ff35356f1af2bb92785b38c657463924d9ec386 DIFF: https://github.com/llvm/llvm-project/commit/5ff35356f1af2bb92785b38c657463924d9ec386.diff LOG: [DFSan] Appease the custom wrapper lint script. Added: Modified: compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index e21f35426cf0..a78152f5dcc1 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -800,6 +800,10 @@ void test_pthread_create() { ASSERT_ZERO_LABEL(cbrv); } +// Tested by test_pthread_create(). This empty function is here to appease the +// check-wrappers script. +void test_pthread_join() {} + int dl_iterate_phdr_test_cb(struct dl_phdr_info *info, size_t size, void *data) { assert(data == (void *)3); @@ -1220,6 +1224,7 @@ int main(void) { test_poll(); test_pread(); test_pthread_create(); + test_pthread_join(); test_read(); test_recvmsg(); test_sched_getaffinity(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 7bc7501 - [DFSan] Add custom wrapper for recvmmsg.
Author: Matt Morehouse Date: 2020-12-11T06:24:56-08:00 New Revision: 7bc7501ac1cb95bb8c410d93d4ed54e4aa19a3cd URL: https://github.com/llvm/llvm-project/commit/7bc7501ac1cb95bb8c410d93d4ed54e4aa19a3cd DIFF: https://github.com/llvm/llvm-project/commit/7bc7501ac1cb95bb8c410d93d4ed54e4aa19a3cd.diff LOG: [DFSan] Add custom wrapper for recvmmsg. Uses the recvmsg wrapper logic in a loop. Reviewed By: stephan.yichao.zhao Differential Revision: https://reviews.llvm.org/D93059 Added: Modified: compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/lib/dfsan/done_abilist.txt compiler-rt/test/dfsan/custom.cpp Removed: diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 0da66c7a440d..94901cee0d5c 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -916,22 +916,40 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_nanosleep(const struct timespec *req, return ret; } +static void clear_msghdr_labels(size_t bytes_written, struct msghdr *msg) { + dfsan_set_label(0, msg, sizeof(*msg)); + dfsan_set_label(0, msg->msg_name, msg->msg_namelen); + dfsan_set_label(0, msg->msg_control, msg->msg_controllen); + for (size_t i = 0; bytes_written > 0; ++i) { +assert(i < msg->msg_iovlen); +struct iovec *iov = &msg->msg_iov[i]; +size_t iov_written = +bytes_written < iov->iov_len ? bytes_written : iov->iov_len; +dfsan_set_label(0, iov->iov_base, iov_written); +bytes_written -= iov_written; + } +} + +SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_recvmmsg( +int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, +struct timespec *timeout, dfsan_label sockfd_label, +dfsan_label msgvec_label, dfsan_label vlen_label, dfsan_label flags_label, +dfsan_label timeout_label, dfsan_label *ret_label) { + int ret = recvmmsg(sockfd, msgvec, vlen, flags, timeout); + for (int i = 0; i < ret; ++i) { +dfsan_set_label(0, &msgvec[i].msg_len, sizeof(msgvec[i].msg_len)); +clear_msghdr_labels(msgvec[i].msg_len, &msgvec[i].msg_hdr); + } + *ret_label = 0; + return ret; +} + SANITIZER_INTERFACE_ATTRIBUTE ssize_t __dfsw_recvmsg( int sockfd, struct msghdr *msg, int flags, dfsan_label sockfd_label, dfsan_label msg_label, dfsan_label flags_label, dfsan_label *ret_label) { ssize_t ret = recvmsg(sockfd, msg, flags); - if (ret >= 0) { -dfsan_set_label(0, msg, sizeof(*msg)); -dfsan_set_label(0, msg->msg_name, msg->msg_namelen); -dfsan_set_label(0, msg->msg_control, msg->msg_controllen); -for (size_t remaining = ret, i = 0; remaining > 0; ++i) { - assert(i < msg->msg_iovlen); - struct iovec *iov = &msg->msg_iov[i]; - size_t written = remaining < iov->iov_len ? remaining : iov->iov_len; - dfsan_set_label(0, iov->iov_base, written); - remaining -= written; -} - } + if (ret >= 0) +clear_msghdr_labels(ret, msg); *ret_label = 0; return ret; } diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt index 513c9ea13de3..e90dbc17a3cd 100644 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -201,6 +201,7 @@ fun:getsockopt=custom fun:nanosleep=custom fun:pread=custom fun:read=custom +fun:recvmmsg=custom fun:recvmsg=custom fun:sigaltstack=custom fun:socketpair=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index a78152f5dcc1..804904bbef9f 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -337,6 +337,64 @@ void test_calloc() { free(crv); } +void test_recvmmsg() { + int sockfds[2]; + int ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sockfds); + assert(ret != -1); + + // Setup messages to send. + struct mmsghdr smmsg[2] = {}; + char sbuf0[] = "abcdefghijkl"; + struct iovec siov0[2] = {{&sbuf0[0], 4}, {&sbuf0[4], 4}}; + smmsg[0].msg_hdr.msg_iov = siov0; + smmsg[0].msg_hdr.msg_iovlen = 2; + char sbuf1[] = "1234567890"; + struct iovec siov1[1] = {{&sbuf1[0], 7}}; + smmsg[1].msg_hdr.msg_iov = siov1; + smmsg[1].msg_hdr.msg_iovlen = 1; + + // Send messages. + int sent_msgs = sendmmsg(sockfds[0], smmsg, 2, 0); + assert(sent_msgs == 2); + + // Setup receive buffers. + struct mmsghdr rmmsg[2] = {}; + char rbuf0[128]; + struct iovec riov0[2] = {{&rbuf0[0], 4}, {&rbuf0[4], 4}}; + rmmsg[0].msg_hdr.msg_iov = riov0; + rmmsg[0].msg_hdr.msg_iovlen = 2; + char rbuf1[128]; + struct iovec riov1[1] = {{&rbuf1[0], 16}}; + rmmsg[1].msg_hdr.msg_iov = riov1; + rmmsg[1].msg_hdr.msg_iovlen = 1; + struct timespec timeout = {1, 1}; + dfsan_set_label(i_label, rbuf0, sizeof(rbuf0)); + dfsan_set_label(i_label, rbuf1, sizeof(rbuf1)); + dfsan_set_label(i_label, &rmmsg[0].msg_len, sizeof(rmmsg[0].msg_len)); + dfsan_set_label(i_label, &rmmsg[1].msg_len, sizeof(rmmsg[1].msg_len