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]
Date: Mon, 06 May 2024 12:33:28 +0206
From: John Ogness <john.ogness@...utronix.de>
To: Petr Mladek <pmladek@...e.com>
Cc: Sergey Senozhatsky <senozhatsky@...omium.org>, Steven Rostedt
 <rostedt@...dmis.org>, Thomas Gleixner <tglx@...utronix.de>,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH printk v5 07/30] printk: nbcon: Use driver
 synchronization while (un)registering

On 2024-05-02, John Ogness <john.ogness@...utronix.de> wrote:
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index e6b91401895f..15d19d8461ed 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3537,6 +3538,19 @@ void register_console(struct console *newcon)
>  		newcon->seq = init_seq;
>  	}
>  
> +	/*
> +	 * If another context is actively using the hardware of this new
> +	 * console, it will not be aware of the nbcon synchronization. This
> +	 * is a risk that two contexts could access the hardware
> +	 * simultaneously if this new console is used for atomic printing
> +	 * and the other context is still using the hardware.
> +	 *
> +	 * Use the driver synchronization to ensure that the hardware is not
> +	 * in use while this new console transitions to being registered.
> +	 */
> +	if ((newcon->flags & CON_NBCON) && newcon->write_atomic)
> +		newcon->device_lock(newcon, &flags);
> +
>  	/*
>  	 * Put this console in the list - keep the
>  	 * preferred driver at the head of the list.
> @@ -3561,6 +3575,10 @@ void register_console(struct console *newcon)
>  	 * register_console() completes.
>  	 */
>  
> +	/* This new console is now registered. */
> +	if ((newcon->flags & CON_NBCON) && newcon->write_atomic)
> +		newcon->device_unlock(newcon, flags);
> +

Rather than writing the conditions twice, I will add a local variable
and check that instead.

bool use_device_lock = (newcon->flags & CON_NBCON) && newcon->write_atomic;

..

if (use_device_lock)
	newcon->device_lock(newcon, &flags);

..

if (use_device_lock)
	newcon->device_unlock(newcon, flags);

> @@ -3607,8 +3626,18 @@ static int unregister_console_locked(struct console *console)
>  	if (!console_is_registered_locked(console))
>  		return -ENODEV;
>  
> +	/*
> +	 * Use the driver synchronization to ensure that the hardware is not
> +	 * in use while this console transitions to being unregistered.
> +	 */
> +	if ((console->flags & CON_NBCON) && console->write_atomic)
> +		console->device_lock(console, &flags);
> +
>  	hlist_del_init_rcu(&console->node);
>  
> +	if ((console->flags & CON_NBCON) && console->write_atomic)
> +		console->device_unlock(console, flags);
> +

Ditto for unregister_console_locked().

John

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ