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 <[email protected]> Cc: Arnd Bergmann <[email protected]> Reported-by: Ondřej Jirman <[email protected]> Reported-by: Guenter Roeck <[email protected]> Reported-by: Naresh Kamboju <[email protected]> Reported-and-tested-by: Borislav Petkov <[email protected]> Tested-by: Chris Clayton <[email protected]> Tested-by: Eric Biggers <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Tested-by: Guido Günther <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d1eef1c commit 7de7de7

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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)