Skip to content

Commit

Permalink
mm/fremap.c: fix possible oops on error path
Browse files Browse the repository at this point in the history
The vm_flags introduced in 6d7825b ("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: Michel Lespinasse <[email protected]>
Cc: Tommi Rantala <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
walken-google authored and torvalds committed Mar 15, 2013
1 parent f4846e5 commit a2362d2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mm/fremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
struct vm_area_struct *vma;
int err = -EINVAL;
int has_write_lock = 0;
vm_flags_t vm_flags;
vm_flags_t vm_flags = 0;

if (prot)
return err;
Expand Down Expand Up @@ -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
* the single existing vma.
*/
vm_flags = vma->vm_flags;
if (!vma || !(vm_flags & VM_SHARED))
if (!vma || !(vma->vm_flags & VM_SHARED))
goto out;

if (!vma->vm_ops || !vma->vm_ops->remap_pages)
Expand Down

0 comments on commit a2362d2

Please sign in to comment.