From nobody Fri Oct 2 12:20:43 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A4362F7EE1 for ; Fri, 31 Jul 2026 14:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785508804; cv=none; b=rswszvOXwIeMmn/BQnRYJpFLMW8SsjayPMpLOxNCKKZqWnGrM1K86hFwpUdwBK+TV2dWwB+nDaQB/cACO8AafvO04pKAHCVPAYdO4Jk0ZIAng/ugGpAniLaTK2xb9Vt/Y2xuMh6qWXNWG+qBQfauYodddOY4o6s5ooAugXTad24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785508804; c=relaxed/simple; bh=+f/c9oEZn6j4EoYSJchkzGC8JCU8OtfmGT2eBHL1R8I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CKeuLNvBVMAFC/zfW3a3tvvhh9Af6b18YAlPq6NPTkDHeGDRIPyw6zqFYHB70xbtW4TGoR0o6kt4vbthwZ2DnlYjl7jdJ4KZ03jhnD9CEenZZactztgsn0ZccL9WpTAnOZzxWsk7ieZWR3Cib+o/JQzKmgmE0if/VXAHchdjPFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p34wsPdx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HzdcTc18; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p34wsPdx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HzdcTc18" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1785508801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OuVzqpQ+oL8pMnDthH7PM35WrGrI3Pm56Nppam9r+fM=; b=p34wsPdx9gIRthgc7KBfSA1uyfedcVngUACKWgLz57TR1HeEO7euYtQ94xVqQ67N8lgx+K w2jFbzRdpeQ1y4TPuq3fuoAFt/LW1ZD1wCxe4m8kG4V1B8cjnLEEYB0sDpDT657GZeCD5+ Ncsc038JsAMHGB70Mk5jU4JXInJCzF4TTbjxuf1Xeu0uEhhuBrjXlluHPWLPQt7xqpZvSb iznLyNLnu9nX53iyGGa96hEABUsGXdQC3WR5VegBYd4rNb+Cvx/B0sVaNvkGJkv30WfMVz 2Hrhqc41D0ftunjrTHtJCvufC2tSXBwkvSRg0WCeZJOiYRue+YYYouyXMR5I5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1785508801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OuVzqpQ+oL8pMnDthH7PM35WrGrI3Pm56Nppam9r+fM=; b=HzdcTc18R/N7QzM9Xpq5FgasfO5bPQPypOwyBSQ8rklCvNXQNUTWRqNCltQ71Xt6yfbpiE kEU5EKOZtIh0fFAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org Subject: [PATCH printk v2] printk/nbcon: WARN on unsafe reentrance Date: Fri, 31 Jul 2026 16:45:46 +0206 Message-ID: <20260731144000.592883-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Link: https://lore.kernel.org/lkml/87o6fwms02.fsf@jogness.linutronix.de --- Changes since v1: - Move the WARN to after the can_proceed() check. Otherwise cur.unsafe could be referring to a different owning context. kernel/printk/nbcon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 4b03b019cd5ee..e88ddd742d5a0 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -848,6 +848,9 @@ static bool __nbcon_context_update_unsafe(struct nbcon_= context *ctxt, bool unsaf if (!nbcon_context_can_proceed(ctxt, &cur)) return false; =20 + /* Unsafe sections are not reentrant. */ + WARN_ON_ONCE(unsafe && cur.unsafe); + new.atom =3D cur.atom; new.unsafe =3D unsafe; } while (!nbcon_state_try_cmpxchg(con, &cur, &new)); base-commit: 703a9d76a45dd97b19b2432fc1ba4beb4d67a94f --=20 2.47.3