Skip to contentSkip to conversation

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

PATCH In review Ming Lei 2 participants 3 messages Mar 16, 2013 – Mar 17, 2013 Memory management

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 mm/fremap.c: fix another oops on error path

Since find_vma() may return NULL, so don't dereference the returned 'vma' until it is valid.

The problem is introduced by the commit in linus tree:

6d7825b(mm/fremap.c: fix oops on error path).

Also mark vm_flags as ninitialized_var() to avoid compile warning.

Cc Tommi Rantala <[email protected]>
Cc Michel Lespinasse <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 mm/fremap.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/fremap.c +2 -3
index 6a8da7e..80088e9 100644
@@ -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 uninitialized_var(vm_flags);
 
 	if (prot)
 		return err;
@@ -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)
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 2 lines · Ming Lei

Since find_vma() may return NULL, so don't dereference the returned 'vma' until it is valid.

Agree this was an issue. This is fixed with commit a2362d24764a.

Signature · 2 lines
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
author
#2 lore raw
Quoted 5 lines · Michel Lespinasse
Quoted 2 lines · Ming Lei

Since find_vma() may return NULL, so don't dereference the returned 'vma' until it is valid.

Agree this was an issue. This is fixed with commit a2362d24764a.

It is fine if the issue has been fixed, but I didn't see the commit a2362d or other fix on both linus and next tree.

Thanks,

Signature · 1 line
Ming Lei