* [PATCH] Make setsid more robust.
@ 2006-03-08 20:05 Eric W. Biederman
0 siblings, 0 replies; only message in thread
From: Eric W. Biederman @ 2006-03-08 20:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: Oleg Nesterov, linux-kernel
- 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-03-08 20:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-08 20:05 [PATCH] Make setsid more robust Eric W. Biederman
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®