Index: rtemsbsd/include/machine/rtems-bsd-muteximpl.h
===================================================================
--- rtemsbsd/include/machine/rtems-bsd-muteximpl.h	(revision 2275776d21768c18570a2a4bf7d8b2fff8088dc5)
+++ rtemsbsd/include/machine/rtems-bsd-muteximpl.h	(revision eae664ea8fdae9e514dc7970c6cf21a0b9767ddd)
@@ -9,5 +9,5 @@
 
 /*
- * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
@@ -47,4 +47,7 @@
 #include <sys/types.h>
 #include <sys/lock.h>
+#include <sys/systm.h>
+
+#include <inttypes.h>
 
 #include <rtems/score/threadimpl.h>
@@ -161,5 +164,10 @@
 		success = 1;
 	} else if (owner == executing) {
-		BSD_ASSERT(lock->lo_flags & LO_RECURSABLE);
+		if ((lock->lo_flags & LO_RECURSABLE) == 0) {
+			rtems_bsd_mutex_release(m, isr_level, &queue_context);
+			panic("mutex trylock: %s: not LO_RECURSABLE\n",
+			    m->queue.Queue.name);
+		}
+
 		++m->nest_level;
 		success = 1;
@@ -179,4 +187,5 @@
 	Thread_queue_Context queue_context;
 	Thread_Control *owner;
+	Thread_Control *executing;
 	int nest_level;
 
@@ -187,6 +196,12 @@
 	nest_level = m->nest_level;
 	owner = m->queue.Queue.owner;
-
-	BSD_ASSERT(owner == _Thread_Executing);
+	executing = _Thread_Executing;
+
+	if (__predict_false(owner != executing)) {
+		rtems_bsd_mutex_release(m, isr_level, &queue_context);
+		panic("mutex unlock: %s: owner 0x%08" PRIx32
+		    " != executing 0x%08" PRIx32 "\n", m->queue.Queue.name,
+		    owner->Object.id, executing->Object.id);
+	}
 
 	if (__predict_true(nest_level == 0)) {
Index: rtemsbsd/rtems/rtems-kernel-muteximpl.c
===================================================================
--- rtemsbsd/rtems/rtems-kernel-muteximpl.c	(revision 2275776d21768c18570a2a4bf7d8b2fff8088dc5)
+++ rtemsbsd/rtems/rtems-kernel-muteximpl.c	(revision eae664ea8fdae9e514dc7970c6cf21a0b9767ddd)
@@ -8,5 +8,5 @@
 
 /*
- * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
@@ -49,7 +49,11 @@
 {
 	if (owner == executing) {
-		BSD_ASSERT(lock->lo_flags & LO_RECURSABLE);
+		if ((lock->lo_flags & LO_RECURSABLE) == 0) {
+			_Thread_queue_Release(&m->queue, queue_context);
+			panic("mutex lock: %s: not LO_RECURSABLE\n",
+			    m->queue.Queue.name);
+		}
+
 		++m->nest_level;
-
 		_Thread_queue_Release(&m->queue, queue_context);
 	} else {
Index: testsuite/mutex01/test_main.c
===================================================================
--- testsuite/mutex01/test_main.c	(revision 2275776d21768c18570a2a4bf7d8b2fff8088dc5)
+++ testsuite/mutex01/test_main.c	(revision eae664ea8fdae9e514dc7970c6cf21a0b9767ddd)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
@@ -67,4 +67,5 @@
 	rtems_id worker_task[WORKER_COUNT];
 	bool done[WORKER_COUNT];
+	rtems_id panic_task;
 } test_context;
 
@@ -479,4 +480,100 @@
 }
 
+#define PANIC_DO_LOCK 0
+
+#define PANIC_DO_TRYLOCK 1
+
+#define PANIC_DO_UNLOCK 2
+
+static void
+panic_task(rtems_task_argument arg)
+{
+	test_context *ctx = &test_instance;
+	struct mtx *mtx = &ctx->mtx;
+
+	switch (arg) {
+	case PANIC_DO_LOCK:
+		mtx_lock(mtx);
+		mtx_lock(mtx);
+		break;
+	case PANIC_DO_TRYLOCK:
+		mtx_lock(mtx);
+		mtx_trylock(mtx);
+		break;
+	case PANIC_DO_UNLOCK:
+		mtx_unlock(mtx);
+		break;
+	default:
+		assert(0);
+		break;
+	}
+
+	rtems_task_suspend(RTEMS_SELF);
+}
+
+static void
+test_mtx_panic(test_context *ctx)
+{
+	struct mtx *mtx = &ctx->mtx;
+	rtems_status_code sc;
+
+	puts("test mtx panic");
+
+	sc = rtems_task_create(rtems_build_name('P', 'A', 'N', 'I'),
+	    get_self_prio(), RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
+	    RTEMS_FLOATING_POINT, &ctx->panic_task);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	assert(!mtx_initialized(mtx));
+	mtx_init(mtx, "test", NULL, MTX_DEF);
+	assert(mtx_initialized(mtx));
+
+	/* Lock recursive panic */
+
+	sc = rtems_task_start(ctx->panic_task, panic_task, PANIC_DO_LOCK);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_restart(ctx->panic_task, PANIC_DO_UNLOCK);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	/* Try lock recursive panic */
+
+	sc = rtems_task_restart(ctx->panic_task, PANIC_DO_TRYLOCK);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_restart(ctx->panic_task, PANIC_DO_UNLOCK);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	/* Unlock not owner panic */
+
+	mtx_lock(mtx);
+
+	sc = rtems_task_restart(ctx->panic_task, PANIC_DO_UNLOCK);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+	assert(sc == RTEMS_SUCCESSFUL);
+
+	mtx_unlock(mtx);
+
+	mtx_destroy(mtx);
+	assert(!mtx_initialized(mtx));
+
+	sc = rtems_task_delete(ctx->panic_task);
+	assert(sc == RTEMS_SUCCESSFUL);
+}
+
 static void
 alloc_basic_resources(void)
@@ -505,4 +602,5 @@
 	test_mtx_trylock(ctx);
 	test_mtx_lock(ctx);
+	test_mtx_panic(ctx);
 
 	assert(rtems_resource_snapshot_check(&snapshot_1));
