Author: Matt Morehouse Date: 2020-12-10T08:13:05-08:00 New Revision: 8a874a427777298d030715e041dcaae132095dee
URL: https://github.com/llvm/llvm-project/commit/8a874a427777298d030715e041dcaae132095dee DIFF: https://github.com/llvm/llvm-project/commit/8a874a427777298d030715e041dcaae132095dee.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