From: Jason Yan <yanaijie@huawei.com>
To: Christophe Leroy <christophe.leroy@c-s.fr>, <mpe@ellerman.id.au>,
<linuxppc-dev@lists.ozlabs.org>, <diana.craciun@nxp.com>,
<benh@kernel.crashing.org>, <paulus@samba.org>,
<npiggin@gmail.com>, <keescook@chromium.org>,
<kernel-hardening@lists.openwall.com>
Cc: wangkefeng.wang@huawei.com, linux-kernel@vger.kernel.org,
jingxiangfeng@huawei.com, zhaohongjiang@huawei.com,
thunder.leizhen@huawei.com, fanchengyang@huawei.com,
yebin10@huawei.com
Subject: Re: [PATCH v4 07/10] powerpc/fsl_booke/32: randomize the kernel image offset
Date: Wed, 7 Aug 2019 11:16:19 +0800 [thread overview]
Message-ID: <16e058a4-9794-6998-46e4-0e63b9fce7e3@huawei.com> (raw)
In-Reply-To: <3edec35b-8d61-07ff-558d-2d7e0c28a0e2@c-s.fr>
On 2019/8/6 15:56, Christophe Leroy wrote:
>
>
> Le 05/08/2019 à 08:43, Jason Yan a écrit :
>> After we have the basic support of relocate the kernel in some
>> appropriate place, we can start to randomize the offset now.
>>
>> Entropy is derived from the banner and timer, which will change every
>> build and boot. This not so much safe so additionally the bootloader may
>> pass entropy via the /chosen/kaslr-seed node in device tree.
>>
>> We will use the first 512M of the low memory to randomize the kernel
>> image. The memory will be split in 64M zones. We will use the lower 8
>> bit of the entropy to decide the index of the 64M zone. Then we chose a
>> 16K aligned offset inside the 64M zone to put the kernel in.
>>
>> KERNELBASE
>>
>> |--> 64M <--|
>> | |
>> +---------------+ +----------------+---------------+
>> | |....| |kernel| | |
>> +---------------+ +----------------+---------------+
>> | |
>> |-----> offset <-----|
>>
>> kimage_vaddr
>>
>> We also check if we will overlap with some areas like the dtb area, the
>> initrd area or the crashkernel area. If we cannot find a proper area,
>> kaslr will be disabled and boot from the original kernel.
>>
>> Signed-off-by: Jason Yan <yanaijie@huawei.com>
>> Cc: Diana Craciun <diana.craciun@nxp.com>
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Cc: Christophe Leroy <christophe.leroy@c-s.fr>
>> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> Cc: Paul Mackerras <paulus@samba.org>
>> Cc: Nicholas Piggin <npiggin@gmail.com>
>> Cc: Kees Cook <keescook@chromium.org>
>> Reviewed-by: Diana Craciun <diana.craciun@nxp.com>
>> Tested-by: Diana Craciun <diana.craciun@nxp.com>
>
> Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>
>
Thanks for your help,
> One small comment below
>
>> ---
>> arch/powerpc/kernel/kaslr_booke.c | 322 +++++++++++++++++++++++++++++-
>> 1 file changed, 320 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/powerpc/kernel/kaslr_booke.c
>> b/arch/powerpc/kernel/kaslr_booke.c
>> index 30f84c0321b2..97250cad71de 100644
>> --- a/arch/powerpc/kernel/kaslr_booke.c
>> +++ b/arch/powerpc/kernel/kaslr_booke.c
>> @@ -23,6 +23,8 @@
>> #include <linux/delay.h>
>> #include <linux/highmem.h>
>> #include <linux/memblock.h>
>> +#include <linux/libfdt.h>
>> +#include <linux/crash_core.h>
>> #include <asm/pgalloc.h>
>> #include <asm/prom.h>
>> #include <asm/io.h>
>> @@ -34,15 +36,329 @@
>> #include <asm/machdep.h>
>> #include <asm/setup.h>
>> #include <asm/paca.h>
>> +#include <asm/kdump.h>
>> #include <mm/mmu_decl.h>
>> +#include <generated/compile.h>
>> +#include <generated/utsrelease.h>
>> +
>> +#ifdef DEBUG
>> +#define DBG(fmt...) printk(KERN_ERR fmt)
>> +#else
>> +#define DBG(fmt...)
>> +#endif
>> +
>> +struct regions {
>> + unsigned long pa_start;
>> + unsigned long pa_end;
>> + unsigned long kernel_size;
>> + unsigned long dtb_start;
>> + unsigned long dtb_end;
>> + unsigned long initrd_start;
>> + unsigned long initrd_end;
>> + unsigned long crash_start;
>> + unsigned long crash_end;
>> + int reserved_mem;
>> + int reserved_mem_addr_cells;
>> + int reserved_mem_size_cells;
>> +};
>> extern int is_second_reloc;
>> +/* Simplified build-specific string for starting entropy. */
>> +static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@"
>> + LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION;
>> +
>> +static __init void kaslr_get_cmdline(void *fdt)
>> +{
>> + int node = fdt_path_offset(fdt, "/chosen");
>> +
>> + early_init_dt_scan_chosen(node, "chosen", 1, boot_command_line);
>> +}
>> +
>> +static unsigned long __init rotate_xor(unsigned long hash, const void
>> *area,
>> + size_t size)
>> +{
>> + size_t i;
>> + unsigned long *ptr = (unsigned long *)area;
>
> As area is a void *, this cast shouldn't be necessary. Or maybe it is
> necessary because it discards the const ?
>
It's true the cast is not necessary. The ptr can be made const and then
remove the cast.
> Christophe
>
next prev parent reply other threads:[~2019-08-07 3:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-05 6:43 [PATCH v4 00/10] implement KASLR for powerpc/fsl_booke/32 Jason Yan
2019-08-05 6:43 ` [PATCH v4 01/10] powerpc: unify definition of M_IF_NEEDED Jason Yan
2019-08-05 6:43 ` [PATCH v4 02/10] powerpc: move memstart_addr and kernstart_addr to init-common.c Jason Yan
2019-08-05 6:43 ` [PATCH v4 03/10] powerpc: introduce kimage_vaddr to store the kernel base Jason Yan
2019-08-05 6:43 ` [PATCH v4 04/10] powerpc/fsl_booke/32: introduce create_tlb_entry() helper Jason Yan
2019-08-05 6:43 ` [PATCH v4 05/10] powerpc/fsl_booke/32: introduce reloc_kernel_entry() helper Jason Yan
2019-08-05 6:43 ` [PATCH v4 06/10] powerpc/fsl_booke/32: implement KASLR infrastructure Jason Yan
2019-08-06 7:52 ` Christophe Leroy
2019-08-05 6:43 ` [PATCH v4 07/10] powerpc/fsl_booke/32: randomize the kernel image offset Jason Yan
2019-08-06 7:56 ` Christophe Leroy
2019-08-07 3:16 ` Jason Yan [this message]
2019-08-05 6:43 ` [PATCH v4 08/10] powerpc/fsl_booke/kaslr: clear the original kernel if randomized Jason Yan
2019-08-05 6:43 ` [PATCH v4 09/10] powerpc/fsl_booke/kaslr: support nokaslr cmdline parameter Jason Yan
2019-08-06 7:59 ` Christophe Leroy
2019-08-07 3:22 ` Jason Yan
2019-08-05 6:43 ` [PATCH v4 10/10] powerpc/fsl_booke/kaslr: dump out kernel offset information on panic Jason Yan
2019-08-06 1:29 ` [PATCH v4 00/10] implement KASLR for powerpc/fsl_booke/32 Jason Yan
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=16e058a4-9794-6998-46e4-0e63b9fce7e3@huawei.com \
--to=yanaijie@huawei.com \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@c-s.fr \
--cc=diana.craciun@nxp.com \
--cc=fanchengyang@huawei.com \
--cc=jingxiangfeng@huawei.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=paulus@samba.org \
--cc=thunder.leizhen@huawei.com \
--cc=wangkefeng.wang@huawei.com \
--cc=yebin10@huawei.com \
--cc=zhaohongjiang@huawei.com \
/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