aboutsummaryrefslogtreecommitdiffstats
path: root/mm/madvise.c
diff options
context:
space:
mode:
authorNick Piggin <npiggin@suse.de>2009-06-16 18:32:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-16 22:47:40 -0400
commit75927af8bcb940dad4fe281713d526cb520869ff (patch)
tree96b2b903ce215d3c47204b7b77724c9fa0aa6502 /mm/madvise.c
parentdab48dab37d2770824420d1e01730a107fade1aa (diff)
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>
Diffstat (limited to 'mm/madvise.c')
-rw-r--r--mm/madvise.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/mm/madvise.c b/mm/madvise.c
index e994dcb479d6..76eb4193acdd 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -238,12 +238,30 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
238 break; 238 break;
239 239
240 default: 240 default:
241 error = -EINVAL; 241 BUG();
242 break; 242 break;
243 } 243 }
244 return error; 244 return error;
245} 245}
246 246
247static int
248madvise_behavior_valid(int behavior)
249{
250 switch (behavior) {
251 case MADV_DOFORK:
252 case MADV_DONTFORK:
253 case MADV_NORMAL:
254 case MADV_SEQUENTIAL:
255 case MADV_RANDOM:
256 case MADV_REMOVE:
257 case MADV_WILLNEED:
258 case MADV_DONTNEED:
259 return 1;
260
261 default:
262 return 0;
263 }
264}
247/* 265/*
248 * The madvise(2) system call. 266 * The madvise(2) system call.
249 * 267 *
@@ -289,6 +307,9 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
289 int write; 307 int write;
290 size_t len; 308 size_t len;
291 309
310 if (!madvise_behavior_valid(behavior))
311 return error;
312
292 write = madvise_need_mmap_write(behavior); 313 write = madvise_need_mmap_write(behavior);
293 if (write) 314 if (write)
294 down_write(&current->mm->mmap_sem); 315 down_write(&current->mm->mmap_sem);