Fortify ppoll64.
I've deliberately not bothered with the GCC implementation because we'll have removed GCC from the NDK before anyone gets to use this. Bug: http://b/72493232 Test: ran tests Change-Id: Icfc2a3b214739ab53aa41bacacc11b5c67498fb4
This commit is contained in:
parent
1423bb8498
commit
b83bf14a35
|
@ -169,6 +169,12 @@ int __ppoll_chk(pollfd* fds, nfds_t fd_count, const timespec* timeout,
|
|||
return ppoll(fds, fd_count, timeout, mask);
|
||||
}
|
||||
|
||||
int __ppoll64_chk(pollfd* fds, nfds_t fd_count, const timespec* timeout,
|
||||
const sigset64_t* mask, size_t fds_size) {
|
||||
__check_pollfd_array("ppoll64", fds_size, fd_count);
|
||||
return ppoll64(fds, fd_count, timeout, mask);
|
||||
}
|
||||
|
||||
ssize_t __pread64_chk(int fd, void* buf, size_t count, off64_t offset, size_t buf_size) {
|
||||
__check_count("pread64", "count", count);
|
||||
__check_buffer_access("pread64", "write into", count, buf_size);
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#endif
|
||||
|
||||
int __poll_chk(struct pollfd*, nfds_t, int, size_t) __INTRODUCED_IN(23);
|
||||
int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t)
|
||||
__INTRODUCED_IN(23);
|
||||
int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t) __INTRODUCED_IN(23);
|
||||
int __ppoll64_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset64_t*, size_t) __INTRODUCED_IN(28);
|
||||
|
||||
#if defined(__BIONIC_FORTIFY)
|
||||
#if __ANDROID_API__ >= __ANDROID_API_M__
|
||||
|
@ -64,7 +64,24 @@ int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const st
|
|||
}
|
||||
return __ppoll_chk(fds, fd_count, timeout, mask, bos_fds);
|
||||
}
|
||||
#else /* defined(__clang__) */
|
||||
|
||||
#if __ANDROID_API__ >= __ANDROID_API_P__
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
int ppoll64(struct pollfd* const fds __pass_object_size, nfds_t fd_count, const struct timespec* timeout, const sigset64_t* mask)
|
||||
__overloadable
|
||||
__clang_error_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&
|
||||
__bos(fds) < sizeof(*fds) * fd_count,
|
||||
"in call to 'ppoll64', fd_count is larger than the given buffer") {
|
||||
size_t bos_fds = __bos(fds);
|
||||
|
||||
if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
|
||||
return __call_bypassing_fortify(ppoll64)(fds, fd_count, timeout, mask);
|
||||
}
|
||||
return __ppoll64_chk(fds, fd_count, timeout, mask, bos_fds);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else /* !defined(__clang__) */
|
||||
int __poll_real(struct pollfd*, nfds_t, int) __RENAME(poll);
|
||||
__errordecl(__poll_too_small_error, "poll: pollfd array smaller than fd count");
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ LIBC {
|
|||
__poll_chk; # introduced=23
|
||||
__ppoll; # arm x86 mips introduced=21
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -74,6 +74,7 @@ LIBC {
|
|||
__p_type_syms; # var
|
||||
__poll_chk; # introduced=23
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -115,6 +115,7 @@ LIBC {
|
|||
__poll_chk; # introduced=23
|
||||
__ppoll; # arm x86 mips introduced=21
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -112,6 +112,7 @@ LIBC {
|
|||
__poll_chk; # introduced=23
|
||||
__ppoll; # arm x86 mips introduced=21
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -74,6 +74,7 @@ LIBC {
|
|||
__p_type_syms; # var
|
||||
__poll_chk; # introduced=23
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -112,6 +112,7 @@ LIBC {
|
|||
__poll_chk; # introduced=23
|
||||
__ppoll; # arm x86 mips introduced=21
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -74,6 +74,7 @@ LIBC {
|
|||
__p_type_syms; # var
|
||||
__poll_chk; # introduced=23
|
||||
__ppoll_chk; # introduced=23
|
||||
__ppoll64_chk; # introduced=28
|
||||
__pread64_chk; # introduced=23
|
||||
__pread_chk; # introduced=23
|
||||
__progname; # var
|
||||
|
|
|
@ -278,7 +278,15 @@ void test_ppoll() {
|
|||
// NOLINTNEXTLINE(whitespace/line_length)
|
||||
// GCC: error: call to '__ppoll_too_small_error' declared with attribute error: ppoll: pollfd array smaller than fd count
|
||||
// CLANG: error: in call to 'ppoll', fd_count is larger than the given buffer
|
||||
ppoll(fds, 2, &timeout, NULL);
|
||||
ppoll(fds, 2, &timeout, nullptr);
|
||||
}
|
||||
|
||||
void test_ppoll64() {
|
||||
pollfd fds[1];
|
||||
timespec timeout;
|
||||
// NOLINTNEXTLINE(whitespace/line_length)
|
||||
// CLANG: error: in call to 'ppoll64', fd_count is larger than the given buffer
|
||||
ppoll64(fds, 2, &timeout, nullptr);
|
||||
}
|
||||
|
||||
void test_fread_overflow() {
|
||||
|
|
|
@ -995,7 +995,18 @@ TEST_F(DEATHTEST, ppoll_fortified) {
|
|||
// Set timeout to zero to prevent waiting in ppoll when fortify test fails.
|
||||
timespec timeout;
|
||||
timeout.tv_sec = timeout.tv_nsec = 0;
|
||||
ASSERT_FORTIFY(ppoll(buf, fd_count, &timeout, NULL));
|
||||
ASSERT_FORTIFY(ppoll(buf, fd_count, &timeout, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(DEATHTEST, ppoll64_fortified) {
|
||||
#if __BIONIC__ // glibc doesn't have ppoll64.
|
||||
nfds_t fd_count = atoi("2"); // suppress compiler optimizations
|
||||
pollfd buf[1] = {{0, POLLIN, 0}};
|
||||
// Set timeout to zero to prevent waiting in ppoll when fortify test fails.
|
||||
timespec timeout;
|
||||
timeout.tv_sec = timeout.tv_nsec = 0;
|
||||
ASSERT_FORTIFY(ppoll64(buf, fd_count, &timeout, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(DEATHTEST, open_O_CREAT_without_mode_fortified) {
|
||||
|
|
Loading…
Reference in New Issue