public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: "Serge E. Hallyn" <serue@us.ibm.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Pavel Emelyanov <xemul@openvz.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sukadev Bhattiprolu <sukadev@us.ibm.com>
Subject: [PATCH] fix SEM_UNDO with namespaces, take 2
Date: Sun, 06 Apr 2008 18:26:05 +0200	[thread overview]
Message-ID: <47F8F99D.1070701@colorfullife.com> (raw)
In-Reply-To: <47F8E824.6090600@colorfullife.com>

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

Hi,

below is the second attempt to fix SEM_UNDO + unshare():
lookup_undo (in ipc/sem.c) is not namespace-aware, thus all entries in 
sysvsem.undo_list must be from the same namespace.
The patch enforces that by detaching the current thread from 
sysvsem.undo_list in switch_task_namespaces() if the ipc namespace is 
changed.

The patch boots and passes simple sysvsem+unshare tests.

Signed-Off-By: Manfred Spraul <manfred@colorfullife.com>

[-- Attachment #2: patch-namespace-detach --]
[-- Type: text/plain, Size: 1128 bytes --]

diff --git a/ipc/sem.c b/ipc/sem.c
index 0b45a4d..35841bd 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1298,6 +1298,7 @@ void exit_sem(struct task_struct *tsk)
 	undo_list = tsk->sysvsem.undo_list;
 	if (!undo_list)
 		return;
+	tsk->sysvsem.undo_list = NULL;
 
 	if (!atomic_dec_and_test(&undo_list->refcnt))
 		return;
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index f5d332c..ddeb9d1 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -211,6 +211,18 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
 
 	might_sleep();
 
+	if ((p->nsproxy == NULL && new != NULL) ||
+		(p->nsproxy != NULL && new == NULL) ||
+		(p->nsproxy != NULL && new != NULL && p->nsproxy->ipc_ns != new->ipc_ns)) {
+		/* switching the IPC namespace is considered equivalent to sys_exit() wrt.
+		 * to outstanding SEM_UNDO undos: After switching to the new IPC namespace,
+		 * the semaphore arrays from the old namespace are not accessible anymore.
+		 * 
+		 * Additionally, an implicit sys_unshare(CLONE_SYSVSEM) is performed.
+		 */
+		exit_sem(p);
+	}
+
 	ns = p->nsproxy;
 
 	rcu_assign_pointer(p->nsproxy, new);

  reply	other threads:[~2008-04-06 16:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-30 20:50 [RFC, PATCH] fix SEM_UNDO with namespaces Manfred Spraul
2008-03-31  7:12 ` Pavel Emelyanov
2008-03-31 16:14   ` Manfred Spraul
2008-04-01  9:44     ` Pavel Emelyanov
2008-04-01 14:15       ` Serge E. Hallyn
2008-04-03 19:04         ` Andrew Morton
2008-04-03 19:31           ` Manfred Spraul
2008-04-01 15:25       ` Eric W. Biederman
2008-04-03 19:40         ` Manfred Spraul
2008-04-03 19:44         ` Serge E. Hallyn
2008-04-04  4:39           ` Serge E. Hallyn
2008-04-06 15:11             ` Manfred Spraul
2008-04-06 16:26               ` Manfred Spraul [this message]
2008-04-07  7:21                 ` [PATCH] fix SEM_UNDO with namespaces, take 2 Pavel Emelyanov
2008-04-07 17:03                   ` Manfred Spraul
2008-04-08  8:09                     ` Pavel Emelyanov
2008-04-14 21:10               ` [RFC, PATCH] fix SEM_UNDO with namespaces 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=47F8F99D.1070701@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serue@us.ibm.com \
    --cc=sukadev@us.ibm.com \
    --cc=xemul@openvz.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox