[LTP] [PATCH 2/2] mq_timedreceive01: Workaround segfault on libc variant on 32 bit

Wei Gao wegao@suse.com
Wed Nov 13 04:00:21 CET 2024


On Tue, Nov 12, 2024 at 06:18:31PM +0100, Petr Vorel wrote:
> EFAULT test 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.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  .../mq_timedreceive/mq_timedreceive01.c       | 78 ++++++++++++++-----
>  1 file changed, 58 insertions(+), 20 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> index d4f447d047..a5a43a1771 100644
> --- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> +++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> @@ -129,32 +129,16 @@ static void setup(void)
>  	setup_common();
>  }
>  
> -static void do_test(unsigned int i)
> +
> +static void verify_mqt_receive(unsigned int i, pid_t pid)
>  {
>  	struct time64_variants *tv = &variants[tst_variant];
>  	const struct test_case *tc = &tcase[i];
> -	unsigned int j;
> -	unsigned int prio;
>  	size_t len = MAX_MSGSIZE;
>  	char rmsg[len];
> -	pid_t pid = -1;
>  	void *abs_timeout;
> -
> -	tst_ts_set_sec(&ts, tc->tv_sec);
> -	tst_ts_set_nsec(&ts, tc->tv_nsec);
> -
> -	if (tc->signal)
> -		pid = set_sig(tc->rq, tv->clock_gettime);
> -
> -	if (tc->timeout)
> -		set_timeout(tc->rq, tv->clock_gettime);
> -
> -	if (tc->send) {
> -		if (tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
> -			tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
> -			return;
> -		}
> -	}
> +	unsigned int j;
> +	unsigned int prio;
>  
>  	if (tc->invalid_msg)
>  		len -= 1;
> @@ -208,6 +192,60 @@ static void do_test(unsigned int i)
>  			TST_RET, prio, len);
>  }
>  
> +static void test_bad_addr(unsigned int i)
> +{
> +	struct time64_variants *tv = &variants[tst_variant];
> +	pid_t pid;
> +	int status;
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		verify_mqt_receive(i, pid);
> +		_exit(0);
nit:
If this is a normal exit, i suggest use s/_exit(0)/exit(0) ?
> +	}
> +
> +	SAFE_WAITPID(pid, &status, 0);
> +
> +	if (WIFEXITED(status) && !WEXITSTATUS(status))
> +		return;
> +
> +	if (tv->ts_type == TST_LIBC_TIMESPEC &&
> +		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)
> +{
> +	struct time64_variants *tv = &variants[tst_variant];
> +	const struct test_case *tc = &tcase[i];
> +	pid_t pid = -1;
> +
> +	tst_ts_set_sec(&ts, tc->tv_sec);
> +	tst_ts_set_nsec(&ts, tc->tv_nsec);
> +
> +	if (tc->bad_ts_addr) {
> +		test_bad_addr(i);
> +		return;
> +	}
> +
> +	if (tc->signal)
> +		pid = set_sig(tc->rq, tv->clock_gettime);
> +
> +	if (tc->timeout)
> +		set_timeout(tc->rq, tv->clock_gettime);
> +
> +	if (tc->send && tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
> +		tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
> +		return;
> +	}
> +
> +	verify_mqt_receive(i, pid);
> +}
> +
>  static struct tst_test test = {
>  	.tcnt = ARRAY_SIZE(tcase),
>  	.test = do_test,
> -- 
> 2.47.0
> 


More information about the ltp mailing list