All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usblp: fix race between disconnect() and read()
@ 2020-09-17 10:34 Oliver Neukum
  2020-09-17 11:43 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2020-09-17 10:34 UTC (permalink / raw)
  To: gregKH, linux-usb; +Cc: Oliver Neukum

read() needs to check whether the device has been
disconnected before it tries to talk to the device.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Reported-by: syzbot+be5b5f86a162a6c281e6@syzkaller.appspotmail.com
---
 drivers/usb/class/usblp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 084c48c5848f..67cbd42421be 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
 	if (rv < 0)
 		return rv;
 
+	if (!usblp->present) {
+		count = -ENODEV;
+		goto done;
+	}
+
 	if ((avail = usblp->rstatus) < 0) {
 		printk(KERN_ERR "usblp%d: error %d reading from printer\n",
 		    usblp->minor, (int)avail);
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usblp: fix race between disconnect() and read()
  2020-09-17 10:34 [PATCH] usblp: fix race between disconnect() and read() Oliver Neukum
@ 2020-09-17 11:43 ` Greg KH
  2020-09-17 12:03   ` Oliver Neukum
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2020-09-17 11:43 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-usb

On Thu, Sep 17, 2020 at 12:34:27PM +0200, Oliver Neukum wrote:
> read() needs to check whether the device has been
> disconnected before it tries to talk to the device.
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> Reported-by: syzbot+be5b5f86a162a6c281e6@syzkaller.appspotmail.com
> ---
>  drivers/usb/class/usblp.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
> index 084c48c5848f..67cbd42421be 100644
> --- a/drivers/usb/class/usblp.c
> +++ b/drivers/usb/class/usblp.c
> @@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
>  	if (rv < 0)
>  		return rv;
>  
> +	if (!usblp->present) {
> +		count = -ENODEV;
> +		goto done;
> +	}
> +

What prevents ->present from not being changed right after this test?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usblp: fix race between disconnect() and read()
  2020-09-17 11:43 ` Greg KH
@ 2020-09-17 12:03   ` Oliver Neukum
  2020-09-17 16:45     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2020-09-17 12:03 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb

Am Donnerstag, den 17.09.2020, 13:43 +0200 schrieb Greg KH:
> On Thu, Sep 17, 2020 at 12:34:27PM +0200, Oliver Neukum wrote:
> > read() needs to check whether the device has been
> > disconnected before it tries to talk to the device.
> > 
> > Signed-off-by: Oliver Neukum <oneukum@suse.com>
> > Reported-by: syzbot+be5b5f86a162a6c281e6@syzkaller.appspotmail.com
> > ---
> >  drivers/usb/class/usblp.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
> > index 084c48c5848f..67cbd42421be 100644
> > --- a/drivers/usb/class/usblp.c
> > +++ b/drivers/usb/class/usblp.c
> > @@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
> >  	if (rv < 0)
> >  		return rv;
> >  
> > +	if (!usblp->present) {
> > +		count = -ENODEV;
> > +		goto done;
> > +	}
> > +
> 
> What prevents ->present from not being changed right after this test?

Hi,

the mutex taken in

rv = usblp_rwait_and_lock(usblp, !!(file->f_flags & O_NONBLOCK));

right above it. Yes, this driver is a mess. But short of adding
a ton of comments or rewriting the whole thing I have no idea
what to do about that.

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usblp: fix race between disconnect() and read()
  2020-09-17 12:03   ` Oliver Neukum
@ 2020-09-17 16:45     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2020-09-17 16:45 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-usb

On Thu, Sep 17, 2020 at 02:03:11PM +0200, Oliver Neukum wrote:
> Am Donnerstag, den 17.09.2020, 13:43 +0200 schrieb Greg KH:
> > On Thu, Sep 17, 2020 at 12:34:27PM +0200, Oliver Neukum wrote:
> > > read() needs to check whether the device has been
> > > disconnected before it tries to talk to the device.
> > > 
> > > Signed-off-by: Oliver Neukum <oneukum@suse.com>
> > > Reported-by: syzbot+be5b5f86a162a6c281e6@syzkaller.appspotmail.com
> > > ---
> > >  drivers/usb/class/usblp.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > > 
> > > diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
> > > index 084c48c5848f..67cbd42421be 100644
> > > --- a/drivers/usb/class/usblp.c
> > > +++ b/drivers/usb/class/usblp.c
> > > @@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
> > >  	if (rv < 0)
> > >  		return rv;
> > >  
> > > +	if (!usblp->present) {
> > > +		count = -ENODEV;
> > > +		goto done;
> > > +	}
> > > +
> > 
> > What prevents ->present from not being changed right after this test?
> 
> Hi,
> 
> the mutex taken in
> 
> rv = usblp_rwait_and_lock(usblp, !!(file->f_flags & O_NONBLOCK));

Ah, missed that, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-17 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 10:34 [PATCH] usblp: fix race between disconnect() and read() Oliver Neukum
2020-09-17 11:43 ` Greg KH
2020-09-17 12:03   ` Oliver Neukum
2020-09-17 16:45     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.