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: <6068387e-7064-0c2b-700a-3817bea1045b@linux.intel.com>
Date: Mon, 2 Jun 2025 13:31:49 +0300 (EEST)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: Max Staudt <max@...as.org>
cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
    Jiri Slaby <jirislaby@...nel.org>, Johan Hovold <johan@...nel.org>, 
    linux-serial <linux-serial@...r.kernel.org>, 
    LKML <linux-kernel@...r.kernel.org>, stable@...r.kernel.org
Subject: Re: [PATCH v2 2/2] tty: Fix race against tty_open() in
 tty_register_device_attr()

On Wed, 28 May 2025, Max Staudt wrote:

> Since the chardev is now created before the class device is registered,
> an attempt to tty_[k]open() the chardev between these two steps will
> lead to tty->dev being assigned NULL by alloc_tty_struct().
> 
> alloc_tty_struct() is called via tty_init_dev() when the tty is firstly
> opened, and is entered with tty_mutex held, so let's lock the critical
> section in tty_register_device_attr() with the same global mutex.
> This guarantees that tty->dev can be assigned a sane value.
> 
> Fixes: 6a7e6f78c235 ("tty: close race between device register and open")
> Signed-off-by: Max Staudt <max@...as.org>
> Cc: <stable@...r.kernel.org>
> ---
>  drivers/tty/tty_io.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index e922b84524d2..94768509e2d2 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -3258,6 +3258,8 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
>  	else
>  		tty_line_name(driver, index, name);
>  
> +	mutex_lock(&tty_mutex);

Use guard() so you don't need to change the returns and rollback path.

> +
>  	if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
>  		/*
>  		 * Free any saved termios data so that the termios state is
> @@ -3271,7 +3273,7 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
>  
>  		retval = tty_cdev_add(driver, devt, index, 1);
>  		if (retval)
> -			return ERR_PTR(retval);
> +			goto err_unlock;
>  
>  		cdev_added = true;
>  	}
> @@ -3294,6 +3296,8 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
>  	if (retval)
>  		goto err_put;
>  
> +	mutex_unlock(&tty_mutex);
> +
>  	return dev;
>  
>  err_put:
> @@ -3309,6 +3313,9 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
>  		driver->cdevs[index] = NULL;
>  	}
>  
> +err_unlock:
> +	mutex_unlock(&tty_mutex);
> +
>  	return ERR_PTR(retval);
>  }
>  EXPORT_SYMBOL_GPL(tty_register_device_attr);
> 

-- 
 i.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ