public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpuset: make ntasks to be a monotonic increasing value
@ 2008-07-31  3:22 Lai Jiangshan
  2008-07-31  7:10 ` Li Zefan
  2008-07-31 12:23 ` Paul Jackson
  0 siblings, 2 replies; 10+ messages in thread
From: Lai Jiangshan @ 2008-07-31  3:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Paul Jackson, Paul Menage, Linux Kernel Mailing List


ntasks is not a monotonic increasing value,
So maybe fudge+1 processes are created when kmalloc and killed
when kfree in every loop. And the loop will not end or
repetition a long time.

This patch prevent this kind of attack.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index d5ab79c..65eaa2b 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -949,16 +949,20 @@ static int update_tasks_nodemask(struct cpuset *cs, const nodemask_t *oldmem)
 	 * few more lines of code, we can retry until we get a big
 	 * enough mmarray[] w/o using GFP_ATOMIC.
 	 */
+	ntasks = cgroup_task_count(cs->css.cgroup);	/* guess */
 	while (1) {
-		ntasks = cgroup_task_count(cs->css.cgroup);  /* guess */
+		int ntasks_now;
 		ntasks += fudge;
 		mmarray = kmalloc(ntasks * sizeof(*mmarray), GFP_KERNEL);
 		if (!mmarray)
 			goto done;
 		read_lock(&tasklist_lock);		/* block fork */
-		if (cgroup_task_count(cs->css.cgroup) <= ntasks)
+		ntasks_now = cgroup_task_count(cs->css.cgroup);
+		if (ntasks_now <= ntasks)
 			break;				/* got enough */
 		read_unlock(&tasklist_lock);		/* try again */
+		ntasks = ntasks_now;
+		fudge += fudge >> 3;
 		kfree(mmarray);
 	}
 



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

end of thread, other threads:[~2008-08-01  1:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-31  3:22 [PATCH] cpuset: make ntasks to be a monotonic increasing value Lai Jiangshan
2008-07-31  7:10 ` Li Zefan
2008-07-31  7:45   ` Lai Jiangshan
2008-07-31 12:23 ` Paul Jackson
2008-07-31 13:10   ` Lai Jiangshan
2008-07-31 13:37     ` Paul Jackson
2008-07-31 17:06       ` Paul Menage
2008-07-31 19:38         ` Paul Jackson
2008-07-31 20:02           ` Paul Menage
2008-08-01  1:35       ` Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox