From: takahiro.akashi@linaro.org (AKASHI Takahiro)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v11 10/15] arm64: kexec_file: allow for loading Image-format kernel
Date: Fri, 20 Jul 2018 15:14:36 +0900 [thread overview]
Message-ID: <20180720061434.GK11258@linaro.org> (raw)
In-Reply-To: <bfbb8d3f-6d7b-3ebb-d805-15b89c55aaeb@arm.com>
On Wed, Jul 18, 2018 at 05:47:50PM +0100, James Morse wrote:
> Hi Akashi,
>
> On 11/07/18 08:41, AKASHI Takahiro wrote:
> > This patch provides kexec_file_ops for "Image"-format kernel. In this
> > implementation, a binary is always loaded with a fixed offset identified
> > in text_offset field of its header.
> >
> > Regarding signature verification for trusted boot, this patch doesn't
> > contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later
> > in this series, but file-attribute-based verification is still a viable
> > option by enabling IMA security subsystem.
> >
> > You can sign(label) a to-be-kexec'ed kernel image on target file system
> > with:
> > $ evmctl ima_sign --key /path/to/private_key.pem Image
> >
> > On live system, you must have IMA enforced with, at least, the following
> > security policy:
> > "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig"
> >
> > See more details about IMA here:
> > https://sourceforge.net/p/linux-ima/wiki/Home/
>
> This looks useful to set a keys/signature/policy for a kernel that wasn't built
> to enforce signatures at compile time, so its a good thing to have from a
> single-image perspective.
>
> I haven't managed to get IMA working to test this, but its all done by the kexec
> core code, so I don't think we're missing anything.
>
>
> > diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> > new file mode 100644
> > index 000000000000..a47cf9bc699e
> > --- /dev/null
> > +++ b/arch/arm64/kernel/kexec_image.c
>
> > +static int image_probe(const char *kernel_buf, unsigned long kernel_len)
> > +{
> > + const struct arm64_image_header *h;
> > +
> > + h = (const struct arm64_image_header *)(kernel_buf);
> > +
> > + if (!h || (kernel_len < sizeof(*h)) ||
>
> > + !memcmp(&h->magic, ARM64_MAGIC, sizeof(ARM64_MAGIC)))
>
> Doesn't memcmp() return 0 if the memory regions are the same?
> This would always match the correct magic, rejecting the image.
>
> That's not whats happening, as kexec-file works, so this never matches anything.
>
> sizeof(ARM64_MAGIC) includes the null terminator, but this sequence is output in
> head.S using '.ascii' which doesn't include the terminator, (otherwise it
> wouldn't fit in the 4byte magic field). The memcmp() here is also consuming the
> least significant bytes of the next field.
>
> I think this line should be:
> | memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic)))
Absolutely you're right!
>
> > +static void *image_load(struct kimage *image,
> > + char *kernel, unsigned long kernel_len,
> > + char *initrd, unsigned long initrd_len,
> > + char *cmdline, unsigned long cmdline_len)
>
> > + kbuf.buffer = kernel;
> > + kbuf.bufsz = kernel_len;
> > + kbuf.memsz = le64_to_cpu(h->image_size);
> > + text_offset = le64_to_cpu(h->text_offset);
> > + kbuf.buf_align = SZ_2M;
>
> Nit: MIN_KIMG_ALIGN ?
OK.
>
> > + /* Adjust kernel segment with TEXT_OFFSET */
> > + kbuf.memsz += text_offset;
> > +
> > + ret = kexec_add_buffer(&kbuf);
> > + if (ret)
> > + goto out;
>
> You just return in the error cases above but here you goto ... the return
> statement at the end. Seems a bit odd.
Will fix it.
>
> With the memcmp() thing fixed:
> Reviewed-by: James Morse <james.morse@arm.com>
Always appreciate you reviewing.
-Takahiro AKASHI
>
> Thanks,
>
> James
next prev parent reply other threads:[~2018-07-20 6:14 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-11 7:41 [PATCH v11 00/15] subject: arm64: kexec: add kexec_file_load() support AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 01/15] asm-generic: add kexec_file_load system call to unistd.h AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 02/15] kexec_file: make kexec_image_post_load_cleanup_default() global AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 03/15] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() AKASHI Takahiro
2018-07-14 1:52 ` Dave Young
2018-07-16 11:04 ` James Morse
2018-07-16 12:24 ` Dave Young
2018-07-17 5:31 ` AKASHI Takahiro
2018-07-17 7:49 ` Dave Young
2018-07-18 5:38 ` AKASHI Takahiro
2018-07-18 6:13 ` Dave Young
2018-07-18 6:40 ` AKASHI Takahiro
2018-07-18 6:45 ` Dave Young
2018-07-20 5:33 ` AKASHI Takahiro
2018-07-20 5:57 ` Dave Young
2018-07-20 6:25 ` AKASHI Takahiro
2018-07-16 12:26 ` Dave Young
2018-07-18 16:52 ` James Morse
2018-07-19 2:23 ` Dave Young
2018-07-11 7:41 ` [PATCH v11 04/15] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 05/15] of/fdt: add helper functions for handling properties AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 06/15] arm64: add image head flag definitions AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 07/15] arm64: cpufeature: add MMFR0 helper functions AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 08/15] arm64: enable KEXEC_FILE config AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 09/15] arm64: kexec_file: load initrd and device-tree AKASHI Takahiro
2018-07-17 16:57 ` James Morse
2018-07-18 5:56 ` AKASHI Takahiro
2018-07-11 7:41 ` [PATCH v11 10/15] arm64: kexec_file: allow for loading Image-format kernel AKASHI Takahiro
2018-07-18 16:47 ` James Morse
2018-07-20 6:14 ` AKASHI Takahiro [this message]
2018-07-11 7:41 ` [PATCH v11 11/15] arm64: kexec_file: add crash dump support AKASHI Takahiro
2018-07-18 16:50 ` James Morse
2018-07-23 5:39 ` AKASHI Takahiro
2018-07-23 17:04 ` James Morse
2018-07-11 7:42 ` [PATCH v11 12/15] arm64: kexec_file: invoke the kernel without purgatory AKASHI Takahiro
2018-07-11 7:42 ` [PATCH v11 13/15] include: pe.h: remove message[] from mz header definition AKASHI Takahiro
2018-07-11 7:42 ` [PATCH v11 14/15] arm64: kexec_file: add kernel signature verification support AKASHI Takahiro
2018-07-11 7:42 ` [PATCH v11 15/15] arm64: kexec_file: add kaslr support AKASHI Takahiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180720061434.GK11258@linaro.org \
--to=takahiro.akashi@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).