From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4EFAC4167B for ; Wed, 29 Nov 2023 11:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0S7pQvq2swJP9tRC22B0UDYUryvA2+3B+QZ8xSua2p0=; b=MVzUd04mQGe51KdyVZJIH2b1Pa 0MT1Lq2Q/D2yy2Od3tVWbR4FCsiFB57gtXlXnNgK8Rcl9BEsv9iY9z2llfGvmSSpVbGnPhSVjLNpY YCPKhZOb2UBcrUbRlCVSqkUFbAC5EucYMq+wAAU3J7WOiUwCcm/oob0UTvKiLBYjv3/wB+Iv+XLTo hRzcI4Kg715VS7VKSD8ibdULEld5cL8nkHHClk8WQEHYybf88M/VD+QxFUUzKbk025Dl5W4iKld+c FtDovGNsB9JbjrUXC50GuUCP7aAOqsZGwpATPXoaq2jd1RsecW4BZMposC/BJzdCOa9dZNKD80SGs F4Q+axzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8IZP-007z3B-0o; Wed, 29 Nov 2023 11:17:31 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8IZF-007ytB-1u for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 11:17:23 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-332e61e2480so4210491f8f.0 for ; Wed, 29 Nov 2023 03:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701256639; x=1701861439; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=c/0kHqi5ZIPX7uCJiko3eeawbTMfWCgSYmmSJYACJmA=; b=yMrW4MzDLV1EOj67mpWnzT8Azx9zLjGazZeu+ZIttfjt2vrETCWov7s/XkoPRLRPh+ ndrWNIYXsePH+ErTFlXZDfDr02dOQylRXWgOAZopCtse1bVEdYZWPueM94Fh6ZktfmVD 2lVLj1sxzGRa1XY/nWCsaiqpcqnoYjdq48xl+3LJ9czlTvYgbCbngIlorA2X9jozPpPg /it3gabUS+ezyZslA7ANcIhkDi0JPVB/ASuZPbrClPueHJcMa9FOeaPcbAHMPzjPNoPa cek0p+IU6gaeRBblgQMjOJpjvyb3eSTRDxQCvW8C2JD3aurgc5QMceaL8mZjlxkzB7gx sZwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701256639; x=1701861439; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c/0kHqi5ZIPX7uCJiko3eeawbTMfWCgSYmmSJYACJmA=; b=wIj7W+1rBwSEuoIRHaRuxkgqSfRNVTRZQzctgMcShbtLC/MzGtwfOwrtklzE1Rrr+m 5FU9yztY4IY6lzhOEpcsJrBSrISzzWds/Olx5jB4V93wc3WyuHk1OMogKuk+f2YcaFJH FQxHfcQ6cF/FOprI6MvdMBpd//yjdstWI73lHK33o1WW6RGWYLqnUI0Z0TMdwF2J4YR4 8xmWfAQS3O3hk3eTTfZ1sb3zu1WGaM+BXzq644NsKDwszHHEkHiN/qvjDZvY717FEKZn 75ycIXVgLxNaV0DFLjz/b8jfUpgQX3i7lgAO6C8GE1hH6W3i6PycN+Z99KcbtonmmVm+ QOYg== X-Gm-Message-State: AOJu0YwX1xQH2TpAJSDU153CKoXEHBNTU3A7wuuigHfJ+xQ1k0Kr7rrR y+rZMrbBo5PZ0EkpyzO4xAnWBubQ3ldZzqqtkzTYiATG+JLLrE2O4jP4dS9LJAwqbRfF6yg/tc2 SrYaKjfI7x52rz40epQbqSW691Z+/hK/oq3vFnSgTfY8ZiaETy+i8oRFloLnqpp052XjqMYjBAu w= X-Google-Smtp-Source: AGHT+IGbXQZ8oMOIfFO78myHn3PaevuK4xCN45M8mqZ3IeaKTWUJUFJ5ahfD1P6x64tcYNVyKY+pBfLC X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:f6d1:0:b0:332:e431:99e8 with SMTP id y17-20020adff6d1000000b00332e43199e8mr273005wrp.8.1701256638638; Wed, 29 Nov 2023 03:17:18 -0800 (PST) Date: Wed, 29 Nov 2023 12:15:58 +0100 In-Reply-To: <20231129111555.3594833-43-ardb@google.com> Mime-Version: 1.0 References: <20231129111555.3594833-43-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2831; i=ardb@kernel.org; h=from:subject; bh=ZfuLl88gFL9uskT9e1AlkywoKWtb5bgNB+HGXf4gRmk=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JITVdNo/B2bnxmE5ssarqKWFrWYUAP4MNEYphwovN7a1Lx Fmb5neUsjCIcTDIiimyCMz++27n6YlStc6zZGHmsDKBDeHiFICJFJgw/JVj99X6sTdAIdduHf9x 6YkTeoM2zzB/oXJ+mbfJH80fy5MZGa7pWvtnBhds2PHuk+B3AzUjvX/RhmyVHCuXZL+ftMGxmB8 A X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129111555.3594833-45-ardb@google.com> Subject: [PATCH v6 02/41] arm64: mm: Take potential load offset into account when KASLR is off From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_031721_642283_4BE218B5 X-CRM114-Status: GOOD ( 19.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel We enable CONFIG_RELOCATABLE even when CONFIG_RANDOMIZE_BASE is disabled, and this permits the loader (i.e., EFI) to place the kernel anywhere in physical memory as long as the base address is 64k aligned. This means that the 'KASLR' case described in the header that defines the size of the statically allocated page tables could take effect even when CONFIG_RANDMIZE_BASE=n. So check for CONFIG_RELOCATABLE instead. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/kernel-pgtable.h | 27 +++++--------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 85d26143faa5..83ddb14b95a5 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -37,27 +37,12 @@ /* - * If KASLR is enabled, then an offset K is added to the kernel address - * space. The bottom 21 bits of this offset are zero to guarantee 2MB - * alignment for PA and VA. - * - * For each pagetable level of the swapper, we know that the shift will - * be larger than 21 (for the 4KB granule case we use section maps thus - * the smallest shift is actually 30) thus there is the possibility that - * KASLR can increase the number of pagetable entries by 1, so we make - * room for this extra entry. - * - * Note KASLR cannot increase the number of required entries for a level - * by more than one because it increments both the virtual start and end - * addresses equally (the extra entry comes from the case where the end - * address is just pushed over a boundary and the start address isn't). + * A relocatable kernel may execute from an address that differs from the one at + * which it was linked. In the worst case, its runtime placement may intersect + * with two adjacent PGDIR entries, which means that an additional page table + * may be needed at each subordinate level. */ - -#ifdef CONFIG_RANDOMIZE_BASE -#define EARLY_KASLR (1) -#else -#define EARLY_KASLR (0) -#endif +#define EXTRA_PAGE __is_defined(CONFIG_RELOCATABLE) #define SPAN_NR_ENTRIES(vstart, vend, shift) \ ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1) @@ -83,7 +68,7 @@ + EARLY_PGDS((vstart), (vend), add) /* each PGDIR needs a next level page table */ \ + EARLY_PUDS((vstart), (vend), add) /* each PUD needs a next level page table */ \ + EARLY_PMDS((vstart), (vend), add)) /* each PMD needs a next level page table */ -#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EARLY_KASLR)) +#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EXTRA_PAGE)) /* the initial ID map may need two extra pages if it needs to be extended */ #if VA_BITS < 48 -- 2.43.0.rc1.413.gea7ed67945-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel