All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Fleming <matt@codeblueprint.co.uk>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	kernel-hardening@lists.openwall.com, will.deacon@arm.com,
	catalin.marinas@arm.com, mark.rutland@arm.com,
	leif.lindholm@linaro.org, keescook@chromium.org,
	linux-kernel@vger.kernel.org, stuart.yoder@freescale.com,
	bhupesh.sharma@freescale.com, arnd@arndb.de,
	marc.zyngier@arm.com, christoffer.dall@linaro.org,
	labbott@fedoraproject.org
Subject: [kernel-hardening] Re: [PATCH v4 22/22] arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness
Date: Fri, 29 Jan 2016 15:57:01 +0000	[thread overview]
Message-ID: <20160129155701.GC2611@codeblueprint.co.uk> (raw)
In-Reply-To: <1453828249-14467-23-git-send-email-ard.biesheuvel@linaro.org>

On Tue, 26 Jan, at 06:10:49PM, Ard Biesheuvel wrote:
> Since arm64 does not use a decompressor that supplies an execution
> environment where it is feasible to some extent to provide a source of
> randomness, the arm64 KASLR kernel depends on the bootloader to supply
> some random bits in the /chosen/kaslr-seed DT property upon kernel entry.
> 
> On UEFI systems, we can use the EFI_RNG_PROTOCOL, if supplied, to obtain
> some random bits. At the same time, use it to randomize the offset of the
> kernel Image in physical memory.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  arch/arm64/Kconfig                        |  5 ++
>  drivers/firmware/efi/libstub/arm-stub.c   | 40 ++++++----
>  drivers/firmware/efi/libstub/arm64-stub.c | 78 ++++++++++++++------
>  drivers/firmware/efi/libstub/fdt.c        |  9 +++
>  4 files changed, 97 insertions(+), 35 deletions(-)
 
[...]

> diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
> index cf7b7d46302a..04c9302b0ef1 100644
> --- a/drivers/firmware/efi/libstub/fdt.c
> +++ b/drivers/firmware/efi/libstub/fdt.c
> @@ -147,6 +147,15 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
>  	if (status)
>  		goto fdt_set_fail;
>  
> +	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
> +		status = efi_get_random_bytes(sys_table, sizeof(fdt_val64),
> +					      (u8 *)&fdt_val64);
> +		if (status == EFI_SUCCESS)
> +			status = fdt_setprop(fdt, node, "kaslr-seed",
> +					     &fdt_val64, sizeof(fdt_val64));
> +		else if (status != EFI_NOT_FOUND)
> +			goto fdt_set_fail;
> +	}
>  	return EFI_SUCCESS;
>  
>  fdt_set_fail:

I think you want to handle the case where fdt_setprop() fails. With
this new code you'll silently return EFI_SUCCESS even if you fail to
set "kaslr-seed".

WARNING: multiple messages have this Message-ID (diff)
From: matt@codeblueprint.co.uk (Matt Fleming)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 22/22] arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness
Date: Fri, 29 Jan 2016 15:57:01 +0000	[thread overview]
Message-ID: <20160129155701.GC2611@codeblueprint.co.uk> (raw)
In-Reply-To: <1453828249-14467-23-git-send-email-ard.biesheuvel@linaro.org>

On Tue, 26 Jan, at 06:10:49PM, Ard Biesheuvel wrote:
> Since arm64 does not use a decompressor that supplies an execution
> environment where it is feasible to some extent to provide a source of
> randomness, the arm64 KASLR kernel depends on the bootloader to supply
> some random bits in the /chosen/kaslr-seed DT property upon kernel entry.
> 
> On UEFI systems, we can use the EFI_RNG_PROTOCOL, if supplied, to obtain
> some random bits. At the same time, use it to randomize the offset of the
> kernel Image in physical memory.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  arch/arm64/Kconfig                        |  5 ++
>  drivers/firmware/efi/libstub/arm-stub.c   | 40 ++++++----
>  drivers/firmware/efi/libstub/arm64-stub.c | 78 ++++++++++++++------
>  drivers/firmware/efi/libstub/fdt.c        |  9 +++
>  4 files changed, 97 insertions(+), 35 deletions(-)
 
[...]

> diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
> index cf7b7d46302a..04c9302b0ef1 100644
> --- a/drivers/firmware/efi/libstub/fdt.c
> +++ b/drivers/firmware/efi/libstub/fdt.c
> @@ -147,6 +147,15 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
>  	if (status)
>  		goto fdt_set_fail;
>  
> +	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
> +		status = efi_get_random_bytes(sys_table, sizeof(fdt_val64),
> +					      (u8 *)&fdt_val64);
> +		if (status == EFI_SUCCESS)
> +			status = fdt_setprop(fdt, node, "kaslr-seed",
> +					     &fdt_val64, sizeof(fdt_val64));
> +		else if (status != EFI_NOT_FOUND)
> +			goto fdt_set_fail;
> +	}
>  	return EFI_SUCCESS;
>  
>  fdt_set_fail:

I think you want to handle the case where fdt_setprop() fails. With
this new code you'll silently return EFI_SUCCESS even if you fail to
set "kaslr-seed".

WARNING: multiple messages have this Message-ID (diff)
From: Matt Fleming <matt@codeblueprint.co.uk>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	kernel-hardening@lists.openwall.com, will.deacon@arm.com,
	catalin.marinas@arm.com, mark.rutland@arm.com,
	leif.lindholm@linaro.org, keescook@chromium.org,
	linux-kernel@vger.kernel.org, stuart.yoder@freescale.com,
	bhupesh.sharma@freescale.com, arnd@arndb.de,
	marc.zyngier@arm.com, christoffer.dall@linaro.org,
	labbott@fedoraproject.org
Subject: Re: [PATCH v4 22/22] arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness
Date: Fri, 29 Jan 2016 15:57:01 +0000	[thread overview]
Message-ID: <20160129155701.GC2611@codeblueprint.co.uk> (raw)
In-Reply-To: <1453828249-14467-23-git-send-email-ard.biesheuvel@linaro.org>

On Tue, 26 Jan, at 06:10:49PM, Ard Biesheuvel wrote:
> Since arm64 does not use a decompressor that supplies an execution
> environment where it is feasible to some extent to provide a source of
> randomness, the arm64 KASLR kernel depends on the bootloader to supply
> some random bits in the /chosen/kaslr-seed DT property upon kernel entry.
> 
> On UEFI systems, we can use the EFI_RNG_PROTOCOL, if supplied, to obtain
> some random bits. At the same time, use it to randomize the offset of the
> kernel Image in physical memory.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  arch/arm64/Kconfig                        |  5 ++
>  drivers/firmware/efi/libstub/arm-stub.c   | 40 ++++++----
>  drivers/firmware/efi/libstub/arm64-stub.c | 78 ++++++++++++++------
>  drivers/firmware/efi/libstub/fdt.c        |  9 +++
>  4 files changed, 97 insertions(+), 35 deletions(-)
 
[...]

> diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
> index cf7b7d46302a..04c9302b0ef1 100644
> --- a/drivers/firmware/efi/libstub/fdt.c
> +++ b/drivers/firmware/efi/libstub/fdt.c
> @@ -147,6 +147,15 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
>  	if (status)
>  		goto fdt_set_fail;
>  
> +	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
> +		status = efi_get_random_bytes(sys_table, sizeof(fdt_val64),
> +					      (u8 *)&fdt_val64);
> +		if (status == EFI_SUCCESS)
> +			status = fdt_setprop(fdt, node, "kaslr-seed",
> +					     &fdt_val64, sizeof(fdt_val64));
> +		else if (status != EFI_NOT_FOUND)
> +			goto fdt_set_fail;
> +	}
>  	return EFI_SUCCESS;
>  
>  fdt_set_fail:

I think you want to handle the case where fdt_setprop() fails. With
this new code you'll silently return EFI_SUCCESS even if you fail to
set "kaslr-seed".

  reply	other threads:[~2016-01-29 15:57 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 17:10 [kernel-hardening] [PATCH v4 00/22] arm64: implement support for KASLR Ard Biesheuvel
2016-01-26 17:10 ` Ard Biesheuvel
2016-01-26 17:10 ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 01/22] of/fdt: make memblock minimum physical address arch configurable Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 02/22] arm64: introduce KIMAGE_VADDR as the virtual base of the kernel region Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 03/22] arm64: pgtable: implement static [pte|pmd|pud]_offset variants Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 04/22] arm64: decouple early fixmap init from linear mapping Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 05/22] arm64: kvm: deal with kernel symbols outside of " Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:45   ` [kernel-hardening] " Marc Zyngier
2016-01-26 17:45     ` Marc Zyngier
2016-01-26 17:45     ` Marc Zyngier
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 06/22] arm64: add support for ioremap() block mappings Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 07/22] arm64: move kernel image to base of vmalloc area Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 08/22] arm64: add support for module PLTs Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 09/22] extable: add support for relative extables to search and sort routines Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 10/22] arm64: switch to relative exception tables Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 11/22] arm64: avoid R_AARCH64_ABS64 relocations for Image header fields Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 12/22] arm64: avoid dynamic relocations in early boot code Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 13/22] arm64: allow kernel Image to be loaded anywhere in physical memory Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 14/22] arm64: make asm/elf.h available to asm files Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:42   ` [kernel-hardening] " Mark Rutland
2016-01-26 17:42     ` Mark Rutland
2016-01-26 17:42     ` Mark Rutland
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 15/22] scripts/sortextable: add support for ET_DYN binaries Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 23:25   ` [kernel-hardening] " Kees Cook
2016-01-26 23:25     ` Kees Cook
2016-01-26 23:25     ` Kees Cook
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 16/22] kallsyms: add support for relative offsets in kallsyms address table Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 17/22] arm64: add support for building the kernel as a relocate PIE binary Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 18/22] arm64: add support for kernel ASLR Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 19/22] efi: stub: implement efi_get_random_bytes() based on EFI_RNG_PROTOCOL Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 20/22] efi: stub: add implementation of efi_random_alloc() Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 23:52   ` [kernel-hardening] " Kees Cook
2016-01-26 23:52     ` Kees Cook
2016-01-26 23:52     ` Kees Cook
2016-01-29 15:39   ` [kernel-hardening] " Matt Fleming
2016-01-29 15:39     ` Matt Fleming
2016-01-29 15:39     ` Matt Fleming
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 21/22] efi: stub: use high allocation for converted command line Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10 ` [kernel-hardening] [PATCH v4 22/22] arm64: efi: invoke EFI_RNG_PROTOCOL to supply KASLR randomness Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-26 17:10   ` Ard Biesheuvel
2016-01-29 15:57   ` Matt Fleming [this message]
2016-01-29 15:57     ` Matt Fleming
2016-01-29 15:57     ` Matt Fleming
2016-01-29 18:26 ` [kernel-hardening] Re: [PATCH v4 00/22] arm64: implement support for KASLR Catalin Marinas
2016-01-29 18:26   ` Catalin Marinas
2016-01-29 18:26   ` Catalin Marinas
2016-01-29 18:49   ` [kernel-hardening] " Ard Biesheuvel
2016-01-29 18:49     ` Ard Biesheuvel
2016-01-29 18:49     ` Ard Biesheuvel

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=20160129155701.GC2611@codeblueprint.co.uk \
    --to=matt@codeblueprint.co.uk \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=bhupesh.sharma@freescale.com \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=labbott@fedoraproject.org \
    --cc=leif.lindholm@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=stuart.yoder@freescale.com \
    --cc=will.deacon@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.