1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
4 * Copyright (c) Linux Test Project, 2020-2023
5 * Author: Yang Xu <[email protected]>
6 */
7
8 /*\
9 * [Description]
10 *
11 * capset() fails with errno set or EPERM if the new_Inheritable is
12 * not a subset of old_Inheritable and old_Permitted without CAP_SETPCAP.
13 */
14
15 #include <stdlib.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include "tst_test.h"
19 #include "lapi/syscalls.h"
20 #include <linux/capability.h>
21
22 #define CAP1 (1 << CAP_KILL)
23 #define CAP2 (CAP1 | 1 << CAP_NET_RAW)
24
25 static struct __user_cap_header_struct *header;
26 static struct __user_cap_data_struct *data;
27
verify_capset(void)28 static void verify_capset(void)
29 {
30 tst_res(TINFO, "Test bad value data(when pI is not old pP or old pI without CAP_SETPCAP)");
31 data[0].inheritable = CAP2;
32 TST_EXP_FAIL(tst_syscall(__NR_capset, header, data), EPERM, "capset()");
33 }
34
setup(void)35 static void setup(void)
36 {
37 header->version = 0x20080522;
38
39 data[0].effective = CAP1;
40 data[0].permitted = CAP1;
41 data[0].inheritable = CAP1;
42
43 TEST(tst_syscall(__NR_capset, header, data));
44 if (TST_RET == -1)
45 tst_brk(TBROK | TTERRNO, "capset data failed");
46 }
47
48 static struct tst_test test = {
49 .setup = setup,
50 .test_all = verify_capset,
51 .needs_root = 1,
52 .bufs = (struct tst_buffers []) {
53 {&header, .size = sizeof(*header)},
54 {&data, .size = 2 * sizeof(*data)},
55 {},
56 }
57 };
58