public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND 1/1] um: oops on accessing a non-present page in the vmalloc area
@ 2024-02-23 14:04 Petr Tesarik
  2024-03-12 15:07 ` Petr Tesarik
  2024-03-21  4:44 ` David Gow
  0 siblings, 2 replies; 9+ messages in thread
From: Petr Tesarik @ 2024-02-23 14:04 UTC (permalink / raw)
  To: Richard Weinberger, Anton Ivanov, Johannes Berg,
	open list:USER-MODE LINUX (UML), open list
  Cc: Roberto Sassu, Petr Tesarik

From: Petr Tesarik <petr.tesarik1@huawei-partners.com>

If a segmentation fault is caused by accessing an address in the vmalloc
area, check that the target page is present.

Currently, if the kernel hits a guard page in the vmalloc area, UML blindly
assumes that the fault is caused by a stale mapping and will be fixed by
flush_tlb_kernel_vm(). Unsurprisingly, if the fault is caused by accessing
a guard page, no mapping is created, and when the faulting instruction is
restarted, it will cause exactly the same fault again, effectively creating
an infinite loop.

Signed-off-by: Petr Tesarik <petr.tesarik1@huawei-partners.com>
---
 arch/um/kernel/trap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index 6d8ae86ae978..d5b85f1bfe33 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -206,11 +206,15 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
 	int err;
 	int is_write = FAULT_WRITE(fi);
 	unsigned long address = FAULT_ADDRESS(fi);
+	pte_t *pte;
 
 	if (!is_user && regs)
 		current->thread.segv_regs = container_of(regs, struct pt_regs, regs);
 
 	if (!is_user && (address >= start_vm) && (address < end_vm)) {
+		pte = virt_to_pte(&init_mm, address);
+		if (!pte_present(*pte))
+			page_fault_oops(regs, address, ip);
 		flush_tlb_kernel_vm();
 		goto out;
 	}
-- 
2.34.1


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

end of thread, other threads:[~2024-03-21 17:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-23 14:04 [PATCH RESEND 1/1] um: oops on accessing a non-present page in the vmalloc area Petr Tesarik
2024-03-12 15:07 ` Petr Tesarik
2024-03-18 13:09   ` Petr Tesarik
2024-03-19 22:18     ` Richard Weinberger
2024-03-20 13:58       ` Petr Tesarik
2024-03-20 14:09         ` Richard Weinberger
2024-03-20 15:14           ` Anton Ivanov
2024-03-21  4:44 ` David Gow
2024-03-21 17:30   ` Petr Tesarik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox