linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	"Daniel Díaz" <daniel.diaz@linaro.org>,
	tytso@mit.edu, "Guenter Roeck" <linux@roeck-us.net>,
	"Qian Cai" <cai@lca.pw>, "Mark Brown" <broonie@kernel.org>
Subject: [PATCH] arm64: kaslr: Use standard early random function
Date: Thu,  6 Aug 2020 17:49:04 -0700	[thread overview]
Message-ID: <20200807004904.72893-1-linux@roeck-us.net> (raw)

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).

Reported-by: Qian Cai <cai@lca.pw>
Fixes: 585524081ecd ("random: random.h should include archrandom.h, not the other way around")
Fixes: 2e8e1ea88cbc ("arm64: Use v8.5-RNG entropy for KASLR seed")
Cc: Qian Cai <cai@lca.pw>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 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


             reply	other threads:[~2020-08-07  0:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07  0:49 Guenter Roeck [this message]
2020-08-07  2:17 ` [PATCH] arm64: kaslr: Use standard early random function Linus Torvalds
2020-08-07 10:17 ` Mark Rutland
2020-08-07 14:41   ` Guenter Roeck
2020-08-07 11:09 ` Mark Brown

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=20200807004904.72893-1-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=broonie@kernel.org \
    --cc=cai@lca.pw \
    --cc=catalin.marinas@arm.com \
    --cc=daniel.diaz@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=will@kernel.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).