lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200807101723.GB72666@C02TD0UTHF1T.local>
Date:   Fri, 7 Aug 2020 11:17:23 +0100
From:   Mark Rutland <mark.rutland@....com>
To:     Guenter Roeck <linux@...ck-us.net>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Catalin Marinas <catalin.marinas@....com>,
        Will Deacon <will@...nel.org>,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        Daniel Díaz <daniel.diaz@...aro.org>,
        tytso@....edu, Qian Cai <cai@....pw>,
        Mark Brown <broonie@...nel.org>
Subject: Re: [PATCH] arm64: kaslr: Use standard early random function

Hi Guenter,

On Thu, Aug 06, 2020 at 05:49:04PM -0700, Guenter Roeck wrote:
> Commit 585524081ecd ("random: random.h should include archrandom.h, not
> the other way around") tries to fix a problem with recursive inclusion
> of linux/random.h and arch/archrandom.h for arm64. Unfortunately, this
> results in the following compile error if ARCH_RANDOM is disabled.
> 
> arch/arm64/kernel/kaslr.c: In function 'kaslr_early_init':
> arch/arm64/kernel/kaslr.c:128:6: error: implicit declaration of function
> '__early_cpu_has_rndr'; did you mean '__early_pfn_to_nid'?
> [-Werror=implicit-function-declaration]
>   if (__early_cpu_has_rndr()) {
>       ^~~~~~~~~~~~~~~~~~~~
>       __early_pfn_to_nid
> arch/arm64/kernel/kaslr.c:131:7: error: implicit declaration of function
> '__arm64_rndr' [-Werror=implicit-function-declaration]
>    if (__arm64_rndr(&raw))
>        ^~~~~~~~~~~~
> 
> Problem is that arch/archrandom.h is only included from linux/random.h if
> ARCH_RANDOM is enabled. If not, __arm64_rndr() and __early_cpu_has_rndr()
> are undeclared, causing the problem.
> 
> Use arch_get_random_seed_long_early() instead of arm64 specific functions
> to solve the problem. As a side effect of this change, the code no longer
> bypasses ARCH_RANDOM, which I consider desirable (after all, ARCH_RANDOM
> was disabled for a reason).

There's no bypass of ARCH_RANDOM; the bits KASLR depends on are empty
stubs when ARCH_RANDOM is not selected. I added the common early
functions after this code was written.

> Reported-by: Qian Cai <cai@....pw>
> Fixes: 585524081ecd ("random: random.h should include archrandom.h, not the other way around")

This is where things broke; there was no need to change kaslr.c's
include of <asm/archrandom.h>, since kaslr.c only depends on the RNDR
bits defined there./

> Fixes: 2e8e1ea88cbc ("arm64: Use v8.5-RNG entropy for KASLR seed")

I don't think this tag is necessary; this commit built and worked fine,
and there wasn't any ARCH_RANDOM bypass to speak of.

> Cc: Qian Cai <cai@....pw>
> Cc: Mark Brown <broonie@...nel.org>
> Signed-off-by: Guenter Roeck <linux@...ck-us.net>

This patch itself looks fine, but as above I think the commit message is
misleading w.r.t. bypassing ARCH_RANDOM, and the second fixes tag isn't
necessary.

With those bits gone:

Reviewed-by: Mark Rutland <mark.rutland@....com>

Mark.

> ---
>  arch/arm64/kernel/kaslr.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
> index 9ded4237e1c1..b181e0544b79 100644
> --- a/arch/arm64/kernel/kaslr.c
> +++ b/arch/arm64/kernel/kaslr.c
> @@ -84,6 +84,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
>  	void *fdt;
>  	u64 seed, offset, mask, module_range;
>  	const u8 *cmdline, *str;
> +	unsigned long raw;
>  	int size;
>  
>  	/*
> @@ -122,15 +123,12 @@ u64 __init kaslr_early_init(u64 dt_phys)
>  	}
>  
>  	/*
> -	 * Mix in any entropy obtainable architecturally, open coded
> -	 * since this runs extremely early.
> +	 * Mix in any entropy obtainable architecturally if enabled
> +	 * and supported.
>  	 */
> -	if (__early_cpu_has_rndr()) {
> -		unsigned long raw;
>  
> -		if (__arm64_rndr(&raw))
> -			seed ^= raw;
> -	}
> +	if (arch_get_random_seed_long_early(&raw))
> +		seed ^= raw;
>  
>  	if (!seed) {
>  		kaslr_status = KASLR_DISABLED_NO_SEED;
> -- 
> 2.17.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ