From nobody Sun Feb 8 14:51:59 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2B36314B78 for ; Mon, 26 Jan 2026 09:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769419668; cv=none; b=gUrg5qWUXafyX7sQyD7yi6d/dkXf6kG57NSVgpId40P4EFW8rv8ntUgT9mdd6EWS9ojAWPAcmEDCCetllpGgm4SLGqh09URIjjUpwb1zUpPndRF07KDSegXX1wsFCgRdexew+rKV5Rl6y6D5aJRQat569A+vNGr6V5qJi5eQjNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769419668; c=relaxed/simple; bh=Gxq4ie03bv9H1pRh3OM+DBK3rL8bxlKAHagD9uGKsVw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KRLUjv3WXjpSMNDS0ly4KFd8EZCPIVc2kQOVzhVw7h+m8CiR0CmVu0j5O1YQdpc56PpEtzavq6/bjp8jyQhiskiDri4KkOyIcOdeLLQh7gFvjvYEm3iwZgWAG2dSk8b5NtnYgCOMqq1g2NUspvXWUYZwCKAoNMKmbOCQVORHyTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ap5IDeU1; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ap5IDeU1" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47d62cc05daso41419045e9.3 for ; Mon, 26 Jan 2026 01:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769419660; x=1770024460; darn=vger.kernel.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=qFepSabf96QcVfXCKhTiM0/xD6vjSZxLElXj77bKxb0=; b=Ap5IDeU1nUozan2BOaUVG3wo1hJ+VdqpjtDvftHp6RLZMVQlKi2NE+4hi7JYlNmgMi 4IkWzjolexttRk5Gqv1HljqRPWVVpHIyNvIdxx2Jl9Bomi0a1WqZQ9GvS1VDA+8Gxl+U IrsOtrQwYbcmUsEXNaDm0vEYl0Srmfe0TQbqjFCO3USR1BfA4W8K/2TOg5PRqs2NWIyv PPgBu9A5ZMV93nGtjRz1qj609sC4fEC5Y0e8lqnui7paMcWggCXTS/6IseirEmLN/B7E BtZNxptJTgWvSNUwBgMXHmnSxjtyAg12b3tZ27Po7OTsCqg2gbiICnzt9rzvKj4W6m+k OXgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769419660; x=1770024460; 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=qFepSabf96QcVfXCKhTiM0/xD6vjSZxLElXj77bKxb0=; b=QCdtLZ4UM0JGGyOdv+7vl7bltWOwKVSU+k0FKJ+ngczfHav+mbdpFsRoos3X1mrwEH fNisxJN0JEbQCaQBV1RasV2quDgW+zmMBrWNmImQUt/TWiiFoQuUbiSmD++jA8LfHl/f 6dvR9Wl14wkqfzNd9Jo1myiBCucgPw2B/qObw/UnqQdxSLJj0ljs+0viIUAMGuuLGzP9 N48GXxAfO1n8e/6P0xgiy2RPlg0VsPyzw0HIrb9Ruf6zqsZUDrDdfJ0e6jkejnwSDnXi 2iR3o5dv47BCplmyBGnujux9l6gn8zV77svPp7Ox9H7HFZRqZVNTcB/LnrdzRMPll7pA jX+A== X-Gm-Message-State: AOJu0YwG4LyDeq5yRJRIE4qK5n6xTrdsu7QVHW1g6L4OC7ilytsqCHgY i0BX2Kv8ugiPq9+zyPCke+lF1CsyrCGpSHXoBOMJuVrQoXyaSpKHnJSYyq9vNg0gkDsuUGDQXy+ Dl6o07PDPf1EknowBkqAPA7l663r/oeOA2gsR1CEiLhu3yt/wqtn8+4aPoP3DwhI5R7Y8DewS8x WlXTNALGs+uPSenvW9m1M8WNTh2yEjabcqgw== X-Received: from wmlz11.prod.google.com ([2002:a05:600c:220b:b0:47d:8744:3dc3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f8e:b0:45d:d97c:236c with SMTP id 5b1f17b1804b1-4805cf6699cmr52231985e9.21.1769419659870; Mon, 26 Jan 2026 01:27:39 -0800 (PST) Date: Mon, 26 Jan 2026 10:26:40 +0100 In-Reply-To: <20260126092630.1800589-12-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260126092630.1800589-12-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2789; i=ardb@kernel.org; h=from:subject; bh=jiHSf63B3FCpPY5LRg5zb9pMV7UOm8DsB0K5QVCNRaU=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIbPc2PvMs/ffLc8t0UhLlfXbtjQx61Xhpd9aidZnP7BJe a3lidXtKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABN51MXwz0quV/X2CbNbF+fy zWmfb8/PosuzbKH55rsCnUf0XFObfRkZpuns+C7x8Nb8GRsO3Z0lduATA0vcHI4NP3wiZ77cf3R jExsA X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260126092630.1800589-21-ardb+git@google.com> Subject: [PATCH v2 09/10] arm64: mm: Map the kernel data/bss read-only in the linear map From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Ard Biesheuvel , Ryan Roberts , Anshuman Khandual , Liz Prucka , Seth Jenkins , Kees Cook , linux-hardening@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel On systems where the bootloader adheres to the original arm64 boot protocol, the placement of the kernel in the physical address space is highly predictable, and this makes the placement of its linear alias in the kernel virtual address space equally predictable, given the lack of randomization of the linear map. The linear aliases of the kernel text and rodata regions are already mapped read-only, but the kernel data and bss are mapped read-write in this region. This is not needed, so map them read-only as well. Note that the statically allocated kernel page tables do need to be modifiable via the linear map, so leave these mapped read-write. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/mm/mmu.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sec= tions.h index 51b0d594239e..f7fe2bcbfd03 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -23,6 +23,7 @@ extern char __irqentry_text_start[], __irqentry_text_end[= ]; extern char __mmuoff_data_start[], __mmuoff_data_end[]; extern char __entry_tramp_text_start[], __entry_tramp_text_end[]; extern char __relocate_new_kernel_start[], __relocate_new_kernel_end[]; +extern char __pgdir_start[]; =20 static inline size_t entry_tramp_text_size(void) { diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 18415d4743bf..fdbbb018adc5 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1122,7 +1122,9 @@ static void __init map_mem(void) { static const u64 direct_map_end =3D _PAGE_END(VA_BITS_MIN); phys_addr_t kernel_start =3D __pa_symbol(_text); - phys_addr_t kernel_end =3D __pa_symbol(__init_begin); + phys_addr_t init_begin =3D __pa_symbol(__init_begin); + phys_addr_t init_end =3D __pa_symbol(__init_end); + phys_addr_t kernel_end =3D __pa_symbol(__pgdir_start); phys_addr_t start, end; phys_addr_t early_kfence_pool; int flags =3D NO_EXEC_MAPPINGS; @@ -1158,7 +1160,9 @@ static void __init map_mem(void) * Note that contiguous mappings cannot be remapped in this way, * so we should avoid them here. */ - __map_memblock(kernel_start, kernel_end, PAGE_KERNEL, + __map_memblock(kernel_start, init_begin, PAGE_KERNEL, + flags | NO_CONT_MAPPINGS); + __map_memblock(init_end, kernel_end, PAGE_KERNEL, flags | NO_CONT_MAPPINGS); =20 /* map all the memory banks */ @@ -1172,6 +1176,8 @@ static void __init map_mem(void) flags); } =20 + __map_memblock(init_end, kernel_end, PAGE_KERNEL_RO, + flags | NO_CONT_MAPPINGS); arm64_kfence_map_pool(early_kfence_pool); } =20 --=20 2.52.0.457.g6b5491de43-goog