Skip to contentSkip to conversation

atm/fore200e: Fix possible data race in fore200e_open()

PATCH Superseded Gui-Dong Han 3 participants 5 messages Jan 15, 2025 – Jan 22, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 atm/fore200e: Fix possible data race in fore200e_open()

Protect access to fore200e->available_cell_rate with rate_mtx lock to prevent potential data race.

The field fore200e.available_cell_rate is generally protected by the lock fore200e.rate_mtx when accessed. In all other read and write cases, this field is consistently protected by the lock, except for this case and during initialization.

This potential bug was detected by our experimental static analysis tool, which analyzes locking APIs and paired functions to identify data races and atomicity violations.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/atm/fore200e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/atm/fore200e.c +2 -0
index 4fea1149e003..f62e38571440 100644
@@ -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;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 7 lines · On Wed, 15 Jan 2025 13:10:06 +0000 Gui-Dong Han wrote:

Protect access to fore200e->available_cell_rate with rate_mtx lock to prevent potential data race.

The field fore200e.available_cell_rate is generally protected by the lock fore200e.rate_mtx when accessed. In all other read and write cases, this field is consistently protected by the lock, except for this case and during initialization.

That's not sufficient in terms of analysis.

You need to be able to articulate what can go wrong.

Signature · 1 line
pw-bot: reject
#2 lore raw
Quoted 12 lines · On Wed, 15 Jan 2025 13:10:06 +0000 Gui-Dong Han wrote:
Quoted 7 lines

Protect access to fore200e->available_cell_rate with rate_mtx lock to prevent potential data race.

The field fore200e.available_cell_rate is generally protected by the lock fore200e.rate_mtx when accessed. In all other read and write cases, this field is consistently protected by the lock, except for this case and during initialization.

That's not sufficient in terms of analysis.

You need to be able to articulate what can go wrong.

fore200e->available_cell_rate += vcc->qos.txtp.max_pcr; In this case, since the update depends on a prior read, a data race could lead to a wrong fore200e.available_cell_rate value.

Regards,
Han

reviewer
#3 lore raw
Quoted 9 lines · Gui-Dong Han
Quoted 9 lines · On Wed, 15 Jan 2025 13:10:06 +0000 Gui-Dong Han wrote:
Quoted 7 lines

Protect access to fore200e->available_cell_rate with rate_mtx lock to prevent potential data race.

The field fore200e.available_cell_rate is generally protected by the lock fore200e.rate_mtx when accessed. In all other read and write cases, this field is consistently protected by the lock, except for this case and during initialization.

Quoted 7 lines
Quoted 3 lines

That's not sufficient in terms of analysis.

You need to be able to articulate what can go wrong.

fore200e->available_cell_rate += vcc->qos.txtp.max_pcr; In this case, since the update depends on a prior read, a data race could lead to a wrong fore200e.available_cell_rate value.

Hi Gui-Dong Han,

I think it would be good to post a v2 of this patch with an explanation along the lines of the above included in the patch description.

#4 lore raw
Quoted 18 lines · Gui-Dong Han
Quoted 9 lines
Quoted 9 lines · On Wed, 15 Jan 2025 13:10:06 +0000 Gui-Dong Han wrote:
Quoted 7 lines

Protect access to fore200e->available_cell_rate with rate_mtx lock to prevent potential data race.

The field fore200e.available_cell_rate is generally protected by the lock fore200e.rate_mtx when accessed. In all other read and write cases, this field is consistently protected by the lock, except for this case and during initialization.

Quoted 7 lines
Quoted 3 lines

That's not sufficient in terms of analysis.

You need to be able to articulate what can go wrong.

fore200e->available_cell_rate += vcc->qos.txtp.max_pcr; In this case, since the update depends on a prior read, a data race could lead to a wrong fore200e.available_cell_rate value.

Quoted 5 lines

Hi Gui-Dong Han,

I think it would be good to post a v2 of this patch with an explanation along the lines of the above included in the patch description.

Hi Simon Horman,

Thank you for your feedback. I have submitted a v2 version of the patch with an added description of the data race hazard, as suggested.