-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ioctl01: Workaround segfault on EFAULT tests
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
Showing
1 changed file
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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) | ||
|
@@ -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, | ||
}; |