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