From patchwork Fri Aug 7 00:49:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11704601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1472A14DD for ; Fri, 7 Aug 2020 00:51:00 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F32012075A for ; Fri, 7 Aug 2020 00:50:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="r99u0nm0"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mz7Atwns" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F32012075A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lioAygDEiyqjFkHqetHgFGJcVsq5nBGZDDFkQWEVhMo=; b=r99u0nm02JHUKYxhZbWSN3TF5J FPrdEO1wOL7yjlX2UCpPE6ygsfZBakaN4mxZvx/j0BfbYw4GlisJ7/NSaRVeZTHkzekD/j8bXuQfR 5LzGxh/kkOyCcIN3yfZPifCKnN74YGLv1Xy2wrqjB3mqCp6I1nUQmFuksXNt0pRPECOkaY3i55Lzs qsa/uB8GVfbF8PpogzEeSbLdhA+czRPYA3alzheLW5nPr+drfZNLiNjp9Ee9TZ/fsCvXZdkbsd/LL pRbf+Aze5d9Uk4+yIm+/9jXrhQDJdmbbDTeuoi+s94IHYniFnCDQKGEAFjP3bkGNrgzedkfYb6txp 3WdfuXqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3qZN-0002AJ-85; Fri, 07 Aug 2020 00:49:13 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3qZK-00029i-ST for linux-arm-kernel@lists.infradead.org; Fri, 07 Aug 2020 00:49:11 +0000 Received: by mail-pl1-x643.google.com with SMTP id u10so246062plr.7 for ; Thu, 06 Aug 2020 17:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=PP4HULyUxqDd1w6PKeB4Lgbah/DbES+FeBMEx2CugQk=; b=mz7Atwnsv1eAoEUP9SJmYSReTl4tBjjVonCdFFIq+nDsfdmsD5vJCgDP4EsUxtLYy3 YfCX0gIm/IazZ/1DB5zdWsY9wlQS5GhI5/KgajMXgccP0usV2PSNOa7W2U/OaVZWLrSu 41JisAUqEaI7RN8Og9A0l7dL/79y/ZSiOGZlHI95x8CT18JzCJWuWwKJd3C7OKxK+TY6 yfZ5U8BgrRPvgx75joYikaYqT8odlSehyvQdBy2d6QpKEIJfD13ONSFIOH/TX+FxS2s9 r/hqVcMwDRRrJOYQXlcW1y1dsu3QsMaM/ucSiw/dA8dju97MT9JgmcB5NcPjPae7DF5v mm6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=PP4HULyUxqDd1w6PKeB4Lgbah/DbES+FeBMEx2CugQk=; b=AuBw6CWqSEmIXgvrHGvCyw169u5AXFDnHBl3JT0togwzZNk8GgMqv5F3uahiaOAUDk JJOEBWDDeERprKL7Vh4SmWb1spXUjdmcujf6HeEcKyuAZen1iHFrX3y1E22Z6Xas2LiJ voa3CHduUDbDMtjJteEieaQ4ocCagKQCXsiSl8USxfBjtCMhHCcu08+eA+l3yhj9SoG3 id3t+u3/Bfa1sB0EJau268DL+NzX69l3y0SJsf4hy7NhgMXHgIqTTaE+Ux6EjayrXSMu O3zkpW5tSQ4s0ubYmgugezyHHn3ulwrCCGiozA1REw14Sx1X2A0gU1ex7NYE8bR4FTni 1Qzw== X-Gm-Message-State: AOAM533obFENQrvjkZQgqU4vspeRBy9Y07l6ThPHbJpsDH251POs0kCM 8G+l6xDJmU2UIxuK/5pYx6k= X-Google-Smtp-Source: ABdhPJwaBXO8RAqfMUXeX+3Zhd54RJq4uQVPPDQO7c5NcpJJkuUkSlrKWgwXt83Mw3TuhF9YQVa1GQ== X-Received: by 2002:a17:90a:36a7:: with SMTP id t36mr11265340pjb.36.1596761348877; Thu, 06 Aug 2020 17:49:08 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 202sm9916655pfy.6.2020.08.06.17.49.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Aug 2020 17:49:07 -0700 (PDT) From: Guenter Roeck To: Linus Torvalds Subject: [PATCH] arm64: kaslr: Use standard early random function Date: Thu, 6 Aug 2020 17:49:04 -0700 Message-Id: <20200807004904.72893-1-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200806_204910_947195_44D31CFC X-CRM114-Status: GOOD ( 15.67 ) X-Spam-Score: 0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [groeck7[at]gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [groeck7[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Daniel_D=C3=ADaz?= , tytso@mit.edu, Catalin Marinas , linux-kernel@vger.kernel.org, Mark Brown , Qian Cai , Guenter Roeck , Will Deacon , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 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 Cc: Mark Brown Signed-off-by: Guenter Roeck Reviewed-by: Mark Rutland Reviewed-by: Mark Brown Tested-by: Mark Brown --- 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;