* [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library
@ 2019-12-11 7:25 Yang Xu
2019-12-11 7:25 ` [LTP] [PATCH 2/2] syscalls/capget02: " Yang Xu
2020-01-07 12:02 ` [LTP] [PATCH 1/2] syscalls/capget01: " Cyril Hrubis
0 siblings, 2 replies; 6+ messages in thread
From: Yang Xu @ 2019-12-11 7:25 UTC (permalink / raw)
To: ltp
Test capget() syscall on three versions and check the result buf.
I don't want to use ".need_root", so we only can test Effective
set by using ltp capability library code.
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/capget/capget01.c | 161 ++++++--------------
1 file changed, 49 insertions(+), 112 deletions(-)
diff --git a/testcases/kernel/syscalls/capget/capget01.c b/testcases/kernel/syscalls/capget/capget01.c
index 8a2a8921a..743e307c5 100644
--- a/testcases/kernel/syscalls/capget/capget01.c
+++ b/testcases/kernel/syscalls/capget/capget01.c
@@ -1,127 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
+ * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Description:
+ * This case tests capget() syscall whether works well on three versions.
+ * Also, it checks the results buffer.
*/
-/**********************************************************
- *
- * TEST IDENTIFIER : capget01
- *
- * EXECUTED BY : anyone
- *
- * TEST TITLE : Basic test for capget(2)
- *
- * TEST CASE TOTAL : 1
- *
- * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
- * DESCRIPTION
- * This is a Phase I test for the capget(2) system call.
- * It is intended to provide a limited exposure of the system call.
- *
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * call capget()
- * if return value == 0
- * Test passed
- * Otherwise
- * Test failed
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- *
- * USAGE: <for command-line>
- * capget01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -h : Show help screen
- * -f : Turn off functional testing
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -p : Pause for SIGUSR1 before starting
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- ****************************************************************/
-
-#include <errno.h>
-#include <unistd.h>
-#include "test.h"
+#include <sys/types.h>
+#include "tst_test.h"
#include "lapi/syscalls.h"
-
#include <linux/capability.h>
-static void setup();
-static void cleanup();
-
-char *TCID = "capget01";
-int TST_TOTAL = 1;
+static pid_t pid;
-static struct __user_cap_header_struct header; /* cap_user_header_t is a pointer
- to __user_cap_header_struct */
+static struct tcase {
+ int version;
+ char *message;
+} tcases[] = {
+ {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"},
+ {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"},
+ {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"},
+};
-static struct __user_cap_data_struct data; /* cap_user_data_t is a pointer to
- __user_cap_data_struct */
-
-int main(int ac, char **av)
+static void verify_capget(unsigned int n)
{
-
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- /* header.version must be _LINUX_CAPABILITY_VERSION */
- header.version = _LINUX_CAPABILITY_VERSION;
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- TEST(ltp_syscall(__NR_capget, &header, &data));
-
- if (TEST_RETURN == 0) {
- tst_resm(TPASS, "capget() returned %ld", TEST_RETURN);
- } else {
- tst_resm(TFAIL | TTERRNO,
- "Test Failed, capget() returned %ld",
- TEST_RETURN);
- }
- }
-
- cleanup();
-
- tst_exit();
+ struct tcase *tc = &tcases[n];
+ struct __user_cap_header_struct hdr = {
+ .version = tc->version,
+ .pid = pid,
+ };
+
+ struct __user_cap_data_struct data;
+
+ tst_res(TINFO, "%s", tc->message);
+
+ TEST(tst_syscall(__NR_capget, &hdr, &data));
+ if (TST_RET == 0)
+ tst_res(TPASS, "capget() returned %ld", TST_RET);
+ else
+ tst_res(TFAIL | TTERRNO, "Test Failed, capget() returned %ld",
+ TST_RET);
+
+ if (data.effective & 1 << CAP_NET_RAW)
+ tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
+ else
+ tst_res(TPASS, "capget() doesn't get CAP_NET_RAW as expected in PE");
}
-void setup(void)
+static void setup(void)
{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
+ pid = getpid();
}
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_capget,
+ .caps = (struct tst_cap []) {
+ TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
+ {}
+ },
+};
--
2.18.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] syscalls/capget02: Cleanup & convert to new library
2019-12-11 7:25 [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library Yang Xu
@ 2019-12-11 7:25 ` Yang Xu
2020-01-07 12:23 ` Cyril Hrubis
2020-01-07 12:02 ` [LTP] [PATCH 1/2] syscalls/capget01: " Cyril Hrubis
1 sibling, 1 reply; 6+ messages in thread
From: Yang Xu @ 2019-12-11 7:25 UTC (permalink / raw)
To: ltp
It also adds a check for whether kernel returns preferred linux
capability version when we use a bad version.
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/capget/capget02.c | 245 ++++++--------------
1 file changed, 73 insertions(+), 172 deletions(-)
diff --git a/testcases/kernel/syscalls/capget/capget02.c b/testcases/kernel/syscalls/capget/capget02.c
index e8d237779..42c76a011 100644
--- a/testcases/kernel/syscalls/capget/capget02.c
+++ b/testcases/kernel/syscalls/capget/capget02.c
@@ -1,199 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
+ *
+ * Tests basic error handling of the capget syscall.
+ * 1) capget() fails with errno set to EFAULT if an invalid address
+ * is given for header.
+ * 2) capget() fails with errno set to EFAULT if an invalid address
+ * is given for data
+ * 3) capget() fails with errno set to EINVAL if an invalid value
+ * is given for header->version
+ * 4) capget() fails with errno set to EINVAL if header->pid < 0
+ * 5) capget() fails with errno set to ESRCH if the process with
+ * pid, header->pid does not exist.
*/
-/**********************************************************
- *
- * TEST IDENTIFIER : capget02
- *
- * EXECUTED BY : anyone
- *
- * TEST TITLE : Tests for error conditions.
- *
- * TEST CASE TOTAL : 5
- *
- * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
- * DESCRIPTION
- * Verify that
- * 1) capget() fails with errno set to EFAULT if an invalid address
- * is given for header
- * 2) capget() fails with errno set to EFAULT if an invalid address
- * is given for data
- * 3) capget() fails with errno set to EINVAL if an invalid value
- * is given for header->version
- * 4) capget() fails with errno set to EINVAL if header->pid < 0
- * 5) capget() fails with errno set to ESRCH if the process with
- * pid, header->pid does not exit
- *
- *
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * call capget with proper arguments
- * if capget() fails with expected errno
- * Test passed
- * Otherwise
- * Test failed
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- *
- * USAGE: <for command-line>
- * capget02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -h : Show help screen
- * -f : Turn off functional testing
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -p : Pause for SIGUSR1 before starting
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- ****************************************************************/
-#include <errno.h>
-#include "test.h"
+#include <sys/types.h>
+#include "tst_test.h"
#include "lapi/syscalls.h"
-
-/**************************************************************************/
-/* */
-/* Some archs do not have the manpage documented sys/capability.h file, */
-/* and require the use of the line below */
-
#include <linux/capability.h>
-/* If you are having issues with including this file and have the sys/ */
-/* version, then you may want to try switching to it. -Robbie W. */
-/**************************************************************************/
-
-static void setup();
-static void cleanup();
-static void test_setup(int);
-
-char *TCID = "capget02";
-
-static struct __user_cap_header_struct header;
+static struct __user_cap_header_struct header, bad_version_header, bad_pid_header, unused_pid_header;
static struct __user_cap_data_struct data;
-struct test_case_t {
+static struct tcase {
cap_user_header_t headerp;
cap_user_data_t datap;
- int exp_errno;
- char *errdesc;
-} test_cases[] = {
-#ifndef UCLINUX
- /* Skip since uClinux does not implement memory protection */
- {
- (cap_user_header_t) - 1, &data, EFAULT, "EFAULT"}, {
- &header, (cap_user_data_t) - 1, EFAULT, "EFAULT"},
-#endif
- {
- &header, &data, EINVAL, "EINVAL"}, {
- &header, &data, EINVAL, "EINVAL"}, {
- &header, &data, ESRCH, "ESRCH"}
+ int exp_err;
+ int reset_flag;
+ char *message;
+} tcases[] = {
+ {NULL, &data, EFAULT, 0, "Test bad address header"},
+ {&header, NULL, EFAULT, 0, "Test bad address data"},
+ {&bad_version_header, &data, EINVAL, 1, "Test bad version"},
+ {&bad_pid_header, &data, EINVAL, 0, "Test bad pid"},
+ {&unused_pid_header, &data, ESRCH, 0, "Test unused pid"},
};
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static void verify_capget(unsigned int n)
{
+ struct tcase *tc = &tcases[n];
- int lc, i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; ++i) {
- test_setup(i);
- TEST(ltp_syscall(__NR_capget, test_cases[i].headerp,
- test_cases[i].datap));
-
- if (TEST_RETURN == -1 &&
- TEST_ERRNO == test_cases[i].exp_errno) {
- tst_resm(TPASS | TTERRNO,
- "capget failed as expected");
- } else {
- tst_resm(TFAIL | TTERRNO,
- "capget failed unexpectedly (%ld)",
- TEST_RETURN);
- }
- }
+ tst_res(TINFO, "%s", tc->message);
+ TEST(tst_syscall(__NR_capget, tc->headerp, tc->datap));
+ if (TST_RET == 0) {
+ tst_res(TFAIL, "capget() succeed unexpectedly");
+ return;
+ }
+ if (TST_ERR == tc->exp_err)
+ tst_res(TPASS | TTERRNO, "capget() failed as expected");
+ else
+ tst_res(TFAIL | TTERRNO, "capget() expected %s got ",
+ tst_strerrno(tc->exp_err));
+
+ /*
+ * When an unsupported version value is specified, it will
+ * return the kernel preferred value of _LINUX_CAPABILITY_VERSION_?.
+ * Since linux 2.6.26, version 3 is default. We use it.
+ */
+ if (tc->reset_flag) {
+ if (tc->headerp->version == 0x20080522)
+ tc->headerp->version = 0;
+ else
+ tst_res(TFAIL, "kernel doesn't return preferred linux"
+ " capability version when using bad version");
}
-
- cleanup();
-
- tst_exit();
-
}
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
+static void setup(void)
{
+ unsigned int i, pid;
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ pid = getpid();
- TEST_PAUSE;
+ header.version = 0x19980330;
+ header.pid = pid;
-}
+ bad_version_header.version = 0;
+ bad_version_header.pid = pid;
-/*
- *cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup(void)
-{
-}
+ bad_pid_header.version = 0x19980330;
+ bad_pid_header.pid = -1;
-void test_setup(int i)
-{
-#ifdef UCLINUX
- i = i + 2;
-#endif
- switch (i) {
+ unused_pid_header.version = 0x19980330;
+ unused_pid_header.pid = tst_get_unused_pid();
- case 0:
- break;
- case 1:
- header.version = _LINUX_CAPABILITY_VERSION;
- header.pid = getpid();
- break;
- case 2:
- header.version = 0;
- header.pid = getpid();
- break;
- case 3:
- header.version = _LINUX_CAPABILITY_VERSION;
- header.pid = -1;
- break;
- case 4:
- header.version = _LINUX_CAPABILITY_VERSION;
- header.pid = tst_get_unused_pid(cleanup);
- break;
+ for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+ if (!tcases[i].headerp)
+ tcases[i].headerp = tst_get_bad_addr(NULL);
+ if (!tcases[i].datap)
+ tcases[i].datap = tst_get_bad_addr(NULL);
}
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_capget,
+};
--
2.18.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library
2019-12-11 7:25 [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library Yang Xu
2019-12-11 7:25 ` [LTP] [PATCH 2/2] syscalls/capget02: " Yang Xu
@ 2020-01-07 12:02 ` Cyril Hrubis
2020-01-07 12:26 ` Cyril Hrubis
1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2020-01-07 12:02 UTC (permalink / raw)
To: ltp
Hi!
Pushed with following changes:
diff --git a/testcases/kernel/syscalls/capget/capget01.c b/testcases/kernel/syscalls/capget/capget01.c
index 743e307c5..bc8bd7ce7 100644
--- a/testcases/kernel/syscalls/capget/capget01.c
+++ b/testcases/kernel/syscalls/capget/capget01.c
@@ -31,18 +31,18 @@ static void verify_capget(unsigned int n)
.pid = pid,
};
- struct __user_cap_data_struct data;
+ struct __user_cap_data_struct data[2];
tst_res(TINFO, "%s", tc->message);
- TEST(tst_syscall(__NR_capget, &hdr, &data));
+ TEST(tst_syscall(__NR_capget, &hdr, data));
if (TST_RET == 0)
tst_res(TPASS, "capget() returned %ld", TST_RET);
else
tst_res(TFAIL | TTERRNO, "Test Failed, capget() returned %ld",
TST_RET);
- if (data.effective & 1 << CAP_NET_RAW)
+ if (data[0].effective & 1 << CAP_NET_RAW)
tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
else
tst_res(TPASS, "capget() doesn't get CAP_NET_RAW as expected in PE");
The version 2 and 3 are 64 bit capabilities, hence we have to pass array of cap_struct_data instead.
Otherwise this is a nice improvement on the testcase, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] syscalls/capget02: Cleanup & convert to new library
2019-12-11 7:25 ` [LTP] [PATCH 2/2] syscalls/capget02: " Yang Xu
@ 2020-01-07 12:23 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2020-01-07 12:23 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library
2020-01-07 12:02 ` [LTP] [PATCH 1/2] syscalls/capget01: " Cyril Hrubis
@ 2020-01-07 12:26 ` Cyril Hrubis
2020-01-08 2:34 ` Yang Xu
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2020-01-07 12:26 UTC (permalink / raw)
To: ltp
Hi!
Also btw, we do not cover the case with pid == 0 now, which should
return the capabilities for the calling thread. I guess that we can run
the capget01 verify function twice, once for pid == getpid() and once
for pid == 0.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library
2020-01-07 12:26 ` Cyril Hrubis
@ 2020-01-08 2:34 ` Yang Xu
0 siblings, 0 replies; 6+ messages in thread
From: Yang Xu @ 2020-01-08 2:34 UTC (permalink / raw)
To: ltp
Hi Cyril
> Hi!
> Also btw, we do not cover the case with pid == 0 now, which should
> return the capabilities for the calling thread. I guess that we can run
> the capget01 verify function twice, once for pid == getpid() and once
> for pid == 0.
>Sorry, I didn't notice this before.
I double read capget/capset man-pages and refer to kernel code.
pid = 0 that it indeed returns the the capabilities for the calling
thread. I will add it.
Also, for capget syscall, it can get the capabilities for any existed
process. I think we should also test this by using child process in a
new case like capset04.c.
Best Regards
Yang Xu
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-01-08 2:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 7:25 [LTP] [PATCH 1/2] syscalls/capget01: Cleanup & convert to new library Yang Xu
2019-12-11 7:25 ` [LTP] [PATCH 2/2] syscalls/capget02: " Yang Xu
2020-01-07 12:23 ` Cyril Hrubis
2020-01-07 12:02 ` [LTP] [PATCH 1/2] syscalls/capget01: " Cyril Hrubis
2020-01-07 12:26 ` Cyril Hrubis
2020-01-08 2:34 ` Yang Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.