blob: 6fc955ef11c3292f36275b7327f7eb443aac4164 [file] [log] [blame]
robbiewd771da72002-12-27 18:41:54 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiewd771da72002-12-27 18:41:54 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiewd771da72002-12-27 18:41:54 +000019 * TEST IDENTIFIER : capget02
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiewd771da72002-12-27 18:41:54 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiewd771da72002-12-27 18:41:54 +000023 * TEST TITLE : Tests for error conditions.
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewd771da72002-12-27 18:41:54 +000025 * TEST CASE TOTAL : 5
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiewd771da72002-12-27 18:41:54 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiewd771da72002-12-27 18:41:54 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * Verify that
35 * 1) capget() fails with errno set to EFAULT if an invalid address
36 * is given for header
37 * 2) capget() fails with errno set to EFAULT if an invalid address
38 * is given for data
39 * 3) capget() fails with errno set to EINVAL if an invalid value
40 * is given for header->version
41 * 4) capget() fails with errno set to EINVAL if header->pid < 0
42 * 5) capget() fails with errno set to ESRCH if the process with
43 * pid, header->pid does not exit
subrata_modakbdbaec52009-02-26 12:14:51 +000044 *
subrata_modak4bb656a2009-02-26 12:02:09 +000045 *
robbiewd771da72002-12-27 18:41:54 +000046 * Setup:
47 * Setup signal handling.
48 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
robbiewd771da72002-12-27 18:41:54 +000050 * Test:
51 * Loop if the proper options are given.
52 * call capget with proper arguments
53 * if capget() fails with expected errno
54 * Test passed
55 * Otherwise
56 * Test failed
subrata_modak4bb656a2009-02-26 12:02:09 +000057 *
robbiewd771da72002-12-27 18:41:54 +000058 * Cleanup:
59 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000060 *
robbiewd771da72002-12-27 18:41:54 +000061 * USAGE: <for command-line>
62 * capget02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
63 * where, -c n : Run n copies concurrently.
64 * -e : Turn on errno logging.
65 * -h : Show help screen
66 * -f : Turn off functional testing
67 * -i n : Execute test n times.
68 * -I x : Execute test for x seconds.
69 * -p : Pause for SIGUSR1 before starting
70 * -P x : Pause for x seconds between iterations.
71 * -t : Turn on syscall timing.
72 *
73 ****************************************************************/
robbiewd771da72002-12-27 18:41:54 +000074
75#include <errno.h>
robbiewd771da72002-12-27 18:41:54 +000076#include "test.h"
77#include "usctest.h"
Garrett Cooper17b121b2010-12-17 11:05:05 -080078#include "linux_syscall_numbers.h"
robbiewe7757592003-10-01 17:23:49 +000079
80/**************************************************************************/
robbiewe7757592003-10-01 17:23:49 +000081/* */
82/* Some archs do not have the manpage documented sys/capability.h file, */
robbiew04a8ba52003-10-02 17:38:04 +000083/* and require the use of the line below */
84
85#include <linux/capability.h>
86
87/* If you are having issues with including this file and have the sys/ */
88/* version, then you may want to try switching to it. -Robbie W. */
robbiewe7757592003-10-01 17:23:49 +000089/**************************************************************************/
robbiewd771da72002-12-27 18:41:54 +000090
91#define INVALID_PID 999999
92
robbiewd771da72002-12-27 18:41:54 +000093static void setup();
94static void cleanup();
95static void test_setup(int);
96
97char *TCID = "capget02"; /* Test program identifier. */
subrata_modak56207ce2009-03-23 13:35:39 +000098static int exp_enos[] = { EFAULT, EINVAL, ESRCH, 0 };
robbiewd771da72002-12-27 18:41:54 +000099
100static struct __user_cap_header_struct header;
101static struct __user_cap_data_struct data;
102
103struct test_case_t {
104 cap_user_header_t headerp;
105 cap_user_data_t datap;
106 int exp_errno;
107 char *errdesc;
108} test_cases[] = {
vapier7ec19d92006-02-27 04:38:56 +0000109#ifndef UCLINUX
110 /* Skip since uClinux does not implement memory protection */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111 {
112 (cap_user_header_t) - 1, &data, EFAULT, "EFAULT"}, {
113 &header, (cap_user_data_t) - 1, EFAULT, "EFAULT"},
vapier7ec19d92006-02-27 04:38:56 +0000114#endif
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115 {
116 &header, &data, EINVAL, "EINVAL"}, {
117 &header, &data, EINVAL, "EINVAL"}, {
118 &header, &data, ESRCH, "ESRCH"}
robbiewd771da72002-12-27 18:41:54 +0000119};
120
121int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
122
subrata_modak56207ce2009-03-23 13:35:39 +0000123int main(int ac, char **av)
robbiewd771da72002-12-27 18:41:54 +0000124{
125
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200126 int lc, i;
127 char *msg;
robbiewd771da72002-12-27 18:41:54 +0000128
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800129 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800130 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewd771da72002-12-27 18:41:54 +0000131
robbiewd771da72002-12-27 18:41:54 +0000132 setup();
133
robbiewd771da72002-12-27 18:41:54 +0000134 for (lc = 0; TEST_LOOPING(lc); lc++) {
135
robbiewd771da72002-12-27 18:41:54 +0000136 Tst_count = 0;
137
138 for (i = 0; i < TST_TOTAL; ++i) {
139 test_setup(i);
Jan Stancek359980f2013-02-15 10:16:05 +0100140 TEST(ltp_syscall(__NR_capget, test_cases[i].headerp,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800141 test_cases[i].datap));
robbiewd771da72002-12-27 18:41:54 +0000142
Garrett Cooper17b121b2010-12-17 11:05:05 -0800143 if (TEST_RETURN == -1 &&
144 TEST_ERRNO == test_cases[i].exp_errno) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 tst_resm(TPASS | TTERRNO,
146 "capget failed as expected");
robbiewd771da72002-12-27 18:41:54 +0000147 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800148 tst_resm(TFAIL | TTERRNO,
149 "capget failed unexpectedly (%ld)",
150 TEST_RETURN);
robbiewd771da72002-12-27 18:41:54 +0000151 }
subrata_modak4bb656a2009-02-26 12:02:09 +0000152 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800153 }
robbiewd771da72002-12-27 18:41:54 +0000154
robbiewd771da72002-12-27 18:41:54 +0000155 cleanup();
156
Garrett Cooper53740502010-12-16 00:04:01 -0800157 tst_exit();
robbiewd771da72002-12-27 18:41:54 +0000158
Garrett Cooper2c282152010-12-16 00:55:50 -0800159}
robbiewd771da72002-12-27 18:41:54 +0000160
161/* setup() - performs all ONE TIME setup for this test */
subrata_modak56207ce2009-03-23 13:35:39 +0000162void setup()
robbiewd771da72002-12-27 18:41:54 +0000163{
Garrett Cooper2c282152010-12-16 00:55:50 -0800164
robbiewd771da72002-12-27 18:41:54 +0000165 tst_sig(NOFORK, DEF_HANDLER, cleanup);
166
robbiewd771da72002-12-27 18:41:54 +0000167 TEST_EXP_ENOS(exp_enos);
168
robbiewd771da72002-12-27 18:41:54 +0000169 TEST_PAUSE;
170
Garrett Cooper2c282152010-12-16 00:55:50 -0800171}
robbiewd771da72002-12-27 18:41:54 +0000172
173/*
174 *cleanup() - performs all ONE TIME cleanup for this test at
175 * completion or premature exit.
176 */
subrata_modak56207ce2009-03-23 13:35:39 +0000177void cleanup()
robbiewd771da72002-12-27 18:41:54 +0000178{
robbiewd771da72002-12-27 18:41:54 +0000179 TEST_CLEANUP;
180
Garrett Cooper2c282152010-12-16 00:55:50 -0800181}
robbiewd771da72002-12-27 18:41:54 +0000182
subrata_modak56207ce2009-03-23 13:35:39 +0000183void test_setup(int i)
robbiewd771da72002-12-27 18:41:54 +0000184{
vapier7ec19d92006-02-27 04:38:56 +0000185#ifdef UCLINUX
subrata_modak56207ce2009-03-23 13:35:39 +0000186 i = i + 2;
vapier7ec19d92006-02-27 04:38:56 +0000187#endif
robbiewd771da72002-12-27 18:41:54 +0000188 switch (i) {
189
subrata_modak56207ce2009-03-23 13:35:39 +0000190 case 0:
robbiewd771da72002-12-27 18:41:54 +0000191 break;
subrata_modak56207ce2009-03-23 13:35:39 +0000192 case 1:
robbiewd771da72002-12-27 18:41:54 +0000193 header.version = _LINUX_CAPABILITY_VERSION;
194 header.pid = getpid();
195 break;
subrata_modak56207ce2009-03-23 13:35:39 +0000196 case 2:
robbiewd771da72002-12-27 18:41:54 +0000197 header.version = 0;
198 header.pid = getpid();
199 break;
subrata_modak56207ce2009-03-23 13:35:39 +0000200 case 3:
robbiewd771da72002-12-27 18:41:54 +0000201 header.version = _LINUX_CAPABILITY_VERSION;
202 header.pid = -1;
203 break;
subrata_modak56207ce2009-03-23 13:35:39 +0000204 case 4:
robbiewd771da72002-12-27 18:41:54 +0000205 header.version = _LINUX_CAPABILITY_VERSION;
206 header.pid = INVALID_PID;
207 break;
208 }
Chris Dearmanec6edca2012-10-17 19:54:01 -0700209}