fs: Handle intra-page faults in copy_mount_options()
[sfrench/cifs-2.6.git] / fs / namespace.c
index bae0e95b3713a3bf143754a523f603a5a330b8ab..32a0b9146757e57c800dc4297b35a5fd12ca9ff1 100644 (file)
@@ -3075,7 +3075,7 @@ static void shrink_submounts(struct mount *mnt)
 void *copy_mount_options(const void __user * data)
 {
        char *copy;
-       unsigned size;
+       unsigned left, offset;
 
        if (!data)
                return NULL;
@@ -3084,16 +3084,27 @@ void *copy_mount_options(const void __user * data)
        if (!copy)
                return ERR_PTR(-ENOMEM);
 
-       size = PAGE_SIZE - offset_in_page(data);
+       left = copy_from_user(copy, data, PAGE_SIZE);
 
-       if (copy_from_user(copy, data, size)) {
+       /*
+        * Not all architectures have an exact copy_from_user(). Resort to
+        * byte at a time.
+        */
+       offset = PAGE_SIZE - left;
+       while (left) {
+               char c;
+               if (get_user(c, (const char __user *)data + offset))
+                       break;
+               copy[offset] = c;
+               left--;
+               offset++;
+       }
+
+       if (left == PAGE_SIZE) {
                kfree(copy);
                return ERR_PTR(-EFAULT);
        }
-       if (size != PAGE_SIZE) {
-               if (copy_from_user(copy + size, data + size, PAGE_SIZE - size))
-                       memset(copy + size, 0, PAGE_SIZE - size);
-       }
+
        return copy;
 }