mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mohammed Naser <mnaser@vexxhost.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com,
	Mohammed Naser <mnaser@vexxhost.com>
Subject: [PATCH] sched/fair: Fix null pointer dereference of empty queues
Date: Mon, 25 May 2015 14:00:51 -0400	[thread overview]
Message-ID: <1432576851-24831-1-git-send-email-mnaser@vexxhost.com> (raw)

Calling put_prev_task() can result in nr_running being updated
to zero, which would then crash the system when the kernel
attempts to pick_next_entity() with an empty queue.

Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
---
 kernel/sched/fair.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0d4632f..dd0a74a 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5374,12 +5374,11 @@ again:
 simple:
 	cfs_rq = &rq->cfs;
 #endif
+	put_prev_task(rq, prev);
 
 	if (!cfs_rq->nr_running)
 		goto idle;
 
-	put_prev_task(rq, prev);
-
 	do {
 		se = pick_next_entity(cfs_rq, NULL);
 		set_next_entity(cfs_rq, se);
@@ -5415,7 +5414,10 @@ idle:
 static void put_prev_task_fair(struct rq *rq, struct task_struct *prev)
 {
 	struct sched_entity *se = &prev->se;
-	struct cfs_rq *cfs_rq;
+	struct cfs_rq *cfs_rq = &rq->cfs;
+
+	if (!cfs_rq->nr_running)
+		return;
 
 	for_each_sched_entity(se) {
 		cfs_rq = cfs_rq_of(se);
-- 
2.3.2 (Apple Git-55)


             reply	other threads:[~2015-05-25 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-25 18:00 Mohammed Naser [this message]
2015-05-25 20:38 ` Peter Zijlstra
     [not found]   ` <CAEs876hF0rcSdqoKf-JASnKP0SFs70EREzpxFs9M9qC51Ea6zA@mail.gmail.com>
2015-05-25 20:49     ` Mohammed Naser
2015-05-25 21:51       ` Kirill Tkhai
2015-05-26 17:38         ` bsegall
2015-05-26 17:56           ` Mohammed Naser
2015-05-26 18:05             ` Mohammed Naser
2015-05-27 12:33           ` Kirill Tkhai

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=1432576851-24831-1-git-send-email-mnaser@vexxhost.com \
    --to=mnaser@vexxhost.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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®