Skip to content

Commit 676758b

Browse files
Andrew MortonLinus Torvalds
authored andcommitted
[PATCH] msync: fix return value
msync() does a strange thing. Essentially: vma = find_vma(); for ( ; ; ) { if (!vma) return -ENOMEM; ... vma = vma->vm_next; } so an msync() request which starts within or before a valid VMA and which ends within or beyond the final VMA will incorrectly return -ENOMEM. Fix. Cc: Hugh Dickins <hugh@veritas.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 707c21c commit 676758b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎mm/msync.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
146146
{
147147
unsigned long end;
148148
struct vm_area_struct *vma;
149-
int unmapped_error, error = -EINVAL;
149+
int unmapped_error = 0;
150+
int error = -EINVAL;
150151
int done = 0;
151152

152153
if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC))
@@ -171,15 +172,14 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
171172
if (flags & MS_SYNC)
172173
current->flags |= PF_SYNCWRITE;
173174
vma = find_vma(current->mm, start);
174-
unmapped_error = 0;
175+
if (!vma) {
176+
error = -ENOMEM;
177+
goto out_unlock;
178+
}
175179
do {
176180
unsigned long nr_pages_dirtied = 0;
177181
struct file *file;
178182

179-
/* Still start < end. */
180-
error = -ENOMEM;
181-
if (!vma)
182-
goto out_unlock;
183183
/* Here start < vma->vm_end. */
184184
if (start < vma->vm_start) {
185185
unmapped_error = -ENOMEM;
@@ -239,7 +239,7 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
239239
} else {
240240
vma = vma->vm_next;
241241
}
242-
} while (!done);
242+
} while (vma && !done);
243243
out_unlock:
244244
current->flags &= ~PF_SYNCWRITE;
245245
up_read(&current->mm->mmap_sem);

0 commit comments

Comments
 (0)