mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@osdl.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] Make setsid more robust.
Date: Wed, 08 Mar 2006 13:05:07 -0700	[thread overview]
Message-ID: <m1hd68vh1o.fsf@ebiederm.dsl.xmission.com> (raw)


- Carefully allow init (pid == 1) to call setsid despite the kernel using
  it's session.
- Use find_task_by_pid instead of find_pid because find_pid taking a pidtype
  is going away.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>


---

Andrew this can replaces my fork-allow-init-to-become-a-session-leader patch.

 kernel/sys.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

a051dfe3df38b6cb1cc11209f1f8274531d761e3
diff --git a/kernel/sys.c b/kernel/sys.c
index 6a8157e..5831641 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1384,18 +1384,29 @@ asmlinkage long sys_getsid(pid_t pid)
 asmlinkage long sys_setsid(void)
 {
 	struct task_struct *group_leader = current->group_leader;
-	struct pid *pid;
+	pid_t session;
 	int err = -EPERM;
 
 	mutex_lock(&tty_mutex);
 	write_lock_irq(&tasklist_lock);
 
-	pid = find_pid(PIDTYPE_PGID, group_leader->pid);
-	if (pid)
+	/* 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.  
+	 *
+	 * 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.
+	 */
+	if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
 		goto out;
 
 	group_leader->signal->leader = 1;
-	__set_special_pids(group_leader->pid, group_leader->pid);
+	__set_special_pids(session, session);
 	group_leader->signal->tty = NULL;
 	group_leader->signal->tty_old_pgrp = 0;
 	err = process_group(group_leader);
-- 
1.2.2.g709a-dirty


                 reply	other threads:[~2006-03-08 20:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=m1hd68vh1o.fsf@ebiederm.dsl.xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@osdl.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®