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: <c96e95c2-aa59-4ef0-b211-c1cea71519ea@suse.com>
Date: Tue, 17 Sep 2024 10:33:21 +0200
From: Oliver Neukum <oneukum@...e.com>
To: Jeongjun Park <aha310510@...il.com>, Oliver Neukum <oneukum@...e.com>
Cc: Greg KH <gregkh@...uxfoundation.org>, colin.i.king@...il.com,
 linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] usb: use mutex_lock in iowarrior_read()

On 17.09.24 08:23, Jeongjun Park wrote:
> Oliver Neukum <oneukum@...e.com> wrote:

> Okay. But O_NONBLOCK flag check already exists, and I don't know
> if we need to branch separately to mutex_trylock just because O_NONBLOCK
> flag exists. I think mutex_lock_interruptible is enough.

It will still block.

> And the point of locking is too late. I think it would be more appropriate to
> read file->private_data and then lock it right away.

You are right. dev->present should be checked under the lock only.

> I think this patch is a more appropriate patch:
> 
> ---
>   drivers/usb/misc/iowarrior.c | 41 +++++++++++++++++++++++++++---------
>   1 file changed, 31 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
> index 6d28467ce352..6fb4ecebbc15 100644
> --- a/drivers/usb/misc/iowarrior.c
> +++ b/drivers/usb/misc/iowarrior.c
> @@ -277,28 +277,40 @@ static ssize_t iowarrior_read(struct file *file,
> char __user *buffer,
>      struct iowarrior *dev;
>      int read_idx;
>      int offset;
> +   int retval = 0;
> 
>      dev = file->private_data;
> 
> +   if (mutex_lock_interruptible(&dev->mutex)) {

This blocks. To quote the man page:

        O_NONBLOCK or O_NDELAY
               When  possible,  the file is opened in nonblocking mode.
		Neither the open() nor any subsequent I/O operations on the file descriptor which is
               returned will cause the calling process to wait.

          

[..]
> +unlock_exit:
> +   mutex_unlock(&dev->mutex);
> +exit:
> +   return retval;

The rest looks good to me.

	Regards
		Oliver


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ