Skip to content

Commit 12efec5

Browse files
author
Al Viro
committed
saner copy_mount_options()
don't bother with the byte-by-byte loops, etc. Signed-off-by: Al Viro <[email protected]>
1 parent 324282c commit 12efec5

File tree

1 file changed

+7
-42
lines changed

1 file changed

+7
-42
lines changed

fs/namespace.c

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,39 +2979,10 @@ static void shrink_submounts(struct mount *mnt)
29792979
}
29802980
}
29812981

2982-
/*
2983-
* Some copy_from_user() implementations do not return the exact number of
2984-
* bytes remaining to copy on a fault. But copy_mount_options() requires that.
2985-
* Note that this function differs from copy_from_user() in that it will oops
2986-
* on bad values of `to', rather than returning a short copy.
2987-
*/
2988-
static long exact_copy_from_user(void *to, const void __user * from,
2989-
unsigned long n)
2990-
{
2991-
char *t = to;
2992-
const char __user *f = from;
2993-
char c;
2994-
2995-
if (!access_ok(from, n))
2996-
return n;
2997-
2998-
while (n) {
2999-
if (__get_user(c, f)) {
3000-
memset(t, 0, n);
3001-
break;
3002-
}
3003-
*t++ = c;
3004-
f++;
3005-
n--;
3006-
}
3007-
return n;
3008-
}
3009-
30102982
void *copy_mount_options(const void __user * data)
30112983
{
3012-
int i;
3013-
unsigned long size;
30142984
char *copy;
2985+
unsigned size;
30152986

30162987
if (!data)
30172988
return NULL;
@@ -3020,22 +2991,16 @@ void *copy_mount_options(const void __user * data)
30202991
if (!copy)
30212992
return ERR_PTR(-ENOMEM);
30222993

3023-
/* We only care that *some* data at the address the user
3024-
* gave us is valid. Just in case, we'll zero
3025-
* the remainder of the page.
3026-
*/
3027-
/* copy_from_user cannot cross TASK_SIZE ! */
3028-
size = TASK_SIZE - (unsigned long)untagged_addr(data);
3029-
if (size > PAGE_SIZE)
3030-
size = PAGE_SIZE;
2994+
size = PAGE_SIZE - offset_in_page(data);
30312995

3032-
i = size - exact_copy_from_user(copy, data, size);
3033-
if (!i) {
2996+
if (copy_from_user(copy, data, size)) {
30342997
kfree(copy);
30352998
return ERR_PTR(-EFAULT);
30362999
}
3037-
if (i != PAGE_SIZE)
3038-
memset(copy + i, 0, PAGE_SIZE - i);
3000+
if (size != PAGE_SIZE) {
3001+
if (copy_from_user(copy + size, data + size, PAGE_SIZE - size))
3002+
memset(copy + size, 0, PAGE_SIZE - size);
3003+
}
30393004
return copy;
30403005
}
30413006

0 commit comments

Comments
 (0)