Skip to content

Commit

Permalink
[PATCH] mm: fix madvise infinine loop
Browse files Browse the repository at this point in the history
madvise(MADV_REMOVE) can go into an infinite loop or cause an oops if the
call covers a region from the start of a vma, and extending past that vma.

Signed-off-by: Nick Piggin <[email protected]>
Cc: Badari Pulavarty <[email protected]>
Acked-by: Hugh Dickins <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Mar 17, 2007
1 parent 0465fc0 commit 00e9fa2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mm/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ static long madvise_dontneed(struct vm_area_struct * vma,
* Other filesystems return -ENOSYS.
*/
static long madvise_remove(struct vm_area_struct *vma,
struct vm_area_struct **prev,
unsigned long start, unsigned long end)
{
struct address_space *mapping;
loff_t offset, endoff;

*prev = vma;

if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
return -EINVAL;

Expand Down Expand Up @@ -199,7 +202,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
error = madvise_behavior(vma, prev, start, end, behavior);
break;
case MADV_REMOVE:
error = madvise_remove(vma, start, end);
error = madvise_remove(vma, prev, start, end);
break;

case MADV_WILLNEED:
Expand Down

0 comments on commit 00e9fa2

Please sign in to comment.