Commit 7c79eddb authored by Simon Glass's avatar Simon Glass Committed by Bin Meng
Browse files

x86: zimage: Sanity-check the kernel version before printing it



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: default avatarSimon Glass <sjg@chromium.org>
Reviewed-by: default avatarBin Meng <bmeng.cn@gmail.com>
parent b73d61a5
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <asm/arch/timestamp.h> #include <asm/arch/timestamp.h>
#endif #endif
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/libfdt.h> #include <linux/libfdt.h>
/* /*
...@@ -175,11 +176,19 @@ static const char *get_kernel_version(struct boot_params *params, ...@@ -175,11 +176,19 @@ static const char *get_kernel_version(struct boot_params *params,
{ {
struct setup_header *hdr = &params->hdr; struct setup_header *hdr = &params->hdr;
int bootproto; int bootproto;
const char *s, *end;
bootproto = get_boot_protocol(hdr, false); bootproto = get_boot_protocol(hdr, false);
if (bootproto < 0x0200 || hdr->setup_sects < 15) if (bootproto < 0x0200 || hdr->setup_sects < 15)
return NULL; 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; return kernel_base + hdr->kernel_version + 0x200;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment