Module Name:    src
Committed By:   ryo
Date:           Thu Jan  9 01:38:34 UTC 2020

Modified Files:
        src/sys/arch/aarch64/aarch64: fault.c pmap.c

Log Message:
fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/aarch64/aarch64/fault.c
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/aarch64/aarch64/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/fault.c
diff -u src/sys/arch/aarch64/aarch64/fault.c:1.10 src/sys/arch/aarch64/aarch64/fault.c:1.11
--- src/sys/arch/aarch64/aarch64/fault.c:1.10	Mon Jun 10 05:56:15 2019
+++ src/sys/arch/aarch64/aarch64/fault.c	Thu Jan  9 01:38:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fault.c,v 1.10 2019/06/10 05:56:15 ryo Exp $	*/
+/*	$NetBSD: fault.c,v 1.11 2020/01/09 01:38:34 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.10 2019/06/10 05:56:15 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.11 2020/01/09 01:38:34 ryo Exp $");
 
 #include "opt_compat_netbsd32.h"
 #include "opt_ddb.h"
@@ -170,7 +170,7 @@ data_abort_handler(struct trapframe *tf,
 	}
 
 	if ((eclass == ESR_EC_INSN_ABT_EL0) || (eclass == ESR_EC_INSN_ABT_EL1))
-		ftype = VM_PROT_READ | VM_PROT_EXECUTE;
+		ftype = VM_PROT_EXECUTE;
 	else if (__SHIFTOUT(esr, ESR_ISS_DATAABORT_CM))
 		ftype = VM_PROT_READ;
 	else

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.60 src/sys/arch/aarch64/aarch64/pmap.c:1.61
--- src/sys/arch/aarch64/aarch64/pmap.c:1.60	Mon Dec 30 16:03:48 2019
+++ src/sys/arch/aarch64/aarch64/pmap.c	Thu Jan  9 01:38:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.60 2019/12/30 16:03:48 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.61 2020/01/09 01:38:34 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.60 2019/12/30 16:03:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.61 2020/01/09 01:38:34 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -1232,6 +1232,10 @@ pmap_protect(struct pmap *pm, vaddr_t sv
 	KASSERT_PM_ADDR(pm, sva);
 	KASSERT(!IN_KSEG_ADDR(sva));
 
+	/* PROT_EXEC requires implicit PROT_READ */
+	if (prot & VM_PROT_EXECUTE)
+		prot |= VM_PROT_READ;
+
 	if ((prot & VM_PROT_READ) == VM_PROT_NONE) {
 		PMAP_COUNT(protect_remove_fallback);
 		pmap_remove(pm, sva, eva);
@@ -2139,6 +2143,10 @@ pmap_fault_fixup(struct pmap *pm, vaddr_
 	/* ignore except read/write */
 	accessprot &= (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
 
+	/* PROT_EXEC requires implicit PROT_READ */
+	if (accessprot & VM_PROT_EXECUTE)
+		accessprot |= VM_PROT_READ;
+
 	/* no permission to read/write/execute for this page */
 	if ((pmap_prot & accessprot) != accessprot) {
 		UVMHIST_LOG(pmaphist, "no permission to access", 0, 0, 0, 0);

Reply via email to