lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87ecp5wd0i.fsf@jogness.linutronix.de>
Date: Mon, 08 Dec 2025 10:21:09 +0106
From: John Ogness <john.ogness@...utronix.de>
To: Marcos Paulo de Souza <mpdesouza@...e.com>, Petr Mladek
 <pmladek@...e.com>, Steven Rostedt <rostedt@...dmis.org>, Sergey
 Senozhatsky <senozhatsky@...omium.org>
Cc: linux-kernel@...r.kernel.org, marcos@...esouza.com, Marcos Paulo de
 Souza <mpdesouza@...e.com>
Subject: Re: [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks

On 2025-12-05, Marcos Paulo de Souza <mpdesouza@...e.com> wrote:
> These callbacks are necessary to synchronize ->write_thread callback
> against other operations using the same device.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@...e.com>
> ---
> I found this issue while creating a custom kernel module that implements
> the nbcon interfaces.
> ---
>  kernel/printk/nbcon.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 3fa403f9831f..02809c44d7ea 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con)
>  	if (WARN_ON(!con->write_thread))
>  		return false;
>  
> +	/* The device_lock() and device_unlock() callbacks are mandatory. */
> +	if (WARN_ON(!con->device_lock || !con->device_unlock))
> +		return false;
> +

The code itself is fine and this is an important contribution. But I
would prefer to combine it with the previous mandatory check. So it
looks more like this:

diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f..f096282b0625 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1760,9 +1758,12 @@ bool nbcon_alloc(struct console *con)
 	/* Synchronize the kthread start. */
 	lockdep_assert_console_list_lock_held();
 
-	/* The write_thread() callback is mandatory. */
-	if (WARN_ON(!con->write_thread))
+	/* Check for mandatory nbcon callbacks. */
+	if (WARN_ON(!con->write_thread ||
+		    !con->device_lock ||
+		    !con->device_unlock)) {
 		return false;
+	}
 
 	rcuwait_init(&con->rcuwait);
 	init_irq_work(&con->irq_work, nbcon_irq_work);

John Ogness

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ