usblp: fix race between disconnect() and read()
Subsystems (2)
PATCH 1/1 usblp: fix race between disconnect() and read()
read() needs to check whether the device has been disconnected before it tries to talk to the device.
--- drivers/usb/class/usblp.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/class/usblp.c +5 -0
@@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, loif (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);
Signature · 1 line
2.16.4
Greg KH
maintainerQuoted 14 lines · 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 <[email protected]>Reported-by [email protected]--- drivers/usb/class/usblp.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/class/usblp.c +0
-0
drivers/usb/class/usblp.c static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo · line 834
Quoted 8 lines
drivers/usb/class/usblp.c +5
-0@@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, loif (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
Am Donnerstag, den 17.09.2020, 13:43 +0200 schrieb Greg KH:
Quoted 18 lines · Oliver Neukum
Quoted 17 lines
read()needs to check whether the device has been disconnected before it tries to talk to the device.Signed-off-by Oliver Neukum <[email protected]>Reported-by [email protected]--- drivers/usb/class/usblp.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/class/usblp.c +0
-0@@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, loif (rv <0 )return rv;
Quoted 7 lines
drivers/usb/class/usblp.c static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo · line 834
Quoted 5 lines
drivers/usb/class/usblp.c +5
-0+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
Greg KH
maintainerQuoted 27 lines · Oliver Neukum
Am Donnerstag, den 17.09.2020, 13:43 +0200 schrieb Greg KH:
Quoted 18 lines · Oliver Neukum
Quoted 17 lines
read()needs to check whether the device has been disconnected before it tries to talk to the device.Signed-off-by Oliver Neukum <[email protected]>Reported-by [email protected]--- drivers/usb/class/usblp.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/class/usblp.c +0
-0@@ -827,6 +827,11 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, loif (rv <0 )return rv;Quoted 7 lines
drivers/usb/class/usblp.c static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo · line 834
Quoted 5 lines
drivers/usb/class/usblp.c +5
-0+if (!usblp->present) { + count = -ENODEV ; + goto done; + } +What prevents ->present from not being changed right after this test?
Quoted 5 lines
Hi,
the mutex taken in
rv =
usblp_rwait_and_lock(usblp, !!(file->f_flags & O_NONBLOCK));
Ah, missed that, thanks.
greg k-h