lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis via lttng-dev <lttng-dev@lists.lttng.org>
To: Alistair Francis <alistair.francis@opensource.wdc.com>
Cc: lttng-dev@lists.lttng.org
Subject: Re: [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64
Date: Tue, 13 Dec 2022 15:09:29 +1000	[thread overview]
Message-ID: <CAKmqyKO2Kv72-c98_nC-Aprf8gFUJYrW1=kUkhf7B=cHMwmdtQ@mail.gmail.com> (raw)
In-Reply-To: <20221027055428.406908-1-alistair.francis@opensource.wdc.com>

On Thu, Oct 27, 2022 at 3:54 PM Alistair Francis
<alistair.francis@opensource.wdc.com> wrote:
>
> From: Alistair Francis <alistair.francis@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.francis@wdc.com>

Ping!

Alistair

> ---
> 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	other threads:[~2022-12-13 14:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27  5:54 [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64 Alistair Francis via lttng-dev
2022-12-13  5:09 ` Alistair Francis via lttng-dev [this message]
2022-12-14 20:20   ` Jérémie Galarneau via lttng-dev
2023-01-31  8:56     ` Alistair Francis via lttng-dev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKmqyKO2Kv72-c98_nC-Aprf8gFUJYrW1=kUkhf7B=cHMwmdtQ@mail.gmail.com' \
    --to=lttng-dev@lists.lttng.org \
    --cc=alistair.francis@opensource.wdc.com \
    --cc=alistair23@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).