All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Marc Zyngier <maz@kernel.org>,
	kvmarm@lists.cs.columbia.edu, linux-hardening@vger.kernel.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>
Subject: [RFC PATCH 02/12] arm64: mm: add helpers to remap page tables read-only/read-write
Date: Wed, 26 Jan 2022 18:30:01 +0100	[thread overview]
Message-ID: <20220126173011.3476262-3-ardb@kernel.org> (raw)
In-Reply-To: <20220126173011.3476262-1-ardb@kernel.org>

Add a couple of helpers to remap a single page read-only or read-write
via its linear address. This will be used for mappings of page table
pages in the linear region.

Note that set_memory_ro/set_memory_rw operate on addresses in the
vmalloc space only, so they cannot be used here.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/pgtable.h |  3 +++
 arch/arm64/mm/pageattr.c         | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c4ba047a82d2..8d3806c68687 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -34,6 +34,9 @@
 #include <linux/mm_types.h>
 #include <linux/sched.h>
 
+int set_pgtable_ro(void *addr);
+int set_pgtable_rw(void *addr);
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
 
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index a3bacd79507a..61f4aca08b95 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -153,6 +153,20 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
 					__pgprot(PTE_VALID));
 }
 
+int set_pgtable_ro(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_RDONLY),
+				      __pgprot(PTE_WRITE));
+}
+
+int set_pgtable_rw(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_WRITE),
+				      __pgprot(PTE_RDONLY));
+}
+
 int set_direct_map_invalid_noflush(struct page *page)
 {
 	struct page_change_data data = {
-- 
2.30.2

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: kvmarm@lists.cs.columbia.edu, linux-hardening@vger.kernel.org,
	Ard Biesheuvel <ardb@kernel.org>, Will Deacon <will@kernel.org>,
	Marc Zyngier <maz@kernel.org>, Fuad Tabba <tabba@google.com>,
	Quentin Perret <qperret@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>
Subject: [RFC PATCH 02/12] arm64: mm: add helpers to remap page tables read-only/read-write
Date: Wed, 26 Jan 2022 18:30:01 +0100	[thread overview]
Message-ID: <20220126173011.3476262-3-ardb@kernel.org> (raw)
In-Reply-To: <20220126173011.3476262-1-ardb@kernel.org>

Add a couple of helpers to remap a single page read-only or read-write
via its linear address. This will be used for mappings of page table
pages in the linear region.

Note that set_memory_ro/set_memory_rw operate on addresses in the
vmalloc space only, so they cannot be used here.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/pgtable.h |  3 +++
 arch/arm64/mm/pageattr.c         | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c4ba047a82d2..8d3806c68687 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -34,6 +34,9 @@
 #include <linux/mm_types.h>
 #include <linux/sched.h>
 
+int set_pgtable_ro(void *addr);
+int set_pgtable_rw(void *addr);
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
 
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index a3bacd79507a..61f4aca08b95 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -153,6 +153,20 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
 					__pgprot(PTE_VALID));
 }
 
+int set_pgtable_ro(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_RDONLY),
+				      __pgprot(PTE_WRITE));
+}
+
+int set_pgtable_rw(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_WRITE),
+				      __pgprot(PTE_RDONLY));
+}
+
 int set_direct_map_invalid_noflush(struct page *page)
 {
 	struct page_change_data data = {
-- 
2.30.2


WARNING: multiple messages have this Message-ID (diff)
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: kvmarm@lists.cs.columbia.edu, linux-hardening@vger.kernel.org,
	Ard Biesheuvel <ardb@kernel.org>, Will Deacon <will@kernel.org>,
	Marc Zyngier <maz@kernel.org>, Fuad Tabba <tabba@google.com>,
	Quentin Perret <qperret@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>
Subject: [RFC PATCH 02/12] arm64: mm: add helpers to remap page tables read-only/read-write
Date: Wed, 26 Jan 2022 18:30:01 +0100	[thread overview]
Message-ID: <20220126173011.3476262-3-ardb@kernel.org> (raw)
In-Reply-To: <20220126173011.3476262-1-ardb@kernel.org>

Add a couple of helpers to remap a single page read-only or read-write
via its linear address. This will be used for mappings of page table
pages in the linear region.

Note that set_memory_ro/set_memory_rw operate on addresses in the
vmalloc space only, so they cannot be used here.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/pgtable.h |  3 +++
 arch/arm64/mm/pageattr.c         | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c4ba047a82d2..8d3806c68687 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -34,6 +34,9 @@
 #include <linux/mm_types.h>
 #include <linux/sched.h>
 
+int set_pgtable_ro(void *addr);
+int set_pgtable_rw(void *addr);
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
 
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index a3bacd79507a..61f4aca08b95 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -153,6 +153,20 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
 					__pgprot(PTE_VALID));
 }
 
+int set_pgtable_ro(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_RDONLY),
+				      __pgprot(PTE_WRITE));
+}
+
+int set_pgtable_rw(void *addr)
+{
+	return __change_memory_common((u64)addr, PAGE_SIZE,
+				      __pgprot(PTE_WRITE),
+				      __pgprot(PTE_RDONLY));
+}
+
 int set_direct_map_invalid_noflush(struct page *page)
 {
 	struct page_change_data data = {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-01-26 17:30 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 17:29 [RFC PATCH 00/12] arm64: implement read-only page tables Ard Biesheuvel
2022-01-26 17:29 ` Ard Biesheuvel
2022-01-26 17:29 ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 01/12] asm-generic/pgalloc: allow arch to override PMD alloc/free routines Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` Ard Biesheuvel [this message]
2022-01-26 17:30   ` [RFC PATCH 02/12] arm64: mm: add helpers to remap page tables read-only/read-write Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 03/12] arm64: mm: use a fixmap slot for user page table modifications Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-28 16:08   ` Steven Price
2022-01-28 16:08     ` Steven Price
2022-01-28 16:08     ` Steven Price
2022-01-26 17:30 ` [RFC PATCH 04/12] arm64: mm: remap PGD pages r/o in the linear region after allocation Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 05/12] arm64: mm: remap PUD pages r/o in linear region Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 06/12] arm64: mm: remap PMD " Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 07/12] arm64: mm: remap PTE level user page tables r/o in the " Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 08/12] arm64: mm: remap kernel PTE level " Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 09/12] arm64: mm: remap kernel page tables read-only at end of init Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 10/12] mm: add default definition of p4d_index() Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 11/12] arm64: efi: use set_pte_at() not set_pte() in order to pass mm pointer Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30 ` [RFC PATCH 12/12] arm64: hugetlb: use set_pte_at() not set_pte() to provide " Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel
2022-01-26 17:30   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220126173011.3476262-3-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.