Messages in this thread Patch in this message |  | | Date | Sun, 06 Apr 2008 18:26:05 +0200 | From | Manfred Spraul <> | Subject | [PATCH] fix SEM_UNDO with namespaces, take 2 |
| |
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> 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); |  |