All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: "Américo Wang" <xiyou.wangcong@gmail.com>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Hugh Dickins" <hughd@google.com>
Cc: "Robert Święcki" <robert@swiecki.net>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] __mlock_vma_pages_range: stack_guard_page() case returns the wrong value
Date: Tue, 12 Apr 2011 21:08:04 +0200	[thread overview]
Message-ID: <20110412190804.GB13752@redhat.com> (raw)
In-Reply-To: <20110412190731.GA13752@redhat.com>

__mlock_vma_pages_range() simply changes addr/nr_pages when
stack_guard_page(vma, start). But this means that __get_user_pages()
returns a number which doesn't match the [start, end) interval and
the caller can be confused.

If we skip the first page, we should return 1 if gup fails, or add
1 to the number it returns.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 mm/mlock.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- sigprocmask/mm/mlock.c~do_mlock_pages_stack_guard_page	2011-04-06 21:33:50.000000000 +0200
+++ sigprocmask/mm/mlock.c	2011-04-12 20:50:30.000000000 +0200
@@ -159,9 +159,8 @@ static long __mlock_vma_pages_range(stru
 				    int *nonblocking)
 {
 	struct mm_struct *mm = vma->vm_mm;
-	unsigned long addr = start;
 	int nr_pages = (end - start) / PAGE_SIZE;
-	int gup_flags;
+	int gup_flags, skip_page, ret;
 
 	VM_BUG_ON(start & ~PAGE_MASK);
 	VM_BUG_ON(end   & ~PAGE_MASK);
@@ -189,13 +188,22 @@ static long __mlock_vma_pages_range(stru
 		gup_flags |= FOLL_MLOCK;
 
 	/* We don't try to access the guard page of a stack vma */
+	skip_page = 0;
 	if (stack_guard_page(vma, start)) {
-		addr += PAGE_SIZE;
+		skip_page = 1;
+		start += PAGE_SIZE;
 		nr_pages--;
 	}
 
-	return __get_user_pages(current, mm, addr, nr_pages, gup_flags,
+	ret = __get_user_pages(current, mm, start, nr_pages, gup_flags,
 				NULL, NULL, nonblocking);
+
+	if (ret >= 0)
+		ret += skip_page;
+	else if (skip_page)
+		ret = 1;
+
+	return ret;
 }
 
 /*


  reply	other threads:[~2011-04-12 19:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 10:32 Processes hang in an unkillable state Robert Święcki
2011-04-12 12:44 ` Américo Wang
2011-04-12 13:03   ` Robert Święcki
2011-04-12 13:08     ` Robert Święcki
2011-04-12 18:28   ` Oleg Nesterov
2011-04-12 18:34     ` Robert Święcki
2011-04-12 19:20       ` Oleg Nesterov
     [not found]         ` <BANLkTimJgx_x=0bpBDWaUkJgZPYs3_iwsg@mail.gmail.com>
     [not found]           ` <BANLkTimBegMUq2fX67o2YnoATWG-NDbKgA@mail.gmail.com>
2011-04-12 20:22             ` Linus Torvalds
     [not found]               ` <BANLkTi=HyK+8DhJS3db0j2fefdOjwVMN3w@mail.gmail.com>
2011-04-12 21:46                 ` Linus Torvalds
2011-04-12 21:59                   ` Robert Święcki
2011-04-12 22:12                     ` Linus Torvalds
2011-04-12 22:16                       ` Robert Święcki
2011-04-12 22:18                         ` Linus Torvalds
2011-04-12 22:30                           ` Robert Święcki
2011-04-12 22:43                             ` Linus Torvalds
2011-04-13 12:19                               ` Robert Święcki
2011-04-12 19:07     ` [PATCH 0/1] Was: " Oleg Nesterov
2011-04-12 19:08       ` Oleg Nesterov [this message]
2011-04-12 19:18         ` [PATCH 1/1] __mlock_vma_pages_range: stack_guard_page() case returns the wrong value Robert Święcki

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=20110412190804.GB13752@redhat.com \
    --to=oleg@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robert@swiecki.net \
    --cc=torvalds@linux-foundation.org \
    --cc=xiyou.wangcong@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.