Skip to content

Commit f1c0a2a

Browse files
Pete ZaitcevGreg Kroah-Hartman
authored andcommitted
USB: usbmon: fix read(2)
There's a bug in the usbmon binary reader: When using read() to fetch the packets and a packet's data is partially read, the next read call will once again return up to len_cap bytes of data. The b_read counter is not regarded when determining the remaining chunk size. So, when dumping USB data with "cat /dev/usbmon0 > usbmon.trace" while reading from a USB storage device and analyzing the dump file afterwards it will get out of sync after a couple of packets. Signed-off-by: Ingo van Lil <[email protected]> Signed-off-by: Pete Zaitcev <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff34950 commit f1c0a2a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/usb/mon/mon_bin.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,10 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
687687
}
688688

689689
if (rp->b_read >= sizeof(struct mon_bin_hdr)) {
690-
step_len = min(nbytes, (size_t)ep->len_cap);
690+
step_len = ep->len_cap;
691+
step_len -= rp->b_read - sizeof(struct mon_bin_hdr);
692+
if (step_len > nbytes)
693+
step_len = nbytes;
691694
offset = rp->b_out + PKT_SIZE;
692695
offset += rp->b_read - sizeof(struct mon_bin_hdr);
693696
if (offset >= rp->b_size)

0 commit comments

Comments
 (0)