All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/3] add new syscall test for setns(2)
@ 2013-02-05 15:57 Jan Stancek
  2013-02-05 15:57 ` [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jan Stancek @ 2013-02-05 15:57 UTC (permalink / raw)
  To: ltp-list

This patchset adds 2 new syscall tests for setns(2).
Sample output:

setns01     1  TPASS  :  invalid fd exp_errno=9
setns01     2  TPASS  :  regular file fd exp_errno=22
setns01     3  TPASS  :  invalid ns_type exp_errno=22
setns01     4  TPASS  :  mismatch ns_type/fd exp_errno=22
setns01     5  TPASS  :  without CAP_SYS_ADMIN exp_errno=1

setns02     0  TINFO  :  test_newuts
setns02     0  TINFO  :  creating child with clone_flag=0x4000000, ns_flag=0x4000000
setns02     0  TINFO  :  (child) hostnane (inherited from parent): dhcp-27-145.brq.redhat.com
setns02     0  TINFO  :  (child) hostname changed to: setns_dummy_uts
setns02     1  TPASS  :  (child) hostname is different in parent/child
setns02     0  TINFO  :  (child) attemping to switch ns back to parent ns
setns02     0  TINFO  :  (child) hostname: dhcp-27-145.brq.redhat.com
setns02     2  TPASS  :  (child) hostname now as expected
setns02     1  TPASS  :  child finished succesfully
setns02     0  TINFO  :  creating child with clone_flag=0x4000000, ns_flag=0x0
setns02     0  TINFO  :  (child) hostnane (inherited from parent): dhcp-27-145.brq.redhat.com
setns02     0  TINFO  :  (child) hostname changed to: setns_dummy_uts
setns02     2  TPASS  :  (child) hostname is different in parent/child
setns02     0  TINFO  :  (child) attemping to switch ns back to parent ns
setns02     0  TINFO  :  (child) hostname: dhcp-27-145.brq.redhat.com
setns02     3  TPASS  :  (child) hostname now as expected
setns02     2  TPASS  :  child finished succesfully
setns02     0  TINFO  :  test_newipc
setns02     0  TINFO  :  creating child with clone_flag=0x8000000, ns_flag=0x8000000
setns02     3  TPASS  :  (child) shmat failed as expected: errno=EINVAL(22): Invalid argument
setns02     0  TINFO  :  (child) attemping to switch ns back to parent ns
setns02     4  TPASS  :  (child) shmat suceeded
setns02     3  TPASS  :  child finished succesfully
setns02     0  TINFO  :  creating child with clone_flag=0x8000000, ns_flag=0x0
setns02     4  TPASS  :  (child) shmat failed as expected: errno=EINVAL(22): Invalid argument
setns02     0  TINFO  :  (child) attemping to switch ns back to parent ns
setns02     5  TPASS  :  (child) shmat suceeded
setns02     4  TPASS  :  child finished succesfully

Jan Stancek (3):
  setns: setup directory at kernel/syscalls/setns
  setns: add new syscall test setns01
  setns: add new syscall test setns02

 runtest/syscalls                          |    3 +
 testcases/kernel/syscalls/.gitignore      |    2 +
 testcases/kernel/syscalls/setns/Makefile  |   22 +++
 testcases/kernel/syscalls/setns/setns.h   |   41 +++++
 testcases/kernel/syscalls/setns/setns01.c |  245 +++++++++++++++++++++++++++++
 testcases/kernel/syscalls/setns/setns02.c |  231 +++++++++++++++++++++++++++
 6 files changed, 544 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setns/Makefile
 create mode 100644 testcases/kernel/syscalls/setns/setns.h
 create mode 100644 testcases/kernel/syscalls/setns/setns01.c
 create mode 100644 testcases/kernel/syscalls/setns/setns02.c


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns
  2013-02-05 15:57 [LTP] [PATCH 0/3] add new syscall test for setns(2) Jan Stancek
@ 2013-02-05 15:57 ` Jan Stancek
  2013-02-06  8:44   ` Wanlong Gao
  2013-02-05 15:57 ` [LTP] [PATCH 2/3] setns: add new syscall test setns01 Jan Stancek
  2013-02-05 15:57 ` [LTP] [PATCH 3/3] setns: add new syscall test setns02 Jan Stancek
  2 siblings, 1 reply; 10+ messages in thread
From: Jan Stancek @ 2013-02-05 15:57 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/setns/Makefile |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setns/Makefile

diff --git a/testcases/kernel/syscalls/setns/Makefile b/testcases/kernel/syscalls/setns/Makefile
new file mode 100644
index 0000000..b1179c4
--- /dev/null
+++ b/testcases/kernel/syscalls/setns/Makefile
@@ -0,0 +1,22 @@
+#
+#  Copyright (C) 2013 Linux Test Project, Inc.
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
-- 
1.7.1


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 2/3] setns: add new syscall test setns01
  2013-02-05 15:57 [LTP] [PATCH 0/3] add new syscall test for setns(2) Jan Stancek
  2013-02-05 15:57 ` [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
@ 2013-02-05 15:57 ` Jan Stancek
  2013-02-06  7:05   ` Wanlong Gao
  2013-02-05 15:57 ` [LTP] [PATCH 3/3] setns: add new syscall test setns02 Jan Stancek
  2 siblings, 1 reply; 10+ messages in thread
From: Jan Stancek @ 2013-02-05 15:57 UTC (permalink / raw)
  To: ltp-list

errno tests for setns(2) - reassociate thread with a namespace

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 runtest/syscalls                          |    2 +
 testcases/kernel/syscalls/.gitignore      |    1 +
 testcases/kernel/syscalls/setns/setns.h   |   41 +++++
 testcases/kernel/syscalls/setns/setns01.c |  245 +++++++++++++++++++++++++++++
 4 files changed, 289 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setns/setns.h
 create mode 100644 testcases/kernel/syscalls/setns/setns01.c

diff --git a/runtest/syscalls b/runtest/syscalls
index db5a075..a881479 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -962,6 +962,8 @@ setitimer01 setitimer01
 setitimer02 setitimer02
 setitimer03 setitimer03
 
+setns01 setns01
+
 setpgid01 setpgid01
 setpgid02 setpgid02
 setpgid03 setpgid03
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 003c5d0..d3bf8b7 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -763,6 +763,7 @@
 /setitimer/setitimer01
 /setitimer/setitimer02
 /setitimer/setitimer03
+/setns/setns01
 /setpgid/setpgid01
 /setpgid/setpgid02
 /setpgid/setpgid03
diff --git a/testcases/kernel/syscalls/setns/setns.h b/testcases/kernel/syscalls/setns/setns.h
new file mode 100644
index 0000000..1613e6c
--- /dev/null
+++ b/testcases/kernel/syscalls/setns/setns.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2013 Linux Test Project, Inc.
+ *
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+
+static int get_ns_fd(int pid, const char *ns)
+{
+	char tmp[PATH_MAX];
+	struct stat st;
+	int fd = -1;
+
+	sprintf(tmp, "/proc/%d/%s", pid, ns);
+	if (stat(tmp, &st) == 0) {
+		fd = open(tmp, O_RDONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, NULL, "failed to open %s", tmp);
+	} else {
+		if (errno != ENOENT)
+			tst_brkm(TBROK|TERRNO, NULL, "failed to stat %s", tmp);
+	}
+	return fd;
+}
diff --git a/testcases/kernel/syscalls/setns/setns01.c b/testcases/kernel/syscalls/setns/setns01.c
new file mode 100644
index 0000000..6469266
--- /dev/null
+++ b/testcases/kernel/syscalls/setns/setns01.c
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2013 Linux Test Project, Inc.
+ *
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+/*
+ * errno tests for setns(2) - reassociate thread with a namespace
+ */
+#define _GNU_SOURCE
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sched.h>
+#include <pwd.h>
+#include <string.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "linux_syscall_numbers.h"
+#include "safe_macros.h"
+
+#define NS_TOTAL 3
+char *TCID = "setns01";
+
+#if defined(__NR_setns) && defined(CLONE_NEWIPC) && defined(CLONE_NEWUTS) \
+	&& defined(CLONE_NEWNET)
+#include "setns.h"
+
+struct testcase_t {
+	const char *msg;
+	int fd;
+	int ns_type;
+	int exp_ret;
+	int exp_errno;
+	int skip;
+	void (*setup) (struct testcase_t *);
+	void (*cleanup) (struct testcase_t *);
+};
+
+static void setup(void);
+static void cleanup(void);
+static void setup1(struct testcase_t *);
+static void setup2(struct testcase_t *);
+static void setup3(struct testcase_t *);
+static void setup4(struct testcase_t *);
+static void cleanup1(struct testcase_t *);
+static void cleanup4(struct testcase_t *);
+
+struct testcase_t tdat[] = {
+	{
+		.msg = "invalid fd",
+		.fd = -1,
+		.ns_type = CLONE_NEWIPC,
+		.exp_ret = -1,
+		.exp_errno = EBADF,
+	},
+	{
+		.msg = "regular file fd",
+		.ns_type = CLONE_NEWIPC,
+		.exp_ret = -1,
+		.exp_errno = EINVAL,
+		.setup = setup1,
+		.cleanup = cleanup1
+	},
+	{
+		.msg = "invalid ns_type",
+		.ns_type = -1,
+		.exp_ret = -1,
+		.exp_errno = EINVAL,
+		.setup = setup2,
+	},
+	{
+		.msg = "mismatch ns_type/fd",
+		.exp_ret = -1,
+		.exp_errno = EINVAL,
+		.setup = setup3,
+	},
+	{
+		.msg = "without CAP_SYS_ADMIN",
+		.exp_ret = -1,
+		.exp_errno = EPERM,
+		.setup = setup4,
+		.cleanup = cleanup4,
+	}
+};
+
+static const char *ns_names[NS_TOTAL] = {"ns/ipc", "ns/net", "ns/uts"};
+static int ns_types[NS_TOTAL] = { CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWUTS };
+static int ns_fds[NS_TOTAL];
+static int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
+
+static void setup1(struct testcase_t *t)
+{
+	t->fd = open("dummy", O_CREAT);
+	if (t->fd == -1)
+		tst_brkm(TFAIL|TERRNO, cleanup, "setup1:open failed");
+	unlink("dummy");
+}
+
+static void cleanup1(struct testcase_t *t)
+{
+	close(t->fd);
+}
+
+static void setup2(struct testcase_t *t)
+{
+	int i;
+	for (i = 0; i < NS_TOTAL; i++)
+		if (ns_fds[i] != -1) {
+			t->fd = ns_fds[i];
+			return;
+		}
+	t->skip = 1;
+}
+
+static void setup3(struct testcase_t *t)
+{
+	int i;
+	for (i = 0; i < NS_TOTAL; i++)
+		if (ns_fds[i] != -1) {
+			t->fd = ns_fds[i];
+			t->ns_type = ns_types[(i+1) % NS_TOTAL];
+			return;
+		}
+	t->skip = 1;
+}
+
+static void setup4(struct testcase_t *t)
+{
+	if (seteuid(ltpuser->pw_uid) == -1)
+		tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
+}
+
+static void cleanup4(struct testcase_t *t)
+{
+	if (seteuid(0) == -1)
+		tst_brkm(TBROK | TERRNO, NULL, "seteuid restore failed");
+}
+
+static void test_setns(struct testcase_t *t)
+{
+	int ret;
+
+	if (t->setup)
+		t->setup(t);
+
+	if (t->skip) {
+		tst_resm(TINFO, "skip %s", tdat->msg);
+		return;
+	}
+
+	ret = syscall(__NR_setns, t->fd, t->ns_type);
+	if (ret == t->exp_ret) {
+		if (ret == -1 && errno == t->exp_errno)
+			tst_resm(TPASS, "%s exp_errno=%d", t->msg,
+				t->exp_errno);
+		else
+			tst_resm(TFAIL|TERRNO, "%s exp_errno=%d", t->msg,
+				t->exp_errno);
+	} else {
+		tst_resm(TFAIL, "%s ret=%d expected=%d", t->msg,
+			ret, t->exp_ret);
+	}
+
+	if (t->cleanup)
+		t->cleanup(t);
+}
+
+int main(int argc, char *argv[])
+{
+	int lc, testno;
+	char *msg;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		for (testno = 0; testno < TST_TOTAL; testno++)
+			test_setns(&tdat[testno]);
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int i;
+
+	tst_require_root(NULL);
+
+	/* runtime check if syscall is supported */
+	syscall(__NR_setns, -1, 0);
+
+	ltpuser = getpwnam(nobody_uid);
+	if (ltpuser == NULL)
+		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
+
+	for (i = 0; i < NS_TOTAL; i++)
+		ns_fds[i] = get_ns_fd(getpid(), ns_names[i]);
+
+	tst_tmpdir();
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	for (i = 0; i < NS_TOTAL; i++)
+		if (ns_fds[i] != -1)
+			close(ns_fds[i]);
+	tst_rmdir();
+	TEST_CLEANUP;
+}
+#else
+int main(int argc, char *argv[])
+{
+	tst_brkm(TCONF, NULL, "__NR_setns, CLONE_NEWIPC, CLONE_NEWNET or "
+		"CLONE_NEWUTS is not defined on your system.");
+
+}
+#endif
-- 
1.7.1


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 3/3] setns: add new syscall test setns02
  2013-02-05 15:57 [LTP] [PATCH 0/3] add new syscall test for setns(2) Jan Stancek
  2013-02-05 15:57 ` [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
  2013-02-05 15:57 ` [LTP] [PATCH 2/3] setns: add new syscall test setns01 Jan Stancek
@ 2013-02-05 15:57 ` Jan Stancek
  2013-02-06  8:44   ` Wanlong Gao
  2 siblings, 1 reply; 10+ messages in thread
From: Jan Stancek @ 2013-02-05 15:57 UTC (permalink / raw)
  To: ltp-list

functional test for setns(2) - reassociate thread with a namespace

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 runtest/syscalls                          |    1 +
 testcases/kernel/syscalls/.gitignore      |    1 +
 testcases/kernel/syscalls/setns/setns02.c |  231 +++++++++++++++++++++++++++++
 3 files changed, 233 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setns/setns02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index a881479..c70bcbd 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -963,6 +963,7 @@ setitimer02 setitimer02
 setitimer03 setitimer03
 
 setns01 setns01
+setns02 setns02
 
 setpgid01 setpgid01
 setpgid02 setpgid02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d3bf8b7..90b521e 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -764,6 +764,7 @@
 /setitimer/setitimer02
 /setitimer/setitimer03
 /setns/setns01
+/setns/setns02
 /setpgid/setpgid01
 /setpgid/setpgid02
 /setpgid/setpgid03
diff --git a/testcases/kernel/syscalls/setns/setns02.c b/testcases/kernel/syscalls/setns/setns02.c
new file mode 100644
index 0000000..fa8ea74
--- /dev/null
+++ b/testcases/kernel/syscalls/setns/setns02.c
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2013 Linux Test Project, Inc.
+ *
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+/*
+ * functional test for setns(2) - reassociate thread with a namespace
+ * 1. create child with CLONE_NEWUTS, set different hostname in child,
+ *    set namespace back to parent ns and check that hostname has changed
+ * 2. create child with CLONE_NEWIPC, set up shared memory in parent
+ *    and verify that child can't shmat it, then set namespace
+ *    back to parent one and verify that child is able to do shmat
+ */
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/utsname.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "linux_syscall_numbers.h"
+#include "safe_macros.h"
+
+#define CHILD_STACK_SIZE (1024*1024)
+#define CP "(child) "
+char *TCID = "setns02";
+
+#if defined(__NR_setns) && defined(CLONE_NEWIPC) && defined(CLONE_NEWUTS)
+#include "setns.h"
+
+static char *dummy_hostname = "setns_dummy_uts";
+static int ns_ipc_fd;
+static int ns_uts_fd;
+static key_t ipc_key;
+static int shmid;
+
+static void setup(void);
+static void cleanup(void);
+
+static int do_child_newuts(void *arg)
+{
+	struct utsname uts, uts_parent;
+	int ns_flag = *(int *)arg;
+
+	if (uname(&uts_parent) == -1)
+		tst_resm(TFAIL|TERRNO, CP"uname");
+	tst_resm(TINFO, CP"hostnane (inherited from parent): %s",
+		uts_parent.nodename);
+
+	if (sethostname(dummy_hostname, strlen(dummy_hostname)) == -1)
+		tst_resm(TFAIL|TERRNO, CP"sethostname");
+	if (uname(&uts) == -1)
+		tst_resm(TFAIL|TERRNO, CP"uname");
+
+	tst_resm(TINFO, CP"hostname changed to: %s", uts.nodename);
+	if (strcmp(uts_parent.nodename, uts.nodename) == 0) {
+		tst_resm(TFAIL, CP"expected hostname to be different");
+		return 1;
+	} else {
+		tst_resm(TPASS, CP"hostname is different in parent/child");
+	}
+
+	tst_resm(TINFO, CP"attemping to switch ns back to parent ns");
+	if (syscall(__NR_setns, ns_uts_fd, ns_flag) == -1) {
+		tst_resm(TFAIL|TERRNO, CP"setns");
+		return 2;
+	}
+	if (uname(&uts) == -1)
+		tst_resm(TFAIL|TERRNO, CP"uname");
+
+	tst_resm(TINFO, CP"hostname: %s", uts.nodename);
+	if (strcmp(uts_parent.nodename, uts.nodename) != 0) {
+		tst_resm(TFAIL, CP"expected hostname to match parent");
+		return 3;
+	} else {
+		tst_resm(TPASS, CP"hostname now as expected");
+	}
+	return 0;
+}
+
+static int do_child_newipc(void *arg)
+{
+	void *p;
+	int ns_flag = *(int *)arg;
+
+	p = shmat(shmid, NULL, 0);
+	if (p == (void *) -1) {
+		tst_resm(TPASS|TERRNO, CP"shmat failed as expected");
+	} else {
+		tst_resm(TFAIL, CP"shmat unexpectedly suceeded");
+		shmdt(p);
+		return 1;
+	}
+
+	tst_resm(TINFO, CP"attemping to switch ns back to parent ns");
+	if (syscall(__NR_setns, ns_ipc_fd, ns_flag) == -1) {
+		tst_resm(TFAIL|TERRNO, CP"setns");
+		return 2;
+	}
+
+	p = shmat(shmid, NULL, 0);
+	if (p == (void *) -1) {
+		tst_resm(TFAIL|TERRNO, CP"shmat failed after setns");
+		return 3;
+	} else {
+		tst_resm(TPASS, CP"shmat suceeded");
+		shmdt(p);
+	}
+
+	return 0;
+}
+
+static void test_flag(int clone_flag, int ns_flag, int (*fn) (void *arg))
+{
+	void *child_stack;
+	int ret, status;
+
+	child_stack = malloc(CHILD_STACK_SIZE);
+	if (child_stack == NULL)
+		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
+
+	tst_resm(TINFO, "creating child with clone_flag=0x%x, ns_flag=0x%x",
+		clone_flag, ns_flag);
+	ret = ltp_clone(SIGCHLD|clone_flag, fn, &ns_flag,
+		CHILD_STACK_SIZE, child_stack);
+	if (ret == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "ltp_clone");
+
+	if (waitpid(ret, &status, 0) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_resm(TFAIL, "child returns %d", status);
+	else
+		tst_resm(TPASS, "child finished succesfully");
+	free(child_stack);
+}
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		if (ns_uts_fd != -1) {
+			tst_resm(TINFO, "test_newuts");
+			test_flag(CLONE_NEWUTS, CLONE_NEWUTS, do_child_newuts);
+			test_flag(CLONE_NEWUTS, 0, do_child_newuts);
+		}
+		if (ns_ipc_fd != -1) {
+			tst_resm(TINFO, "test_newipc");
+			test_flag(CLONE_NEWIPC, CLONE_NEWIPC, do_child_newipc);
+			test_flag(CLONE_NEWIPC, 0, do_child_newipc);
+		}
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	char tmp[PATH_MAX];
+
+	tst_require_root(NULL);
+
+	/* runtime check if syscall is supported */
+	syscall(__NR_setns, -1, 0);
+
+	/* check if kernel has CONFIG_*_NS set and exports /proc entries */
+	ns_ipc_fd = get_ns_fd(getpid(), "ns/ipc");
+	ns_uts_fd = get_ns_fd(getpid(), "ns/uts");
+	if (ns_ipc_fd == -1 && ns_uts_fd == -1)
+		tst_brkm(TCONF, NULL, "your kernel has CONFIG_IPC_NS, "
+			"CONFIG_UTS_NS or CONFIG_PROC disabled");
+
+	if (getcwd(tmp, PATH_MAX) == NULL)
+		tst_brkm(TBROK|TERRNO, NULL, "getcwd");
+	ipc_key = ftok(tmp, 65);
+	shmid = shmget(ipc_key, getpagesize(), IPC_CREAT | 0666);
+	if (shmid == -1)
+		tst_brkm(TBROK|TERRNO, NULL, "shmget");
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	if (ns_ipc_fd != -1)
+		close(ns_ipc_fd);
+	if (ns_uts_fd != -1)
+		close(ns_uts_fd);
+
+	shmctl(shmid, IPC_RMID, NULL);
+	TEST_CLEANUP;
+}
+#else
+int main(int argc, char *argv[])
+{
+	tst_brkm(TCONF, NULL, "__NR_setns, CLONE_NEWIPC or CLONE_NEWUTS "
+		" is not defined on your system.");
+}
+#endif
-- 
1.7.1


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
  2013-02-05 15:57 ` [LTP] [PATCH 2/3] setns: add new syscall test setns01 Jan Stancek
@ 2013-02-06  7:05   ` Wanlong Gao
  2013-02-06  8:48     ` Wanlong Gao
  0 siblings, 1 reply; 10+ messages in thread
From: Wanlong Gao @ 2013-02-06  7:05 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 02/05/2013 11:57 PM, Jan Stancek wrote:
> errno tests for setns(2) - reassociate thread with a namespace
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  runtest/syscalls                          |    2 +
>  testcases/kernel/syscalls/.gitignore      |    1 +
>  testcases/kernel/syscalls/setns/setns.h   |   41 +++++
>  testcases/kernel/syscalls/setns/setns01.c |  245 +++++++++++++++++++++++++++++
>  4 files changed, 289 insertions(+), 0 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/setns/setns.h
>  create mode 100644 testcases/kernel/syscalls/setns/setns01.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index db5a075..a881479 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -962,6 +962,8 @@ setitimer01 setitimer01
>  setitimer02 setitimer02
>  setitimer03 setitimer03
>  
> +setns01 setns01
> +
>  setpgid01 setpgid01
>  setpgid02 setpgid02
>  setpgid03 setpgid03
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index 003c5d0..d3bf8b7 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -763,6 +763,7 @@
>  /setitimer/setitimer01
>  /setitimer/setitimer02
>  /setitimer/setitimer03
> +/setns/setns01
>  /setpgid/setpgid01
>  /setpgid/setpgid02
>  /setpgid/setpgid03
> diff --git a/testcases/kernel/syscalls/setns/setns.h b/testcases/kernel/syscalls/setns/setns.h
> new file mode 100644
> index 0000000..1613e6c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setns/setns.h
> @@ -0,0 +1,41 @@
> +/*
> + * Copyright (C) 2013 Linux Test Project, Inc.
> + *
> + * 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.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * 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.
> + */
> +
> +static int get_ns_fd(int pid, const char *ns)
> +{
> +	char tmp[PATH_MAX];
> +	struct stat st;
> +	int fd = -1;
> +
> +	sprintf(tmp, "/proc/%d/%s", pid, ns);
> +	if (stat(tmp, &st) == 0) {
> +		fd = open(tmp, O_RDONLY);
> +		if (fd == -1)
> +			tst_brkm(TBROK|TERRNO, NULL, "failed to open %s", tmp);
> +	} else {
> +		if (errno != ENOENT)
> +			tst_brkm(TBROK|TERRNO, NULL, "failed to stat %s", tmp);
> +	}
> +	return fd;
> +}
> diff --git a/testcases/kernel/syscalls/setns/setns01.c b/testcases/kernel/syscalls/setns/setns01.c
> new file mode 100644
> index 0000000..6469266
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setns/setns01.c
> @@ -0,0 +1,245 @@
> +/*
> + * Copyright (C) 2013 Linux Test Project, Inc.
> + *
> + * 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.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * 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.
> + */
> +/*
> + * errno tests for setns(2) - reassociate thread with a namespace
> + */
> +#define _GNU_SOURCE
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +#include <sys/types.h>
> +#include <errno.h>
> +#include <sched.h>
> +#include <pwd.h>
> +#include <string.h>
> +#include "config.h"
> +#include "test.h"
> +#include "usctest.h"
> +#include "linux_syscall_numbers.h"
> +#include "safe_macros.h"
> +
> +#define NS_TOTAL 3
> +char *TCID = "setns01";
> +
> +#if defined(__NR_setns) && defined(CLONE_NEWIPC) && defined(CLONE_NEWUTS) \
> +	&& defined(CLONE_NEWNET)
> +#include "setns.h"
> +
> +struct testcase_t {
> +	const char *msg;
> +	int fd;
> +	int ns_type;
> +	int exp_ret;
> +	int exp_errno;
> +	int skip;
> +	void (*setup) (struct testcase_t *);
> +	void (*cleanup) (struct testcase_t *);
> +};
> +
> +static void setup(void);
> +static void cleanup(void);
> +static void setup1(struct testcase_t *);
> +static void setup2(struct testcase_t *);
> +static void setup3(struct testcase_t *);
> +static void setup4(struct testcase_t *);
> +static void cleanup1(struct testcase_t *);
> +static void cleanup4(struct testcase_t *);
> +
> +struct testcase_t tdat[] = {
> +	{
> +		.msg = "invalid fd",
> +		.fd = -1,
> +		.ns_type = CLONE_NEWIPC,
> +		.exp_ret = -1,
> +		.exp_errno = EBADF,
> +	},
> +	{
> +		.msg = "regular file fd",
> +		.ns_type = CLONE_NEWIPC,
> +		.exp_ret = -1,
> +		.exp_errno = EINVAL,
> +		.setup = setup1,
> +		.cleanup = cleanup1
> +	},
> +	{
> +		.msg = "invalid ns_type",
> +		.ns_type = -1,
> +		.exp_ret = -1,
> +		.exp_errno = EINVAL,
> +		.setup = setup2,
> +	},
> +	{
> +		.msg = "mismatch ns_type/fd",
> +		.exp_ret = -1,
> +		.exp_errno = EINVAL,
> +		.setup = setup3,
> +	},
> +	{
> +		.msg = "without CAP_SYS_ADMIN",
> +		.exp_ret = -1,
> +		.exp_errno = EPERM,
> +		.setup = setup4,
> +		.cleanup = cleanup4,
> +	}

In order to allow unprivileged use of namespace, Eric has changed the permission
check to the install methods. Then, the fd and nstype check will go before the
core permission check. So, in order to test the permission, you should set an
valid fd and nstype first. Please see the following commit in kernel.

commit 142e1d1d5f088e7a38659daca6e84a730967774a
Author: Eric W. Biederman <ebiederm@xmission.com>
Date:   Thu Jul 26 01:13:20 2012 -0700

    userns: Allow unprivileged use of setns.
    
    - Push the permission check from the core setns syscall into
      the setns install methods where the user namespace of the
      target namespace can be determined, and used in a ns_capable
      call.
    
    Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
    Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>


Thanks,
Wanlong Gao


> +};
> +
> +static const char *ns_names[NS_TOTAL] = {"ns/ipc", "ns/net", "ns/uts"};
> +static int ns_types[NS_TOTAL] = { CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWUTS };
> +static int ns_fds[NS_TOTAL];
> +static int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
> +static const char nobody_uid[] = "nobody";
> +static struct passwd *ltpuser;
> +
> +static void setup1(struct testcase_t *t)
> +{
> +	t->fd = open("dummy", O_CREAT);
> +	if (t->fd == -1)
> +		tst_brkm(TFAIL|TERRNO, cleanup, "setup1:open failed");
> +	unlink("dummy");
> +}
> +
> +static void cleanup1(struct testcase_t *t)
> +{
> +	close(t->fd);
> +}
> +
> +static void setup2(struct testcase_t *t)
> +{
> +	int i;
> +	for (i = 0; i < NS_TOTAL; i++)
> +		if (ns_fds[i] != -1) {
> +			t->fd = ns_fds[i];
> +			return;
> +		}
> +	t->skip = 1;
> +}
> +
> +static void setup3(struct testcase_t *t)
> +{
> +	int i;
> +	for (i = 0; i < NS_TOTAL; i++)
> +		if (ns_fds[i] != -1) {
> +			t->fd = ns_fds[i];
> +			t->ns_type = ns_types[(i+1) % NS_TOTAL];
> +			return;
> +		}
> +	t->skip = 1;
> +}
> +
> +static void setup4(struct testcase_t *t)
> +{
> +	if (seteuid(ltpuser->pw_uid) == -1)
> +		tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
> +}
> +
> +static void cleanup4(struct testcase_t *t)
> +{
> +	if (seteuid(0) == -1)
> +		tst_brkm(TBROK | TERRNO, NULL, "seteuid restore failed");
> +}
> +
> +static void test_setns(struct testcase_t *t)
> +{
> +	int ret;
> +
> +	if (t->setup)
> +		t->setup(t);
> +
> +	if (t->skip) {
> +		tst_resm(TINFO, "skip %s", tdat->msg);
> +		return;
> +	}
> +
> +	ret = syscall(__NR_setns, t->fd, t->ns_type);
> +	if (ret == t->exp_ret) {
> +		if (ret == -1 && errno == t->exp_errno)
> +			tst_resm(TPASS, "%s exp_errno=%d", t->msg,
> +				t->exp_errno);
> +		else
> +			tst_resm(TFAIL|TERRNO, "%s exp_errno=%d", t->msg,
> +				t->exp_errno);
> +	} else {
> +		tst_resm(TFAIL, "%s ret=%d expected=%d", t->msg,
> +			ret, t->exp_ret);
> +	}
> +
> +	if (t->cleanup)
> +		t->cleanup(t);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc, testno;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		for (testno = 0; testno < TST_TOTAL; testno++)
> +			test_setns(&tdat[testno]);
> +	}
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +	int i;
> +
> +	tst_require_root(NULL);
> +
> +	/* runtime check if syscall is supported */
> +	syscall(__NR_setns, -1, 0);
> +
> +	ltpuser = getpwnam(nobody_uid);
> +	if (ltpuser == NULL)
> +		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
> +
> +	for (i = 0; i < NS_TOTAL; i++)
> +		ns_fds[i] = get_ns_fd(getpid(), ns_names[i]);
> +
> +	tst_tmpdir();
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	int i;
> +
> +	for (i = 0; i < NS_TOTAL; i++)
> +		if (ns_fds[i] != -1)
> +			close(ns_fds[i]);
> +	tst_rmdir();
> +	TEST_CLEANUP;
> +}
> +#else
> +int main(int argc, char *argv[])
> +{
> +	tst_brkm(TCONF, NULL, "__NR_setns, CLONE_NEWIPC, CLONE_NEWNET or "
> +		"CLONE_NEWUTS is not defined on your system.");
> +
> +}
> +#endif
> 


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 3/3] setns: add new syscall test setns02
  2013-02-05 15:57 ` [LTP] [PATCH 3/3] setns: add new syscall test setns02 Jan Stancek
@ 2013-02-06  8:44   ` Wanlong Gao
  0 siblings, 0 replies; 10+ messages in thread
From: Wanlong Gao @ 2013-02-06  8:44 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 02/05/2013 11:57 PM, Jan Stancek wrote:
> functional test for setns(2) - reassociate thread with a namespace
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  runtest/syscalls                          |    1 +
>  testcases/kernel/syscalls/.gitignore      |    1 +
>  testcases/kernel/syscalls/setns/setns02.c |  231 +++++++++++++++++++++++++++++
>  3 files changed, 233 insertions(+), 0 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/setns/setns02.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index a881479..c70bcbd 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -963,6 +963,7 @@ setitimer02 setitimer02
>  setitimer03 setitimer03
>  
>  setns01 setns01
> +setns02 setns02
>  
>  setpgid01 setpgid01
>  setpgid02 setpgid02
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index d3bf8b7..90b521e 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -764,6 +764,7 @@
>  /setitimer/setitimer02
>  /setitimer/setitimer03
>  /setns/setns01
> +/setns/setns02
>  /setpgid/setpgid01
>  /setpgid/setpgid02
>  /setpgid/setpgid03
> diff --git a/testcases/kernel/syscalls/setns/setns02.c b/testcases/kernel/syscalls/setns/setns02.c
> new file mode 100644
> index 0000000..fa8ea74
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setns/setns02.c
> @@ -0,0 +1,231 @@
> +/*
> + * Copyright (C) 2013 Linux Test Project, Inc.
> + *
> + * 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.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * 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.
> + */
> +/*
> + * functional test for setns(2) - reassociate thread with a namespace
> + * 1. create child with CLONE_NEWUTS, set different hostname in child,
> + *    set namespace back to parent ns and check that hostname has changed
> + * 2. create child with CLONE_NEWIPC, set up shared memory in parent
> + *    and verify that child can't shmat it, then set namespace
> + *    back to parent one and verify that child is able to do shmat
> + */
> +#define _GNU_SOURCE
> +#include <sys/ipc.h>
> +#include <sys/shm.h>
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +#include <sys/types.h>
> +#include <sys/utsname.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <sched.h>
> +#include <string.h>
> +#include "config.h"
> +#include "test.h"
> +#include "usctest.h"
> +#include "linux_syscall_numbers.h"
> +#include "safe_macros.h"
> +
> +#define CHILD_STACK_SIZE (1024*1024)
> +#define CP "(child) "
> +char *TCID = "setns02";
> +
> +#if defined(__NR_setns) && defined(CLONE_NEWIPC) && defined(CLONE_NEWUTS)
> +#include "setns.h"
> +
> +static char *dummy_hostname = "setns_dummy_uts";
> +static int ns_ipc_fd;
> +static int ns_uts_fd;
> +static key_t ipc_key;
> +static int shmid;
> +
> +static void setup(void);
> +static void cleanup(void);
> +
> +static int do_child_newuts(void *arg)
> +{
> +	struct utsname uts, uts_parent;
> +	int ns_flag = *(int *)arg;
> +
> +	if (uname(&uts_parent) == -1)
> +		tst_resm(TFAIL|TERRNO, CP"uname");
> +	tst_resm(TINFO, CP"hostnane (inherited from parent): %s",

s/hostnane/hostname/

> +		uts_parent.nodename);
> +
> +	if (sethostname(dummy_hostname, strlen(dummy_hostname)) == -1)
> +		tst_resm(TFAIL|TERRNO, CP"sethostname");
> +	if (uname(&uts) == -1)
> +		tst_resm(TFAIL|TERRNO, CP"uname");
> +
> +	tst_resm(TINFO, CP"hostname changed to: %s", uts.nodename);
> +	if (strcmp(uts_parent.nodename, uts.nodename) == 0) {
> +		tst_resm(TFAIL, CP"expected hostname to be different");
> +		return 1;
> +	} else {
> +		tst_resm(TPASS, CP"hostname is different in parent/child");
> +	}
> +
> +	tst_resm(TINFO, CP"attemping to switch ns back to parent ns");

s/attemping/attempting/

> +	if (syscall(__NR_setns, ns_uts_fd, ns_flag) == -1) {
> +		tst_resm(TFAIL|TERRNO, CP"setns");
> +		return 2;
> +	}
> +	if (uname(&uts) == -1)
> +		tst_resm(TFAIL|TERRNO, CP"uname");
> +
> +	tst_resm(TINFO, CP"hostname: %s", uts.nodename);
> +	if (strcmp(uts_parent.nodename, uts.nodename) != 0) {
> +		tst_resm(TFAIL, CP"expected hostname to match parent");
> +		return 3;
> +	} else {
> +		tst_resm(TPASS, CP"hostname now as expected");
> +	}
> +	return 0;
> +}
> +
> +static int do_child_newipc(void *arg)
> +{
> +	void *p;
> +	int ns_flag = *(int *)arg;
> +
> +	p = shmat(shmid, NULL, 0);
> +	if (p == (void *) -1) {
> +		tst_resm(TPASS|TERRNO, CP"shmat failed as expected");
> +	} else {
> +		tst_resm(TFAIL, CP"shmat unexpectedly suceeded");
> +		shmdt(p);
> +		return 1;
> +	}
> +
> +	tst_resm(TINFO, CP"attemping to switch ns back to parent ns");

s/attemping/attempting/

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>



Thanks,
Wanlong Gao


> +	if (syscall(__NR_setns, ns_ipc_fd, ns_flag) == -1) {
> +		tst_resm(TFAIL|TERRNO, CP"setns");
> +		return 2;
> +	}
> +
> +	p = shmat(shmid, NULL, 0);
> +	if (p == (void *) -1) {
> +		tst_resm(TFAIL|TERRNO, CP"shmat failed after setns");
> +		return 3;
> +	} else {
> +		tst_resm(TPASS, CP"shmat suceeded");
> +		shmdt(p);
> +	}
> +
> +	return 0;
> +}
> +
> +static void test_flag(int clone_flag, int ns_flag, int (*fn) (void *arg))
> +{
> +	void *child_stack;
> +	int ret, status;
> +
> +	child_stack = malloc(CHILD_STACK_SIZE);
> +	if (child_stack == NULL)
> +		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
> +
> +	tst_resm(TINFO, "creating child with clone_flag=0x%x, ns_flag=0x%x",
> +		clone_flag, ns_flag);
> +	ret = ltp_clone(SIGCHLD|clone_flag, fn, &ns_flag,
> +		CHILD_STACK_SIZE, child_stack);
> +	if (ret == -1)
> +		tst_brkm(TBROK|TERRNO, cleanup, "ltp_clone");
> +
> +	if (waitpid(ret, &status, 0) == -1)
> +		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
> +	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
> +		tst_resm(TFAIL, "child returns %d", status);
> +	else
> +		tst_resm(TPASS, "child finished succesfully");
> +	free(child_stack);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		if (ns_uts_fd != -1) {
> +			tst_resm(TINFO, "test_newuts");
> +			test_flag(CLONE_NEWUTS, CLONE_NEWUTS, do_child_newuts);
> +			test_flag(CLONE_NEWUTS, 0, do_child_newuts);
> +		}
> +		if (ns_ipc_fd != -1) {
> +			tst_resm(TINFO, "test_newipc");
> +			test_flag(CLONE_NEWIPC, CLONE_NEWIPC, do_child_newipc);
> +			test_flag(CLONE_NEWIPC, 0, do_child_newipc);
> +		}
> +	}
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +	char tmp[PATH_MAX];
> +
> +	tst_require_root(NULL);
> +
> +	/* runtime check if syscall is supported */
> +	syscall(__NR_setns, -1, 0);
> +
> +	/* check if kernel has CONFIG_*_NS set and exports /proc entries */
> +	ns_ipc_fd = get_ns_fd(getpid(), "ns/ipc");
> +	ns_uts_fd = get_ns_fd(getpid(), "ns/uts");
> +	if (ns_ipc_fd == -1 && ns_uts_fd == -1)
> +		tst_brkm(TCONF, NULL, "your kernel has CONFIG_IPC_NS, "
> +			"CONFIG_UTS_NS or CONFIG_PROC disabled");
> +
> +	if (getcwd(tmp, PATH_MAX) == NULL)
> +		tst_brkm(TBROK|TERRNO, NULL, "getcwd");
> +	ipc_key = ftok(tmp, 65);
> +	shmid = shmget(ipc_key, getpagesize(), IPC_CREAT | 0666);
> +	if (shmid == -1)
> +		tst_brkm(TBROK|TERRNO, NULL, "shmget");
> +
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (ns_ipc_fd != -1)
> +		close(ns_ipc_fd);
> +	if (ns_uts_fd != -1)
> +		close(ns_uts_fd);
> +
> +	shmctl(shmid, IPC_RMID, NULL);
> +	TEST_CLEANUP;
> +}
> +#else
> +int main(int argc, char *argv[])
> +{
> +	tst_brkm(TCONF, NULL, "__NR_setns, CLONE_NEWIPC or CLONE_NEWUTS "
> +		" is not defined on your system.");
> +}
> +#endif
> 


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns
  2013-02-05 15:57 ` [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
@ 2013-02-06  8:44   ` Wanlong Gao
  0 siblings, 0 replies; 10+ messages in thread
From: Wanlong Gao @ 2013-02-06  8:44 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 02/05/2013 11:57 PM, Jan Stancek wrote:
> Signed-off-by: Jan Stancek <jstancek@redhat.com>

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  testcases/kernel/syscalls/setns/Makefile |   22 ++++++++++++++++++++++
>  1 files changed, 22 insertions(+), 0 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/setns/Makefile
> 
> diff --git a/testcases/kernel/syscalls/setns/Makefile b/testcases/kernel/syscalls/setns/Makefile
> new file mode 100644
> index 0000000..b1179c4
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setns/Makefile
> @@ -0,0 +1,22 @@
> +#
> +#  Copyright (C) 2013 Linux Test Project, Inc.
> +#
> +#  This program is free software;  you can redistribute it and/or modify
> +#  it under the terms of the GNU General Public License as published by
> +#  the Free Software Foundation; either version 2 of the License, or
> +#  (at your option) any later version.
> +#
> +#  This program is distributed in the hope that it will be useful,
> +#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
> +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> +#  the GNU General Public License for more details.
> +#
> +#  You should have received a copy of the GNU General Public License
> +#  along with this program;  if not, write to the Free Software
> +#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +#
> +
> +top_srcdir		?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> 


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
  2013-02-06  7:05   ` Wanlong Gao
@ 2013-02-06  8:48     ` Wanlong Gao
  2013-02-06  8:57       ` Jan Stancek
  0 siblings, 1 reply; 10+ messages in thread
From: Wanlong Gao @ 2013-02-06  8:48 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 02/06/2013 03:05 PM, Wanlong Gao wrote:
> On 02/05/2013 11:57 PM, Jan Stancek wrote:
>> errno tests for setns(2) - reassociate thread with a namespace
>>
>> Signed-off-by: Jan Stancek <jstancek@redhat.com>
>> ---
>>  runtest/syscalls                          |    2 +
>>  testcases/kernel/syscalls/.gitignore      |    1 +
>>  testcases/kernel/syscalls/setns/setns.h   |   41 +++++
>>  testcases/kernel/syscalls/setns/setns01.c |  245 +++++++++++++++++++++++++++++
>>  4 files changed, 289 insertions(+), 0 deletions(-)
>>  create mode 100644 testcases/kernel/syscalls/setns/setns.h
>>  create mode 100644 testcases/kernel/syscalls/setns/setns01.c
>>
>> diff --git a/runtest/syscalls b/runtest/syscalls
>> index db5a075..a881479 100644
>> --- a/runtest/syscalls
>> +++ b/runtest/syscalls
>> @@ -962,6 +962,8 @@ setitimer01 setitimer01
>>  setitimer02 setitimer02
>>  setitimer03 setitimer03
>>  
>> +setns01 setns01
>> +
>>  setpgid01 setpgid01
>>  setpgid02 setpgid02
>>  setpgid03 setpgid03
>> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
>> index 003c5d0..d3bf8b7 100644
>> --- a/testcases/kernel/syscalls/.gitignore
>> +++ b/testcases/kernel/syscalls/.gitignore
>> @@ -763,6 +763,7 @@
>>  /setitimer/setitimer01
>>  /setitimer/setitimer02
>>  /setitimer/setitimer03
>> +/setns/setns01
>>  /setpgid/setpgid01
>>  /setpgid/setpgid02
>>  /setpgid/setpgid03
>> diff --git a/testcases/kernel/syscalls/setns/setns.h b/testcases/kernel/syscalls/setns/setns.h
>> new file mode 100644
>> index 0000000..1613e6c
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/setns/setns.h
>> @@ -0,0 +1,41 @@
>> +/*
>> + * Copyright (C) 2013 Linux Test Project, Inc.
>> + *
>> + * 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.
>> + *
>> + * Further, this software is distributed without any warranty that it
>> + * is free of the rightful claim of any third person regarding
>> + * infringement or the like.  Any license provided herein, whether
>> + * implied or otherwise, applies only to this software file.  Patent
>> + * licenses, if any, provided herein do not apply to combinations of
>> + * this program with other software, or any other product whatsoever.
>> + *
>> + * 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.
>> + */
>> +
>> +static int get_ns_fd(int pid, const char *ns)
>> +{
>> +	char tmp[PATH_MAX];
>> +	struct stat st;
>> +	int fd = -1;
>> +
>> +	sprintf(tmp, "/proc/%d/%s", pid, ns);
>> +	if (stat(tmp, &st) == 0) {
>> +		fd = open(tmp, O_RDONLY);
>> +		if (fd == -1)
>> +			tst_brkm(TBROK|TERRNO, NULL, "failed to open %s", tmp);
>> +	} else {
>> +		if (errno != ENOENT)
>> +			tst_brkm(TBROK|TERRNO, NULL, "failed to stat %s", tmp);
>> +	}
>> +	return fd;
>> +}
>> diff --git a/testcases/kernel/syscalls/setns/setns01.c b/testcases/kernel/syscalls/setns/setns01.c
>> new file mode 100644
>> index 0000000..6469266
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/setns/setns01.c
>> @@ -0,0 +1,245 @@
>> +/*
>> + * Copyright (C) 2013 Linux Test Project, Inc.
>> + *
>> + * 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.
>> + *
>> + * Further, this software is distributed without any warranty that it
>> + * is free of the rightful claim of any third person regarding
>> + * infringement or the like.  Any license provided herein, whether
>> + * implied or otherwise, applies only to this software file.  Patent
>> + * licenses, if any, provided herein do not apply to combinations of
>> + * this program with other software, or any other product whatsoever.
>> + *
>> + * 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.
>> + */
>> +/*
>> + * errno tests for setns(2) - reassociate thread with a namespace
>> + */
>> +#define _GNU_SOURCE
>> +#include <sys/stat.h>
>> +#include <sys/syscall.h>
>> +#include <sys/types.h>
>> +#include <errno.h>
>> +#include <sched.h>
>> +#include <pwd.h>
>> +#include <string.h>
>> +#include "config.h"
>> +#include "test.h"
>> +#include "usctest.h"
>> +#include "linux_syscall_numbers.h"
>> +#include "safe_macros.h"
>> +
>> +#define NS_TOTAL 3
>> +char *TCID = "setns01";
>> +
>> +#if defined(__NR_setns) && defined(CLONE_NEWIPC) && defined(CLONE_NEWUTS) \
>> +	&& defined(CLONE_NEWNET)
>> +#include "setns.h"
>> +
>> +struct testcase_t {
>> +	const char *msg;
>> +	int fd;
>> +	int ns_type;
>> +	int exp_ret;
>> +	int exp_errno;
>> +	int skip;
>> +	void (*setup) (struct testcase_t *);
>> +	void (*cleanup) (struct testcase_t *);
>> +};
>> +
>> +static void setup(void);
>> +static void cleanup(void);
>> +static void setup1(struct testcase_t *);
>> +static void setup2(struct testcase_t *);
>> +static void setup3(struct testcase_t *);
>> +static void setup4(struct testcase_t *);
>> +static void cleanup1(struct testcase_t *);
>> +static void cleanup4(struct testcase_t *);
>> +
>> +struct testcase_t tdat[] = {
>> +	{
>> +		.msg = "invalid fd",
>> +		.fd = -1,
>> +		.ns_type = CLONE_NEWIPC,
>> +		.exp_ret = -1,
>> +		.exp_errno = EBADF,
>> +	},
>> +	{
>> +		.msg = "regular file fd",
>> +		.ns_type = CLONE_NEWIPC,
>> +		.exp_ret = -1,
>> +		.exp_errno = EINVAL,
>> +		.setup = setup1,
>> +		.cleanup = cleanup1
>> +	},
>> +	{
>> +		.msg = "invalid ns_type",
>> +		.ns_type = -1,
>> +		.exp_ret = -1,
>> +		.exp_errno = EINVAL,
>> +		.setup = setup2,
>> +	},
>> +	{
>> +		.msg = "mismatch ns_type/fd",
>> +		.exp_ret = -1,
>> +		.exp_errno = EINVAL,
>> +		.setup = setup3,
>> +	},
>> +	{
>> +		.msg = "without CAP_SYS_ADMIN",
>> +		.exp_ret = -1,
>> +		.exp_errno = EPERM,
>> +		.setup = setup4,
>> +		.cleanup = cleanup4,
>> +	}
> 
> In order to allow unprivileged use of namespace, Eric has changed the permission
> check to the install methods. Then, the fd and nstype check will go before the
> core permission check. So, in order to test the permission, you should set an
> valid fd and nstype first. Please see the following commit in kernel.
> 
> commit 142e1d1d5f088e7a38659daca6e84a730967774a
> Author: Eric W. Biederman <ebiederm@xmission.com>
> Date:   Thu Jul 26 01:13:20 2012 -0700
> 
>     userns: Allow unprivileged use of setns.
>     
>     - Push the permission check from the core setns syscall into
>       the setns install methods where the user namespace of the
>       target namespace can be determined, and used in a ns_capable
>       call.
>     
>     Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
>     Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> 
> 
> Thanks,
> Wanlong Gao
> 
> 
>> +};
>> +
>> +static const char *ns_names[NS_TOTAL] = {"ns/ipc", "ns/net", "ns/uts"};
>> +static int ns_types[NS_TOTAL] = { CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWUTS };
>> +static int ns_fds[NS_TOTAL];
>> +static int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
>> +static const char nobody_uid[] = "nobody";
>> +static struct passwd *ltpuser;
>> +
>> +static void setup1(struct testcase_t *t)
>> +{
>> +	t->fd = open("dummy", O_CREAT);
>> +	if (t->fd == -1)
>> +		tst_brkm(TFAIL|TERRNO, cleanup, "setup1:open failed");
>> +	unlink("dummy");
>> +}
>> +
>> +static void cleanup1(struct testcase_t *t)
>> +{
>> +	close(t->fd);
>> +}
>> +
>> +static void setup2(struct testcase_t *t)
>> +{
>> +	int i;
>> +	for (i = 0; i < NS_TOTAL; i++)
>> +		if (ns_fds[i] != -1) {
>> +			t->fd = ns_fds[i];
>> +			return;
>> +		}
>> +	t->skip = 1;
>> +}
>> +
>> +static void setup3(struct testcase_t *t)
>> +{
>> +	int i;
>> +	for (i = 0; i < NS_TOTAL; i++)
>> +		if (ns_fds[i] != -1) {
>> +			t->fd = ns_fds[i];
>> +			t->ns_type = ns_types[(i+1) % NS_TOTAL];
>> +			return;
>> +		}
>> +	t->skip = 1;
>> +}
>> +
>> +static void setup4(struct testcase_t *t)
>> +{

So, how about adding fd and ns_type setting in setup4:

+	int i;
+	for (i = 0; i < NS_TOTAL; i++)
+		if (ns_fds[i] != -1) {
+			t->fd = ns_fds[i];
+			t->ns_type = ns_types[i];
+			return;
+		}
+	t->skip = 1;


Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

Thanks,
Wanlong Gao

>> +	if (seteuid(ltpuser->pw_uid) == -1)
>> +		tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
>> +}
>> +
>> +static void cleanup4(struct testcase_t *t)
>> +{
>> +	if (seteuid(0) == -1)
>> +		tst_brkm(TBROK | TERRNO, NULL, "seteuid restore failed");
>> +}
>> +
>> +static void test_setns(struct testcase_t *t)
>> +{
>> +	int ret;
>> +
>> +	if (t->setup)
>> +		t->setup(t);
>> +
>> +	if (t->skip) {
>> +		tst_resm(TINFO, "skip %s", tdat->msg);
>> +		return;
>> +	}
>> +
>> +	ret = syscall(__NR_setns, t->fd, t->ns_type);
>> +	if (ret == t->exp_ret) {
>> +		if (ret == -1 && errno == t->exp_errno)
>> +			tst_resm(TPASS, "%s exp_errno=%d", t->msg,
>> +				t->exp_errno);
>> +		else
>> +			tst_resm(TFAIL|TERRNO, "%s exp_errno=%d", t->msg,
>> +				t->exp_errno);
>> +	} else {
>> +		tst_resm(TFAIL, "%s ret=%d expected=%d", t->msg,
>> +			ret, t->exp_ret);
>> +	}
>> +
>> +	if (t->cleanup)
>> +		t->cleanup(t);
>> +}
>> +
>> +int main(int argc, char *argv[])
>> +{
>> +	int lc, testno;
>> +	char *msg;
>> +
>> +	msg = parse_opts(argc, argv, NULL, NULL);
>> +	if (msg != NULL)
>> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
>> +
>> +	setup();
>> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
>> +		for (testno = 0; testno < TST_TOTAL; testno++)
>> +			test_setns(&tdat[testno]);
>> +	}
>> +	cleanup();
>> +	tst_exit();
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	int i;
>> +
>> +	tst_require_root(NULL);
>> +
>> +	/* runtime check if syscall is supported */
>> +	syscall(__NR_setns, -1, 0);
>> +
>> +	ltpuser = getpwnam(nobody_uid);
>> +	if (ltpuser == NULL)
>> +		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
>> +
>> +	for (i = 0; i < NS_TOTAL; i++)
>> +		ns_fds[i] = get_ns_fd(getpid(), ns_names[i]);
>> +
>> +	tst_tmpdir();
>> +	TEST_PAUSE;
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	int i;
>> +
>> +	for (i = 0; i < NS_TOTAL; i++)
>> +		if (ns_fds[i] != -1)
>> +			close(ns_fds[i]);
>> +	tst_rmdir();
>> +	TEST_CLEANUP;
>> +}
>> +#else
>> +int main(int argc, char *argv[])
>> +{
>> +	tst_brkm(TCONF, NULL, "__NR_setns, CLONE_NEWIPC, CLONE_NEWNET or "
>> +		"CLONE_NEWUTS is not defined on your system.");
>> +
>> +}
>> +#endif
>>
> 
> 
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013 
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
  2013-02-06  8:48     ` Wanlong Gao
@ 2013-02-06  8:57       ` Jan Stancek
  2013-02-06  9:07         ` Wanlong Gao
  0 siblings, 1 reply; 10+ messages in thread
From: Jan Stancek @ 2013-02-06  8:57 UTC (permalink / raw)
  To: gaowanlong; +Cc: ltp-list



----- Original Message -----
> From: "Wanlong Gao" <gaowanlong@cn.fujitsu.com>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: gaowanlong@cn.fujitsu.com, ltp-list@lists.sourceforge.net
> Sent: Wednesday, 6 February, 2013 9:48:17 AM
> Subject: Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
> 
> 
> So, how about adding fd and ns_type setting in setup4:
> 
> +	int i;
> +	for (i = 0; i < NS_TOTAL; i++)
> +		if (ns_fds[i] != -1) {
> +			t->fd = ns_fds[i];
> +			t->ns_type = ns_types[i];
> +			return;
> +		}
> +	t->skip = 1;
> 
> 
> Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
> 
> Thanks,
> Wanlong Gao

Thanks for having a look. I was thinking the same, I'm just building
latest kernel tree to double check it. I'll send v2 afterwards.

Regards,
Jan

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
  2013-02-06  8:57       ` Jan Stancek
@ 2013-02-06  9:07         ` Wanlong Gao
  0 siblings, 0 replies; 10+ messages in thread
From: Wanlong Gao @ 2013-02-06  9:07 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 02/06/2013 04:57 PM, Jan Stancek wrote:
> 
> 
> ----- Original Message -----
>> From: "Wanlong Gao" <gaowanlong@cn.fujitsu.com>
>> To: "Jan Stancek" <jstancek@redhat.com>
>> Cc: gaowanlong@cn.fujitsu.com, ltp-list@lists.sourceforge.net
>> Sent: Wednesday, 6 February, 2013 9:48:17 AM
>> Subject: Re: [LTP] [PATCH 2/3] setns: add new syscall test setns01
>>
>>
>> So, how about adding fd and ns_type setting in setup4:
>>
>> +	int i;
>> +	for (i = 0; i < NS_TOTAL; i++)
>> +		if (ns_fds[i] != -1) {
>> +			t->fd = ns_fds[i];
>> +			t->ns_type = ns_types[i];
>> +			return;
>> +		}
>> +	t->skip = 1;
>>
>>
>> Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
>>
>> Thanks,
>> Wanlong Gao
> 
> Thanks for having a look. I was thinking the same, I'm just building
> latest kernel tree to double check it. I'll send v2 afterwards.

Yeah, thank you. namespace part is in heavy development
recently, your contribution is very useful. 8-)

Thanks,
Wanlong Gao

> 
> Regards,
> Jan
> 


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-02-06  9:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-05 15:57 [LTP] [PATCH 0/3] add new syscall test for setns(2) Jan Stancek
2013-02-05 15:57 ` [LTP] [PATCH 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
2013-02-06  8:44   ` Wanlong Gao
2013-02-05 15:57 ` [LTP] [PATCH 2/3] setns: add new syscall test setns01 Jan Stancek
2013-02-06  7:05   ` Wanlong Gao
2013-02-06  8:48     ` Wanlong Gao
2013-02-06  8:57       ` Jan Stancek
2013-02-06  9:07         ` Wanlong Gao
2013-02-05 15:57 ` [LTP] [PATCH 3/3] setns: add new syscall test setns02 Jan Stancek
2013-02-06  8:44   ` Wanlong Gao

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.