All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul@openvz.org>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] fix setsid() for sub-namespace /sbin/init
Date: Mon, 26 Nov 2007 18:00:36 +0300	[thread overview]
Message-ID: <474ADF94.5050500@openvz.org> (raw)
In-Reply-To: <20071126142553.GA16525@tv-sign.ru>

Oleg Nesterov wrote:
> sys_setsid() still deals with pid_t's from the global namespace. This means
> that the "session > 1" check can't help for sub-namespace init, setsid() can't
> succeed because copy_process(CLONE_NEWPID) populates PIDTYPE_PGID/SID links.
> 
> Remove the usage of task_struct->pid and convert the code to use "struct pid".
> This also simplifies and speedups the code, saves one find_pid().
> 
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

Acked-by: Pavel Emelyanov <xemul@openvz.org>

> --- PT/kernel/sys.c~1_setsid	2007-11-26 15:52:15.000000000 +0300
> +++ PT/kernel/sys.c	2007-11-26 16:10:43.000000000 +0300
> @@ -1045,35 +1045,33 @@ asmlinkage long sys_getsid(pid_t pid)
>  asmlinkage long sys_setsid(void)
>  {
>  	struct task_struct *group_leader = current->group_leader;
> -	pid_t session;
> +	struct pid *sid = task_pid(group_leader);
> +	pid_t session = pid_vnr(sid);
>  	int err = -EPERM;
>  
>  	write_lock_irq(&tasklist_lock);
> -
>  	/* Fail if I am already a session leader */
>  	if (group_leader->signal->leader)
>  		goto out;
>  
> -	session = group_leader->pid;
> -	/* Fail if a process group id already exists that equals the
> -	 * proposed session id.
> +	/* Fail if a process group id already exists that equals the proposed
> +	 * session id.
>  	 *
> -	 * Don't check if session id == 1 because kernel threads use this
> -	 * session id and so the check will always fail and make it so
> -	 * init cannot successfully call setsid.
> +	 * Don't check if session == 1 because kernel threads and CLONE_NEWPID
> +	 * tasks use this session id and so the check will always fail and make
> +	 * it so init cannot successfully call setsid.
>  	 */
> -	if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
> -				session, &init_pid_ns))
> +	if (session != 1 && pid_task(sid, PIDTYPE_PGID))
>  		goto out;
>  
>  	group_leader->signal->leader = 1;
> -	__set_special_pids(session, session);
> +	__set_special_pids(pid_nr(sid), pid_nr(sid));
>  
>  	spin_lock(&group_leader->sighand->siglock);
>  	group_leader->signal->tty = NULL;
>  	spin_unlock(&group_leader->sighand->siglock);
>  
> -	err = task_pgrp_vnr(group_leader);
> +	err = session;
>  out:
>  	write_unlock_irq(&tasklist_lock);
>  	return err;
> 
> 


  parent reply	other threads:[~2007-11-26 15:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-26 14:25 [PATCH 1/3] fix setsid() for sub-namespace /sbin/init Oleg Nesterov
2007-11-26 14:43 ` Oleg Nesterov
2007-11-26 15:00 ` Pavel Emelyanov [this message]
2007-11-26 19:16 ` Eric W. Biederman
2007-11-26 20:11   ` Oleg Nesterov
2007-11-26 21:40     ` Eric W. Biederman
2007-11-26 22:46       ` Oleg Nesterov

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=474ADF94.5050500@openvz.org \
    --to=xemul@openvz.org \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.