• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) International Business Machines  Corp., 2003.
4  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Test for a libc bug where exiting child function by returning from
11  * it caused SIGSEGV.
12  */
13 
14 #include <sched.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "tst_test.h"
18 #include "lapi/syscalls.h"
19 #include "clone_platform.h"
20 
21 static void *child_stack;
22 
do_child(void * arg LTP_ATTRIBUTE_UNUSED)23 static int do_child(void *arg LTP_ATTRIBUTE_UNUSED)
24 {
25 	return 0;
26 }
27 
verify_clone(void)28 static void verify_clone(void)
29 {
30 	int status;
31 	pid_t pid = 0;
32 
33 	TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE,
34 				child_stack));
35 
36 	if (!TST_PASS)
37 		return;
38 
39 	SAFE_WAITPID(pid, &status, 0);
40 
41 	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
42 		tst_res(TPASS, "Using return in child will not cause abnormal exit");
43 		return;
44 	}
45 
46 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
47 		tst_res(TFAIL, "Use of return in child caused SIGSEGV");
48 		return;
49 	}
50 
51 	tst_res(TFAIL, "Using return 0 in child the child %s", tst_strstatus(status));
52 }
53 
54 static struct tst_test test = {
55 	.test_all = verify_clone,
56 	.bufs = (struct tst_buffers []) {
57 		{&child_stack, .size = CHILD_STACK_SIZE},
58 		{},
59 	},
60 };
61