xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/wait4/wait403.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2021 SUSE LLC <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
10*49cdfc7eSAndroid Build Coastguard Worker  * searching for a group with that pid. Negating INT_MIN is not
11*49cdfc7eSAndroid Build Coastguard Worker  * defined so UBSAN will be triggered if enabled. Also see kill13.
12*49cdfc7eSAndroid Build Coastguard Worker  *
13*49cdfc7eSAndroid Build Coastguard Worker  * If the bug is present, but UBSAN is not enabled, then it should
14*49cdfc7eSAndroid Build Coastguard Worker  * result in ECHILD.
15*49cdfc7eSAndroid Build Coastguard Worker  */
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
19*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
20*49cdfc7eSAndroid Build Coastguard Worker #define _USE_BSD
21*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
22*49cdfc7eSAndroid Build Coastguard Worker #include <sys/resource.h>
23*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
24*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
25*49cdfc7eSAndroid Build Coastguard Worker 
run(void)26*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
27*49cdfc7eSAndroid Build Coastguard Worker {
28*49cdfc7eSAndroid Build Coastguard Worker 	int status = 1;
29*49cdfc7eSAndroid Build Coastguard Worker 	struct rusage rusage;
30*49cdfc7eSAndroid Build Coastguard Worker 
31*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL2(wait4(INT_MIN, &status, 0, &rusage), ESRCH,
32*49cdfc7eSAndroid Build Coastguard Worker 		      "wait4 fails with ESRCH");
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
37*49cdfc7eSAndroid Build Coastguard Worker 	.taint_check = TST_TAINT_W | TST_TAINT_D,
38*49cdfc7eSAndroid Build Coastguard Worker 	.tags = (const struct tst_tag[]) {
39*49cdfc7eSAndroid Build Coastguard Worker 		{"linux-git", "dd83c161fbcc"},
40*49cdfc7eSAndroid Build Coastguard Worker 		{}
41*49cdfc7eSAndroid Build Coastguard Worker 	}
42*49cdfc7eSAndroid Build Coastguard Worker };
43