linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Chen Yu <yu.c.chen@intel.com>, Chen Yu <yu.chen.surf@gmail.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org
Subject: [RFC PATCH 1/3] bootconfig: Use hexadecimal ASCII string for size and checksum
Date: Thu, 19 Nov 2020 23:31:42 +0900	[thread overview]
Message-ID: <160579630249.503380.8122135672657958396.stgit@devnote2> (raw)
In-Reply-To: <160579629161.503380.9118263439060046721.stgit@devnote2>

To make the bootconfig format more platform independent, use
8-bytes hexadecimal ASCII string for size and checksum field
in the footer. This will allow us to apply bootconfig to the
cross build initrd without caring the endianness.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 init/main.c |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/init/main.c b/init/main.c
index 20baced721ad..b82f23cff709 100644
--- a/init/main.c
+++ b/init/main.c
@@ -267,8 +267,8 @@ early_param("loglevel", loglevel);
 static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
 {
 	u32 size, csum;
+	char buf[9];
 	char *data;
-	u32 *hdr;
 	int i;
 
 	if (!initrd_end)
@@ -287,11 +287,21 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
 	return NULL;
 
 found:
-	hdr = (u32 *)(data - 8);
-	size = hdr[0];
-	csum = hdr[1];
+	buf[8] = '\0';
+	data -= 8;
+	memcpy(buf, data, 8);
+	if (kstrtou32(buf, 16, &csum) != 0) {
+		pr_err("bootconfig checksum field is invalid\n");
+		return NULL;
+	}
+	data -= 8;
+	memcpy(buf, data, 8);
+	if (kstrtou32(buf, 16, &size) != 0) {
+		pr_err("bootconfig size field is invalid\n");
+		return NULL;
+	}
+	data -= size;
 
-	data = ((void *)hdr) - size;
 	if ((unsigned long)data < initrd_start) {
 		pr_err("bootconfig size %d is greater than initrd size %ld\n",
 			size, initrd_end - initrd_start);


  reply	other threads:[~2020-11-19 14:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19 14:31 [RFC PATCH 0/3] bootconfig: Use hexadecimal ASCII string for size and checksum Masami Hiramatsu
2020-11-19 14:31 ` Masami Hiramatsu [this message]
2020-11-19 14:31 ` [RFC PATCH 2/3] tools/bootconfig: " Masami Hiramatsu
2020-11-19 14:32 ` [RFC PATCH 3/3] docs: bootconfig: " Masami Hiramatsu
2020-11-19 17:36 ` [RFC PATCH 0/3] " Linus Torvalds
2020-11-19 17:42   ` Steven Rostedt
2020-11-19 23:58     ` Masami Hiramatsu

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=160579630249.503380.8122135672657958396.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=yu.c.chen@intel.com \
    --cc=yu.chen.surf@gmail.com \
    /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).