Skip to content

Commit ce6e52c

Browse files
2045geminigregkh
authored andcommitted
media: xc4000: Fix atomicity violation in xc4000_get_frequency
[ Upstream commit 36d503a ] 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: 4c07e32 ("[media] xc4000: Fix get_frequency()") Cc: [email protected] Reported-by: BassCheck <[email protected]> Signed-off-by: Gui-Dong Han <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 7d271b7 commit ce6e52c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/media/tuners/xc4000.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,10 +1517,10 @@ static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
15171517
{
15181518
struct xc4000_priv *priv = fe->tuner_priv;
15191519

1520+
mutex_lock(&priv->lock);
15201521
*freq = priv->freq_hz + priv->freq_offset;
15211522

15221523
if (debug) {
1523-
mutex_lock(&priv->lock);
15241524
if ((priv->cur_fw.type
15251525
& (BASE | FM | DTV6 | DTV7 | DTV78 | DTV8)) == BASE) {
15261526
u16 snr = 0;
@@ -1531,8 +1531,8 @@ static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
15311531
return 0;
15321532
}
15331533
}
1534-
mutex_unlock(&priv->lock);
15351534
}
1535+
mutex_unlock(&priv->lock);
15361536

15371537
dprintk(1, "%s()\n", __func__);
15381538

0 commit comments

Comments
 (0)