Skip to content

Commit

Permalink
ioctl01: Workaround segfault on EFAULT tests
Browse files Browse the repository at this point in the history
Testing termio/termios invalid/NULL address for EFAULT fails on ppc64le.
Use typical LTP workaround to test by forked child + checking the
terminating signal (on all archs).

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Wei Gao <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
pevik committed Nov 26, 2024
1 parent b52aef0 commit ad651be
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions testcases/kernel/syscalls/ioctl/ioctl01.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Copyright (c) International Business Machines Corp., 2001
* Copyright (c) 2020 Petr Vorel <[email protected]>
* Copyright (c) Linux Test Project, 2002-2023
* Copyright (c) Linux Test Project, 2002-2024
* 07/2001 Ported by Wayne Boyer
* 04/2002 Fixes by wjhuie
*/
Expand Down Expand Up @@ -59,8 +59,42 @@ static struct tcase {

static void verify_ioctl(unsigned int i)
{
TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tio),
tcases[i].error, "%s", tcases[i].desc);
struct tcase *tc = &tcases[i];

TST_EXP_FAIL(ioctl(*(tc->fd), tc->request, tc->s_tio), tc->error, "%s",
tc->desc);
}

static void test_bad_addr(unsigned int i)
{
pid_t pid;
int status;

pid = SAFE_FORK();
if (!pid) {
verify_ioctl(i);
exit(0);
}

SAFE_WAITPID(pid, &status, 0);

if (WIFEXITED(status) && !WEXITSTATUS(status))
return;

if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
tst_res(TPASS, "Child killed by expected signal");
return;
}

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

static void do_test(unsigned int i)
{
if (tcases[i].error == EFAULT)
test_bad_addr(i);
else
verify_ioctl(i);
}

static void setup(void)
Expand All @@ -86,6 +120,7 @@ static struct tst_test test = {
.needs_tmpdir = 1,
.setup = setup,
.cleanup = cleanup,
.test = verify_ioctl,
.tcnt = ARRAY_SIZE(tcases)
.test = do_test,
.tcnt = ARRAY_SIZE(tcases),
.forks_child = 1,
};

0 comments on commit ad651be

Please sign in to comment.