Skip to content

Commit a90a52c

Browse files
bwh-ctgregkh
authored andcommitted
USB: yurex: Check for truncation in yurex_read()
[ Upstream commit 14427b8 ] snprintf() always returns the full length of the string it could have printed, even if it was truncated because the buffer was too small. So in case the counter value is truncated, we will over-read from in_buffer and over-write to the caller's buffer. I don't think it's actually possible for this to happen, but in case truncation occurs, WARN and return -EIO. Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2c42331 commit a90a52c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/usb/misc/yurex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
417417
spin_unlock_irqrestore(&dev->lock, flags);
418418
mutex_unlock(&dev->io_mutex);
419419

420+
if (WARN_ON_ONCE(len >= sizeof(in_buffer)))
421+
return -EIO;
422+
420423
return simple_read_from_buffer(buffer, count, ppos, in_buffer, len);
421424
}
422425

0 commit comments

Comments
 (0)