diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -913,6 +913,20 @@ 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 --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -194,6 +194,7 @@ 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 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -931,6 +931,27 @@ 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 @@ test_getpwuid_r(); test_getrlimit(); test_getrusage(); + test_getsockopt(); test_gettimeofday(); test_inet_pton(); test_localtime_r();