Skip to content

Commit 02fdb36

Browse files
Serge E. Hallyntorvalds
authored andcommitted
ipc: sysvsem: refuse clone(CLONE_SYSVSEM|CLONE_NEWIPC)
CLONE_NEWIPC|CLONE_SYSVSEM interaction isn't handled properly. This can cause a kernel memory corruption. CLONE_NEWIPC must detach from the existing undo lists. Fix, part 3: refuse clone(CLONE_SYSVSEM|CLONE_NEWIPC). With unshare, specifying CLONE_SYSVSEM means unshare the sysvsem. So it seems reasonable that CLONE_NEWIPC without CLONE_SYSVSEM would just imply CLONE_SYSVSEM. However with clone, specifying CLONE_SYSVSEM means *share* the sysvsem. So calling clone(CLONE_SYSVSEM|CLONE_NEWIPC) is explicitly asking for something we can't allow. So return -EINVAL in that case. [akpm@linux-foundation.org: cleanups] Signed-off-by: Serge E. Hallyn <serue@us.ibm.com> Cc: Manfred Spraul <manfred@colorfullife.com> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Cc: Pierre Peiffer <peifferp@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6013f67 commit 02fdb36

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎kernel/nsproxy.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
139139
goto out;
140140
}
141141

142+
/*
143+
* CLONE_NEWIPC must detach from the undolist: after switching
144+
* to a new ipc namespace, the semaphore arrays from the old
145+
* namespace are unreachable. In clone parlance, CLONE_SYSVSEM
146+
* means share undolist with parent, so we must forbid using
147+
* it along with CLONE_NEWIPC.
148+
*/
149+
if ((flags & CLONE_NEWIPC) && (flags & CLONE_SYSVSEM)) {
150+
err = -EINVAL;
151+
goto out;
152+
}
153+
142154
new_ns = create_new_namespaces(flags, tsk, tsk->fs);
143155
if (IS_ERR(new_ns)) {
144156
err = PTR_ERR(new_ns);

0 commit comments

Comments
 (0)