From: Rik van Riel <riel@redhat.com>
To: pageexec@freemail.hu
Cc: Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Michel Lespinasse <walken@google.com>,
Cyrill Gorcunov <gorcunov@openvz.org>,
Hugh Dickins <hughd@google.com>,
linux-mm@kvack.org, Dmitry Vyukov <dvyukov@google.com>
Subject: [PATCH -v2] mm: fix use-after-free in sys_remap_file_pages
Date: Fri, 13 Dec 2013 09:43:20 -0500 [thread overview]
Message-ID: <20131213094320.2291c210@annuminas.surriel.com> (raw)
In-Reply-To: <52AAEB19.27706.CCB8B7D@pageexec.freemail.hu>
On Fri, 13 Dec 2013 12:10:17 +0100
"PaX Team" <pageexec@freemail.hu> wrote:
> pass in vm_flags instead of vma->vm_flags just to prevent someone
> from 'optimizing' away the read in the future?
In that case, we should probably also use ACCESS_ONCE, if
only to be explicit about it.
> perhaps {copy,move} this comment above the previous hunk since that's
> where the relevant action is?
See the new version below:
---8<---
Subject: mm: fix use-after-free in sys_remap_file_pages
remap_file_pages calls mmap_region, which may merge the VMA with other existing
VMAs, and free "vma". This can lead to a use-after-free bug. Avoid the bug by
remembering vm_flags before calling mmap_region, and not trying to dereference
vma later.
Signed-off-by: Rik van Riel <riel@redhat.com>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Cc: stable@vger.kernel.org
---
mm/fremap.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/fremap.c b/mm/fremap.c
index 87da359..c85e2ec 100644
--- a/mm/fremap.c
+++ b/mm/fremap.c
@@ -203,9 +203,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
if (mapping_cap_account_dirty(mapping)) {
unsigned long addr;
struct file *file = get_file(vma->vm_file);
+ /* mmap_region may free vma; grab the info now */
+ vm_flags = ACCESS_ONCE(vma->vm_flags);
- addr = mmap_region(file, start, size,
- vma->vm_flags, pgoff);
+ addr = mmap_region(file, start, size, vm_flags, pgoff);
fput(file);
if (IS_ERR_VALUE(addr)) {
err = addr;
@@ -213,7 +214,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
BUG_ON(addr != start);
err = 0;
}
- goto out;
+ goto out_freed;
}
mutex_lock(&mapping->i_mmap_mutex);
flush_dcache_mmap_lock(mapping);
@@ -248,6 +249,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
out:
if (vma)
vm_flags = vma->vm_flags;
+out_freed:
if (likely(!has_write_lock))
up_read(&mm->mmap_sem);
else
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2013-12-13 15:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-12 22:07 [PATCH] mm: fix use-after-free in sys_remap_file_pages Kees Cook
2013-12-13 3:41 ` Rik van Riel
2013-12-13 6:24 ` Cyrill Gorcunov
2013-12-13 11:10 ` PaX Team
2013-12-13 14:43 ` Rik van Riel [this message]
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=20131213094320.2291c210@annuminas.surriel.com \
--to=riel@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=gorcunov@openvz.org \
--cc=hughd@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pageexec@freemail.hu \
--cc=walken@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).