mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
USB: ldusb: fix ring-buffer locking
commitd98ee2a19cupstream. The custom ring-buffer implementation was merged without any locking or explicit memory barriers, but a spinlock was later added by commit9d33efd9a7("USB: ldusb bugfix"). The lock did not cover the update of the tail index once the entry had been processed, something which could lead to memory corruption on weakly ordered architectures or due to compiler optimisations. Specifically, a completion handler running on another CPU might observe the incremented tail index and update the entry before ld_usb_read() is done with it. Fixes:2824bd250f("[PATCH] USB: add ldusb driver") Fixes:9d33efd9a7("USB: ldusb bugfix") Cc: stable <stable@vger.kernel.org> # 2.6.13 Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20191022143203.5260-2-johan@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
37b5f15e02
commit
cc9c0f0113
@@ -495,11 +495,11 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
|
||||
retval = -EFAULT;
|
||||
goto unlock_exit;
|
||||
}
|
||||
dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
|
||||
|
||||
retval = bytes_to_read;
|
||||
|
||||
spin_lock_irq(&dev->rbsl);
|
||||
dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
|
||||
|
||||
if (dev->buffer_overflow) {
|
||||
dev->buffer_overflow = 0;
|
||||
spin_unlock_irq(&dev->rbsl);
|
||||
|
||||
Reference in New Issue
Block a user