forked from OSchip/llvm-project
[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
This commit is contained in:
parent
b0d02b698b
commit
4eedc2e3af
|
@ -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)(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue