1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2021, BELLSOFT. All rights reserved.
4 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
5 * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Verify that sched_setparam() fails if the user does not have proper
12 * privileges.
13 */
14
15 #include <stdlib.h>
16 #include <pwd.h>
17
18 #include "tst_test.h"
19 #include "tst_sched.h"
20
run(void)21 static void run(void)
22 {
23 struct sched_variant *tv = &sched_variants[tst_variant];
24 pid_t child_pid = SAFE_FORK();
25
26 if (!child_pid) {
27 struct sched_param p = { .sched_priority = 0 };
28 struct passwd *pw = SAFE_GETPWNAM("nobody");
29
30 SAFE_SETEUID(pw->pw_uid);
31 TST_EXP_FAIL(tv->sched_setparam(getppid(), &p), EPERM,
32 "sched_setparam(%d, 0)", getppid());
33
34 exit(0);
35 }
36
37 tst_reap_children();
38 }
39
setup(void)40 static void setup(void)
41 {
42 tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
43 }
44
45 static struct tst_test test = {
46 .needs_root = 1,
47 .forks_child = 1,
48 .setup = setup,
49 .test_variants = ARRAY_SIZE(sched_variants),
50 .test_all = run,
51 };
52