diff options
author | Alexandru Elisei <alexandru.elisei@arm.com> | 2021-09-23 15:45:04 +0100 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2021-10-12 09:40:46 +0100 |
commit | 5303f0964ffdc4940e323e1e28d28cd1e0172aa3 (patch) | |
tree | e345434fcab2baeff9154470d41a7e1d2cc97079 | |
parent | 5613ae26b9989dec93869090b426c99913ea9ab4 (diff) | |
download | kvmtool-5303f0964ffdc4940e323e1e28d28cd1e0172aa3.tar.gz |
arm64: Use the default offset when the kernel image magic is not found
Commit fd0a05bd27dd ("arm64: Obtain text offset from kernel image") added
support for getting the kernel offset from the kernel header. The code
checks for the kernel header magic number, and if not found, prints a
warning and continues searching for the kernel offset in the image.
The -k/--kernel option can be used to load things which are not a Linux
kernel, but behave like one, like a kvm-unit-tests test. The tests don't
have a valid kernel header, and because kvmtool insists on searching for
the offset, creating a virtual machine can fail with this message:
$ ./vm run -c2 -m256 -k ../kvm-unit-tests/arm/cache.flat
# lkvm run -k ../kvm-unit-tests/arm/cache.flat -m 256 -c 2 --name guest-7529
Warning: Kernel image magic not matching
Warning: unable to translate host address 0x910100a502a00085 to guest
Fatal: kernel image too big to contain in guest memory.
The host address is a random number read from the test binary from the
location where text_offset is found in the kernel header. Before the
commit, the test was executing just fine:
$ ./vm run -c2 -m256 -k ../kvm-unit-tests/arm/cache.flat
# lkvm run -k ../kvm-unit-tests/arm/cache.flat -m 256 -c 2 --name guest-8105
INFO: IDC-DIC: dcache clean to PoU required
INFO: IDC-DIC: icache invalidation to PoU required
PASS: IDC-DIC: code generation
SUMMARY: 1 tests
Change kvm__arch_get_kern_offset() so it returns the default text_offset
value if the kernel image magic number is not found, making it possible
again to use something other than a Linux kernel with --kernel.
Reported-by: Vivek Kumar Gautam <vivek.gautam@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Link: https://lore.kernel.org/r/20210923144505.60776-10-alexandru.elisei@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | arm/aarch64/kvm.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 4e66a22e..b38365fb 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -35,8 +35,10 @@ unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd) lseek(fd, cur_offset, SEEK_SET); - if (memcmp(&header.magic, ARM64_IMAGE_MAGIC, sizeof(header.magic))) - pr_warning("Kernel image magic not matching"); + if (memcmp(&header.magic, ARM64_IMAGE_MAGIC, sizeof(header.magic))) { + warn_str = "Kernel image magic not matching"; + goto fail; + } if (le64_to_cpu(header.image_size)) return le64_to_cpu(header.text_offset); |