1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (C) International Business Machines Corp., 2008 4f08c3bdfSopenharmony_ci * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Clone a process with CLONE_NEWPID flag and check that parent process can't 11f08c3bdfSopenharmony_ci * be killed from child namespace. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include "tst_test.h" 15f08c3bdfSopenharmony_ci#include "lapi/sched.h" 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_cistatic void child_func(int pid) 18f08c3bdfSopenharmony_ci{ 19f08c3bdfSopenharmony_ci pid_t cpid = tst_getpid(); 20f08c3bdfSopenharmony_ci pid_t ppid = getppid(); 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(cpid, 1); 23f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(ppid, 0); 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci tst_res(TINFO, "Trying to kill parent from within container"); 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci TST_EXP_FAIL(kill(pid, SIGKILL), ESRCH); 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void run(void) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci const struct tst_clone_args args = { 33f08c3bdfSopenharmony_ci .flags = CLONE_NEWPID, 34f08c3bdfSopenharmony_ci .exit_signal = SIGCHLD, 35f08c3bdfSopenharmony_ci }; 36f08c3bdfSopenharmony_ci pid_t pid = getpid(); 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci if (!SAFE_CLONE(&args)) { 39f08c3bdfSopenharmony_ci child_func(pid); 40f08c3bdfSopenharmony_ci return; 41f08c3bdfSopenharmony_ci } 42f08c3bdfSopenharmony_ci} 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_cistatic struct tst_test test = { 45f08c3bdfSopenharmony_ci .test_all = run, 46f08c3bdfSopenharmony_ci .needs_root = 1, 47f08c3bdfSopenharmony_ci .forks_child = 1, 48f08c3bdfSopenharmony_ci}; 49