mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
mm: madvise(): correct return code
The posix_madvise() function succeeds (and does nothing) when called with parameters (NULL, 0, -1); according to LSB tests, it should fail with EINVAL because -1 is not a valid flag. When called with a valid address and size, it correctly fails. So perform an initial check for valid flags first. Reported-by: Jiri Dluhos <jdluhos@novell.com> Signed-off-by: Nick Piggin <npiggin@suse.de> Reviewed-and-Tested-by: WANG Cong <xiyou.wangcong@gmail.com> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
dab48dab37
commit
75927af8bc
1 changed files with 22 additions and 1 deletions
23
mm/madvise.c
23
mm/madvise.c
|
@ -238,12 +238,30 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error = -EINVAL;
|
BUG();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
madvise_behavior_valid(int behavior)
|
||||||
|
{
|
||||||
|
switch (behavior) {
|
||||||
|
case MADV_DOFORK:
|
||||||
|
case MADV_DONTFORK:
|
||||||
|
case MADV_NORMAL:
|
||||||
|
case MADV_SEQUENTIAL:
|
||||||
|
case MADV_RANDOM:
|
||||||
|
case MADV_REMOVE:
|
||||||
|
case MADV_WILLNEED:
|
||||||
|
case MADV_DONTNEED:
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* The madvise(2) system call.
|
* The madvise(2) system call.
|
||||||
*
|
*
|
||||||
|
@ -289,6 +307,9 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
|
||||||
int write;
|
int write;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
if (!madvise_behavior_valid(behavior))
|
||||||
|
return error;
|
||||||
|
|
||||||
write = madvise_need_mmap_write(behavior);
|
write = madvise_need_mmap_write(behavior);
|
||||||
if (write)
|
if (write)
|
||||||
down_write(¤t->mm->mmap_sem);
|
down_write(¤t->mm->mmap_sem);
|
||||||
|
|
Loading…
Reference in a new issue