⬢ DragonFlyBSD Kernel Audit
DF-5721 / fix.diff
← back to finding ↓ download raw
--- a/sys/cpu/x86_64/include/db_machdep.h
+++ b/sys/cpu/x86_64/include/db_machdep.h
@@ -64,6 +64,12 @@
  * Watchpoints are not supported.  The debug exception type is in %dr6
  * and not yet in the args to this macro.
  */
 #define IS_WATCHPOINT_TRAP(type, code)	0
+
+/*
+ * Software (pmap-protect) watchpoints cannot be serviced on this
+ * platform: the resulting page fault is never classified as a
+ * watchpoint (see IS_WATCHPOINT_TRAP above and the #ifdef notused
+ * db_find_watchpoint() in sys/ddb/db_watch.c), the protection is
+ * silently rewired writable by vm_fault() on the first hit, and the
+ * session then continues with a dead instrument.  Refuse to arm one.
+ */
+#define DB_NO_SOFTWARE_WATCHPOINTS	1
 
 #define	I_CALL		0xe8
 #define	I_CALLI		0xff
--- a/sys/ddb/db_watch.c
+++ b/sys/ddb/db_watch.c
@@ -189,6 +189,13 @@ void
 db_watchpoint_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
 		  char *modif)
 {
 	vm_size_t	size;
 	db_expr_t	value;
 
+#ifdef DB_NO_SOFTWARE_WATCHPOINTS
+	db_printf("software watchpoints not supported on this platform "
+		  "(use hwatch)\n");
+	db_skip_to_eol();
+	return;
+#endif
+
 	if (db_expression(&value))
 	    size = (vm_size_t) value;
 	else
 	    size = 4;
```