mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
	torvalds@linux-foundation.org, a.p.zijlstra@chello.nl,
	riel@redhat.com, akpm@linux-foundation.org, aarcange@redhat.com,
	tglx@linutronix.de, dan.carpenter@oracle.com
Subject: [tip:numa/core] numa, sched, mm: Fix NULL-ptr deref
Date: Wed, 24 Oct 2012 02:35:50 -0700	[thread overview]
Message-ID: <tip-mnkio02xxtttiepsg9ek6qkw@git.kernel.org> (raw)

Commit-ID:  836e3bf3d85dfe29309cb62dc1714bb89801eea5
Gitweb:     http://git.kernel.org/tip/836e3bf3d85dfe29309cb62dc1714bb89801eea5
Author:     Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Mon, 22 Oct 2012 19:21:32 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 24 Oct 2012 08:52:12 +0200

numa, sched, mm: Fix NULL-ptr deref

Dan reported that there's a possible NULL pointer deref in this logic,
fix that. Further fix it to avoid a possible inf. loop (completely
unlikely in the case no vma is migratable). Also don't endlessly loop
on large length, simply truncate at the end of the address-space and
restart on the next go.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Link: http://lkml.kernel.org/n/tip-mnkio02xxtttiepsg9ek6qkw@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c |   25 ++++++++-----------------
 1 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 1dad296..dea3ca6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -933,40 +933,31 @@ void task_numa_work(struct callback_head *work)
 	if (cmpxchg(&mm->numa_next_scan, migrate, next_scan) != migrate)
 		return;
 
-
 	offset = mm->numa_scan_offset;
 	length = sysctl_sched_numa_scan_size;
 	length <<= 20;
 
 	down_write(&mm->mmap_sem);
 	vma = find_vma(mm, offset);
-again:
 	if (!vma) {
 		ACCESS_ONCE(mm->numa_scan_seq)++;
 		offset = 0;
 		vma = mm->mmap;
 	}
-	while (vma && !vma_migratable(vma)) {
-		vma = vma->vm_next;
-		if (!vma)
-			goto again;
-	}
-
-	offset = max(offset, vma->vm_start);
-	end = min(ALIGN(offset + length, HPAGE_SIZE), vma->vm_end);
-	length -= end - offset;
+	for (; vma && length > 0; vma = vma->vm_next) {
+		if (!vma_migratable(vma))
+			continue;
 
-	change_prot_none(vma, offset, end);
+		offset = max(offset, vma->vm_start);
+		end = min(ALIGN(offset + length, HPAGE_SIZE), vma->vm_end);
+		length -= end - offset;
 
-	offset = end;
+		change_prot_none(vma, offset, end);
 
-	if (length > 0) {
-		vma = vma->vm_next;
-		goto again;
+		offset = end;
 	}
 	mm->numa_scan_offset = offset;
 	up_write(&mm->mmap_sem);
-
 }
 
 /*

                 reply	other threads:[~2012-10-24  9:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=tip-mnkio02xxtttiepsg9ek6qkw@git.kernel.org \
    --to=a.p.zijlstra@chello.nl \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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

Powered by JetHome