lkml.org 
[lkml]   [2008]   [Apr]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] fix SEM_UNDO with namespaces, take 2
Pavel Emelyanov wrote:
> No, switch_task_namespaces is the wrong place to do this. It is to be
> done in copy_ipc_ns. If you need a task for which a new namespace is
> being prepared, then pass one into it.
>
>
copy_ipc_ns() is also the wrong place:
There are calls after copy_ipc_ns() that can fail (e.g. copy_pid_ns()),
and if they fail, then the whole syscall is aborted.
But undoing outstanding semaphore operations cannot be undone.
Or simpler: the copy_whatever() functions do not modify current.

Another option would be within sys_unshare():
sys_unshare() first creates all new pointers, and then actual unsharing
is performed.

What do you think? I that the right place? The implementation could be
moved into a seperate function, perhaps some of the NULL tests are
superflous, too.

--
Manfred
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/fork.c b/kernel/fork.c
index 9c042f9..a3f3abb 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1733,6 +1733,18 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
if (new_fs || new_mm || new_fd || new_ulist || new_nsproxy) {

if (new_nsproxy) {
+ if ((current->nsproxy == NULL && new_nsproxy != NULL) ||
+ (current->nsproxy != NULL && new_nsproxy == NULL) ||
+ (current->nsproxy != NULL && new_nsproxy != NULL && current->nsproxy->ipc_ns != new_nsproxy->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(current);
+ }
+
switch_task_namespaces(current, new_nsproxy);
new_nsproxy = NULL;
}
\
 
 \ /
  Last update: 2008-04-07 19:07    [W:0.342 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site