Commit a2362d24 authored by Michel Lespinasse's avatar Michel Lespinasse Committed by Linus Torvalds

mm/fremap.c: fix possible oops on error path

The vm_flags introduced in 6d7825b1 ("mm/fremap.c: fix oops on error
path") is supposed to avoid a compiler warning about unitialized
vm_flags without changing the generated code.

However I am concerned that this is going to be very brittle, and fail
with some compiler versions. The failure could be either of:

- compiler could actually load vma->vm_flags before checking for the
  !vma condition, thus reintroducing the oops

- compiler could optimize out the !vma check, since the pointer just got
  dereferenced shortly before (so the compiler knows it can't be NULL!)

I propose reversing this part of the change and initializing vm_flags to 0
just to avoid the bogus uninitialized use warning.
Signed-off-by: default avatarMichel Lespinasse <walken@google.com>
Cc: Tommi Rantala <tt.rantala@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f4846e52
...@@ -129,7 +129,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -129,7 +129,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
struct vm_area_struct *vma; struct vm_area_struct *vma;
int err = -EINVAL; int err = -EINVAL;
int has_write_lock = 0; int has_write_lock = 0;
vm_flags_t vm_flags; vm_flags_t vm_flags = 0;
if (prot) if (prot)
return err; return err;
...@@ -163,8 +163,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -163,8 +163,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
* and that the remapped range is valid and fully within * and that the remapped range is valid and fully within
* the single existing vma. * the single existing vma.
*/ */
vm_flags = vma->vm_flags; if (!vma || !(vma->vm_flags & VM_SHARED))
if (!vma || !(vm_flags & VM_SHARED))
goto out; goto out;
if (!vma->vm_ops || !vma->vm_ops->remap_pages) if (!vma->vm_ops || !vma->vm_ops->remap_pages)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment