kernel_samsung_a53x/tools
Reinette Chatre 443af7c29d selftests/resctrl: Protect against array overrun during iMC config parsing
[ Upstream commit 48ed4e799e8fbebae838dca404a8527763d41191 ]

The MBM and MBA tests need to discover the event and umask with which to
configure the performance event used to measure read memory bandwidth.
This is done by parsing the
/sys/bus/event_source/devices/uncore_imc_<imc instance>/events/cas_count_read
file for each iMC instance that contains the formatted
output: "event=<event>,umask=<umask>"

Parsing of cas_count_read contents is done by initializing an array of
MAX_TOKENS elements with tokens (deliminated by "=,") from this file.
Remove the unnecessary append of a delimiter to the string needing to be
parsed. Per the strtok() man page: "delimiter bytes at the start or end of
the string are ignored". This has no impact on the token placement within
the array.

After initialization, the actual event and umask is determined by
parsing the tokens directly following the "event" and "umask" tokens
respectively.

Iterating through the array up to index "i < MAX_TOKENS" but then
accessing index "i + 1" risks array overrun during the final iteration.
Avoid array overrun by ensuring that the index used within for
loop will always be valid.

Fixes: 1d3f08687d76 ("selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system")
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-17 13:24:03 +01:00
..
accounting
arch x86/insn: Fix PUSH instruction in x86 instruction decoder opcode map 2024-11-19 12:26:59 +01:00
bootconfig
bpf bpf: Fix potential integer overflow in resolve_btfids 2024-11-19 12:27:10 +01:00
build
cgroup
crypto
debugging
edid
firewire
firmware
gpio
hv
iio Revert "tools/iio: Add memory allocation failure check for trigger_name" 2024-11-24 00:22:58 +01:00
include tools: move alignment-related macros to new <linux/align.h> 2024-11-23 23:20:50 +01:00
io_uring
kvm/kvm_stat
laptop
leds
lib Revert "libbpf: Add NULL checks to bpf_object__{prev_map,next_map}" 2024-11-24 00:23:40 +01:00
memory-model tools/memory-model: Fix bug in lock.cat 2024-11-23 23:20:13 +01:00
objtool exit: Rename module_put_and_exit to module_put_and_kthread_exit 2024-11-19 12:27:50 +01:00
pci
pcmcia
perf perf session: Add missing evlist__delete when deleting a session 2024-11-30 02:33:26 +01:00
power tools/power turbostat: Fix Bzy_MHz documentation typo 2024-11-19 11:32:44 +01:00
scripts
spi
testing selftests/resctrl: Protect against array overrun during iMC config parsing 2024-12-17 13:24:03 +01:00
thermal/tmon
time
usb usbip: tools: Fix detach_port() invalid port error path 2024-11-23 23:22:04 +01:00
virtio
vm
wmi
Makefile