1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
4f08c3bdfSopenharmony_ci * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5f08c3bdfSopenharmony_ci */
6f08c3bdfSopenharmony_ci#ifndef PRCTL06_H
7f08c3bdfSopenharmony_ci#define PRCTL06_H
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_ci#include <errno.h>
10f08c3bdfSopenharmony_ci#include <stdio.h>
11f08c3bdfSopenharmony_ci#include <stdlib.h>
12f08c3bdfSopenharmony_ci#include <sys/prctl.h>
13f08c3bdfSopenharmony_ci#include <pwd.h>
14f08c3bdfSopenharmony_ci#include <sys/types.h>
15f08c3bdfSopenharmony_ci#include <unistd.h>
16f08c3bdfSopenharmony_ci#include <lapi/prctl.h>
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_ci#define PROC_STATUS        "/proc/self/status"
20f08c3bdfSopenharmony_ci#define MNTPOINT           "mntpoint"
21f08c3bdfSopenharmony_ci#define TESTBIN            "prctl06_execve"
22f08c3bdfSopenharmony_ci#define TEST_REL_BIN_DIR   MNTPOINT"/"
23f08c3bdfSopenharmony_ci#define BIN_PATH           MNTPOINT"/"TESTBIN
24f08c3bdfSopenharmony_ci#define SUID_MODE          (S_ISUID|S_ISGID|S_IXUSR|S_IXGRP|S_IXOTH)
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_cistatic void check_no_new_privs(int val, char *name, int flag)
27f08c3bdfSopenharmony_ci{
28f08c3bdfSopenharmony_ci	TEST(prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
29f08c3bdfSopenharmony_ci	if (TST_RET == val)
30f08c3bdfSopenharmony_ci		tst_res(TPASS,
31f08c3bdfSopenharmony_ci			"%s prctl(PR_GET_NO_NEW_PRIVS) expected %d got %d",
32f08c3bdfSopenharmony_ci			name, val, val);
33f08c3bdfSopenharmony_ci	else
34f08c3bdfSopenharmony_ci		tst_res(TFAIL,
35f08c3bdfSopenharmony_ci			"%s prctl(PR_GET_NO_NEW_PRIVS) expected %d got %ld",
36f08c3bdfSopenharmony_ci			name, val, TST_RET);
37f08c3bdfSopenharmony_ci	if (flag)
38f08c3bdfSopenharmony_ci		TST_ASSERT_FILE_INT(PROC_STATUS, "NoNewPrivs:", val);
39f08c3bdfSopenharmony_ci}
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_ci#endif
42