Skip to content

Commit 9390762

Browse files
oneukumgregkh
authored andcommitted
USB: misc: yurex: fix race between read and write
The write code path touches the bbu member in a non atomic manner without taking the spinlock. Fix it. The bug is as old as the driver. Signed-off-by: Oliver Neukum <[email protected]> CC: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 49cd2f4 commit 9390762

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/usb/misc/yurex.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
404404
struct usb_yurex *dev;
405405
int len = 0;
406406
char in_buffer[MAX_S64_STRLEN];
407-
unsigned long flags;
408407

409408
dev = file->private_data;
410409

@@ -419,9 +418,9 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
419418
return -EIO;
420419
}
421420

422-
spin_lock_irqsave(&dev->lock, flags);
421+
spin_lock_irq(&dev->lock);
423422
scnprintf(in_buffer, MAX_S64_STRLEN, "%lld\n", dev->bbu);
424-
spin_unlock_irqrestore(&dev->lock, flags);
423+
spin_unlock_irq(&dev->lock);
425424
mutex_unlock(&dev->io_mutex);
426425

427426
return simple_read_from_buffer(buffer, count, ppos, in_buffer, len);
@@ -511,8 +510,11 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
511510
__func__, retval);
512511
goto error;
513512
}
514-
if (set && timeout)
513+
if (set && timeout) {
514+
spin_lock_irq(&dev->lock);
515515
dev->bbu = c2;
516+
spin_unlock_irq(&dev->lock);
517+
}
516518
return timeout ? count : -EIO;
517519

518520
error:

0 commit comments

Comments
 (0)