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