From c8ccc56fba5cedb5f9a047d145fa37ae16cfd136 Mon Sep 17 00:00:00 2001 From: Chen Zhou Date: Mon, 29 Nov 2021 16:28:57 +0800 Subject: [PATCH] printk: fix potential deadlock in printk() hulk inclusion category: bugfix bugzilla: 34546, https://gitee.com/openeuler/kernel/issues/I4JKT1 CVE: NA ---------------------------------------- When one cpu panic, the panic cpu send NMI to other cpus, if one of the non-panic cpus is in printk() and get stopped in function console_trylock_spinning() before releasing sem->lock, the panic cpu may spin waiting sem->lock in function console_trylock_spinning(). Reinit console_sem in zap_lock() to fix this. Signed-off-by: Chen Zhou Reviewed-by: Jian Cheng Signed-off-by: Chen Zhou Signed-off-by: Cheng Jian Reviewed-by: Xie XiuQi Signed-off-by: Zheng Zengkai --- kernel/printk/printk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e4328bc341f3..69a1be81dd98 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1755,6 +1755,8 @@ void zap_locks(void) console_owner = NULL; console_waiter = false; + + sema_init(&console_sem, 1); } /** -- GitLab