Skip to content

Commit

Permalink
syscalls/select03: Fix segfaults on aarch64
Browse files Browse the repository at this point in the history
The select() syscall is implemented via pselect6() in aarch64 glibc, which
means that glibc has to convert the timeout from timeval to timespec hence it
will segfault rather than return EFAULT.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
CC: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Li Wang <liwang@redhat.com>
  • Loading branch information
metan-ucw committed Nov 24, 2020
1 parent 82ea993 commit de9dd02
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 29 additions & 1 deletion testcases/kernel/syscalls/select/select03.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include "select_var.h"

Expand Down Expand Up @@ -40,7 +42,7 @@ static struct tcases {
{ "Faulty timeout", &maxfds, &preadfds_reg, &pwritefds_reg, &nullfds, &invalid_to, EFAULT },
};

static void run(unsigned int n)
static void verify_select(unsigned int n)
{
struct tcases *tc = &tests[n];

Expand All @@ -61,6 +63,31 @@ static void run(unsigned int n)
}

tst_res(TPASS | TTERRNO, "%s: select() failed as expected", tc->name);

exit(0);
}

static void run(unsigned int n)
{
int pid, status;

pid = SAFE_FORK();
if (!pid)
verify_select(n);

SAFE_WAITPID(pid, &status, 0);

if (WIFEXITED(status))
return;

if (tst_variant == GLIBC_SELECT_VARIANT &&
tests[n].timeout == &invalid_to &&
WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
tst_res(TPASS, "%s: select() killed by signal", tests[n].name);
return;
}

tst_res(TFAIL, "Child %s", tst_strstatus(status));
}

static void setup(void)
Expand Down Expand Up @@ -94,4 +121,5 @@ static struct tst_test test = {
.test_variants = TEST_VARIANTS,
.setup = setup,
.needs_tmpdir = 1,
.forks_child = 1,
};
2 changes: 2 additions & 0 deletions testcases/kernel/syscalls/select/select_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct compat_sel_arg_struct {
long _tvp;
};

#define GLIBC_SELECT_VARIANT 0

static int do_select_faulty_to(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout, int faulty_to)
{
Expand Down

0 comments on commit de9dd02

Please sign in to comment.