Skip to content

Commit

Permalink
mm/fremap.c: fix oops on error path
Browse files Browse the repository at this point in the history
If find_vma() fails, sys_remap_file_pages() will dereference `vma', which
contains NULL.  Fix it by checking the pointer.

(We could alternatively check for err==0, but this seems more direct)

(The vm_flags change is to squish a bogus used-uninitialised warning
without adding extra code).

Reported-by: Tommi Rantala <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
akpm00 authored and torvalds committed Mar 13, 2013
1 parent c8615d3 commit 6d7825b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mm/fremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
* and that the remapped range is valid and fully within
* the single existing vma.
*/
if (!vma || !(vma->vm_flags & VM_SHARED))
vm_flags = vma->vm_flags;
if (!vma || !(vm_flags & VM_SHARED))
goto out;

if (!vma->vm_ops || !vma->vm_ops->remap_pages)
Expand Down Expand Up @@ -254,7 +255,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
*/

out:
vm_flags = vma->vm_flags;
if (vma)
vm_flags = vma->vm_flags;
if (likely(!has_write_lock))
up_read(&mm->mmap_sem);
else
Expand Down

0 comments on commit 6d7825b

Please sign in to comment.