[PATCH] atm/fore200e: Consolidate available cell rate update to prevent race condition
From: Gui-Dong Han
Date: Mon Jun 10 2024 - 23:54:42 EST
In fore200e_change_qos, there is a race condition due to two consecutive
updates to the 'available_cell_rate' variable. If a read operation
occurs between these updates, an intermediate value might be read,
leading to potential bugs.
To fix this issue, 'available_cell_rate' should be adjusted in a single
operation, ensuring consistency and preventing any intermediate states
from being read.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Gui-Dong Han <hanguidong02@xxxxxxxxxxx>
---
drivers/atm/fore200e.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index cb00f8244e41..d54e044d7542 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -1906,8 +1906,7 @@ fore200e_change_qos(struct atm_vcc* vcc,struct atm_qos* qos, int flags)
return -EAGAIN;
}
- fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
- fore200e->available_cell_rate -= qos->txtp.max_pcr;
+ fore200e->available_cell_rate += vcc->qos.txtp.max_pcr - qos->txtp.max_pcr;
mutex_unlock(&fore200e->rate_mtx);
--
2.34.1