Skip to content

Commit faf00da

Browse files
committed
userns,pidns: Force thread group sharing, not signal handler sharing.
The code that places signals in signal queues computes the uids, gids, and pids at the time the signals are enqueued. Which means that tasks that share signal queues must be in the same pid and user namespaces. Sharing signal handlers is fine, but bizarre. So make the code in fork and userns_install clearer by only testing for what is functionally necessary. Also update the comment in unshare about unsharing a user namespace to be a little more explicit and make a little more sense. Acked-by: Oleg Nesterov <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 12c641a commit faf00da

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

kernel/fork.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,10 +1273,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12731273

12741274
/*
12751275
* If the new process will be in a different pid or user namespace
1276-
* do not allow it to share a thread group or signal handlers or
1277-
* parent with the forking task.
1276+
* do not allow it to share a thread group with the forking task.
12781277
*/
1279-
if (clone_flags & CLONE_SIGHAND) {
1278+
if (clone_flags & CLONE_THREAD) {
12801279
if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
12811280
(task_active_pid_ns(current) !=
12821281
current->nsproxy->pid_ns_for_children))
@@ -1944,7 +1943,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
19441943
int err;
19451944

19461945
/*
1947-
* If unsharing a user namespace must also unshare the thread.
1946+
* If unsharing a user namespace must also unshare the thread group
1947+
* and unshare the filesystem root and working directories.
19481948
*/
19491949
if (unshare_flags & CLONE_NEWUSER)
19501950
unshare_flags |= CLONE_THREAD | CLONE_FS;

kernel/user_namespace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,8 @@ static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns)
976976
if (user_ns == current_user_ns())
977977
return -EINVAL;
978978

979-
/* Threaded processes may not enter a different user namespace */
980-
if (atomic_read(&current->mm->mm_users) > 1)
979+
/* Tasks that share a thread group must share a user namespace */
980+
if (!thread_group_empty(current))
981981
return -EINVAL;
982982

983983
if (current->fs->users != 1)

0 commit comments

Comments
 (0)