Skip to content

Commit

Permalink
USB: usbtmc: inhibit corruption
Browse files Browse the repository at this point in the history
Limit data copied to userspace to amount requested.  Prevents a faulty
instrument from overwriting user memory.

Signed-off-by: Steve Holland <sdh4@iastate.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Steve Holland authored and Greg Kroah-Hartman committed Sep 23, 2009
1 parent c2cd26e commit 92d07e4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/usb/class/usbtmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
n_characters = this_part;
}

/* Bound amount of data received by amount of data requested */
if (n_characters > this_part)
n_characters = this_part;

/* Copy buffer to user space */
if (copy_to_user(buf + done, &buffer[12], n_characters)) {
/* There must have been an addressing problem */
Expand Down

0 comments on commit 92d07e4

Please sign in to comment.