From: Michel Lespinasse <walken@google.com>
To: Valdis.Kletnieks@vt.edu
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: mmotm 2010-12-16 - breaks mlockall() call
Date: Mon, 20 Dec 2010 22:26:29 -0800 [thread overview]
Message-ID: <20101221062629.GA17066@google.com> (raw)
In-Reply-To: <131961.1292667059@localhost>
On Sat, Dec 18, 2010 at 05:10:59AM -0500, Valdis.Kletnieks@vt.edu wrote:
> On Thu, 16 Dec 2010 14:56:39 PST, akpm@linux-foundation.org said:
> > The mm-of-the-moment snapshot 2010-12-16-14-56 has been uploaded to
> >
> > http://userweb.kernel.org/~akpm/mmotm/
>
> The patch mlock-only-hold-mmap_sem-in-shared-mode-when-faulting-in-pages.patch
> causes this chunk of code from cryptsetup-luks to fail during the initramfs:
>
> if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
> log_err(ctx, _("WARNING!!! Possibly insecure memory. Are you root?\n"));
> _memlock_count--;
> return 0;
> }
>
> Bisection fingered this patch, which was added after -rc4-mmotm1202, which
> boots without tripping this log_err() call. I haven't tried building a
> -rc6-mmotm1216 with this patch reverted, because reverting it causes apply
> errors for subsequent patches.
>
> Ideas?
So I traced this down using valdis's initramfs image. This is actually
an interesting corner case:
Some VMA has the VM_MAY_(READ/WRITE/EXEC) flags, but is currently protected
with PROT_NONE permissions (VM_READ/WRITE_EXEC flags are all cleared).
When mlockall() is called, the old code would see mlock_fixup() return
an error for that VMA, which would be ignored by do_mlockall(). The new
code did not ignore errors from do_mlock_pages(), which broke backwards
compatibility.
So the trivial fix to make mlockall behave identically as before could be
as follows:
Signed-off-by: Michel Lespinasse <walken@google.com>
diff --git a/mm/mlock.c b/mm/mlock.c
index db0ed84..168b750 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -424,7 +424,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
return error;
}
-static int do_mlock_pages(unsigned long start, size_t len)
+static int do_mlock_pages(unsigned long start, size_t len, int ignore_errors)
{
struct mm_struct *mm = current->mm;
unsigned long end, nstart, nend;
@@ -465,6 +465,10 @@ static int do_mlock_pages(unsigned long start, size_t len)
*/
ret = __mlock_vma_pages_range(vma, nstart, nend, &locked);
if (ret < 0) {
+ if (ignore_errors) {
+ ret = 0;
+ continue; /* continue at next VMA */
+ }
ret = __mlock_posix_error_return(ret);
break;
}
@@ -502,7 +506,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
error = do_mlock(start, len, 1);
up_write(¤t->mm->mmap_sem);
if (!error)
- error = do_mlock_pages(start, len);
+ error = do_mlock_pages(start, len, 0);
return error;
}
@@ -567,8 +571,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
capable(CAP_IPC_LOCK))
ret = do_mlockall(flags);
up_write(¤t->mm->mmap_sem);
- if (!ret && (flags & MCL_CURRENT))
- ret = do_mlock_pages(0, TASK_SIZE);
+ if (!ret && (flags & MCL_CURRENT)) {
+ /* Ignore errors */
+ do_mlock_pages(0, TASK_SIZE, 1);
+ }
out:
return ret;
}
--
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
WARNING: multiple messages have this Message-ID (diff)
From: Michel Lespinasse <walken@google.com>
To: Valdis.Kletnieks@vt.edu
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: mmotm 2010-12-16 - breaks mlockall() call
Date: Mon, 20 Dec 2010 22:26:29 -0800 [thread overview]
Message-ID: <20101221062629.GA17066@google.com> (raw)
In-Reply-To: <131961.1292667059@localhost>
On Sat, Dec 18, 2010 at 05:10:59AM -0500, Valdis.Kletnieks@vt.edu wrote:
> On Thu, 16 Dec 2010 14:56:39 PST, akpm@linux-foundation.org said:
> > The mm-of-the-moment snapshot 2010-12-16-14-56 has been uploaded to
> >
> > http://userweb.kernel.org/~akpm/mmotm/
>
> The patch mlock-only-hold-mmap_sem-in-shared-mode-when-faulting-in-pages.patch
> causes this chunk of code from cryptsetup-luks to fail during the initramfs:
>
> if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
> log_err(ctx, _("WARNING!!! Possibly insecure memory. Are you root?\n"));
> _memlock_count--;
> return 0;
> }
>
> Bisection fingered this patch, which was added after -rc4-mmotm1202, which
> boots without tripping this log_err() call. I haven't tried building a
> -rc6-mmotm1216 with this patch reverted, because reverting it causes apply
> errors for subsequent patches.
>
> Ideas?
So I traced this down using valdis's initramfs image. This is actually
an interesting corner case:
Some VMA has the VM_MAY_(READ/WRITE/EXEC) flags, but is currently protected
with PROT_NONE permissions (VM_READ/WRITE_EXEC flags are all cleared).
When mlockall() is called, the old code would see mlock_fixup() return
an error for that VMA, which would be ignored by do_mlockall(). The new
code did not ignore errors from do_mlock_pages(), which broke backwards
compatibility.
So the trivial fix to make mlockall behave identically as before could be
as follows:
Signed-off-by: Michel Lespinasse <walken@google.com>
diff --git a/mm/mlock.c b/mm/mlock.c
index db0ed84..168b750 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -424,7 +424,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
return error;
}
-static int do_mlock_pages(unsigned long start, size_t len)
+static int do_mlock_pages(unsigned long start, size_t len, int ignore_errors)
{
struct mm_struct *mm = current->mm;
unsigned long end, nstart, nend;
@@ -465,6 +465,10 @@ static int do_mlock_pages(unsigned long start, size_t len)
*/
ret = __mlock_vma_pages_range(vma, nstart, nend, &locked);
if (ret < 0) {
+ if (ignore_errors) {
+ ret = 0;
+ continue; /* continue at next VMA */
+ }
ret = __mlock_posix_error_return(ret);
break;
}
@@ -502,7 +506,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
error = do_mlock(start, len, 1);
up_write(¤t->mm->mmap_sem);
if (!error)
- error = do_mlock_pages(start, len);
+ error = do_mlock_pages(start, len, 0);
return error;
}
@@ -567,8 +571,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
capable(CAP_IPC_LOCK))
ret = do_mlockall(flags);
up_write(¤t->mm->mmap_sem);
- if (!ret && (flags & MCL_CURRENT))
- ret = do_mlock_pages(0, TASK_SIZE);
+ if (!ret && (flags & MCL_CURRENT)) {
+ /* Ignore errors */
+ do_mlock_pages(0, TASK_SIZE, 1);
+ }
out:
return ret;
}
--
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-12-21 6:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-16 22:56 mmotm 2010-12-16-14-56 uploaded akpm
2010-12-16 22:56 ` akpm
2010-12-17 22:33 ` mmotm 2010-12-16-14-56 uploaded (hugetlb) Randy Dunlap
2010-12-17 22:33 ` Randy Dunlap
2010-12-17 22:53 ` Andrew Morton
2010-12-17 22:53 ` Andrew Morton
2010-12-17 23:37 ` Andrea Arcangeli
2010-12-17 23:37 ` Andrea Arcangeli
2010-12-18 0:28 ` Randy Dunlap
2010-12-18 0:28 ` Randy Dunlap
2010-12-18 0:58 ` Andrew Morton
2010-12-18 0:58 ` Andrew Morton
2010-12-18 8:17 ` Andrea Arcangeli
2010-12-18 8:17 ` Andrea Arcangeli
2010-12-18 7:44 ` Andrea Arcangeli
2010-12-18 7:44 ` Andrea Arcangeli
2010-12-18 10:10 ` mmotm 2010-12-16 - breaks mlockall() call Valdis.Kletnieks
2010-12-20 1:48 ` Michel Lespinasse
2010-12-20 1:48 ` Michel Lespinasse
2010-12-21 6:26 ` Michel Lespinasse [this message]
2010-12-21 6:26 ` Michel Lespinasse
2010-12-22 1:07 ` Valdis.Kletnieks
2010-12-20 9:49 ` i915 modeset defunct [was: mmotm 2010-12-16-14-56 uploaded] Jiri Slaby
2010-12-20 9:52 ` Jiri Slaby
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=20101221062629.GA17066@google.com \
--to=walken@google.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mm-commits@vger.kernel.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 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.