1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2020-2023 5f08c3bdfSopenharmony_ci * Author: Saji Kumar.V.R <saji.kumar@wipro.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Test whether capset() can be used to modify the capabilities of a thread 12f08c3bdfSopenharmony_ci * other than itself. Now, most linux distributions with kernel supporting 13f08c3bdfSopenharmony_ci * VFS capabilities, this should be never permitted. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <stdlib.h> 17f08c3bdfSopenharmony_ci#include <sys/types.h> 18f08c3bdfSopenharmony_ci#include <unistd.h> 19f08c3bdfSopenharmony_ci#include "tst_test.h" 20f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 21f08c3bdfSopenharmony_ci#include <linux/capability.h> 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic struct __user_cap_header_struct *header; 24f08c3bdfSopenharmony_cistatic struct __user_cap_data_struct *data; 25f08c3bdfSopenharmony_cistatic pid_t child_pid; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic void verify_capset(void) 28f08c3bdfSopenharmony_ci{ 29f08c3bdfSopenharmony_ci child_pid = SAFE_FORK(); 30f08c3bdfSopenharmony_ci if (!child_pid) 31f08c3bdfSopenharmony_ci pause(); 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci tst_res(TINFO, "Test capset() for a different process"); 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci header->pid = child_pid; 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci TST_EXP_FAIL(tst_syscall(__NR_capset, header, data), EPERM, "capset()"); 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci SAFE_KILL(child_pid, SIGTERM); 40f08c3bdfSopenharmony_ci SAFE_WAIT(NULL); 41f08c3bdfSopenharmony_ci} 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic void setup(void) 44f08c3bdfSopenharmony_ci{ 45f08c3bdfSopenharmony_ci header->version = 0x20080522; 46f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_capget, header, data)); 47f08c3bdfSopenharmony_ci if (TST_RET == -1) 48f08c3bdfSopenharmony_ci tst_brk(TBROK | TTERRNO, "capget data failed"); 49f08c3bdfSopenharmony_ci} 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_cistatic struct tst_test test = { 52f08c3bdfSopenharmony_ci .setup = setup, 53f08c3bdfSopenharmony_ci .test_all = verify_capset, 54f08c3bdfSopenharmony_ci .forks_child = 1, 55f08c3bdfSopenharmony_ci .bufs = (struct tst_buffers []) { 56f08c3bdfSopenharmony_ci {&header, .size = sizeof(*header)}, 57f08c3bdfSopenharmony_ci {&data, .size = 2 * sizeof(*data)}, 58f08c3bdfSopenharmony_ci {}, 59f08c3bdfSopenharmony_ci } 60f08c3bdfSopenharmony_ci}; 61