Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/aarch64/aarch64 fix behaviour mmap()/mprotect() whe...



details:   https://anonhg.NetBSD.org/src/rev/f8e234e7d41a
branches:  trunk
changeset: 968262:f8e234e7d41a
user:      ryo <ryo%NetBSD.org@localhost>
date:      Thu Jan 09 01:38:34 2020 +0000

description:
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)

diffstat:

 sys/arch/aarch64/aarch64/fault.c |   6 +++---
 sys/arch/aarch64/aarch64/pmap.c  |  12 ++++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diffs (67 lines):

diff -r 12fd35094d23 -r f8e234e7d41a sys/arch/aarch64/aarch64/fault.c
--- a/sys/arch/aarch64/aarch64/fault.c  Thu Jan 09 00:42:24 2020 +0000
+++ b/sys/arch/aarch64/aarch64/fault.c  Thu Jan 09 01:38:34 2020 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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 @@
        }
 
        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
diff -r 12fd35094d23 -r f8e234e7d41a sys/arch/aarch64/aarch64/pmap.c
--- a/sys/arch/aarch64/aarch64/pmap.c   Thu Jan 09 00:42:24 2020 +0000
+++ b/sys/arch/aarch64/aarch64/pmap.c   Thu Jan 09 01:38:34 2020 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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 @@
        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 @@
        /* 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);



Home | Main Index | Thread Index | Old Index