Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 0cffa59

Browse files
oneukumgregkh
authored andcommitted
Revert "usb: yurex: Replace snprintf() with the safer scnprintf() variant"
commit 71c717c upstream. This reverts commit 86b20af. This patch leads to passing 0 to simple_read_from_buffer() as a fifth argument, turning the read method into a nop. The change is fundamentally flawed, as it breaks the driver. Signed-off-by: Oliver Neukum <oneukum@suse.com> Cc: stable <stable@kernel.org> Link: https://lore.kernel.org/r/20241007094004.242122-1-oneukum@suse.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 38b569d commit 0cffa59

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/usb/misc/yurex.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#define YUREX_BUF_SIZE 8
3535
#define YUREX_WRITE_TIMEOUT (HZ*2)
3636

37-
#define MAX_S64_STRLEN 20 /* {-}922337203685477580{7,8} */
38-
3937
/* table of devices that work with this driver */
4038
static struct usb_device_id yurex_table[] = {
4139
{ USB_DEVICE(YUREX_VENDOR_ID, YUREX_PRODUCT_ID) },
@@ -403,7 +401,8 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
403401
{
404402
struct usb_yurex *dev;
405403
int len = 0;
406-
char in_buffer[MAX_S64_STRLEN];
404+
char in_buffer[20];
405+
unsigned long flags;
407406

408407
dev = file->private_data;
409408

@@ -413,16 +412,14 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
413412
return -ENODEV;
414413
}
415414

416-
if (WARN_ON_ONCE(dev->bbu > S64_MAX || dev->bbu < S64_MIN)) {
417-
mutex_unlock(&dev->io_mutex);
418-
return -EIO;
419-
}
420-
421-
spin_lock_irq(&dev->lock);
422-
scnprintf(in_buffer, MAX_S64_STRLEN, "%lld\n", dev->bbu);
423-
spin_unlock_irq(&dev->lock);
415+
spin_lock_irqsave(&dev->lock, flags);
416+
len = snprintf(in_buffer, 20, "%lld\n", dev->bbu);
417+
spin_unlock_irqrestore(&dev->lock, flags);
424418
mutex_unlock(&dev->io_mutex);
425419

420+
if (WARN_ON_ONCE(len >= sizeof(in_buffer)))
421+
return -EIO;
422+
426423
return simple_read_from_buffer(buffer, count, ppos, in_buffer, len);
427424
}
428425

0 commit comments

Comments
 (0)