mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Linux-2.5 fix for get_pid() hang
@ 2002-07-29 19:57 Paul Larson
  2002-07-29 20:25 ` [Lse-tech] " Andrea Arcangeli
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Larson @ 2002-07-29 19:57 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: lkml, lse-tech

This is a fix for the problem where get_pid will hang the machine if you
request a new pid when all available pids are in use.  This also adds
the appropriate checking for p->tgid in get_pid that was somehow
overlooked before.  This patch has been in 2.4 since 2.4.19-pre9.

Please apply.

Paul Larson
Linux Test Project
http://ltp.sourceforge.net

diff -Nru a/kernel/fork.c b/kernel/fork.c
--- a/kernel/fork.c	Mon Jul 29 15:15:36 2002
+++ b/kernel/fork.c	Mon Jul 29 15:15:36 2002
@@ -26,6 +26,7 @@
 #include <linux/mman.h>
 #include <linux/fs.h>
 #include <linux/security.h>
+#include <linux/compiler.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -136,12 +137,13 @@
 {
 	static int next_safe = PID_MAX;
 	struct task_struct *p;
-	int pid;
+	int pid, beginpid;
 
 	if (flags & CLONE_IDLETASK)
 		return 0;
 
 	spin_lock(&lastpid_lock);
+	beginpid = last_pid;
 	if((++last_pid) & 0xffff8000) {
 		last_pid = 300;		/* Skip daemons etc. */
 		goto inside;
@@ -161,12 +163,16 @@
 						last_pid = 300;
 					next_safe = PID_MAX;
 				}
+				if(unlikely(last_pid == beginpid))
+					goto nomorepids;
 				goto repeat;
 			}
 			if(p->pid > last_pid && next_safe > p->pid)
 				next_safe = p->pid;
 			if(p->pgrp > last_pid && next_safe > p->pgrp)
 				next_safe = p->pgrp;
+			if(p->tgid > last_pid && next_safe > p->tgid)
+				next_safe = p->tgid;
 			if(p->session > last_pid && next_safe > p->session)
 				next_safe = p->session;
 		}
@@ -176,6 +182,11 @@
 	spin_unlock(&lastpid_lock);
 
 	return pid;
+
+nomorepids:
+	read_unlock(&tasklist_lock);
+	spin_unlock(&lastpid_lock);
+	return 0;
 }
 
 static inline int dup_mmap(struct mm_struct * mm)
@@ -677,6 +688,8 @@
 
 	copy_flags(clone_flags, p);
 	p->pid = get_pid(clone_flags);
+	if (p->pid == 0 && !(clone_flags & CLONE_IDLETASK))
+		goto bad_fork_cleanup;
 	p->proc_dentry = NULL;
 
 	INIT_LIST_HEAD(&p->run_list);


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-07-30 20:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-29 19:57 [PATCH] Linux-2.5 fix for get_pid() hang Paul Larson
2002-07-29 20:25 ` [Lse-tech] " Andrea Arcangeli
2002-07-30 15:31   ` Paul Larson
2002-07-30 20:42   ` Paul Larson

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®