linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mm: mark tramp_pg_dir read-only
@ 2018-05-30  4:48 YaoJun
  2018-05-30  9:14 ` Will Deacon
  0 siblings, 1 reply; 13+ messages in thread
From: YaoJun @ 2018-05-30  4:48 UTC (permalink / raw)
  To: linux-arm-kernel

To protect against KSMA(Kernel Space Mirroring Attack), make
tramp_pg_dir read-only. The principle of KSMA is to insert a
carefully constructed PGD entry into the translation table.
The type of this entry is block, which maps the kernel text
and its access permissions bits are 01. The user process can
then modify kernel text directly through this mapping. In this
way, an arbitrary write can be converted to multiple arbitrary
writes.

Signed-off-by: YaoJun <yaojun8558363@gmail.com>
---
 arch/arm64/mm/mmu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 2dbb2c9f1ec1..ac4b22c7e435 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -551,6 +551,10 @@ static int __init map_entry_trampoline(void)
 	__create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE,
 			     prot, pgd_pgtable_alloc, 0);
 
+	update_mapping_prot(__pa_symbol(tramp_pg_dir),
+				(unsigned long)tramp_pg_dir,
+				PGD_SIZE, PAGE_KERNEL_RO);
+
 	/* Map both the text and data into the kernel page table */
 	__set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot);
 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-06-19 16:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-30  4:48 [PATCH] arm64: mm: mark tramp_pg_dir read-only YaoJun
2018-05-30  9:14 ` Will Deacon
2018-05-30  9:53   ` Ard Biesheuvel
2018-06-19 15:20     ` Will Deacon
2018-06-19 15:23       ` Ard Biesheuvel
2018-06-19 15:28         ` Will Deacon
2018-06-19 15:29           ` Ard Biesheuvel
2018-06-19 15:37             ` Will Deacon
2018-06-19 15:40               ` Ard Biesheuvel
2018-06-19 15:50                 ` Will Deacon
2018-06-19 15:51                   ` Ard Biesheuvel
2018-06-19 15:55                     ` Will Deacon
2018-06-19 16:00                       ` Ard Biesheuvel

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