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