summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2018-03-20 15:45:32 +0000
committermpi <mpi@openbsd.org>2018-03-20 15:45:32 +0000
commit8ed6e35ec4a629d7af0dd1b32a143cc56dbf5b66 (patch)
tree979b5704d9d51114b4884336ab234b802f8dc219 /sys/kern
parentAvoid potentially calling strchr() on a NULL pointer in (diff)
downloadwireguard-openbsd-8ed6e35ec4a629d7af0dd1b32a143cc56dbf5b66.tar.xz
wireguard-openbsd-8ed6e35ec4a629d7af0dd1b32a143cc56dbf5b66.zip
Do not panic from ddb(4) when a lock requirement isn't fulfilled.
Extend the logic already present for panic() to any DDB-related operation such that if ddb(4) is entered because of a fault or other trap it is still possible to call 'boot reboot'. While here stop printing splassert() messages as well, to not fill the buffer. ok visa@, deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_lock.c4
-rw-r--r--sys/kern/kern_rwlock.c10
-rw-r--r--sys/kern/subr_prf.c4
4 files changed, 12 insertions, 9 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 29cd5b2f661..17bff8830fb 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.274 2018/02/28 18:47:33 patrick Exp $ */
+/* $OpenBSD: init_main.c,v 1.275 2018/03/20 15:45:32 mpi Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -124,6 +124,7 @@ extern struct user *proc0paddr;
struct vnode *rootvp, *swapdev_vp;
int boothowto;
struct timespec boottime;
+int db_active = 0;
int ncpus = 1;
int ncpusfound = 1; /* number of cpus we find */
volatile int start_init_exec; /* semaphore for start_init() */
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index 2d79db04ed7..f108c7393e9 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lock.c,v 1.59 2018/02/19 09:18:00 mpi Exp $ */
+/* $OpenBSD: kern_lock.c,v 1.60 2018/03/20 15:45:32 mpi Exp $ */
/*
* Copyright (c) 2017 Visa Hankala
@@ -79,7 +79,7 @@ _kernel_unlock(void)
int
_kernel_lock_held(void)
{
- if (panicstr)
+ if (panicstr || db_active)
return 1;
return (__mp_lock_held(&kernel_lock, curcpu()));
}
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index 88228a224a1..1bde7064757 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_rwlock.c,v 1.33 2017/12/18 10:05:43 mpi Exp $ */
+/* $OpenBSD: kern_rwlock.c,v 1.34 2018/03/20 15:45:32 mpi Exp $ */
/*
* Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org>
@@ -236,8 +236,8 @@ retry:
unsigned long set = o | op->wait_set;
int do_sleep;
- /* Avoid deadlocks after panic */
- if (panicstr)
+ /* Avoid deadlocks after panic or in DDB */
+ if (panicstr || db_active)
return (0);
rw_enter_diag(rwl, flags);
@@ -287,8 +287,8 @@ _rw_exit(struct rwlock *rwl LOCK_FL_VARS)
int wrlock = owner & RWLOCK_WRLOCK;
unsigned long set;
- /* Avoid deadlocks after panic */
- if (panicstr)
+ /* Avoid deadlocks after panic or in DDB */
+ if (panicstr || db_active)
return;
if (wrlock)
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 3572e809d09..c75e2a88769 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_prf.c,v 1.93 2018/01/05 11:10:25 pirofti Exp $ */
+/* $OpenBSD: subr_prf.c,v 1.94 2018/03/20 15:45:32 mpi Exp $ */
/* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */
/*-
@@ -216,6 +216,8 @@ panic(const char *fmt, ...)
void
splassert_fail(int wantipl, int haveipl, const char *func)
{
+ if (panicstr || db_active)
+ return;
printf("splassert: %s: want %d have %d\n", func, wantipl, haveipl);
switch (splassert_ctl) {