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 @@ -892,6 +892,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 @@ -192,6 +192,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 @@ -895,6 +895,25 @@ ASSERT_READ_ZERO_LABEL(fd, sizeof(fd)); } +void test_getsockopt() { + int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + assert(sockfd != -1); + + int optval = -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(optval == 0); + assert(optlen == sizeof(optval)); + ASSERT_ZERO_LABEL(ret); + ASSERT_ZERO_LABEL(optval); + ASSERT_ZERO_LABEL(optlen); + + close(sockfd); +} + void test_write() { int fd = open("/dev/null", O_WRONLY); @@ -1077,6 +1096,7 @@ test_getpwuid_r(); test_getrlimit(); test_getrusage(); + test_getsockopt(); test_gettimeofday(); test_inet_pton(); test_localtime_r();