linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Dominik Brodowski <linux@dominikbrodowski.net>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Date: Sun, 15 Dec 2019 19:50:23 -0800	[thread overview]
Message-ID: <CAHk-=wh8VLe3AEKhz=1bzSO=1fv4EM71EhufxuC=Gp=+bLhXoA@mail.gmail.com> (raw)
In-Reply-To: <20191216013536.5wyvq4vjv5efd35n@core.my.home>

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

On Sun, Dec 15, 2019 at 5:35 PM Ondřej Jirman <megi@xff.cz> wrote:
>
> Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000

Duh. So much for the trivial obvious conversion.

It didn't take "data might be NULL" into account.

A patch like this, perhaps? Untested..

               Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1201 bytes --]

 init/do_mounts.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index f55cbd9cb818..d204f605dbce 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -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);
+		strncpy(data_page, data, PAGE_SIZE - 1);
+		data_page[PAGE_SIZE - 1] = '\0';
+	}
 
 	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;
 }
 

  parent reply	other threads:[~2019-12-16  3:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 13:57 [PATCH 0/3] use do_mount() instead of ksys_mount() Dominik Brodowski
2019-12-12 13:57 ` [PATCH 1/3] devtmpfs: " Dominik Brodowski
2019-12-12 13:57 ` [PATCH 2/3] initrd: " Dominik Brodowski
2019-12-12 13:57 ` [PATCH 3/3] init: " Dominik Brodowski
2019-12-16  1:35   ` Ondřej Jirman
2019-12-16  1:36     ` Ondřej Jirman
2019-12-16  3:50     ` Linus Torvalds [this message]
2019-12-16  5:13       ` Eric Biggers
2019-12-16 13:21         ` Geert Uytterhoeven
2019-12-16 15:04       ` Guenter Roeck
2019-12-16 15:53       ` Guido Günther
2019-12-16 21:12   ` Nick Desaulniers
2019-12-17  6:38     ` Dominik Brodowski
2019-12-17 18:04       ` Nick Desaulniers
2019-12-12 17:11 ` [PATCH 0/3] " Linus Torvalds
2019-12-12 18:37   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=wh8VLe3AEKhz=1bzSO=1fv4EM71EhufxuC=Gp=+bLhXoA@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=mingo@kernel.org \
    --cc=rafael@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).