linux-stable/drivers/media
Gui-Dong Han fec5181960 media: xc4000: Fix atomicity violation in xc4000_get_frequency
[ Upstream commit 36d503ad54 ]

In xc4000_get_frequency():
	*freq = priv->freq_hz + priv->freq_offset;
The code accesses priv->freq_hz and priv->freq_offset without holding any
lock.

In xc4000_set_params():
	// Code that updates priv->freq_hz and priv->freq_offset
	...

xc4000_get_frequency() and xc4000_set_params() may execute concurrently,
risking inconsistent reads of priv->freq_hz and priv->freq_offset. Since
these related data may update during reading, it can result in incorrect
frequency calculation, leading to atomicity violations.

This possible bug is found by an experimental static analysis tool
developed by our team, BassCheck[1]. This tool analyzes the locking APIs
to extract function pairs that can be concurrently executed, and then
analyzes the instructions in the paired functions to identify possible
concurrency bugs including data races and atomicity violations. The above
possible bug is reported when our tool analyzes the source code of
Linux 6.2.

To address this issue, it is proposed to add a mutex lock pair in
xc4000_get_frequency() to ensure atomicity. With this patch applied, our
tool no longer reports the possible bug, with the kernel configuration
allyesconfig for x86_64. Due to the lack of associated hardware, we cannot
test the patch in runtime testing, and just verify it according to the
code logic.

[1] https://sites.google.com/view/basscheck/

Fixes: 4c07e32884 ("[media] xc4000: Fix get_frequency()")
Cc: stable@vger.kernel.org
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Gui-Dong Han <2045gemini@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-10 16:18:34 +02:00
..
cec media: cec: meson: always include meson sub-directory in Makefile 2023-11-28 16:56:21 +00:00
common media: v4l2-tpg: fix some memleaks in tpg_alloc 2024-03-26 18:21:26 -04:00
dvb-core media: edia: dvbdev: fix a use-after-free 2024-03-26 18:21:26 -04:00
dvb-frontends media: dvb-frontends: avoid stack overflow warnings with clang 2024-03-26 18:21:30 -04:00
firewire
i2c media: tc358743: register v4l2 async device only after successful setup 2024-03-26 18:21:25 -04:00
mc
mmc
pci media: ttpci: fix two memleaks in budget_av_attach 2024-03-26 18:21:30 -04:00
platform media: mediatek: vcodec: avoid -Wcast-function-type-strict warning 2024-03-26 18:21:30 -04:00
radio media: radio-shark: Add endpoint checks 2023-05-30 13:55:31 +01:00
rc media: rc: bpf attach/detach requires write permission 2024-02-23 08:55:07 +01:00
spi
test-drivers media: vivid: avoid integer overflow 2023-11-28 16:56:20 +00:00
tuners media: xc4000: Fix atomicity violation in xc4000_get_frequency 2024-04-10 16:18:34 +02:00
usb media: go7007: fix a memleak in go7007_load_encoder 2024-03-26 18:21:30 -04:00
v4l2-core media: v4l2-mem2mem: fix a memleak in v4l2_m2m_register_entity 2024-03-26 18:21:26 -04:00
Kconfig media: correct MEDIA_TEST_SUPPORT help text 2022-01-27 11:05:20 +01:00
Makefile