From: Alistair Francis <alistair.fran...@wdc.com>

Add support for the  64-bit time_t syscalls SYS_ppoll_time64
and SYS_pselect6_time64.

These are the syscalls that exist 32-bit platforms since the 5.1 kernel.
32-bit platforms with a 64-bit time_t only have these and don't have the
original syscalls (such as 32-bit RISC-V).

Fixes: https://github.com/lttng/lttng-tools/pull/162
Signed-off-by: Alistair Francis <alistair.fran...@wdc.com>
---
To keep the test_cases[] array clean I have implemented the functions
for all builds, but the functions are a no-op if the syscall is missing.

v2:
 - Split out a seperate _time64 test

 tests/regression/kernel/select_poll_epoll.cpp | 184 ++++++++++++++++++
 1 file changed, 184 insertions(+)

diff --git a/tests/regression/kernel/select_poll_epoll.cpp 
b/tests/regression/kernel/select_poll_epoll.cpp
index c0b688217..dfaab52c8 100644
--- a/tests/regression/kernel/select_poll_epoll.cpp
+++ b/tests/regression/kernel/select_poll_epoll.cpp
@@ -5,6 +5,7 @@
  *
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <poll.h>
@@ -48,10 +49,14 @@ int lttng_opt_quiet, lttng_opt_verbose, lttng_opt_mi;
 
 static void run_working_cases(FILE *validation_output_file);
 static void pselect_invalid_fd(FILE *validation_output_file);
+static void pselect_time64_invalid_fd(FILE *validation_output_file);
 static void test_ppoll_big(FILE *validation_output_file);
 static void ppoll_fds_buffer_overflow(FILE *validation_output_file);
+static void ppoll_time64_fds_buffer_overflow(FILE *validation_output_file);
 static void pselect_invalid_pointer(FILE *validation_output_file);
+static void pselect_time64_invalid_pointer(FILE *validation_output_file);
 static void ppoll_fds_ulong_max(FILE *validation_output_file);
+static void ppoll_time64_fds_ulong_max(FILE *validation_output_file);
 static void epoll_pwait_invalid_pointer(FILE *validation_output_file);
 static void epoll_pwait_int_max(FILE *validation_output_file);
 static void ppoll_concurrent_write(FILE *validation_output_file);
@@ -69,10 +74,14 @@ const struct test_case {
        { .run = run_working_cases, .produces_validation_info = true, .timeout 
= -1 },
        { .run = run_working_cases, .produces_validation_info = true, .timeout 
= 1 },
        { .run = pselect_invalid_fd, .produces_validation_info = false, 
.timeout = 0 },
+       { .run = pselect_time64_invalid_fd, .produces_validation_info = false, 
.timeout = 0 },
        { .run = test_ppoll_big, .produces_validation_info = false, .timeout = 
0 },
        { .run = ppoll_fds_buffer_overflow, .produces_validation_info = false, 
.timeout = 0 },
+       { .run = ppoll_time64_fds_buffer_overflow, .produces_validation_info = 
false, .timeout = 0 },
        { .run = pselect_invalid_pointer, .produces_validation_info = false, 
.timeout = 0 },
+       { .run = pselect_time64_invalid_pointer, .produces_validation_info = 
false, .timeout = 0 },
        { .run = ppoll_fds_ulong_max, .produces_validation_info = false, 
.timeout = 0 },
+       { .run = ppoll_time64_fds_ulong_max, .produces_validation_info = false, 
.timeout = 0 },
        { .run = epoll_pwait_invalid_pointer, .produces_validation_info = true, 
.timeout = 0 },
        { .run = epoll_pwait_int_max, .produces_validation_info = true, 
.timeout = 0 },
        { .run = ppoll_concurrent_write, .produces_validation_info = false, 
.timeout = 0 },
@@ -440,6 +449,44 @@ end:
        return;
 }
 
+/*
+ * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
+ * segfault (eventually with a "*** stack smashing detected ***" message).
+ * The event should contain an array of 100 FDs filled with garbage.
+ */
+static
+void ppoll_time64_fds_buffer_overflow(
+               FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_ppoll_time64
+       struct pollfd ufds[NB_FD];
+       char buf[BUF_SIZE];
+       int ret;
+
+       ufds[0].fd = wait_fd;
+       ufds[0].events = POLLIN|POLLPRI;
+
+       /*
+        * As there is no timeout value, we don't convert to/from
+        * 64/32-bit time_t.
+        */
+       ret = syscall(SYS_ppoll_time64, ufds, 100, NULL, NULL);
+       /*
+        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
+        * to work and if it doesn't we fail.
+        */
+
+       if (ret < 0) {
+               PERROR("ppoll_time64");
+       } else if (ret > 0) {
+               ret = read(wait_fd, buf, BUF_SIZE);
+               if (ret < 0) {
+                       PERROR("[ppoll_time64] read");
+               }
+       }
+#endif
+}
+
 /*
  * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
  * segfault (eventually with a "*** stack smashing detected ***" message).
@@ -449,6 +496,7 @@ static
 void ppoll_fds_buffer_overflow(
                FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_ppoll
        struct pollfd ufds[NB_FD];
        char buf[BUF_SIZE];
        int ret;
@@ -466,6 +514,46 @@ void ppoll_fds_buffer_overflow(
                        PERROR("[ppoll] read");
                }
        }
+#endif
+}
+
+/*
+ * Ask for ULONG_MAX FDs in a buffer for allocated for only 1 FD, should
+ * cleanly fail with a "Invalid argument".
+ * The event should contain an empty array of FDs and overflow = 1.
+ */
+static
+void ppoll_time64_fds_ulong_max(FILE *validation_output_file 
__attribute__((unused)))
+{
+#ifdef SYS_ppoll_time64
+       struct pollfd ufds[NB_FD];
+       char buf[BUF_SIZE];
+       int ret;
+
+       ufds[0].fd = wait_fd;
+       ufds[0].events = POLLIN|POLLPRI;
+
+       /*
+        * As there is no timeout value, we don't convert to/from
+        * 64/32-bit time_t.
+        */
+       ret = syscall(SYS_ppoll_time64, ufds, ULONG_MAX, NULL, NULL);
+       /*
+        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
+        * to work and if it doesn't we fail.
+        */
+
+       if (ret < 0 && errno != ENOSYS) {
+               /* Expected error. */
+       } else if (errno == ENOSYS) {
+               PERROR("[ppoll_time64] missing syscall");
+       } else if (ret > 0) {
+               ret = read(wait_fd, buf, BUF_SIZE);
+               if (ret < 0) {
+                       PERROR("[ppoll_time64] read");
+               }
+       }
+#endif
 }
 
 /*
@@ -476,6 +564,7 @@ void ppoll_fds_buffer_overflow(
 static
 void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_ppoll
        struct pollfd ufds[NB_FD];
        char buf[BUF_SIZE];
        int ret;
@@ -492,6 +581,59 @@ void ppoll_fds_ulong_max(FILE *validation_output_file 
__attribute__((unused)))
                        PERROR("[ppoll] read");
                }
        }
+#endif
+}
+
+/*
+ * Pass an invalid file descriptor to pselect6(). The syscall should return
+ * -EBADF. The recorded event should contain a "ret = -EBADF (-9)".
+ */
+static
+void pselect_time64_invalid_fd(FILE *validation_output_file 
__attribute__((unused)))
+{
+#ifdef SYS_pselect6_time64
+       fd_set rfds;
+       int ret;
+       int fd;
+       char buf[BUF_SIZE];
+
+       /*
+        * Open a file, close it and use the closed FD in the pselect6 call.
+        */
+       fd = open("/dev/null", O_RDONLY);
+       if (fd == -1) {
+               PERROR("open");
+               goto error;
+       }
+
+       ret = close(fd);
+       if (ret == -1) {
+               PERROR("close");
+               goto error;
+       }
+
+       FD_ZERO(&rfds);
+       FD_SET(fd, &rfds);
+
+       ret = syscall(SYS_pselect6_time64, fd + 1, &rfds, NULL, NULL, NULL, 
NULL);
+       /*
+        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
+        * to work and if it doesn't we fail.
+        */
+
+       if (ret == -1 && errno != ENOSYS) {
+               /* Expected error. */
+       } else if (errno == ENOSYS) {
+               PERROR("[pselect_time64] missing syscall");
+       } else if (ret) {
+               ret = read(wait_fd, buf, BUF_SIZE);
+               if (ret < 0) {
+                       PERROR("[pselect_time64] read");
+               }
+       }
+error:
+       return;
+#endif
 }
 
 /*
@@ -501,6 +643,7 @@ void ppoll_fds_ulong_max(FILE *validation_output_file 
__attribute__((unused)))
 static
 void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_pselect6
        fd_set rfds;
        int ret;
        int fd;
@@ -525,6 +668,7 @@ void pselect_invalid_fd(FILE *validation_output_file 
__attribute__((unused)))
        FD_SET(fd, &rfds);
 
        ret = syscall(SYS_pselect6, fd + 1, &rfds, NULL, NULL, NULL, NULL);
+
        if (ret == -1) {
                /* Expected error. */
        } else if (ret) {
@@ -535,6 +679,44 @@ void pselect_invalid_fd(FILE *validation_output_file 
__attribute__((unused)))
        }
 error:
        return;
+#endif
+}
+
+/*
+ * Invalid pointer as writefds, should output a ppoll event
+ * with 0 FDs.
+ */
+static
+void pselect_time64_invalid_pointer(
+               FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_pselect6_time64
+       fd_set rfds;
+       int ret;
+       char buf[BUF_SIZE];
+       void *invalid = (void *) 0x42;
+
+       FD_ZERO(&rfds);
+       FD_SET(wait_fd, &rfds);
+
+       ret = syscall(SYS_pselect6_time64, 1, &rfds, (fd_set *) invalid, NULL, 
NULL,
+                       NULL);
+       /*
+        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
+        * to work and if it doesn't we fail.
+        */
+
+       if (ret == -1 && errno != ENOSYS) {
+               /* Expected error. */
+       } else if (errno == ENOSYS) {
+               PERROR("[pselect_time64] missing syscall");
+       } else if (ret) {
+               ret = read(wait_fd, buf, BUF_SIZE);
+               if (ret < 0) {
+                       PERROR("[pselect_time64] read");
+               }
+       }
+#endif
 }
 
 /*
@@ -545,6 +727,7 @@ static
 void pselect_invalid_pointer(
                FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_pselect6
        fd_set rfds;
        int ret;
        char buf[BUF_SIZE];
@@ -563,6 +746,7 @@ void pselect_invalid_pointer(
                        PERROR("[pselect] read");
                }
        }
+#endif
 }
 
 /*
-- 
2.37.3

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to