]> git.hungrycats.org Git - linux/commitdiff
[PATCH] copy_mount_options size fix
authorAndrew Morton <akpm@osdl.org>
Fri, 27 Aug 2004 03:34:16 +0000 (20:34 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 27 Aug 2004 03:34:16 +0000 (20:34 -0700)
davem says that copy_mount_options is failing in obscure ways if the
architecture's copy_from_user() doesn't return an exact count of the number of
uncopied bytes.

Fixing that up in each architecture is a pain - it involves falling back to
byte-at-a-time copies.

It's simple to open-code this in namespace.c.  If we find other places in the
kernel which care about this we can promote this to a global function.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/namespace.c

index 9e8350d458f25be6711a70713ec45e9a8c347717..2c5cc697a18db4f71191e00dbfc235691b19a247 100644 (file)
@@ -930,7 +930,35 @@ void mark_mounts_for_expiry(struct list_head *mounts)
 
 EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
 
-int copy_mount_options (const void __user *data, unsigned long *where)
+/*
+ * Some copy_from_user() implementations do not return the exact number of
+ * bytes remaining to copy on a fault.  But copy_mount_options() requires that.
+ * Note that this function differs from copy_from_user() in that it will oops
+ * on bad values of `to', rather than returning a short copy.
+ */
+static long
+exact_copy_from_user(void *to, const void __user *from, unsigned long n)
+{
+       char *t = to;
+       const char __user *f = from;
+       char c;
+
+       if (!access_ok(VERIFY_READ, from, n))
+               return n;
+
+       while (n) {
+               if (__get_user(c, f)) {
+                       memset(t, 0, n);
+                       break;
+               }
+               *t++ = c;
+               f++;
+               n--;
+       }
+       return n;
+}
+
+int copy_mount_options(const void __user *data, unsigned long *where)
 {
        int i;
        unsigned long page;
@@ -952,7 +980,7 @@ int copy_mount_options (const void __user *data, unsigned long *where)
        if (size > PAGE_SIZE)
                size = PAGE_SIZE;
 
-       i = size - copy_from_user((void *)page, data, size);
+       i = size - exact_copy_from_user((void *)page, data, size);
        if (!i) {
                free_page(page); 
                return -EFAULT;