[LTP] [PATCH 4/5] libs/sigwait: Workaround segfault on libc variant on 32 bit

Petr Vorel pvorel@suse.cz
Thu Nov 14 15:40:28 CET 2024


test_bad_address3() test which tests EFAULT segfaults on newer kernels
(e.g. 6.4) on libc variant on 32bit.  Similarly to 1d4d5a0750 use
typical LTP workaround to test by forked child + checking the
terminating signal.

This got broken on sigtimedwait01.c (but not on rt_sigtimedwait01.c).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 libs/sigwait/sigwait.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/libs/sigwait/sigwait.c b/libs/sigwait/sigwait.c
index 86899954d7..cf3c445b4a 100644
--- a/libs/sigwait/sigwait.c
+++ b/libs/sigwait/sigwait.c
@@ -359,17 +359,27 @@ void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
 		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
+	pid_t pid;
+	int status;
 
-	SAFE_SIGEMPTYSET(&sigs);
-	TEST(sigwaitinfo(&sigs, NULL, (void *)1));
-	if (TST_RET == -1) {
-		if (TST_ERR == EFAULT)
-			tst_res(TPASS, "Fault occurred while accessing the buffers");
-		else
-			tst_res(TFAIL | TTERRNO, "Expected error number EFAULT, got");
-	} else {
-		tst_res(TFAIL, "Expected return value -1, got: %ld", TST_RET);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		SAFE_SIGEMPTYSET(&sigs);
+		TST_EXP_FAIL(sigwaitinfo(&sigs, NULL, (void *)1), EFAULT);
+		_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 empty_handler(int sig LTP_ATTRIBUTE_UNUSED)
-- 
2.45.2



More information about the ltp mailing list