forked from OSchip/llvm-project
[msan] Intercept process_vm_readv/writev.
llvm-svn: 251059
This commit is contained in:
parent
83bc4220ce
commit
0d933e0b27
|
@ -5236,6 +5236,39 @@ INTERCEPTOR(int, mincore, void *addr, uptr length, unsigned char *vec) {
|
|||
#define INIT_MINCORE
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_PROCESS_VM_READV
|
||||
INTERCEPTOR(SSIZE_T, process_vm_readv, int pid, __sanitizer_iovec *local_iov,
|
||||
uptr liovcnt, __sanitizer_iovec *remote_iov, uptr riovcnt,
|
||||
uptr flags) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, process_vm_readv, pid, local_iov, liovcnt,
|
||||
remote_iov, riovcnt, flags);
|
||||
SSIZE_T res = REAL(process_vm_readv)(pid, local_iov, liovcnt, remote_iov,
|
||||
riovcnt, flags);
|
||||
if (res > 0)
|
||||
write_iovec(ctx, local_iov, liovcnt, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
INTERCEPTOR(SSIZE_T, process_vm_writev, int pid, __sanitizer_iovec *local_iov,
|
||||
uptr liovcnt, __sanitizer_iovec *remote_iov, uptr riovcnt,
|
||||
uptr flags) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, process_vm_writev, pid, local_iov, liovcnt,
|
||||
remote_iov, riovcnt, flags);
|
||||
SSIZE_T res = REAL(process_vm_writev)(pid, local_iov, liovcnt, remote_iov,
|
||||
riovcnt, flags);
|
||||
if (res > 0)
|
||||
read_iovec(ctx, local_iov, liovcnt, res);
|
||||
return res;
|
||||
}
|
||||
#define INIT_PROCESS_VM_READV \
|
||||
COMMON_INTERCEPT_FUNCTION(process_vm_readv); \
|
||||
COMMON_INTERCEPT_FUNCTION(process_vm_writev);
|
||||
#else
|
||||
#define INIT_PROCESS_VM_READV
|
||||
#endif
|
||||
|
||||
static void InitializeCommonInterceptors() {
|
||||
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
|
||||
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
|
||||
|
@ -5409,4 +5442,5 @@ static void InitializeCommonInterceptors() {
|
|||
INIT_SEM;
|
||||
INIT_PTHREAD_SETCANCEL;
|
||||
INIT_MINCORE;
|
||||
INIT_PROCESS_VM_READV;
|
||||
}
|
||||
|
|
|
@ -259,6 +259,7 @@
|
|||
#define SANITIZER_INTERCEPT_SEM SI_LINUX || SI_FREEBSD
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_MINCORE SI_LINUX
|
||||
#define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX
|
||||
|
||||
#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
|
||||
// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t -DPOSITIVE && not %run %t |& FileCheck %s
|
||||
|
||||
#include <assert.h>
|
||||
#include <sanitizer/msan_interface.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void) {
|
||||
char a[100];
|
||||
memset(a, 0xab, 100);
|
||||
|
||||
char b[100];
|
||||
iovec iov_a[] = {{(void *)a, 20}, (void *)(a + 50), 10};
|
||||
iovec iov_b[] = {{(void *)(b + 10), 10}, (void *)(b + 30), 20};
|
||||
|
||||
__msan_poison(&b, sizeof(b));
|
||||
ssize_t res = process_vm_readv(getpid(), iov_b, 2, iov_a, 2, 0);
|
||||
assert(res == 30);
|
||||
__msan_check_mem_is_initialized(b + 10, 10);
|
||||
__msan_check_mem_is_initialized(b + 30, 20);
|
||||
assert(__msan_test_shadow(b + 9, 1) == 0);
|
||||
assert(__msan_test_shadow(b + 20, 1) == 0);
|
||||
assert(__msan_test_shadow(b + 29, 1) == 0);
|
||||
assert(__msan_test_shadow(b + 50, 1) == 0);
|
||||
|
||||
#ifdef POSITIVE
|
||||
__msan_unpoison(&b, sizeof(b));
|
||||
__msan_poison(b + 32, 1);
|
||||
res = process_vm_writev(getpid(), iov_b, 2, iov_a, 2, 0);
|
||||
// CHECK: Uninitialized bytes {{.*}} at offset 2 inside
|
||||
// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
|
||||
// CHECK: #0 0x{{.*}} in {{.*}}process_vm_writev
|
||||
#else
|
||||
__msan_unpoison(&b, sizeof(b));
|
||||
res = process_vm_writev(getpid(), iov_b, 2, iov_a, 2, 0);
|
||||
assert(res == 30);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue