Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1515684ybm; Thu, 23 May 2019 02:19:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsqceUFK5JOIXTFFZAIaK3iR/eqadZnRHrXv45NmF9iYh28D1QhxR4a+JSDgpBi5ug1l1j X-Received: by 2002:a65:450b:: with SMTP id n11mr53775126pgq.174.1558603157321; Thu, 23 May 2019 02:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558603157; cv=none; d=google.com; s=arc-20160816; b=dHL9kWrelTtczRy1+dcDNwfuT2i/TBPtPntWrbtTXlCzAXKh92NKs1bke5l0aE9O/y SWDaSr/XXWNzBEEyLnhfRtXxnbgJ7obXebKKxSU+RFgBNmYp9o9FA8yupygK8Cluf1hs gXdT6WzOvlK5UCJF4rGbTiPzZLJmCuGqfoPZRgjrx1N3vJ0Q8SUMtrTCMB/j0/MklqR6 fPnowTAb299tGsK34BoZaVGZ41jR89F+JwcCtCfhZHDg5q2O0OhuyoHnCHstmggJD5sS A50zrvd74Ojci0WhjNu8mL38Y9B94scIDasj/tQaeTQ9vn7h24Ird09OrC5BKONIcX2k Bm1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=WV1l0y+w1G7wV7a7YSnqBda23paNM5TQ8VVqdjPi5qQ=; b=f24QZTZ2qcB6fVhk60PjMOhcms8bs5se4GtDqOIIMZpEVJUISaRmFCnSanHZVIVe99 GUho7jrSfh34qJmLA+NxuhjJEW16lI3/c+3nLcR7i39Z9OL7dxq9PnzTcM8Z3JYt1rRA 9u2i9SqH+T0iYoKK+6rU6bZ4iN8PeJ3eclBklu9t8Dy7sE2KTsYwqsHC/AA4o6Ms94uM m+u+V/dyqP9COyeNwJgma6GBoIQnjD+peoKa6G45g418PoIfY6L3eSpKknMfJ2d2iqxo nssP1RjLQOogqb6VugLgLJdMEDA2IneHGNxZp7EY9JjjzeNnU4kfczvR5tDNsjBGSVF/ pZSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si32131865pfb.74.2019.05.23.02.19.02; Thu, 23 May 2019 02:19:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730111AbfEWJRy (ORCPT + 99 others); Thu, 23 May 2019 05:17:54 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41100 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfEWJRy (ORCPT ); Thu, 23 May 2019 05:17:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CE3FC341; Thu, 23 May 2019 02:17:53 -0700 (PDT) Received: from e111045-lin.cambridge.arm.com (unknown [10.1.39.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3827F3F718; Thu, 23 May 2019 02:17:52 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: marc.zyngier@arm.com, james.morse@arm.com, will.deacon@arm.com, guillaume.gardet@arm.com, mark.rutland@arm.com, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: [PATCH] arm64/kernel: kaslr: reduce module randomization range to 2 GB Date: Thu, 23 May 2019 10:17:37 +0100 Message-Id: <20190523091737.18797-1-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit 7290d5809571 ("module: use relative references for __ksymtab entries") updated the ksymtab handling of some KASLR capable architectures so that ksymtab entries are emitted as pairs of 32-bit relative references. This reduces the size of the entries, but more importantly, it gets rid of statically assigned absolute addresses, which require fixing up at boot time if the kernel is self relocating (which takes a 24 byte RELA entry for each member of the ksymtab struct). Since ksymtab entries are always part of the same module as the symbol they export, it was assumed at the time that a 32-bit relative reference is always sufficient to capture the offset between a ksymtab entry and its target symbol. Unfortunately, this is not always true: in the case of per-CPU variables, a per-CPU variable's base address (which usually differs from the actual address of any of its per-CPU copies) is allocated in the vicinity of the ..data.percpu section in the core kernel (i.e., in the per-CPU reserved region which follows the section containing the core kernel's statically allocated per-CPU variables). Since we randomize the module space over a 4 GB window covering the core kernel (based on the -/+ 4 GB range of an ADRP/ADD pair), we may end up putting the core kernel out of the -/+ 2 GB range of 32-bit relative references of module ksymtab entries that refer to per-CPU variables. So reduce the module randomization range a bit further. We lose 1 bit of randomization this way, but this is something we can tolerate. Cc: # v4.19+ Signed-off-by: Ard Biesheuvel --- This supersedes module/ksymtab: use 64-bit relative reference for target symbol x86/tools: deal with 64-bit relative relocations for per-CPU symbols and is complemented by arm64/module: deal with ambiguity in PRELxx relocation ranges arch/arm64/kernel/kaslr.c | 4 ++-- arch/arm64/kernel/module.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index b09b6f75f759..5d5f3ed3e66a 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -152,8 +152,8 @@ u64 __init kaslr_early_init(u64 dt_phys) * resolved via PLTs. (Branches between modules will be * resolved normally.) */ - module_range = SZ_4G - (u64)(_end - _stext); - module_alloc_base = max((u64)_end + offset - SZ_4G, + module_range = SZ_2G - (u64)(_end - _stext); + module_alloc_base = max((u64)_end + offset - SZ_2G, (u64)MODULES_VADDR); } else { /* diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index 2e4e3915b4d0..b2f99ff76ed1 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -56,7 +56,7 @@ void *module_alloc(unsigned long size) * can simply omit this fallback in that case. */ p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base, - module_alloc_base + SZ_4G, GFP_KERNEL, + module_alloc_base + SZ_2G, GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, __builtin_return_address(0)); -- 2.17.1