• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4  *  Author: Saji Kumar.V.R <saji.kumar@wipro.com>
5  *
6  * Description:
7  * This case tests capget() syscall whether works well on three versions.
8  * Also, it checks the results buffer.
9  */
10 #include <sys/types.h>
11 #include "tst_test.h"
12 #include "lapi/syscalls.h"
13 #include <linux/capability.h>
14 
15 static pid_t pid;
16 static struct __user_cap_header_struct *hdr;
17 static struct __user_cap_data_struct *data;
18 
19 static struct tcase {
20 	int version;
21 	char *message;
22 } tcases[] = {
23 	{0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"},
24 	{0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"},
25 	{0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"},
26 };
27 
verify_capget(unsigned int n)28 static void verify_capget(unsigned int n)
29 {
30 	struct tcase *tc = &tcases[n];
31 
32 	tst_res(TINFO, "%s", tc->message);
33 
34 	hdr->version = tc->version;
35 	hdr->pid = pid;
36 	TEST(tst_syscall(__NR_capget, hdr, data));
37 	if (TST_RET == 0)
38 		tst_res(TPASS, "capget() returned %ld", TST_RET);
39 	else
40 		tst_res(TFAIL | TTERRNO, "Test Failed, capget() returned %ld",
41 				TST_RET);
42 
43 	if (data[0].effective & 1 << CAP_NET_RAW)
44 		tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
45 	else
46 		tst_res(TPASS, "capget() doesn't get CAP_NET_RAW as expected in PE");
47 }
48 
setup(void)49 static void setup(void)
50 {
51 	pid = getpid();
52 }
53 
54 static struct tst_test test = {
55 	.setup = setup,
56 	.tcnt = ARRAY_SIZE(tcases),
57 	.test = verify_capget,
58 	.caps = (struct tst_cap []) {
59 		TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
60 		{}
61 	},
62 	.bufs = (struct tst_buffers []) {
63 		{&hdr, .size = sizeof(*hdr)},
64 		{&data, .size = 2 * sizeof(*data)},
65 		{},
66 	}
67 };
68