From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73A9113DDDD; Thu, 11 Apr 2024 09:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712829519; cv=none; b=gJ6ar7fGK8tr6KZ4uOTPsY3cRU7R3fOon3hgOH2c8ZkYPBo/IdUuGJZzSkijWJV81M+MaMjRKRC+1RJ6Uy2lv6wI4uzsOPFTENOIiNDz1WQ/z29AHoij3rH2QfWwl9HFmEfNltiyniaqkpfF3zy6GtGIAA+AgmUa+7+bwsiz/D4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712829519; c=relaxed/simple; bh=Kg/rKohqFpM2L5N4VQQ7BQzjtMgRauZ5Y7fL31Nq37Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UPstk4yughqJNrLRG5z1HFMiwTokHU64crtwhv7wSeUnr1DjZfFjhaJqwE1ISLJRXxcRRDqPRYAp0Q/g2dtpS31R9uPkVTQK9ikgNpJp1lVQo0nX6b/gmKbQSOwDtf0JCDk+iqEUp2ELPDEhPNLZxYzbdL9B4WCGY5OXsOCXaqY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sRWaui0A; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sRWaui0A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E781FC433F1; Thu, 11 Apr 2024 09:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712829519; bh=Kg/rKohqFpM2L5N4VQQ7BQzjtMgRauZ5Y7fL31Nq37Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sRWaui0A9VoBykwDPKtlW4LO2iXFVJPtmUc6l0EXssdMs+j1LylHTBTdOWv5oIcBu UF5KePqVyFV9Q2rsYF+n/zZfZsSVEV37z91J5D2qcSTEi+vpZXJFE8cHdBy4viLpBU YdKmTUSoW+RfhBRjezL9be8C0nn/EMGQ7P7+YZV4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, BassCheck , Gui-Dong Han <2045gemini@gmail.com>, Hans Verkuil , Sasha Levin Subject: [PATCH 4.19 015/175] media: xc4000: Fix atomicity violation in xc4000_get_frequency Date: Thu, 11 Apr 2024 11:53:58 +0200 Message-ID: <20240411095420.004682047@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095419.532012976@linuxfoundation.org> References: <20240411095419.532012976@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gui-Dong Han <2045gemini@gmail.com> [ Upstream commit 36d503ad547d1c75758a6fcdbec2806f1b6aeb41 ] 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: 4c07e32884ab ("[media] xc4000: Fix get_frequency()") Cc: stable@vger.kernel.org Reported-by: BassCheck Signed-off-by: Gui-Dong Han <2045gemini@gmail.com> Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/tuners/xc4000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c index 0ef8f054a7950..6017602aead62 100644 --- a/drivers/media/tuners/xc4000.c +++ b/drivers/media/tuners/xc4000.c @@ -1527,10 +1527,10 @@ static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq) { struct xc4000_priv *priv = fe->tuner_priv; + mutex_lock(&priv->lock); *freq = priv->freq_hz + priv->freq_offset; if (debug) { - mutex_lock(&priv->lock); if ((priv->cur_fw.type & (BASE | FM | DTV6 | DTV7 | DTV78 | DTV8)) == BASE) { u16 snr = 0; @@ -1541,8 +1541,8 @@ static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq) return 0; } } - mutex_unlock(&priv->lock); } + mutex_unlock(&priv->lock); dprintk(1, "%s()\n", __func__); -- 2.43.0