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 don't read memory directly.



details:   https://anonhg.NetBSD.org/src/rev/e1aa6d6a43cd
branches:  trunk
changeset: 1011728:e1aa6d6a43cd
user:      ryo <ryo%NetBSD.org@localhost>
date:      Wed Jul 08 03:44:10 2020 +0000

description:
don't read memory directly.
In particular, userland memory may be unmapped at the time of reading.

diffstat:

 sys/arch/aarch64/aarch64/db_disasm.c |  24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diffs (52 lines):

diff -r 14353c0a26b8 -r e1aa6d6a43cd sys/arch/aarch64/aarch64/db_disasm.c
--- a/sys/arch/aarch64/aarch64/db_disasm.c      Wed Jul 08 00:06:33 2020 +0000
+++ b/sys/arch/aarch64/aarch64/db_disasm.c      Wed Jul 08 03:44:10 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_disasm.c,v 1.7 2019/10/28 18:15:25 joerg Exp $ */
+/* $NetBSD: db_disasm.c,v 1.8 2020/07/08 03:44:10 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.7 2019/10/28 18:15:25 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.8 2020/07/08 03:44:10 ryo Exp $");
 
 #include <sys/param.h>
 #include <machine/db_machdep.h>
@@ -37,6 +37,7 @@
 #include <ddb/db_access.h>
 #include <ddb/db_user.h>
 
+#include <aarch64/cpufunc.h>
 #include <arch/aarch64/aarch64/disasm.h>
 
 static uint32_t
@@ -72,7 +73,24 @@
 static uint32_t
 strdisasm_readword(uintptr_t address)
 {
-       return *(uint32_t *)address;
+       /*
+        * if it cannot be read due to a EFAULT etc.,
+        * ignores the error and returns 0
+        */
+       uint32_t word = 0;
+
+       switch (aarch64_addressspace((vaddr_t)address)) {
+       case AARCH64_ADDRSPACE_UPPER:
+               kcopy((void*)address, &word, sizeof(word));
+               break;
+       case AARCH64_ADDRSPACE_LOWER:
+               ufetch_32((uint32_t *)address, &word);
+               break;
+       default:
+               break;
+       }
+
+       return word;
 }
 
 static void __printflike(1, 2)



Home | Main Index | Thread Index | Old Index