All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Linux Containers <containers@lists.osdl.org>,
	Subrata Modak1 <subrata.modak@in.ibm.com>
Subject: [LTP PATCH 2/4] posix mqns: test parent to child mq access
Date: Wed, 17 Dec 2008 11:57:31 -0600	[thread overview]
Message-ID: <20081217175731.GD23331@us.ibm.com> (raw)
In-Reply-To: <20081217175513.GA23291@us.ibm.com>

It's kind of redundant with test 01 since there is no hierarchical
relationship between ipc namespaces - they are all completely isolated.
But heck it can't hurt.

Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
---
 testcases/kernel/containers/mqns/mqns_02.c      |  138 +++++++++++++++++++++++
 testcases/kernel/containers/mqns/runmqnstest.sh |    2 +-
 2 files changed, 139 insertions(+), 1 deletions(-)
 create mode 100644 testcases/kernel/containers/mqns/mqns_02.c
 mode change 100644 => 100755 testcases/kernel/containers/mqns/runmqnstest.sh

diff --git a/testcases/kernel/containers/mqns/mqns_02.c b/testcases/kernel/containers/mqns/mqns_02.c
new file mode 100644
index 0000000..2414f43
--- /dev/null
+++ b/testcases/kernel/containers/mqns/mqns_02.c
@@ -0,0 +1,138 @@
+/*
+* Copyright (c) International Business Machines Corp., 2007
+* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* Author: Nadia Derbey <Nadia.Derbey@bull.net>
+*
+* Check mqns isolation: child mqns cannot be accessed from father
+*
+* Mount mqueue fs
+* unshare
+* In unshared process:
+*    Mount newinstance mqueuefs
+*    Create a posix mq -->mq1
+* Check that mq1 is not readable from father
+*
+* Changelog:
+* 	Dec 16: accomodate new mqns semantics (Serge Hallyn)
+
+***************************************************************************/
+
+#define _GNU_SOURCE 1
+#include <sys/wait.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include "mqns.h"
+
+char *TCID = "posixmq_namespace_02";
+int TST_TOTAL=1;
+
+int p1[2];
+int p2[2];
+
+int check_mqueue(void *vtest)
+{
+	char buf[3];
+	mqd_t mqd;
+
+	close(p1[1]);
+	close(p2[0]);
+
+	read(p1[0], buf, 3);
+
+	mqd = mq_open(SLASH_MQ1, O_RDWR|O_CREAT|O_EXCL, 0777, NULL);
+	if (mqd == -1) {
+		write(p2[1], "mqfail", 7);
+		tst_exit(3);
+	}
+
+	write(p2[1], "mqopen", 7);
+
+	read(p1[0], buf, 5);
+
+	/* destroy the mqueue */
+	mq_close(mqd);
+	mq_unlink(SLASH_MQ1);
+
+	write(p2[1], "done", 5);
+
+	tst_exit(0);
+
+	/* NOT REACHED */
+	return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+	int r;
+	mqd_t mqd;
+	char buf[7];
+	int use_clone = T_UNSHARE;
+
+	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
+		tst_resm(TINFO, "Testing posix mq namespaces through clone(2).\n");
+		use_clone = T_CLONE;
+	} else
+		tst_resm(TINFO, "Testing posix mq namespaces through unshare(2).\n");
+
+	if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
+	if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
+
+	/* fire off the test */
+	r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
+	if (r < 0) {
+		tst_resm(TFAIL, "failed clone/unshare\n");
+		tst_exit(1);
+	}
+
+	tst_resm(TINFO, "Checking namespaces isolation (child to parent)\n");
+
+	close(p1[0]);
+	close(p2[1]);
+	write(p1[1], "go", 3);
+
+	read(p2[0], buf, 7);
+	if (!strcmp(buf, "mqfail")) {
+		tst_resm(TFAIL, "child process could not create mqueue\n");
+		umount(DEV_MQUEUE);
+		tst_exit(TFAIL);
+	} else if (strcmp(buf, "mqopen")) {
+		tst_resm(TFAIL, "child process could not create mqueue\n");
+		umount(DEV_MQUEUE);
+		tst_exit(TFAIL);
+	}
+
+	mqd = mq_open(SLASH_MQ1, O_RDONLY);
+	if (mqd == -1) {
+		r = TPASS;
+		tst_resm(TPASS, "Father process doesn't see mqueue\n");
+	} else {
+		r = TFAIL;
+		tst_resm(TFAIL, "Father process found mqueue\n");
+		mq_close(mqd);
+	}
+
+	write(p1[1], "cont", 5);
+	read(p2[0], buf, 7);
+
+	tst_exit(r);
+
+	/* NOT REACHED */
+	return 0;
+}
diff --git a/testcases/kernel/containers/mqns/runmqnstest.sh b/testcases/kernel/containers/mqns/runmqnstest.sh
old mode 100644
new mode 100755
index 87c712e..a5bbd24
--- a/testcases/kernel/containers/mqns/runmqnstest.sh
+++ b/testcases/kernel/containers/mqns/runmqnstest.sh
@@ -20,7 +20,7 @@
 ################################################################################
 
 exit_code=0
-tests_list='mqns_01'
+tests_list='mqns_01 mqns_02'
 
 for t in $tests_list
 do
-- 
1.6.0.5

  parent reply	other threads:[~2008-12-17 17:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-17 17:55 [RFC patch 0/2] posix mqueue namespace (v12) Serge E. Hallyn
2008-12-17 17:55 ` [PATCH 1/2] mqueue ns: move mqueue_mnt into struct ipc_namespace Serge E. Hallyn
2008-12-17 18:36   ` Dave Hansen
2008-12-17 18:52     ` Serge E. Hallyn
2008-12-17 18:55       ` Dave Hansen
2008-12-17 17:55 ` [PATCH 2/2] ipc namespaces: implement support for posix msqueues Serge E. Hallyn
2008-12-17 18:54   ` Dave Hansen
2008-12-17 19:08     ` Serge E. Hallyn
2008-12-17 19:08       ` Serge E. Hallyn
2008-12-17 21:25   ` Sukadev Bhattiprolu
     [not found]     ` <20081217212521.GA14740-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-12-18 21:36       ` Serge E. Hallyn
2008-12-18 21:36         ` Serge E. Hallyn
2008-12-17 17:57 ` [LTP PATCH 1/4] posix message queue namespaces: first test Serge E. Hallyn
2008-12-17 17:57 ` Serge E. Hallyn [this message]
2008-12-17 17:58 ` [LTP PATCH 3/4] posix mqns: test vfs and mq interaction Serge E. Hallyn
2008-12-17 17:58 ` [LTP PATCH 4/4] posix mqns: test that user mount of posixmq survivies the ipcns Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081217175731.GD23331@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=subrata.modak@in.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.