How to extract linux kernel version information from a kernel image?

From: Raphael Gianotti
Date: Fri Sep 18 2020 - 15:48:49 EST


Hi,

I have been investigating a way to extract the version strong from a kernel image (e.g., vmlinux). The version string I've been looking at is essentially the linux_banner symbol.

We'll use IMA to measure the version string on the kexec system call, providing a way for an attestation service, for instance, to attest to what version of the kernel is running on the client.

I haven't found a way to extract the version from the image that isn't simply searching the whole image for it. I was hoping someone here may be able to point me to a better approach to retrieve the linux_banner symbol value from an image or  any existing kernel code that does similar parsing.

If that matters for any suggestions, my current focus is on ARM64 images (if the code ends up having to be arch specific).

Thanks,

-Raphael