Skip to content

Commit

Permalink
x86: zimage: Sanity-check the kernel version before printing it
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
  • Loading branch information
sjg20 authored and lbmeng committed Nov 6, 2020
1 parent b73d61a commit 7c79edd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions arch/x86/lib/zimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <asm/arch/timestamp.h>
#endif
#include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/libfdt.h>

/*
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7c79edd

Please sign in to comment.