Skip to content

Commit f6f724c

Browse files
committed
[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
1 parent c777057 commit f6f724c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ POST_SYSCALL(epoll_wait)
21072107
(long res, long epfd, void *events, long maxevents, long timeout) {
21082108
if (res >= 0) {
21092109
if (events)
2110-
POST_WRITE(events, struct_epoll_event_sz);
2110+
POST_WRITE(events, res * struct_epoll_event_sz);
21112111
}
21122112
}
21132113

@@ -2123,7 +2123,7 @@ POST_SYSCALL(epoll_pwait)
21232123
const void *sigmask, long sigsetsize) {
21242124
if (res >= 0) {
21252125
if (events)
2126-
POST_WRITE(events, struct_epoll_event_sz);
2126+
POST_WRITE(events, res * struct_epoll_event_sz);
21272127
}
21282128
}
21292129

compiler-rt/test/msan/Linux/syscalls.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/aio_abi.h>
1111
#include <signal.h>
12+
#include <sys/epoll.h>
1213
#include <sys/ptrace.h>
1314
#include <sys/stat.h>
1415
#include <sys/uio.h>
@@ -128,5 +129,17 @@ int main(int argc, char *argv[]) {
128129
__sanitizer_syscall_post_sigaltstack(0, nullptr, (stack_t *)buf);
129130
assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(stack_t));
130131

132+
__msan_poison(buf, sizeof(buf));
133+
long max_events = sizeof(buf) / sizeof(epoll_event);
134+
__sanitizer_syscall_pre_epoll_wait(0, buf, max_events, 0);
135+
__sanitizer_syscall_post_epoll_wait(max_events, 0, buf, max_events, 0);
136+
assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event));
137+
138+
__msan_poison(buf, sizeof(buf));
139+
sigset_t sigset = {};
140+
__sanitizer_syscall_pre_epoll_pwait(0, buf, max_events, 0, &sigset, sizeof(sigset));
141+
__sanitizer_syscall_post_epoll_pwait(max_events, 0, buf, max_events, 0, &sigset, sizeof(sigset));
142+
assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event));
143+
131144
return 0;
132145
}

0 commit comments

Comments
 (0)