xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/prctl/prctl06.h (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) 2019 FUJITSU LIMITED. All rights reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Yang Xu <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker #ifndef PRCTL06_H
7*49cdfc7eSAndroid Build Coastguard Worker #define PRCTL06_H
8*49cdfc7eSAndroid Build Coastguard Worker 
9*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
10*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
11*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
12*49cdfc7eSAndroid Build Coastguard Worker #include <sys/prctl.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <pwd.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <lapi/prctl.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker #define PROC_STATUS        "/proc/self/status"
20*49cdfc7eSAndroid Build Coastguard Worker #define MNTPOINT           "mntpoint"
21*49cdfc7eSAndroid Build Coastguard Worker #define TESTBIN            "prctl06_execve"
22*49cdfc7eSAndroid Build Coastguard Worker #define TEST_REL_BIN_DIR   MNTPOINT"/"
23*49cdfc7eSAndroid Build Coastguard Worker #define BIN_PATH           MNTPOINT"/"TESTBIN
24*49cdfc7eSAndroid Build Coastguard Worker #define SUID_MODE          (S_ISUID|S_ISGID|S_IXUSR|S_IXGRP|S_IXOTH)
25*49cdfc7eSAndroid Build Coastguard Worker 
check_no_new_privs(int val,char * name,int flag)26*49cdfc7eSAndroid Build Coastguard Worker static void check_no_new_privs(int val, char *name, int flag)
27*49cdfc7eSAndroid Build Coastguard Worker {
28*49cdfc7eSAndroid Build Coastguard Worker 	TEST(prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
29*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET == val)
30*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS,
31*49cdfc7eSAndroid Build Coastguard Worker 			"%s prctl(PR_GET_NO_NEW_PRIVS) expected %d got %d",
32*49cdfc7eSAndroid Build Coastguard Worker 			name, val, val);
33*49cdfc7eSAndroid Build Coastguard Worker 	else
34*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL,
35*49cdfc7eSAndroid Build Coastguard Worker 			"%s prctl(PR_GET_NO_NEW_PRIVS) expected %d got %ld",
36*49cdfc7eSAndroid Build Coastguard Worker 			name, val, TST_RET);
37*49cdfc7eSAndroid Build Coastguard Worker 	if (flag)
38*49cdfc7eSAndroid Build Coastguard Worker 		TST_ASSERT_FILE_INT(PROC_STATUS, "NoNewPrivs:", val);
39*49cdfc7eSAndroid Build Coastguard Worker }
40*49cdfc7eSAndroid Build Coastguard Worker 
41*49cdfc7eSAndroid Build Coastguard Worker #endif
42