aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-11-04 09:59:14 -0700
committerBin Meng <bmeng.cn@gmail.com>2020-11-06 09:51:34 +0800
commit7c79eddbec32d8258df701d95d8b432f9835110b (patch)
treeede22c32cfb03446f3a5858bae0532f747f9b5bc
parentb73d61a5565c3ab9e207a288186049806ce13e1b (diff)
downloadu-boot-7c79eddbec32d8258df701d95d8b432f9835110b.tar.gz
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: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
-rw-r--r--arch/x86/lib/zimage.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 7418c9a5fe..d425ded596 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;
}