Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amd64/amd64 Restrict the check: SMAP faults are alw...



details:   https://anonhg.NetBSD.org/src/rev/e311ae70a53a
branches:  trunk
changeset: 828944:e311ae70a53a
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Jan 10 20:51:11 2018 +0000

description:
Restrict the check: SMAP faults are always protection violations, as the
SDM points out, so make sure we have PGEX_P. This way NULL dereferences -
which are caused by an unmapped VA, and therefore are not protection
violations - don't take this branch, and don't display a misleading
"SMAP" in ddb.

Adding a PGEX_P check, or not, does not essentially change anything from
a security point of view, it's just a matter of what gets displayed when
a fatal fault comes in.

I didn't put PGEX_P until now, because initially when I wrote the SMAP
implementation Qemu did not always receive the fault if the PGEX_P check
was there, while a native i5 would. I'm unable to reproduce this issue
with a recent Qemu, so I assume I did something wrong when testing in the
first place.

diffstat:

 sys/arch/amd64/amd64/trap.c |  12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diffs (35 lines):

diff -r 8196051d2db0 -r e311ae70a53a sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Wed Jan 10 19:56:47 2018 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Wed Jan 10 20:51:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.109 2017/12/09 00:52:41 christos Exp $      */
+/*     $NetBSD: trap.c,v 1.110 2018/01/10 20:51:11 maxv Exp $  */
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.109 2017/12/09 00:52:41 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.110 2018/01/10 20:51:11 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -562,13 +562,11 @@
                        }
                }
 
-               if (cr2 < VM_MAXUSER_ADDRESS) {
+               if ((frame->tf_err & PGEX_P) &&
+                   cr2 < VM_MAXUSER_ADDRESS) {
                        /* SMAP might have brought us here */
                        if (onfault_handler(pcb, frame) == NULL) {
-                               panic("prevented %s %p (SMAP)",
-                                   (cr2 < PAGE_SIZE
-                                       ? "null pointer dereference at"
-                                       : "access to"),
+                               panic("prevented access to %p (SMAP)",
                                    (void *)cr2);
                        }
                }



Home | Main Index | Thread Index | Old Index