Skip to content

Commit 7de7de7

Browse files
committed
Fix root mounting with no mount options
The "trivial conversion" in commit cccaa5e ("init: use do_mount() instead of ksys_mount()") was totally broken, since it didn't handle the case of a NULL mount data pointer. And while I had "tested" it (and presumably Dominik had too) that bug was hidden by me having options. Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Arnd Bergmann <arnd@arndb.de> Reported-by: Ondřej Jirman <megi@xff.cz> Reported-by: Guenter Roeck <linux@roeck-us.net> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> Reported-and-tested-by: Borislav Petkov <bp@suse.de> Tested-by: Chris Clayton <chris2553@googlemail.com> Tested-by: Eric Biggers <ebiggers@kernel.org> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Guido Günther <agx@sigxcpu.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d1eef1c commit 7de7de7

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎init/do_mounts.c‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs,
391391
const int flags, const void *data)
392392
{
393393
struct super_block *s;
394-
char *data_page;
395-
struct page *p;
394+
struct page *p = NULL;
395+
char *data_page = NULL;
396396
int ret;
397397

398-
/* do_mount() requires a full page as fifth argument */
399-
p = alloc_page(GFP_KERNEL);
400-
if (!p)
401-
return -ENOMEM;
402-
403-
data_page = page_address(p);
404-
strncpy(data_page, data, PAGE_SIZE - 1);
398+
if (data) {
399+
/* do_mount() requires a full page as fifth argument */
400+
p = alloc_page(GFP_KERNEL);
401+
if (!p)
402+
return -ENOMEM;
403+
data_page = page_address(p);
404+
/* zero-pad. do_mount() will make sure it's terminated */
405+
strncpy(data_page, data, PAGE_SIZE);
406+
}
405407

406408
ret = do_mount(name, "/root", fs, flags, data_page);
407409
if (ret)
@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs,
417419
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
418420

419421
out:
420-
put_page(p);
422+
if (p)
423+
put_page(p);
421424
return ret;
422425
}
423426

0 commit comments

Comments
 (0)