1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Author: Saji Kumar.V.R <saji.kumar@wipro.com> 5f08c3bdfSopenharmony_ci * 6f08c3bdfSopenharmony_ci * 2005/01/01: add an hint to a possible solution when test fails 7f08c3bdfSopenharmony_ci * Ricky Ng-Adam <rngadam@yahoo.com> 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2003-2023 10f08c3bdfSopenharmony_ci */ 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_ci/*\ 13f08c3bdfSopenharmony_ci * [Description] 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * Test capset() with with LINUX_CAPABILITY_VERSION_{1,2,3}. 16f08c3bdfSopenharmony_ci */ 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include <sys/types.h> 19f08c3bdfSopenharmony_ci#include <unistd.h> 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 22f08c3bdfSopenharmony_ci#include <linux/capability.h> 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic pid_t pid; 25f08c3bdfSopenharmony_cistatic struct __user_cap_header_struct *header; 26f08c3bdfSopenharmony_cistatic struct __user_cap_data_struct *data; 27f08c3bdfSopenharmony_cistatic struct tcase { 28f08c3bdfSopenharmony_ci int version; 29f08c3bdfSopenharmony_ci char *message; 30f08c3bdfSopenharmony_ci} tcases[] = { 31f08c3bdfSopenharmony_ci {0x19980330, "LINUX_CAPABILITY_VERSION_1"}, 32f08c3bdfSopenharmony_ci {0x20071026, "LINUX_CAPABILITY_VERSION_2"}, 33f08c3bdfSopenharmony_ci {0x20080522, "LINUX_CAPABILITY_VERSION_3"}, 34f08c3bdfSopenharmony_ci}; 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic void verify_capset(unsigned int n) 37f08c3bdfSopenharmony_ci{ 38f08c3bdfSopenharmony_ci struct tcase *tc = &tcases[n]; 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci header->version = tc->version; 41f08c3bdfSopenharmony_ci header->pid = pid; 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_capget, header, data)); 44f08c3bdfSopenharmony_ci if (TST_RET == -1) 45f08c3bdfSopenharmony_ci tst_brk(TFAIL | TTERRNO, "capget() failed"); 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci TST_EXP_PASS(tst_syscall(__NR_capset, header, data), 48f08c3bdfSopenharmony_ci "capset() with %s", tc->message); 49f08c3bdfSopenharmony_ci} 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_cistatic void setup(void) 52f08c3bdfSopenharmony_ci{ 53f08c3bdfSopenharmony_ci pid = getpid(); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic struct tst_test test = { 57f08c3bdfSopenharmony_ci .setup = setup, 58f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 59f08c3bdfSopenharmony_ci .test = verify_capset, 60f08c3bdfSopenharmony_ci .bufs = (struct tst_buffers []) { 61f08c3bdfSopenharmony_ci {&header, .size = sizeof(*header)}, 62f08c3bdfSopenharmony_ci {&data, .size = 2 * sizeof(*data)}, 63f08c3bdfSopenharmony_ci {}, 64f08c3bdfSopenharmony_ci } 65f08c3bdfSopenharmony_ci}; 66