diff options
Diffstat (limited to 'mm/madvise.c')
-rw-r--r-- | mm/madvise.c | 23 |
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 | ||
247 | static int | ||
248 | madvise_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(¤t->mm->mmap_sem); | 315 | down_write(¤t->mm->mmap_sem); |