mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-30 11:04:25 +00:00
fix setsid() for sub-namespace /sbin/init
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> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
4e021306cf
commit
e4cc0a9c87
1 changed files with 10 additions and 12 deletions
22
kernel/sys.c
22
kernel/sys.c
|
@ -1045,35 +1045,33 @@ asmlinkage long sys_getsid(pid_t pid)
|
||||||
asmlinkage long sys_setsid(void)
|
asmlinkage long sys_setsid(void)
|
||||||
{
|
{
|
||||||
struct task_struct *group_leader = current->group_leader;
|
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;
|
int err = -EPERM;
|
||||||
|
|
||||||
write_lock_irq(&tasklist_lock);
|
write_lock_irq(&tasklist_lock);
|
||||||
|
|
||||||
/* Fail if I am already a session leader */
|
/* Fail if I am already a session leader */
|
||||||
if (group_leader->signal->leader)
|
if (group_leader->signal->leader)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
session = group_leader->pid;
|
/* Fail if a process group id already exists that equals the proposed
|
||||||
/* Fail if a process group id already exists that equals the
|
* session id.
|
||||||
* proposed session id.
|
|
||||||
*
|
*
|
||||||
* Don't check if session id == 1 because kernel threads use this
|
* Don't check if session == 1 because kernel threads and CLONE_NEWPID
|
||||||
* session id and so the check will always fail and make it so
|
* tasks use this session id and so the check will always fail and make
|
||||||
* init cannot successfully call setsid.
|
* it so init cannot successfully call setsid.
|
||||||
*/
|
*/
|
||||||
if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
|
if (session != 1 && pid_task(sid, PIDTYPE_PGID))
|
||||||
session, &init_pid_ns))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
group_leader->signal->leader = 1;
|
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);
|
spin_lock(&group_leader->sighand->siglock);
|
||||||
group_leader->signal->tty = NULL;
|
group_leader->signal->tty = NULL;
|
||||||
spin_unlock(&group_leader->sighand->siglock);
|
spin_unlock(&group_leader->sighand->siglock);
|
||||||
|
|
||||||
err = task_pgrp_vnr(group_leader);
|
err = session;
|
||||||
out:
|
out:
|
||||||
write_unlock_irq(&tasklist_lock);
|
write_unlock_irq(&tasklist_lock);
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Add table
Reference in a new issue