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