[PATCH printk] printk/nbcon: WARN on unsafe reentrance

John Ogness posted 1 patch 2 months ago
There is a newer version of this series
kernel/printk/nbcon.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH printk] printk/nbcon: WARN on unsafe reentrance
Posted by John Ogness 2 months ago
Since the nbcon unsafe enter/exit functions are simply toggling a
state boolean, a buggy nbcon driver might enter an unsafe section
when the context is already in an unsafe section and it would go
unnoticed, even though doing so is a bug. Unsafe sections are not
reentrant!

Add a WARN_ON_ONCE() to nbcon_enter_unsafe() if the context is
already in an unsafe section.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/lkml/87o6fwms02.fsf@jogness.linutronix.de
---
 kernel/printk/nbcon.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 4b03b019cd5ee..4849f0d1b13b3 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -838,6 +838,9 @@ static bool __nbcon_context_update_unsafe(struct nbcon_context *ctxt, bool unsaf
 	nbcon_state_read(con, &cur);
 
 	do {
+		/* Unsafe sections are not reentrant. */
+		WARN_ON_ONCE(unsafe && cur.unsafe);
+
 		/*
 		 * The unsafe bit must not be cleared if an
 		 * unsafe hostile takeover has occurred.

base-commit: 703a9d76a45dd97b19b2432fc1ba4beb4d67a94f
-- 
2.47.3