Re: [local DoS] Re: Linux 2.6.24-rc4

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Luiz Fernando N. Capitulino <lcapitulino@...>
Cc: Linus Torvalds <torvalds@...>, Linux Kernel Mailing List <linux-kernel@...>, <herton@...>, <dvgevers@...>
Date: Tuesday, December 4, 2007 - 12:08 pm

* Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> wrote:


hm, if you run this as an RT task, right? Or can you trigger it via pure 
SCHED_OTHER tasks as well? Below is my candidate fix.

	Ingo

--------------->
Subject: sched: fix crash in sys_sched_rr_get_interval()
From: Ingo Molnar <mingo@elte.hu>

Luiz Fernando N. Capitulino reported that sched_rr_get_interval()
crashes for SCHED_OTHER tasks that are on an idle runqueue.

The fix is to return a 0 timeslice for tasks that are on an idle
runqueue. (and which are not running, obviously)

Reported-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -4850,17 +4850,21 @@ long sys_sched_rr_get_interval(pid_t pid
 	if (retval)
 		goto out_unlock;
 
-	if (p->policy == SCHED_FIFO)
-		time_slice = 0;
-	else if (p->policy == SCHED_RR)
+	/*
+	 * Time slice is 0 for SCHED_FIFO tasks and for SCHED_OTHER
+	 * tasks that are on an otherwise idle runqueue:
+	 */
+	time_slice = 0;
+	if (p->policy == SCHED_RR) {
 		time_slice = DEF_TIMESLICE;
-	else {
+	} else {
 		struct sched_entity *se = &p->se;
 		unsigned long flags;
 		struct rq *rq;
 
 		rq = task_rq_lock(p, &flags);
-		time_slice = NS_TO_JIFFIES(sched_slice(cfs_rq_of(se), se));
+		if (rq->cfs.load.weight)
+			time_slice = NS_TO_JIFFIES(sched_slice(&rq->cfs, se));
 		task_rq_unlock(rq, &flags);
 	}
 	read_unlock(&tasklist_lock);
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Linux 2.6.24-rc4, Linus Torvalds, (Tue Dec 4, 1:08 am)
Re: Linux 2.6.24-rc4, Diego Calleja, (Tue Dec 4, 8:23 pm)
[local DoS] Re: Linux 2.6.24-rc4, Luiz Fernando N. Capitulino..., (Tue Dec 4, 10:07 am)
Re: [local DoS] Re: Linux 2.6.24-rc4, Linus Torvalds, (Tue Dec 4, 11:56 am)
Re: [local DoS] Re: Linux 2.6.24-rc4, Ingo Molnar, (Tue Dec 4, 12:00 pm)
[git pull] scheduler fixes, Ingo Molnar, (Tue Dec 4, 12:18 pm)
Re: [git pull] scheduler fixes, Greg KH, (Tue Dec 4, 2:28 pm)
Re: [git pull] scheduler fixes, Luiz Fernando N. Capitulino..., (Tue Dec 4, 2:41 pm)
Re: [git pull] scheduler fixes, Ingo Molnar, (Tue Dec 4, 5:04 pm)
Re: [git pull] scheduler fixes, Luiz Fernando N. Capitulino..., (Tue Dec 4, 12:40 pm)
Re: [local DoS] Re: Linux 2.6.24-rc4, Luiz Fernando N. Capitulino..., (Tue Dec 4, 12:04 pm)
Re: [local DoS] Re: Linux 2.6.24-rc4, Ingo Molnar, (Tue Dec 4, 12:08 pm)
Re: Linux 2.6.24-rc4, Nicolas Pitre, (Tue Dec 4, 9:22 am)
Re: Linux 2.6.24-rc4, Jeff Garzik, (Tue Dec 4, 12:04 pm)
[build failure] Re: Linux 2.6.24-rc4 on S390x, Kamalesh Babulal, (Tue Dec 4, 6:23 am)
Re: [build failure] Re: Linux 2.6.24-rc4 on S390x, Ingo Molnar, (Tue Dec 4, 6:32 am)
Re: [build failure] Re: Linux 2.6.24-rc4 on S390x, Martin Schwidefsky, (Tue Dec 4, 6:31 am)