linux-stable/tools
Matti Vaittinen 4e208294de tools: iio: iio_generic_buffer: Fix read size
[ Upstream commit 7c919b619b ]

When noevents is true and small buffer is used the allocated memory for
holding the data may be smaller than the hard-coded 64 bytes. This can
cause the iio_generic_buffer to crash.

Following was recorded on beagle bone black with v6.0 kernel and the
digit fix patch:
https://lore.kernel.org/all/Y0f+tKCz+ZAIoroQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi/
using valgrind;

==339== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==339== Command: /iio_generic_buffer -n kx022-accel -T0 -e -l 10 -a -w 2000000
==339== Parent PID: 307
==339==
==339== Syscall param read(buf) points to unaddressable byte(s)
==339==    at 0x496BFA4: read (read.c:26)
==339==    by 0x11699: main (iio_generic_buffer.c:724)
==339==  Address 0x4ab3518 is 0 bytes after a block of size 160 alloc'd
==339==    at 0x4864B70: malloc (vg_replace_malloc.c:381)
==339==    by 0x115BB: main (iio_generic_buffer.c:677)

Fix this by always using the same size for reading as was used for
data storage allocation.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/Y0kMh0t5qUXJw3nQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-02 17:41:10 +01:00
..
accounting
arch x86/cpu: Restore AMD's DE_CFG MSR after resume 2022-11-16 09:58:31 +01:00
bootconfig
bpf bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE 2022-11-16 09:58:15 +01:00
build tools build: Switch to new openssl API for test-libcrypto 2022-08-25 11:40:14 +02:00
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio tools: iio: iio_generic_buffer: Fix read size 2022-12-02 17:41:10 +01:00
include tools/nolibc/string: Fix memcmp() implementation 2022-11-10 18:15:38 +01:00
io_uring
kvm/kvm_stat tools/kvm_stat: fix display of error when multiple processes are found 2022-08-11 13:07:51 +02:00
laptop
leds
lib selftests/xsk: Avoid use-after-free on ctx 2022-10-26 12:34:41 +02:00
memory-model
objtool objtool: Preserve special st_shndx indexes in elf_update_symbol 2022-10-26 12:34:37 +02:00
pci
pcmcia
perf perf tools: Add the include/perf/ directory to .gitignore 2022-11-16 09:58:20 +01:00
power tools/power turbostat: fix ICX DRAM power numbers 2022-06-09 10:22:32 +02:00
rcu
scripts
spi
testing selftests: mptcp: fix mibit vs mbit mix up 2022-12-02 17:41:03 +01:00
thermal/tmon tools/thermal: Fix possible path truncations 2022-08-17 14:24:15 +02:00
time
tracing tools/latency-collector: Use correct size when writing queue_full_warning 2021-11-18 19:16:19 +01:00
usb
virtio tools/virtio: compile with -pthread 2022-05-25 09:57:25 +02:00
vm tools/vm/slabinfo: use alphabetic order when two values are equal 2022-08-25 11:40:13 +02:00
wmi
Makefile