Module Name:    src
Committed By:   ryo
Date:           Fri Aug 19 08:17:32 UTC 2022

Modified Files:
        src/sys/arch/aarch64/aarch64: aarch64_machdep.c pmap.c
        src/sys/arch/aarch64/include: pte.h

Log Message:
Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 
0x0001000000000000 in /dev/mem with mmap().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/include/pte.h

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/aarch64_machdep.c
diff -u src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.65 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.66
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.65	Sat Mar 12 09:16:05 2022
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.65 2022/03/12 09:16:05 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.66 2022/08/19 08:17:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.65 2022/03/12 09:16:05 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.66 2022/08/19 08:17:32 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -619,6 +619,9 @@ mm_md_physacc(paddr_t pa, vm_prot_t prot
 	if (in_dram_p(pa, 0))
 		return 0;
 
+	if (pa >= AARCH64_MAX_PA)
+		return EFAULT;
+
 	return kauth_authorize_machdep(kauth_cred_get(),
 	    KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL);
 }

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.138 src/sys/arch/aarch64/aarch64/pmap.c:1.139
--- src/sys/arch/aarch64/aarch64/pmap.c:1.138	Fri Aug 19 07:45:50 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.138 2022/08/19 07:45:50 ryo Exp $	*/
+/*	$NetBSD: pmap.c,v 1.139 2022/08/19 08:17:32 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.138 2022/08/19 07:45:50 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.139 2022/08/19 08:17:32 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1915,6 +1915,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	KASSERT_PM_ADDR(pm, va);
 	KASSERT(!IN_DIRECTMAP_ADDR(va));
 	KASSERT((prot & VM_PROT_ALL) != VM_PROT_NONE);
+	KASSERT(pa < AARCH64_MAX_PA);
 
 #ifdef PMAPCOUNTERS
 	PMAP_COUNT(mappings);

Index: src/sys/arch/aarch64/include/pte.h
diff -u src/sys/arch/aarch64/include/pte.h:1.13 src/sys/arch/aarch64/include/pte.h:1.14
--- src/sys/arch/aarch64/include/pte.h:1.13	Sun Oct 10 07:15:25 2021
+++ src/sys/arch/aarch64/include/pte.h	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pte.h,v 1.13 2021/10/10 07:15:25 skrll Exp $ */
+/* $NetBSD: pte.h,v 1.14 2022/08/19 08:17:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -93,6 +93,7 @@ typedef uint64_t pt_entry_t;	/* L3(4k) t
 #define L1_BLK_OA		__BITS(47, 30)	/* 1GB */
 #define L2_BLK_OA		__BITS(47, 21)	/* 2MB */
 #define L3_PAG_OA		__BITS(47, 12)	/* 4KB */
+#define AARCH64_MAX_PA		__BIT(48)
 
 
 /* L0 table, 512GB/entry * 512 */

Reply via email to