]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - init/do_mounts.c
KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks
[linux.git] / init / do_mounts.c
index f55cbd9cb8183f9a36b4da4e2f59c5a1720621c3..0ae9cc22f2ae255c55337812b121a9a2d2eec9ca 100644 (file)
@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs,
                                 const int flags, const void *data)
 {
        struct super_block *s;
-       char *data_page;
-       struct page *p;
+       struct page *p = NULL;
+       char *data_page = NULL;
        int ret;
 
-       /* do_mount() requires a full page as fifth argument */
-       p = alloc_page(GFP_KERNEL);
-       if (!p)
-               return -ENOMEM;
-
-       data_page = page_address(p);
-       strncpy(data_page, data, PAGE_SIZE - 1);
+       if (data) {
+               /* do_mount() requires a full page as fifth argument */
+               p = alloc_page(GFP_KERNEL);
+               if (!p)
+                       return -ENOMEM;
+               data_page = page_address(p);
+               /* zero-pad. do_mount() will make sure it's terminated */
+               strncpy(data_page, data, PAGE_SIZE);
+       }
 
        ret = do_mount(name, "/root", fs, flags, data_page);
        if (ret)
@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs,
               MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
 
 out:
-       put_page(p);
+       if (p)
+               put_page(p);
        return ret;
 }