diff mbox series

[1/1] ioctl01: Workaround segfault on ppc64le

Message ID 20241114172911.362197-1-pvorel@suse.cz
State Accepted
Headers show
Series [1/1] ioctl01: Workaround segfault on ppc64le | expand

Commit Message

Petr Vorel Nov. 14, 2024, 5:29 p.m. UTC
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).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/kernel/syscalls/ioctl/ioctl01.c | 45 ++++++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)

Comments

Wei Gao Nov. 15, 2024, 7:50 a.m. UTC | #1
On Thu, Nov 14, 2024 at 06:29:11PM +0100, Petr Vorel wrote:
> 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).
Very nit:
The title is "[PATCH 1/1] ioctl01: Workaround segfault on ppc64le" but 
your code is create workaround for all archs, so maybe update some words?

Reviewed-by: Wei Gao <wegao@suse.com>
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/kernel/syscalls/ioctl/ioctl01.c | 45 ++++++++++++++++++++---
>  1 file changed, 40 insertions(+), 5 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c
> index c84a72b9a2..e4f32330d0 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl01.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl01.c
> @@ -2,7 +2,7 @@
>  /*
>   * Copyright (c) International Business Machines Corp., 2001
>   * Copyright (c) 2020 Petr Vorel <petr.vorel@gmail.com>
> - * 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,
>  };
> -- 
> 2.45.2
>
Petr Vorel Nov. 15, 2024, 10:37 a.m. UTC | #2
> On Thu, Nov 14, 2024 at 06:29:11PM +0100, Petr Vorel wrote:
> > 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).
> Very nit:
> The title is "[PATCH 1/1] ioctl01: Workaround segfault on ppc64le" but 
> your code is create workaround for all archs, so maybe update some words?

Thanks! I guess I should change it before merge to:

"ioctl01: Workaround segfault on EFAULT tests"

And note later in the message that the problem is only on ppc64le.

Kind regards,
Petr
Cyril Hrubis Nov. 26, 2024, 11:59 a.m. UTC | #3
Hi!
Looks good.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Petr Vorel Nov. 26, 2024, 1:07 p.m. UTC | #4
Hi Cyril,

> Hi!
> Looks good.

Thanks! I'm going to merge with this change below (using exit(0) instead of
_exit(0).

Kind regards,
Petr

diff --git testcases/kernel/syscalls/ioctl/ioctl01.c testcases/kernel/syscalls/ioctl/ioctl01.c
index e4f32330d0..d7886f3586 100644
--- testcases/kernel/syscalls/ioctl/ioctl01.c
+++ testcases/kernel/syscalls/ioctl/ioctl01.c
@@ -73,7 +73,7 @@ static void test_bad_addr(unsigned int i)
 	pid = SAFE_FORK();
 	if (!pid) {
 		verify_ioctl(i);
-		_exit(0);
+		exit(0);
 	}
 
 	SAFE_WAITPID(pid, &status, 0);
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c
index c84a72b9a2..e4f32330d0 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl01.c
@@ -2,7 +2,7 @@ 
 /*
  * Copyright (c) International Business Machines Corp., 2001
  * Copyright (c) 2020 Petr Vorel <petr.vorel@gmail.com>
- * 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,
 };