Module Name:    src
Committed By:   isaki
Date:           Fri Aug  6 04:21:56 UTC 2021

Modified Files:
        src/sys/arch/x68k/x68k: machdep.c

Log Message:
Fix broken mm_md_physacc().
- Fix access to main memory and extended memory.
  This makes /dev/mem work again.
- Introduce kauth(9) to access unmanaged memory area.
  Now you can read/write the internal I/O space via /dev/mem when
  securelevel = -1.
Thanks ryo@, tsutsui@ for advices and reviews.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/arch/x68k/x68k/machdep.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/x68k/x68k/machdep.c
diff -u src/sys/arch/x68k/x68k/machdep.c:1.205 src/sys/arch/x68k/x68k/machdep.c:1.206
--- src/sys/arch/x68k/x68k/machdep.c:1.205	Thu Feb 11 02:37:11 2021
+++ src/sys/arch/x68k/x68k/machdep.c	Fri Aug  6 04:21:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.205 2021/02/11 02:37:11 tsutsui Exp $	*/
+/*	$NetBSD: machdep.c,v 1.206 2021/08/06 04:21:56 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.205 2021/02/11 02:37:11 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.206 2021/08/06 04:21:56 isaki Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1252,15 +1252,28 @@ cpu_intr_p(void)
 int
 mm_md_physacc(paddr_t pa, vm_prot_t prot)
 {
-	uvm_physseg_t i;
+	int i;
 
-	for (i = uvm_physseg_get_first(); uvm_physseg_valid_p(i); i = uvm_physseg_get_next(i)) {
-		if (uvm_physseg_valid_p(i) == false)
-			break;
+	/* Main memory */
+	if (phys_basemem_seg.start <= pa && pa < phys_basemem_seg.end)
+		return 0;
 
-		if (ctob(uvm_physseg_get_start(i)) <= pa &&
-		    pa < ctob(uvm_physseg_get_end(i)))
+#ifdef EXTENDED_MEMORY
+	for (i = 0; i < EXTMEM_SEGS; i++) {
+		if (phys_extmem_seg[i].start == phys_extmem_seg[i].end)
+			continue;
+		if (phys_extmem_seg[i].start <= pa &&
+		    pa < phys_extmem_seg[i].end) {
 			return 0;
+		}
 	}
+#endif
+
+	/* I/O space */
+	if (INTIOBASE <= pa && pa < INTIOTOP) {
+		return kauth_authorize_machdep(kauth_cred_get(),
+		    KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL);
+	}
+
 	return EFAULT;
 }

Reply via email to