[compiler-rt] f6f724c - [sanitizer] Fix __sanitizer_syscall_post_epoll_wait
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 14:14:36 PDT 2021
Author: Vitaly Buka
Date: 2021-08-02T14:14:18-07:00
New Revision: f6f724c02e8ac8b675e3eabeae6b910995eba41b
URL: https://github.com/llvm/llvm-project/commit/f6f724c02e8ac8b675e3eabeae6b910995eba41b
DIFF: https://github.com/llvm/llvm-project/commit/f6f724c02e8ac8b675e3eabeae6b910995eba41b.diff
LOG: [sanitizer] Fix __sanitizer_syscall_post_epoll_wait
Syscall return number of initialized events which
needs to be used for unposoning.
Differential Revision: https://reviews.llvm.org/D107207
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
compiler-rt/test/msan/Linux/syscalls.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
index f2a400b7302de..4faa881ceae9c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
@@ -2107,7 +2107,7 @@ POST_SYSCALL(epoll_wait)
(long res, long epfd, void *events, long maxevents, long timeout) {
if (res >= 0) {
if (events)
- POST_WRITE(events, struct_epoll_event_sz);
+ POST_WRITE(events, res * struct_epoll_event_sz);
}
}
@@ -2123,7 +2123,7 @@ POST_SYSCALL(epoll_pwait)
const void *sigmask, long sigsetsize) {
if (res >= 0) {
if (events)
- POST_WRITE(events, struct_epoll_event_sz);
+ POST_WRITE(events, res * struct_epoll_event_sz);
}
}
diff --git a/compiler-rt/test/msan/Linux/syscalls.cpp b/compiler-rt/test/msan/Linux/syscalls.cpp
index 2f60b0ed9a514..c3111c5117016 100644
--- a/compiler-rt/test/msan/Linux/syscalls.cpp
+++ b/compiler-rt/test/msan/Linux/syscalls.cpp
@@ -9,6 +9,7 @@
#include <linux/aio_abi.h>
#include <signal.h>
+#include <sys/epoll.h>
#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/uio.h>
@@ -128,5 +129,17 @@ int main(int argc, char *argv[]) {
__sanitizer_syscall_post_sigaltstack(0, nullptr, (stack_t *)buf);
assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(stack_t));
+ __msan_poison(buf, sizeof(buf));
+ long max_events = sizeof(buf) / sizeof(epoll_event);
+ __sanitizer_syscall_pre_epoll_wait(0, buf, max_events, 0);
+ __sanitizer_syscall_post_epoll_wait(max_events, 0, buf, max_events, 0);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event));
+
+ __msan_poison(buf, sizeof(buf));
+ sigset_t sigset = {};
+ __sanitizer_syscall_pre_epoll_pwait(0, buf, max_events, 0, &sigset, sizeof(sigset));
+ __sanitizer_syscall_post_epoll_pwait(max_events, 0, buf, max_events, 0, &sigset, sizeof(sigset));
+ assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event));
+
return 0;
}
More information about the llvm-commits
mailing list