]> git.baikalelectronics.ru Git - kernel.git/commit
staging:iio:kfifo_buf: Fix potential buffer overflow in iio_read_first_n_kfifo
authorLars-Peter Clausen <lars@metafoo.de>
Mon, 12 Dec 2011 08:33:14 +0000 (09:33 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 13 Dec 2011 00:51:03 +0000 (16:51 -0800)
commit17f75b31c66d2e86723197f6b041bb40ee4303d3
treee7919ac09cbdb4d27ee04ae1e16b9c4f02fb6d99
parenta5bd2dc2b34177818df7761e5dd355ae4f6ee7e0
staging:iio:kfifo_buf: Fix potential buffer overflow in iio_read_first_n_kfifo

n is the number of bytes to read, not the number of samples. So if there is
enough data available we will write to the userspace buffer beyond its bounds.
Fix this by copying n bytes maximum. Also round n down to the next multiple of
the sample size, so we will only read complete samples. If the buffer is too
small to hold at least one sample return -EINVAL.

Also update the documentation of read_first_n to reflect the fact that 'n' is
supposed to be in bytes and not in samples.

Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/buffer.h
drivers/staging/iio/kfifo_buf.c