netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3] atm/fore200e: Fix possible data race in fore200e_open()
@ 2025-11-20 12:06 Gui-Dong Han
  2025-11-25 11:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Gui-Dong Han @ 2025-11-20 12:06 UTC (permalink / raw)
  To: 3chas3, pabeni, horms, kuba
  Cc: linux-atm-general, netdev, linux-kernel, baijiaju1990,
	Gui-Dong Han, stable

Protect access to fore200e->available_cell_rate with rate_mtx lock in the
error handling path of fore200e_open() to prevent a data race.

The field fore200e->available_cell_rate is a shared resource used to track
available bandwidth. It is concurrently accessed by fore200e_open(),
fore200e_close(), and fore200e_change_qos().

In fore200e_open(), the lock rate_mtx is correctly held when subtracting
vcc->qos.txtp.max_pcr from available_cell_rate to reserve bandwidth.
However, if the subsequent call to fore200e_activate_vcin() fails, the
function restores the reserved bandwidth by adding back to
available_cell_rate without holding the lock.

This introduces a race condition because available_cell_rate is a global
device resource shared across all VCCs. If the error path in
fore200e_open() executes concurrently with operations like
fore200e_close() or fore200e_change_qos() on other VCCs, a
read-modify-write race occurs.

Specifically, the error path reads the rate without the lock. If another
CPU acquires the lock and modifies the rate (e.g., releasing bandwidth in
fore200e_close()) between this read and the subsequent write, the error
path will overwrite the concurrent update with a stale value. This results
in incorrect bandwidth accounting.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
---
v3:
* Expanded the commit message to describe the specific call paths causing
the race, as suggested by Jakub Kicinski and Paolo Abeni.
v2:
* Added a description of the data race hazard in fore200e_open(), as
suggested by Jakub Kicinski and Simon Horman.
---
 drivers/atm/fore200e.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index 4fea1149e003..f62e38571440 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -1374,7 +1374,9 @@ fore200e_open(struct atm_vcc *vcc)
 
 	vcc->dev_data = NULL;
 
+	mutex_lock(&fore200e->rate_mtx);
 	fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
+	mutex_unlock(&fore200e->rate_mtx);
 
 	kfree(fore200e_vcc);
 	return -EINVAL;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net v3] atm/fore200e: Fix possible data race in fore200e_open()
  2025-11-20 12:06 [PATCH net v3] atm/fore200e: Fix possible data race in fore200e_open() Gui-Dong Han
@ 2025-11-25 11:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-25 11:50 UTC (permalink / raw)
  To: Gui-Dong Han
  Cc: 3chas3, pabeni, horms, kuba, linux-atm-general, netdev,
	linux-kernel, baijiaju1990, stable

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 20 Nov 2025 20:06:57 +0800 you wrote:
> Protect access to fore200e->available_cell_rate with rate_mtx lock in the
> error handling path of fore200e_open() to prevent a data race.
> 
> The field fore200e->available_cell_rate is a shared resource used to track
> available bandwidth. It is concurrently accessed by fore200e_open(),
> fore200e_close(), and fore200e_change_qos().
> 
> [...]

Here is the summary with links:
  - [net,v3] atm/fore200e: Fix possible data race in fore200e_open()
    https://git.kernel.org/netdev/net/c/82fca3d8a4a3

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-25 11:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 12:06 [PATCH net v3] atm/fore200e: Fix possible data race in fore200e_open() Gui-Dong Han
2025-11-25 11:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).