diff mbox series

[03/12] x86: zimage: Sanity-check the kernel version before printing it

Message ID 20200928004624.1652803-4-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series Various minor patches | expand

Commit Message

Simon Glass Sept. 28, 2020, 12:46 a.m. UTC
With Chrome OS the kernel setup block is stored in a separate place from
the kernel, so it is not possible to access the kernel version string.
At present, garbage is printed.

Add a sanity check to avoid this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/lib/zimage.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Bin Meng Oct. 16, 2020, 5:59 a.m. UTC | #1
On Mon, Sep 28, 2020 at 8:46 AM Simon Glass <sjg@chromium.org> wrote:
>
> With Chrome OS the kernel setup block is stored in a separate place from
> the kernel, so it is not possible to access the kernel version string.
> At present, garbage is printed.
>
> Add a sanity check to avoid this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/x86/lib/zimage.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox series

Patch

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 7418c9a5fed..d425ded596d 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -31,6 +31,7 @@ 
 #include <asm/arch/timestamp.h>
 #endif
 #include <linux/compiler.h>
+#include <linux/ctype.h>
 #include <linux/libfdt.h>
 
 /*
@@ -175,11 +176,19 @@  static const char *get_kernel_version(struct boot_params *params,
 {
 	struct setup_header *hdr = &params->hdr;
 	int bootproto;
+	const char *s, *end;
 
 	bootproto = get_boot_protocol(hdr, false);
 	if (bootproto < 0x0200 || hdr->setup_sects < 15)
 		return NULL;
 
+	/* sanity-check the kernel version in case it is missing */
+	for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s;
+	     s++) {
+		if (!isprint(*s))
+			return NULL;
+	}
+
 	return kernel_base + hdr->kernel_version + 0x200;
 }