diff options
author | Rik van Riel <riel@redhat.com> | 2014-01-02 15:58:46 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-09 15:24:24 -0500 |
commit | abdd4b8ac01323900fcda70f6d9ee94b873d66e3 (patch) | |
tree | 6d246224f1abe56bd72862db4611b638625ccbcc /mm | |
parent | 398bbc5710f23c0db6ebd4dd30bb331086bd16e7 (diff) |
mm: fix use-after-free in sys_remap_file_pages
commit 4eb919825e6c3c7fb3630d5621f6d11e98a18b3a upstream.
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: PaX Team <pageexec@freemail.hu>
Cc: Kees Cook <keescook@chromium.org>
Cc: Michel Lespinasse <walken@google.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/fremap.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/mm/fremap.c b/mm/fremap.c index 87da3590c61e..1fb6bfe39d8c 100644 --- a/mm/fremap.c +++ b/mm/fremap.c | |||
@@ -203,9 +203,10 @@ get_write_lock: | |||
203 | if (mapping_cap_account_dirty(mapping)) { | 203 | if (mapping_cap_account_dirty(mapping)) { |
204 | unsigned long addr; | 204 | unsigned long addr; |
205 | struct file *file = get_file(vma->vm_file); | 205 | struct file *file = get_file(vma->vm_file); |
206 | /* mmap_region may free vma; grab the info now */ | ||
207 | vm_flags = vma->vm_flags; | ||
206 | 208 | ||
207 | addr = mmap_region(file, start, size, | 209 | addr = mmap_region(file, start, size, vm_flags, pgoff); |
208 | vma->vm_flags, pgoff); | ||
209 | fput(file); | 210 | fput(file); |
210 | if (IS_ERR_VALUE(addr)) { | 211 | if (IS_ERR_VALUE(addr)) { |
211 | err = addr; | 212 | err = addr; |
@@ -213,7 +214,7 @@ get_write_lock: | |||
213 | BUG_ON(addr != start); | 214 | BUG_ON(addr != start); |
214 | err = 0; | 215 | err = 0; |
215 | } | 216 | } |
216 | goto out; | 217 | goto out_freed; |
217 | } | 218 | } |
218 | mutex_lock(&mapping->i_mmap_mutex); | 219 | mutex_lock(&mapping->i_mmap_mutex); |
219 | flush_dcache_mmap_lock(mapping); | 220 | flush_dcache_mmap_lock(mapping); |
@@ -248,6 +249,7 @@ get_write_lock: | |||
248 | out: | 249 | out: |
249 | if (vma) | 250 | if (vma) |
250 | vm_flags = vma->vm_flags; | 251 | vm_flags = vma->vm_flags; |
252 | out_freed: | ||
251 | if (likely(!has_write_lock)) | 253 | if (likely(!has_write_lock)) |
252 | up_read(&mm->mmap_sem); | 254 | up_read(&mm->mmap_sem); |
253 | else | 255 | else |